Search in sources :

Example 1 with MetaStateService

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)));
}
Also used : MetaStateService(org.elasticsearch.gateway.MetaStateService) ClusterState(org.elasticsearch.cluster.ClusterState) ClusterService(org.elasticsearch.cluster.service.ClusterService) NodeEnvironment(org.elasticsearch.env.NodeEnvironment) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Index(org.elasticsearch.index.Index) Settings(org.elasticsearch.common.settings.Settings) IndexSettings(org.elasticsearch.index.IndexSettings) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Aggregations

ClusterState (org.elasticsearch.cluster.ClusterState)1 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)1 MetaData (org.elasticsearch.cluster.metadata.MetaData)1 ClusterService (org.elasticsearch.cluster.service.ClusterService)1 Settings (org.elasticsearch.common.settings.Settings)1 NodeEnvironment (org.elasticsearch.env.NodeEnvironment)1 MetaStateService (org.elasticsearch.gateway.MetaStateService)1 Index (org.elasticsearch.index.Index)1 IndexSettings (org.elasticsearch.index.IndexSettings)1