Search in sources :

Example 1 with GatewayMetaState

use of org.elasticsearch.gateway.GatewayMetaState in project elasticsearch by elastic.

the class IndicesServiceTests method testDeleteIndexStore.

public void testDeleteIndexStore() throws Exception {
    IndicesService indicesService = getIndicesService();
    IndexService test = createIndex("test");
    ClusterService clusterService = getInstanceFromNode(ClusterService.class);
    IndexMetaData firstMetaData = clusterService.state().metaData().index("test");
    assertTrue(test.hasShard(0));
    try {
        indicesService.deleteIndexStore("boom", firstMetaData, clusterService.state());
        fail();
    } catch (IllegalStateException ex) {
    // all good
    }
    GatewayMetaState gwMetaState = getInstanceFromNode(GatewayMetaState.class);
    MetaData meta = gwMetaState.loadMetaState();
    assertNotNull(meta);
    assertNotNull(meta.index("test"));
    assertAcked(client().admin().indices().prepareDelete("test"));
    meta = gwMetaState.loadMetaState();
    assertNotNull(meta);
    assertNull(meta.index("test"));
    test = createIndex("test");
    client().prepareIndex("test", "type", "1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get();
    client().admin().indices().prepareFlush("test").get();
    assertHitCount(client().prepareSearch("test").get(), 1);
    IndexMetaData secondMetaData = clusterService.state().metaData().index("test");
    assertAcked(client().admin().indices().prepareClose("test"));
    ShardPath path = ShardPath.loadShardPath(logger, getNodeEnvironment(), new ShardId(test.index(), 0), test.getIndexSettings());
    assertTrue(path.exists());
    try {
        indicesService.deleteIndexStore("boom", secondMetaData, clusterService.state());
        fail();
    } catch (IllegalStateException ex) {
    // all good
    }
    assertTrue(path.exists());
    // now delete the old one and make sure we resolve against the name
    try {
        indicesService.deleteIndexStore("boom", firstMetaData, clusterService.state());
        fail();
    } catch (IllegalStateException ex) {
    // all good
    }
    assertAcked(client().admin().indices().prepareOpen("test"));
    ensureGreen("test");
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ClusterService(org.elasticsearch.cluster.service.ClusterService) IndexService(org.elasticsearch.index.IndexService) ShardPath(org.elasticsearch.index.shard.ShardPath) MetaData(org.elasticsearch.cluster.metadata.MetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) GatewayMetaState(org.elasticsearch.gateway.GatewayMetaState)

Aggregations

IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)1 MetaData (org.elasticsearch.cluster.metadata.MetaData)1 ClusterService (org.elasticsearch.cluster.service.ClusterService)1 GatewayMetaState (org.elasticsearch.gateway.GatewayMetaState)1 IndexService (org.elasticsearch.index.IndexService)1 ShardId (org.elasticsearch.index.shard.ShardId)1 ShardPath (org.elasticsearch.index.shard.ShardPath)1