use of org.elasticsearch.gateway.MetaStateService in project elasticsearch by elastic.
the class IndicesServiceTests method testVerifyIfIndexContentDeleted.
public void testVerifyIfIndexContentDeleted() throws Exception {
final Index index = new Index("test", UUIDs.randomBase64UUID());
final IndicesService indicesService = getIndicesService();
final NodeEnvironment nodeEnv = getNodeEnvironment();
final MetaStateService metaStateService = getInstanceFromNode(MetaStateService.class);
final ClusterService clusterService = getInstanceFromNode(ClusterService.class);
final Settings idxSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_INDEX_UUID, index.getUUID()).build();
final IndexMetaData indexMetaData = new IndexMetaData.Builder(index.getName()).settings(idxSettings).numberOfShards(1).numberOfReplicas(0).build();
metaStateService.writeIndex("test index being created", indexMetaData);
final MetaData metaData = MetaData.builder(clusterService.state().metaData()).put(indexMetaData, true).build();
final ClusterState csWithIndex = new ClusterState.Builder(clusterService.state()).metaData(metaData).build();
try {
indicesService.verifyIndexIsDeleted(index, csWithIndex);
fail("Should not be able to delete index contents when the index is part of the cluster state.");
} catch (IllegalStateException e) {
assertThat(e.getMessage(), containsString("Cannot delete index"));
}
final ClusterState withoutIndex = new ClusterState.Builder(csWithIndex).metaData(MetaData.builder(csWithIndex.metaData()).remove(index.getName())).build();
indicesService.verifyIndexIsDeleted(index, withoutIndex);
assertFalse("index files should be deleted", FileSystemUtils.exists(nodeEnv.indexPaths(index)));
}
Aggregations