Search in sources :

Example 1 with TestCustomMetaData

use of org.elasticsearch.test.TestCustomMetaData in project elasticsearch by elastic.

the class TribeIT method assertCustomMetaDataUpdated.

private static void assertCustomMetaDataUpdated(InternalTestCluster cluster, TestCustomMetaData expectedCustomMetaData) throws Exception {
    assertBusy(() -> {
        ClusterState tribeState = cluster.getInstance(ClusterService.class, cluster.getNodeNames()[0]).state();
        MetaData.Custom custom = tribeState.metaData().custom(expectedCustomMetaData.getWriteableName());
        assertNotNull(custom);
        assertThat(custom, equalTo(expectedCustomMetaData));
    });
}
Also used : ClusterState(org.elasticsearch.cluster.ClusterState) ClusterService(org.elasticsearch.cluster.service.ClusterService) MetaData(org.elasticsearch.cluster.metadata.MetaData) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData)

Example 2 with TestCustomMetaData

use of org.elasticsearch.test.TestCustomMetaData in project elasticsearch by elastic.

the class TribeServiceTests method testMergeMultipleCustomMetaData.

public void testMergeMultipleCustomMetaData() {
    Map<String, List<TribeService.MergableCustomMetaData>> inputMap = new HashMap<>();
    inputMap.put(MergableCustomMetaData1.TYPE, Arrays.asList(new MergableCustomMetaData1("data10"), new MergableCustomMetaData1("data11")));
    inputMap.put(MergableCustomMetaData2.TYPE, Arrays.asList(new MergableCustomMetaData2("data21"), new MergableCustomMetaData2("data20")));
    Map<String, MetaData.Custom> mergedCustoms = TribeService.mergeChangedCustomMetaData(Sets.newHashSet(MergableCustomMetaData1.TYPE, MergableCustomMetaData2.TYPE), inputMap::get);
    TestCustomMetaData mergedCustom = (TestCustomMetaData) mergedCustoms.get(MergableCustomMetaData1.TYPE);
    assertNotNull(mergedCustom);
    assertThat(mergedCustom, instanceOf(MergableCustomMetaData1.class));
    assertEquals(mergedCustom.getData(), "data11");
    mergedCustom = (TestCustomMetaData) mergedCustoms.get(MergableCustomMetaData2.TYPE);
    assertNotNull(mergedCustom);
    assertThat(mergedCustom, instanceOf(MergableCustomMetaData2.class));
    assertEquals(mergedCustom.getData(), "data21");
}
Also used : TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with TestCustomMetaData

use of org.elasticsearch.test.TestCustomMetaData in project elasticsearch by elastic.

the class GatewayMetaStateTests method testAddCustomMetaDataOnUpgrade.

public void testAddCustomMetaDataOnUpgrade() throws Exception {
    MetaData metaData = randomMetaData();
    MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(Collections.singletonList(customs -> {
        customs.put(CustomMetaData1.TYPE, new CustomMetaData1("modified_data1"));
        return customs;
    }));
    MetaData upgrade = GatewayMetaState.upgradeMetaData(metaData, new MockMetaDataIndexUpgradeService(false), metaDataUpgrader);
    assertTrue(upgrade != metaData);
    assertFalse(MetaData.isGlobalStateEquals(upgrade, metaData));
    assertNotNull(upgrade.custom(CustomMetaData1.TYPE));
    assertThat(((TestCustomMetaData) upgrade.custom(CustomMetaData1.TYPE)).getData(), equalTo("modified_data1"));
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) ESAllocationTestCase(org.elasticsearch.cluster.ESAllocationTestCase) Arrays(java.util.Arrays) MetaDataUpgrader(org.elasticsearch.plugins.MetaDataUpgrader) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) INITIALIZING(org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING) HashMap(java.util.HashMap) Index(org.elasticsearch.index.Index) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) ClusterRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider) EnumSet(java.util.EnumSet) Before(org.junit.Before) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Iterator(java.util.Iterator) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) Version(org.elasticsearch.Version) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) MetaDataIndexUpgradeService(org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) MetaDataUpgrader(org.elasticsearch.plugins.MetaDataUpgrader) MetaData(org.elasticsearch.cluster.metadata.MetaData) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 4 with TestCustomMetaData

use of org.elasticsearch.test.TestCustomMetaData in project elasticsearch by elastic.

the class GatewayMetaStateTests method testMultipleCustomMetaDataUpgrade.

public void testMultipleCustomMetaDataUpgrade() throws Exception {
    final MetaData metaData;
    switch(randomIntBetween(0, 2)) {
        case 0:
            metaData = randomMetaData(new CustomMetaData1("data1"), new CustomMetaData2("data2"));
            break;
        case 1:
            metaData = randomMetaData(randomBoolean() ? new CustomMetaData1("data1") : new CustomMetaData2("data2"));
            break;
        case 2:
            metaData = randomMetaData();
            break;
        default:
            throw new IllegalStateException("should never happen");
    }
    MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(Arrays.asList(customs -> {
        customs.put(CustomMetaData1.TYPE, new CustomMetaData1("modified_data1"));
        return customs;
    }, customs -> {
        customs.put(CustomMetaData2.TYPE, new CustomMetaData1("modified_data2"));
        return customs;
    }));
    MetaData upgrade = GatewayMetaState.upgradeMetaData(metaData, new MockMetaDataIndexUpgradeService(false), metaDataUpgrader);
    assertTrue(upgrade != metaData);
    assertFalse(MetaData.isGlobalStateEquals(upgrade, metaData));
    assertNotNull(upgrade.custom(CustomMetaData1.TYPE));
    assertThat(((TestCustomMetaData) upgrade.custom(CustomMetaData1.TYPE)).getData(), equalTo("modified_data1"));
    assertNotNull(upgrade.custom(CustomMetaData2.TYPE));
    assertThat(((TestCustomMetaData) upgrade.custom(CustomMetaData2.TYPE)).getData(), equalTo("modified_data2"));
    for (IndexMetaData indexMetaData : upgrade) {
        assertTrue(metaData.hasIndexMetaData(indexMetaData));
    }
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) ESAllocationTestCase(org.elasticsearch.cluster.ESAllocationTestCase) Arrays(java.util.Arrays) MetaDataUpgrader(org.elasticsearch.plugins.MetaDataUpgrader) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) INITIALIZING(org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING) HashMap(java.util.HashMap) Index(org.elasticsearch.index.Index) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) ClusterRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider) EnumSet(java.util.EnumSet) Before(org.junit.Before) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Iterator(java.util.Iterator) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) Version(org.elasticsearch.Version) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) MetaDataIndexUpgradeService(org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) MetaDataUpgrader(org.elasticsearch.plugins.MetaDataUpgrader) MetaData(org.elasticsearch.cluster.metadata.MetaData) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 5 with TestCustomMetaData

use of org.elasticsearch.test.TestCustomMetaData in project elasticsearch by elastic.

the class GatewayMetaStateTests method testUpdateCustomMetaDataOnUpgrade.

public void testUpdateCustomMetaDataOnUpgrade() throws Exception {
    MetaData metaData = randomMetaData(new CustomMetaData1("data"));
    MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(Collections.singletonList(customs -> {
        customs.put(CustomMetaData1.TYPE, new CustomMetaData1("modified_data1"));
        return customs;
    }));
    MetaData upgrade = GatewayMetaState.upgradeMetaData(metaData, new MockMetaDataIndexUpgradeService(false), metaDataUpgrader);
    assertTrue(upgrade != metaData);
    assertFalse(MetaData.isGlobalStateEquals(upgrade, metaData));
    assertNotNull(upgrade.custom(CustomMetaData1.TYPE));
    assertThat(((TestCustomMetaData) upgrade.custom(CustomMetaData1.TYPE)).getData(), equalTo("modified_data1"));
}
Also used : MetaData(org.elasticsearch.cluster.metadata.MetaData) ESAllocationTestCase(org.elasticsearch.cluster.ESAllocationTestCase) Arrays(java.util.Arrays) MetaDataUpgrader(org.elasticsearch.plugins.MetaDataUpgrader) AllocationService(org.elasticsearch.cluster.routing.allocation.AllocationService) INITIALIZING(org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING) HashMap(java.util.HashMap) Index(org.elasticsearch.index.Index) ClusterState(org.elasticsearch.cluster.ClusterState) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) ClusterRebalanceAllocationDecider(org.elasticsearch.cluster.routing.allocation.decider.ClusterRebalanceAllocationDecider) EnumSet(java.util.EnumSet) Before(org.junit.Before) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) Iterator(java.util.Iterator) Collections.emptySet(java.util.Collections.emptySet) Set(java.util.Set) ClusterChangedEvent(org.elasticsearch.cluster.ClusterChangedEvent) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) Version(org.elasticsearch.Version) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) MetaDataIndexUpgradeService(org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService) RoutingTable(org.elasticsearch.cluster.routing.RoutingTable) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Collections(java.util.Collections) MetaDataUpgrader(org.elasticsearch.plugins.MetaDataUpgrader) MetaData(org.elasticsearch.cluster.metadata.MetaData) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Aggregations

TestCustomMetaData (org.elasticsearch.test.TestCustomMetaData)9 HashMap (java.util.HashMap)5 MetaData (org.elasticsearch.cluster.metadata.MetaData)5 ClusterState (org.elasticsearch.cluster.ClusterState)4 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)4 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 Collections.emptySet (java.util.Collections.emptySet)3 EnumSet (java.util.EnumSet)3 Iterator (java.util.Iterator)3 Set (java.util.Set)3 Version (org.elasticsearch.Version)3 ClusterChangedEvent (org.elasticsearch.cluster.ClusterChangedEvent)3 ESAllocationTestCase (org.elasticsearch.cluster.ESAllocationTestCase)3 MetaDataIndexUpgradeService (org.elasticsearch.cluster.metadata.MetaDataIndexUpgradeService)3 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)3 DiscoveryNodes (org.elasticsearch.cluster.node.DiscoveryNodes)3 RoutingTable (org.elasticsearch.cluster.routing.RoutingTable)3 INITIALIZING (org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING)3 AllocationService (org.elasticsearch.cluster.routing.allocation.AllocationService)3