Skip to content

Commit

Permalink
Rework es:migrate to allow dump/restore using files (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrebouthinon authored Jan 11, 2023
1 parent 9c22eff commit a18690a
Show file tree
Hide file tree
Showing 11 changed files with 3,259 additions and 1,067 deletions.
26 changes: 26 additions & 0 deletions features/Elasticsearch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,29 @@ Feature: Elasticsearch commands
When I run the command "es:snapshot:list" with:
| arg | backup | |
Then I should match stdout with "test-snapshot"

Scenario: Dump and restore ES data to a dump folder using the pattern option
Given an index "nyc-open-data"
Given a collection "nyc-open-data":"yellow-taxi"
Then I create the following document:
| _id | "chuon-chuon-kim" |
| body | { "city": "hcmc", "district": 1 } |
Then I create the following document:
| _id | "the-hive-vn" |
| body | { "city": "hcmc", "district": 2 } |
Then I create the following document:
| _id | "the-hive-th" |
| body | { "city": "changmai", "district": 7 } |
Then I count 3 documents
Then I run the command "es:migrate" with:
| flag | --src | http://localhost:9200 |
| flag | --dest | ./kourou-dump |
Then I should have 3 lines in file "./kourou-dump/&nyc-open-data.yellow-taxi.json"
Then I run the command "es:migrate" with:
| flag | --src | ./kourou-dump |
| flag | --dest | http://localhost:9200 |
| flag | --reset | |
| flag | --no-interactive | |
Given an existing collection "nyc-open-data":"yellow-taxi"
Then I refresh the collection
And I count 3 documents
30 changes: 30 additions & 0 deletions features/step_definitions/cli-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,33 @@ Then(
}
}
);

Then("I delete index {string} using the Elasticsearch API", async function (index) {
await this.esClient.indices.delete({ index });
});

Then("I restart and wait for Kuzzle", async function () {
const { exec } = require('child_process');

exec('docker restart kuzzle', (error) => {
if (error) {
console.error(`Error: ${error}`);
return;
}
});

// eslint-disable-next-line no-constant-condition
while (true) {
try {
await this.sdk.server.now();
break;
} catch (error) {
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}
});

Then("I should have {int} lines in file {string}", function (count, filename) {
const lines = fs.readFileSync(filename, "utf8").split("\n");
should(lines.filter((line) => line !== "").length).be.eql(count);
});
3 changes: 2 additions & 1 deletion features/step_definitions/common/documents-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ Given("I create the following document:", async function (dataTable) {
index,
collection,
document.body,
document._id
document._id,
{ refresh: "wait_for" }
);

this.props.documentId = this.props.result._id;
Expand Down
6 changes: 6 additions & 0 deletions features/support/world.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { Kuzzle, WebSocket, Http } = require("kuzzle-sdk"),
{ Client } = require("@elastic/elasticsearch"),
{ setWorldConstructor } = require("cucumber");

require("./assertions");
Expand All @@ -16,6 +17,11 @@ class KuzzleWorld {
this.props = {};

this._sdk = this._getSdk();
this._esClient = new Client({ node: process.env.ELASTICSEARCH_URL || "http://localhost:9200" });
}

get esClient() {
return this._esClient;
}

get sdk() {
Expand Down
Loading

0 comments on commit a18690a

Please sign in to comment.