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