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();
}
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");
}
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));
}
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");
}
Aggregations