Search in sources :

Example 1 with LocalAllocateDangledIndices

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

the class IndicesServiceTests method testDanglingIndicesWithAliasConflict.

public void testDanglingIndicesWithAliasConflict() throws Exception {
    final String indexName = "test-idx1";
    final String alias = "test-alias";
    final ClusterService clusterService = getInstanceFromNode(ClusterService.class);
    createIndex(indexName);
    // create the alias for the index
    client().admin().indices().prepareAliases().addAlias(indexName, alias).get();
    final ClusterState originalState = clusterService.state();
    // try to import a dangling index with the same name as the alias, it should fail
    final LocalAllocateDangledIndices dangling = getInstanceFromNode(LocalAllocateDangledIndices.class);
    final Settings idxSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).put(IndexMetaData.SETTING_INDEX_UUID, UUIDs.randomBase64UUID()).build();
    final IndexMetaData indexMetaData = new IndexMetaData.Builder(alias).settings(idxSettings).numberOfShards(1).numberOfReplicas(0).build();
    DanglingListener listener = new DanglingListener();
    dangling.allocateDangled(Arrays.asList(indexMetaData), listener);
    listener.latch.await();
    assertThat(clusterService.state(), equalTo(originalState));
    // remove the alias
    client().admin().indices().prepareAliases().removeAlias(indexName, alias).get();
    // now try importing a dangling index with the same name as the alias, it should succeed.
    listener = new DanglingListener();
    dangling.allocateDangled(Arrays.asList(indexMetaData), listener);
    listener.latch.await();
    assertThat(clusterService.state(), not(originalState));
    assertNotNull(clusterService.state().getMetaData().index(alias));
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) LocalAllocateDangledIndices(org.elasticsearch.gateway.LocalAllocateDangledIndices) ClusterService(org.elasticsearch.cluster.service.ClusterService) Matchers.containsString(org.hamcrest.Matchers.containsString) 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 ClusterService (org.elasticsearch.cluster.service.ClusterService)1 Settings (org.elasticsearch.common.settings.Settings)1 LocalAllocateDangledIndices (org.elasticsearch.gateway.LocalAllocateDangledIndices)1 IndexSettings (org.elasticsearch.index.IndexSettings)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1