Search in sources :

Example 1 with KEY

use of org.apache.ignite.internal.configuration.FirstConfiguration.KEY 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());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) Data(org.apache.ignite.internal.configuration.storage.Data) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) TimeoutException(java.util.concurrent.TimeoutException) ConstructableTreeNode(org.apache.ignite.internal.configuration.tree.ConstructableTreeNode) CompletableFuture(java.util.concurrent.CompletableFuture) ConfigurationStorage(org.apache.ignite.internal.configuration.storage.ConfigurationStorage) Validator(org.apache.ignite.configuration.validation.Validator) Retention(java.lang.annotation.Retention) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) Immutable(org.apache.ignite.configuration.validation.Immutable) AfterAll(org.junit.jupiter.api.AfterAll) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) KeyPathNode(org.apache.ignite.internal.configuration.direct.KeyPathNode) Map(java.util.Map) KEY(org.apache.ignite.internal.configuration.FirstConfiguration.KEY) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NoSuchElementException(java.util.NoSuchElementException) FIELD(java.lang.annotation.ElementType.FIELD) ConfigurationRoot(org.apache.ignite.configuration.annotation.ConfigurationRoot) ValidationContext(org.apache.ignite.configuration.validation.ValidationContext) NamedListView(org.apache.ignite.configuration.NamedListView) Set(java.util.Set) Target(java.lang.annotation.Target) ConfigurationChangeException(org.apache.ignite.configuration.ConfigurationChangeException) RootKey(org.apache.ignite.configuration.RootKey) RUNTIME(java.lang.annotation.RetentionPolicy.RUNTIME) Serializable(java.io.Serializable) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) ExecutionException(java.util.concurrent.ExecutionException) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) List(java.util.List) ValidationIssue(org.apache.ignite.configuration.validation.ValidationIssue) LOCAL(org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL) Config(org.apache.ignite.configuration.annotation.Config) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) ConfigurationSource(org.apache.ignite.internal.configuration.tree.ConfigurationSource) Matchers.containsString(org.hamcrest.Matchers.containsString) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Value(org.apache.ignite.configuration.annotation.Value) ConfigurationAsmGenerator(org.apache.ignite.internal.configuration.asm.ConfigurationAsmGenerator) ValidationIssue(org.apache.ignite.configuration.validation.ValidationIssue) Validator(org.apache.ignite.configuration.validation.Validator) ValidationContext(org.apache.ignite.configuration.validation.ValidationContext) Test(org.junit.jupiter.api.Test)

Aggregations

Serializable (java.io.Serializable)1 FIELD (java.lang.annotation.ElementType.FIELD)1 Retention (java.lang.annotation.Retention)1 RUNTIME (java.lang.annotation.RetentionPolicy.RUNTIME)1 Target (java.lang.annotation.Target)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 Set (java.util.Set)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 ExecutionException (java.util.concurrent.ExecutionException)1 SECONDS (java.util.concurrent.TimeUnit.SECONDS)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Consumer (java.util.function.Consumer)1 ConfigurationChangeException (org.apache.ignite.configuration.ConfigurationChangeException)1 NamedListView (org.apache.ignite.configuration.NamedListView)1 RootKey (org.apache.ignite.configuration.RootKey)1 Config (org.apache.ignite.configuration.annotation.Config)1