Search in sources :

Example 6 with TestCustomMetadata

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

the class ClusterChangedEventTests method nextState.

private static ClusterState nextState(final ClusterState previousState, List<TestCustomMetaData> customMetaDataList) {
    final ClusterState.Builder builder = ClusterState.builder(previousState);
    builder.stateUUID(UUIDs.randomBase64UUID());
    MetaData.Builder metaDataBuilder = new MetaData.Builder(previousState.metaData());
    for (ObjectObjectCursor<String, MetaData.Custom> customMetaData : previousState.metaData().customs()) {
        if (customMetaData.value instanceof TestCustomMetaData) {
            metaDataBuilder.removeCustom(customMetaData.key);
        }
    }
    for (TestCustomMetaData testCustomMetaData : customMetaDataList) {
        metaDataBuilder.putCustom(testCustomMetaData.getWriteableName(), testCustomMetaData);
    }
    builder.metaData(metaDataBuilder);
    return builder.build();
}
Also used : TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) MetaData(org.elasticsearch.cluster.metadata.MetaData) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData)

Example 7 with TestCustomMetadata

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

the class TribeServiceTests method testMergeCustomMetaData.

public void testMergeCustomMetaData() {
    Map<String, MetaData.Custom> mergedCustoms = TribeService.mergeChangedCustomMetaData(Collections.singleton(MergableCustomMetaData1.TYPE), s -> Arrays.asList(new MergableCustomMetaData1("data1"), new MergableCustomMetaData1("data2")));
    TestCustomMetaData mergedCustom = (TestCustomMetaData) mergedCustoms.get(MergableCustomMetaData1.TYPE);
    assertThat(mergedCustom, instanceOf(MergableCustomMetaData1.class));
    assertNotNull(mergedCustom);
    assertEquals(mergedCustom.getData(), "data2");
}
Also used : TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData)

Example 8 with TestCustomMetadata

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

the class TribeServiceTests method testMergeCustomMetaDataFromMany.

public void testMergeCustomMetaDataFromMany() {
    Map<String, List<TribeService.MergableCustomMetaData>> inputMap = new HashMap<>();
    int n = randomIntBetween(3, 5);
    List<TribeService.MergableCustomMetaData> customList1 = new ArrayList<>();
    for (int i = 0; i <= n; i++) {
        customList1.add(new MergableCustomMetaData1("data1" + String.valueOf(i)));
    }
    Collections.shuffle(customList1, random());
    inputMap.put(MergableCustomMetaData1.TYPE, customList1);
    List<TribeService.MergableCustomMetaData> customList2 = new ArrayList<>();
    for (int i = 0; i <= n; i++) {
        customList2.add(new MergableCustomMetaData2("data2" + String.valueOf(i)));
    }
    Collections.shuffle(customList2, random());
    inputMap.put(MergableCustomMetaData2.TYPE, customList2);
    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(), "data1" + String.valueOf(n));
    mergedCustom = (TestCustomMetaData) mergedCustoms.get(MergableCustomMetaData2.TYPE);
    assertNotNull(mergedCustom);
    assertThat(mergedCustom, instanceOf(MergableCustomMetaData2.class));
    assertEquals(mergedCustom.getData(), "data2" + String.valueOf(n));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with TestCustomMetadata

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

the class TribeServiceTests method testMergeCustomMetaDataSimple.

public void testMergeCustomMetaDataSimple() {
    Map<String, MetaData.Custom> mergedCustoms = TribeService.mergeChangedCustomMetaData(Collections.singleton(MergableCustomMetaData1.TYPE), s -> Collections.singletonList(new MergableCustomMetaData1("data1")));
    TestCustomMetaData mergedCustom = (TestCustomMetaData) mergedCustoms.get(MergableCustomMetaData1.TYPE);
    assertThat(mergedCustom, instanceOf(MergableCustomMetaData1.class));
    assertNotNull(mergedCustom);
    assertEquals(mergedCustom.getData(), "data1");
}
Also used : TestCustomMetaData(org.elasticsearch.test.TestCustomMetaData)

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