Skip to content

Commit

Permalink
HSEARCH-2456 Support ensuring that an index doesn't exist in TestElas…
Browse files Browse the repository at this point in the history
…ticsearchClient
  • Loading branch information
yrodiere authored and Sanne committed Dec 19, 2016
1 parent 11582f4 commit 06ceb5b
Showing 1 changed file with 15 additions and 0 deletions.
Expand Up @@ -67,6 +67,10 @@ public void deleteAndCreateIndex(Class<?> rootClass) throws IOException {
deleteAndCreateIndex( ElasticsearchIndexNameNormalizer.getElasticsearchIndexName( rootClass.getName() ) );
}

public void ensureIndexDoesNotExist(Class<?> rootClass) throws IOException {
ensureIndexDoesNotExist( ElasticsearchIndexNameNormalizer.getElasticsearchIndexName( rootClass.getName() ) );
}

public void registerForCleanup(Class<?> rootClass) {
createdIndicesNames.add( ElasticsearchIndexNameNormalizer.getElasticsearchIndexName( rootClass.getName() ) );
}
Expand Down Expand Up @@ -120,6 +124,17 @@ public void createTemplate(String templateName, String templateString, JsonObjec
}
}

public void ensureIndexDoesNotExist(String indexName) throws IOException {
JestResult result = client.execute( new DeleteIndex.Builder( indexName ).build() );
if ( !result.isSucceeded() && result.getResponseCode() != 404 /* Index not found is ok */ ) {
throw new AssertionFailure( String.format(
Locale.ENGLISH,
"Error while trying to delete index '%s' as part of test initialization: %s",
indexName, result.getErrorMessage()
) );
}
}

public void registerIndexForCleanup(String indexName) {
createdIndicesNames.add( indexName );
}
Expand Down

0 comments on commit 06ceb5b

Please sign in to comment.