use of org.elasticsearch.plugins.MetaDataUpgrader in project elasticsearch by elastic.
the class GatewayMetaStateTests method testRemoveCustomMetaDataOnUpgrade.
public void testRemoveCustomMetaDataOnUpgrade() throws Exception {
MetaData metaData = randomMetaData(new CustomMetaData1("data"));
MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(Collections.singletonList(customs -> {
customs.remove(CustomMetaData1.TYPE);
return customs;
}));
MetaData upgrade = GatewayMetaState.upgradeMetaData(metaData, new MockMetaDataIndexUpgradeService(false), metaDataUpgrader);
assertTrue(upgrade != metaData);
assertFalse(MetaData.isGlobalStateEquals(upgrade, metaData));
assertNull(upgrade.custom(CustomMetaData1.TYPE));
}
use of org.elasticsearch.plugins.MetaDataUpgrader 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.plugins.MetaDataUpgrader in project elasticsearch by elastic.
the class GatewayMetaStateTests method testNoMetaDataUpgrade.
public void testNoMetaDataUpgrade() throws Exception {
MetaData metaData = randomMetaData(new CustomMetaData1("data"));
MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(Collections.emptyList());
MetaData upgrade = GatewayMetaState.upgradeMetaData(metaData, new MockMetaDataIndexUpgradeService(false), metaDataUpgrader);
assertTrue(upgrade == metaData);
assertTrue(MetaData.isGlobalStateEquals(upgrade, metaData));
for (IndexMetaData indexMetaData : upgrade) {
assertTrue(metaData.hasIndexMetaData(indexMetaData));
}
}
use of org.elasticsearch.plugins.MetaDataUpgrader in project elasticsearch by elastic.
the class GatewayMetaStateTests method testCustomMetaDataNoChange.
public void testCustomMetaDataNoChange() throws Exception {
MetaData metaData = randomMetaData(new CustomMetaData1("data"));
MetaDataUpgrader metaDataUpgrader = new MetaDataUpgrader(Collections.singletonList(HashMap::new));
MetaData upgrade = GatewayMetaState.upgradeMetaData(metaData, new MockMetaDataIndexUpgradeService(false), metaDataUpgrader);
assertTrue(upgrade == metaData);
assertTrue(MetaData.isGlobalStateEquals(upgrade, metaData));
for (IndexMetaData indexMetaData : upgrade) {
assertTrue(metaData.hasIndexMetaData(indexMetaData));
}
}
use of org.elasticsearch.plugins.MetaDataUpgrader 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));
}
}
Aggregations