Skip to content

Commit

Permalink
HSEARCH-3902 Close indexes instead of deleting them to simulate failu…
Browse files Browse the repository at this point in the history
…res on Elasticsearch indexes
  • Loading branch information
yrodiere committed May 13, 2020
1 parent 98f3146 commit 377705c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Expand Up @@ -25,13 +25,7 @@ public void close() throws IOException {

@Override
public void ensureIndexOperationsFail(String indexName) {
client.index( indexName ).delete();
/*
* Automatic index creation might get in the way and make operation succeed
* even though the index doesn't exist, so we disable it.
* We never rely on automatic index creation,
* so leaving this setting in place afterwards is not a problem.
*/
client.clusterSettings( "action.auto_create_index" ).put( "false" );
// Close the index so that every operation will fail
client.index( indexName ).close();
}
}
Expand Up @@ -125,6 +125,11 @@ public IndexClient delete() {
return this;
}

public IndexClient close() {
TestElasticsearchClient.this.closeIndex( primaryIndexName );
return this;
}

public IndexClient ensureDoesNotExist() {
TestElasticsearchClient.this.ensureIndexDoesNotExist( primaryIndexName );
return this;
Expand Down Expand Up @@ -394,6 +399,21 @@ private void deleteIndex(URLEncodedString indexName) {
tryDeleteESIndex( indexName );
}

private void closeIndex(URLEncodedString indexName) {
try {
performRequest( ElasticsearchRequest.post()
.pathComponent( indexName )
.pathComponent( Paths._CLOSE )
.build() );
}
catch (RuntimeException e) {
throw new AssertionFailure(
String.format( Locale.ROOT, "Error while trying to close index '%s' in the test client", indexName ),
e
);
}
}

private void createTemplate(String templateName, String templateString, int templateOrder, JsonObject settings) {
JsonObject source = new JsonObject();
dialect.setTemplatePattern( source, templateString );
Expand Down

0 comments on commit 377705c

Please sign in to comment.