use of org.apache.ignite.configuration.validation.ValidationIssue in project ignite-3 by apache.
the class ConfigurationChangerTest method testModifiedFromAnotherStorageWithIncompatibleChanges.
/**
* Test that subsequent change of configuration is failed if changes are incompatible.
*/
@Test
public void testModifiedFromAnotherStorageWithIncompatibleChanges() throws Exception {
ConfigurationChanger changer1 = createChanger(KEY);
changer1.start();
Validator<MaybeInvalid, Object> validator = new Validator<>() {
/**
* {@inheritDoc}
*/
@Override
public void validate(MaybeInvalid annotation, ValidationContext<Object> ctx) {
ctx.addIssue(new ValidationIssue("foo"));
}
};
ConfigurationChanger changer2 = new TestConfigurationChanger(cgen, List.of(KEY), Map.of(MaybeInvalid.class, Set.of(validator)), storage, List.of(), List.of());
changer2.start();
changer1.change(source(KEY, (FirstChange parent) -> parent.changeChild(change -> change.changeIntCfg(1).changeStrCfg("1")).changeElements(change -> change.create("a", element -> element.changeStrCfg("1"))))).get(1, SECONDS);
assertThrows(ExecutionException.class, () -> changer2.change(source(KEY, (FirstChange parent) -> parent.changeChild(change -> change.changeIntCfg(2).changeStrCfg("2")).changeElements(change -> change.create("a", element -> element.changeStrCfg("2")).create("b", element -> element.changeStrCfg("2"))))).get(1, SECONDS));
FirstView newRoot = (FirstView) changer2.getRootNode(KEY);
assertEquals(1, newRoot.child().intCfg());
assertEquals("1", newRoot.child().strCfg());
assertEquals("1", newRoot.elements().get("a").strCfg());
}
use of org.apache.ignite.configuration.validation.ValidationIssue in project ignite-3 by apache.
the class ValidationUtilTest method validateNamedListNode.
@Test
public void validateNamedListNode() throws Exception {
var rootsNode = new SuperRoot(key -> null, Map.of(ValidatedRootConfiguration.KEY, root));
Validator<NamedListValidation, NamedListView<?>> validator = new Validator<>() {
@Override
public void validate(NamedListValidation annotation, ValidationContext<NamedListView<?>> ctx) {
assertEquals("root.elements", ctx.currentKey());
assertEquals(List.of(), ctx.getOldValue().namedListKeys());
assertEquals(List.of(), ctx.getNewValue().namedListKeys());
ctx.addIssue(new ValidationIssue("bar"));
}
};
Map<Class<? extends Annotation>, Set<Validator<?, ?>>> validators = Map.of(NamedListValidation.class, Set.of(validator));
List<ValidationIssue> issues = ValidationUtil.validate(rootsNode, rootsNode, null, new HashMap<>(), validators);
assertEquals(1, issues.size());
assertEquals("bar", issues.get(0).message());
}
use of org.apache.ignite.configuration.validation.ValidationIssue in project ignite-3 by apache.
the class ExceptKeysValidator method validate.
/**
* {@inheritDoc}
*/
@Override
public void validate(ExceptKeys annotation, ValidationContext<NamedListView<?>> ctx) {
NamedListView<?> nameList = ctx.getNewValue();
List<String> actualNames = nameList.namedListKeys();
for (String exceptedName : annotation.value()) {
if (actualNames.contains(exceptedName)) {
String message = "'" + ctx.currentKey() + "' configuration must not contain elements named '" + exceptedName + "'";
ctx.addIssue(new ValidationIssue(message));
}
}
}
use of org.apache.ignite.configuration.validation.ValidationIssue in project ignite-3 by apache.
the class TableValidatorImplTest method testMisalignedColumnNamedListKeys.
/**
* Tests that column names and column keys inside a Named List must be equal.
*/
@Test
void testMisalignedColumnNamedListKeys(@InjectConfiguration(polymorphicExtensions = RocksDbDataRegionConfigurationSchema.class) DataStorageConfiguration dbCfg) {
NamedListView<TableView> oldValue = tablesCfg.tables().value();
TableConfiguration tableCfg = tablesCfg.tables().get("table");
CompletableFuture<Void> tableChangeFuture = tableCfg.columns().change(columnsChange -> columnsChange.create("ololo", columnChange -> columnChange.changeName("not ololo").changeType(columnTypeChange -> columnTypeChange.changeType("STRING")).changeNullable(true)));
assertThat(tableChangeFuture, willBe(nullValue(Void.class)));
ValidationContext<NamedListView<TableView>> ctx = mockContext(oldValue, dbCfg.value());
ArgumentCaptor<ValidationIssue> issuesCaptor = validate(ctx);
assertThat(issuesCaptor.getAllValues(), hasSize(1));
assertThat(issuesCaptor.getValue().message(), is(equalTo("Column name \"not ololo\" does not match its Named List key: \"ololo\"")));
}
use of org.apache.ignite.configuration.validation.ValidationIssue in project ignite-3 by apache.
the class TableValidatorImplTest method testMisalignedIndexNamedListKeys.
/**
* Tests that index names and index keys inside a Named List must be equal.
*/
@Test
void testMisalignedIndexNamedListKeys(@InjectConfiguration(polymorphicExtensions = RocksDbDataRegionConfigurationSchema.class) DataStorageConfiguration dbCfg) {
NamedListView<TableView> oldValue = tablesCfg.tables().value();
TableConfiguration tableCfg = tablesCfg.tables().get("table");
CompletableFuture<Void> tableChangeFuture = tableCfg.indices().change(indicesChange -> indicesChange.create("ololo", indexChange -> indexChange.changeName("not ololo").convert(HashIndexChange.class).changeColNames("id")));
assertThat(tableChangeFuture, willBe(nullValue(Void.class)));
ValidationContext<NamedListView<TableView>> ctx = mockContext(oldValue, dbCfg.value());
ArgumentCaptor<ValidationIssue> issuesCaptor = validate(ctx);
assertThat(issuesCaptor.getAllValues(), hasSize(1));
assertThat(issuesCaptor.getValue().message(), is(equalTo("Index name \"not ololo\" does not match its Named List key: \"ololo\"")));
}
Aggregations