Search in sources :

Example 1 with LOCAL

use of org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL in project ignite-3 by apache.

the class UsageTest method multiRootConfiguration.

/**
 * Test to show an API to work with multiroot configurations.
 */
@Test
public void multiRootConfiguration() throws Exception {
    final int failureDetectionTimeout = 30_000;
    final int joinTimeout = 10_000;
    long autoAdjustTimeout = 30_000L;
    registry = new ConfigurationRegistry(List.of(NetworkConfiguration.KEY, LocalConfiguration.KEY), Map.of(), new TestConfigurationStorage(LOCAL), List.of(), List.of());
    registry.start();
    registry.getConfiguration(LocalConfiguration.KEY).change(local -> local.changeBaseline(baseline -> baseline.changeAutoAdjust(autoAdjust -> autoAdjust.changeEnabled(true).changeTimeout(autoAdjustTimeout)))).get(1, SECONDS);
    registry.getConfiguration(NetworkConfiguration.KEY).change(network -> network.changeDiscovery(discovery -> discovery.changeFailureDetectionTimeout(failureDetectionTimeout).changeJoinTimeout(joinTimeout))).get(1, SECONDS);
    assertEquals(failureDetectionTimeout, registry.getConfiguration(NetworkConfiguration.KEY).discovery().failureDetectionTimeout().value());
    assertEquals(autoAdjustTimeout, registry.getConfiguration(LocalConfiguration.KEY).baseline().autoAdjust().timeout().value());
}
Also used : TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ConfigurationRegistry(org.apache.ignite.internal.configuration.ConfigurationRegistry) LOCAL(org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Map(java.util.Map) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ConfigurationRegistry(org.apache.ignite.internal.configuration.ConfigurationRegistry) Test(org.junit.jupiter.api.Test)

Example 2 with LOCAL

use of org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL in project ignite-3 by apache.

the class UsageTest method test.

/**
 * Test creation of configuration and calling configuration API methods.
 */
@Test
public void test() throws Exception {
    registry = new ConfigurationRegistry(List.of(LocalConfiguration.KEY), Map.of(), new TestConfigurationStorage(LOCAL), List.of(), List.of());
    registry.start();
    registry.initializeDefaults();
    LocalConfiguration root = registry.getConfiguration(LocalConfiguration.KEY);
    root.change(local -> local.changeBaseline(baseline -> baseline.changeNodes(nodes -> nodes.create("node1", node -> node.changeConsistentId("test").changePort(1000))).changeAutoAdjust(autoAdjust -> autoAdjust.changeEnabled(true).changeTimeout(100_000L)))).get(1, SECONDS);
    assertTrue(root.baseline().autoAdjust().enabled().value());
    root.baseline().autoAdjust().enabled().update(false).get(1, SECONDS);
    assertFalse(root.value().baseline().autoAdjust().enabled());
    assertFalse(root.baseline().value().autoAdjust().enabled());
    assertFalse(root.baseline().autoAdjust().value().enabled());
    assertFalse(root.baseline().autoAdjust().enabled().value());
    root.baseline().nodes().get("node1").autoAdjustEnabled().update(true).get(1, SECONDS);
    assertTrue(root.value().baseline().nodes().get("node1").autoAdjustEnabled());
    assertTrue(root.baseline().value().nodes().get("node1").autoAdjustEnabled());
    assertTrue(root.baseline().nodes().value().get("node1").autoAdjustEnabled());
    assertTrue(root.baseline().nodes().get("node1").value().autoAdjustEnabled());
    assertTrue(root.baseline().nodes().get("node1").autoAdjustEnabled().value());
    root.baseline().nodes().get("node1").change(node -> node.changeAutoAdjustEnabled(false)).get(1, SECONDS);
    assertFalse(root.value().baseline().nodes().get("node1").autoAdjustEnabled());
    root.baseline().nodes().change(nodes -> nodes.delete("node1")).get(1, SECONDS);
    assertNull(root.baseline().nodes().get("node1"));
    assertNull(root.value().baseline().nodes().get("node1"));
}
Also used : TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ConfigurationRegistry(org.apache.ignite.internal.configuration.ConfigurationRegistry) LOCAL(org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Map(java.util.Map) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ConfigurationRegistry(org.apache.ignite.internal.configuration.ConfigurationRegistry) Test(org.junit.jupiter.api.Test)

Example 3 with LOCAL

use of org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL in project ignite-3 by apache.

the class ConfigurationAnyListenerTest method before.

/**
 * Before each.
 */
@BeforeEach
public void before() throws Exception {
    registry = new ConfigurationRegistry(List.of(RootConfiguration.KEY), Map.of(), new TestConfigurationStorage(LOCAL), List.of(), List.of(FirstPolyAnyConfigurationSchema.class, SecondPolyAnyConfigurationSchema.class));
    registry.start();
    registry.initializeDefaults();
    rootConfig = registry.getConfiguration(RootConfiguration.KEY);
    // Add "regular" listeners.
    rootConfig.listen(configListener(ctx -> events.add("root")));
    rootConfig.child().listen(configListener(ctx -> events.add("root.child")));
    rootConfig.child().str().listen(configListener(ctx -> events.add("root.child.str")));
    rootConfig.child().child2().listen(configListener(ctx -> events.add("root.child.child2")));
    rootConfig.child().child2().intVal().listen(configListener(ctx -> events.add("root.child.child2.i")));
    rootConfig.elements().listen(configListener(ctx -> events.add("root.elements")));
    rootConfig.elements().listenElements(configNamedListenerOnCreate(ctx -> events.add("root.elements.onCrt")));
    rootConfig.elements().listenElements(configNamedListenerOnUpdate(ctx -> events.add("root.elements.onUpd")));
    rootConfig.elements().listenElements(configNamedListenerOnRename(ctx -> events.add("root.elements.onRen")));
    rootConfig.elements().listenElements(configNamedListenerOnDelete(ctx -> events.add("root.elements.onDel")));
    rootConfig.elements().change(c -> c.create("0", doNothingConsumer())).get(1, SECONDS);
    FirstSubConfiguration childCfg = this.rootConfig.elements().get("0");
    childCfg.listen(configListener(ctx -> events.add("root.elements.0")));
    childCfg.str().listen(configListener(ctx -> events.add("root.elements.0.str")));
    childCfg.child2().listen(configListener(ctx -> events.add("root.elements.0.child2")));
    childCfg.child2().intVal().listen(configListener(ctx -> events.add("root.elements.0.child2.i")));
    NamedConfigurationTree<SecondSubConfiguration, SecondSubView, SecondSubChange> elements2 = childCfg.elements2();
    elements2.listen(configListener(ctx -> events.add("root.elements.0.elements2")));
    elements2.listenElements(configNamedListenerOnCreate(ctx -> events.add("root.elements.0.elements2.onCrt")));
    elements2.listenElements(configNamedListenerOnUpdate(ctx -> events.add("root.elements.0.elements2.onUpd")));
    elements2.listenElements(configNamedListenerOnRename(ctx -> events.add("root.elements.0.elements2.onRen")));
    elements2.listenElements(configNamedListenerOnDelete(ctx -> events.add("root.elements.0.elements2.onDel")));
    elements2.change(c -> c.create("0", doNothingConsumer())).get(1, SECONDS);
    SecondSubConfiguration child2 = elements2.get("0");
    child2.listen(configListener(ctx -> events.add("root.elements.0.elements2.0")));
    child2.intVal().listen(configListener(ctx -> events.add("root.elements.0.elements2.0.i")));
    // Adding "any" listeners.
    FirstSubConfiguration anyChild = rootConfig.elements().any();
    anyChild.listen(configListener(ctx -> events.add("root.elements.any")));
    anyChild.str().listen(configListener(ctx -> events.add("root.elements.any.str")));
    anyChild.child2().listen(configListener(ctx -> events.add("root.elements.any.child2")));
    anyChild.child2().intVal().listen(configListener(ctx -> events.add("root.elements.any.child2.i")));
    NamedConfigurationTree<SecondSubConfiguration, SecondSubView, SecondSubChange> anyEl2 = anyChild.elements2();
    anyEl2.listen(configListener(ctx -> events.add("root.elements.any.elements2")));
    anyEl2.listenElements(configNamedListenerOnCreate(ctx -> events.add("root.elements.any.elements2.onCrt")));
    anyEl2.listenElements(configNamedListenerOnUpdate(ctx -> events.add("root.elements.any.elements2.onUpd")));
    anyEl2.listenElements(configNamedListenerOnRename(ctx -> events.add("root.elements.any.elements2.onRen")));
    anyEl2.listenElements(configNamedListenerOnDelete(ctx -> events.add("root.elements.any.elements2.onDel")));
    SecondSubConfiguration anyChild2 = anyEl2.any();
    anyChild2.listen(configListener(ctx -> events.add("root.elements.any.elements2.any")));
    anyChild2.intVal().listen(configListener(ctx -> events.add("root.elements.any.elements2.any.i")));
    childCfg.elements2().any().listen(configListener(ctx -> events.add("root.elements.0.elements2.any")));
    childCfg.elements2().any().intVal().listen(configListener(ctx -> events.add("root.elements.0.elements2.any.i")));
}
Also used : TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) PolymorphicId(org.apache.ignite.configuration.annotation.PolymorphicId) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) ConfigurationListenerTestUtils.configNamedListenerOnRename(org.apache.ignite.internal.configuration.notifications.ConfigurationListenerTestUtils.configNamedListenerOnRename) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ConfigurationListenerTestUtils.configNamedListenerOnDelete(org.apache.ignite.internal.configuration.notifications.ConfigurationListenerTestUtils.configNamedListenerOnDelete) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) ConfigurationListenerTestUtils.configListener(org.apache.ignite.internal.configuration.notifications.ConfigurationListenerTestUtils.configListener) Map(java.util.Map) PolymorphicConfig(org.apache.ignite.configuration.annotation.PolymorphicConfig) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NamedConfigurationTree(org.apache.ignite.configuration.NamedConfigurationTree) ConfigurationListenerTestUtils.configNamedListenerOnUpdate(org.apache.ignite.internal.configuration.notifications.ConfigurationListenerTestUtils.configNamedListenerOnUpdate) ConfigurationListenerTestUtils.configNamedListenerOnCreate(org.apache.ignite.internal.configuration.notifications.ConfigurationListenerTestUtils.configNamedListenerOnCreate) ConfigurationListenOnlyException(org.apache.ignite.configuration.ConfigurationListenOnlyException) ConfigurationRoot(org.apache.ignite.configuration.annotation.ConfigurationRoot) ConfigurationListenerTestUtils.checkEqualsListeners(org.apache.ignite.internal.configuration.notifications.ConfigurationListenerTestUtils.checkEqualsListeners) Assertions.assertInstanceOf(org.junit.jupiter.api.Assertions.assertInstanceOf) UUID(java.util.UUID) ConfigurationNamedListListener(org.apache.ignite.configuration.notifications.ConfigurationNamedListListener) Test(org.junit.jupiter.api.Test) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) ConfigurationListener(org.apache.ignite.configuration.notifications.ConfigurationListener) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) ConfigurationListenerTestUtils.checkContainsListeners(org.apache.ignite.internal.configuration.notifications.ConfigurationListenerTestUtils.checkContainsListeners) ConfigurationRegistry(org.apache.ignite.internal.configuration.ConfigurationRegistry) LOCAL(org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL) PolymorphicConfigInstance(org.apache.ignite.configuration.annotation.PolymorphicConfigInstance) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Config(org.apache.ignite.configuration.annotation.Config) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) ConfigurationListenerTestUtils.doNothingConsumer(org.apache.ignite.internal.configuration.notifications.ConfigurationListenerTestUtils.doNothingConsumer) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Value(org.apache.ignite.configuration.annotation.Value) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ConfigurationRegistry(org.apache.ignite.internal.configuration.ConfigurationRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with LOCAL

use of org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL in project ignite-3 by apache.

the class ItClientHandlerTest method startServer.

private ClientHandlerModule startServer(TestInfo testInfo) {
    configurationManager = new ConfigurationManager(List.of(ClientConnectorConfiguration.KEY, NetworkConfiguration.KEY), Map.of(), new TestConfigurationStorage(LOCAL), List.of(), List.of());
    configurationManager.start();
    var registry = configurationManager.configurationRegistry();
    registry.getConfiguration(ClientConnectorConfiguration.KEY).change(local -> local.changePort(10800).changePortRange(10)).join();
    bootstrapFactory = new NettyBootstrapFactory(registry.getConfiguration(NetworkConfiguration.KEY), testInfo.getDisplayName());
    bootstrapFactory.start();
    var module = new ClientHandlerModule(mock(QueryProcessor.class), mock(IgniteTables.class), mock(IgniteTransactions.class), registry, bootstrapFactory);
    module.start();
    return module;
}
Also used : TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) Socket(java.net.Socket) NettyBootstrapFactory(org.apache.ignite.network.NettyBootstrapFactory) QueryProcessor(org.apache.ignite.internal.sql.engine.QueryProcessor) NetworkConfiguration(org.apache.ignite.configuration.schemas.network.NetworkConfiguration) Map(java.util.Map) IgniteTables(org.apache.ignite.table.manager.IgniteTables) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) OutputStream(java.io.OutputStream) IOException(java.io.IOException) MessagePack(org.msgpack.core.MessagePack) ConfigurationManager(org.apache.ignite.internal.configuration.ConfigurationManager) InetSocketAddress(java.net.InetSocketAddress) TestInfo(org.junit.jupiter.api.TestInfo) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) LOCAL(org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) IgniteTransactions(org.apache.ignite.tx.IgniteTransactions) Mockito.mock(org.mockito.Mockito.mock) ClientConnectorConfiguration(org.apache.ignite.configuration.schemas.clientconnector.ClientConnectorConfiguration) NettyBootstrapFactory(org.apache.ignite.network.NettyBootstrapFactory) IgniteTables(org.apache.ignite.table.manager.IgniteTables) IgniteTransactions(org.apache.ignite.tx.IgniteTransactions) ConfigurationManager(org.apache.ignite.internal.configuration.ConfigurationManager) QueryProcessor(org.apache.ignite.internal.sql.engine.QueryProcessor)

Example 5 with LOCAL

use of org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL in project ignite-3 by apache.

the class ConfigurationRegistryTest method testComplicatedPolymorphicConfig.

@Test
void testComplicatedPolymorphicConfig() throws Exception {
    ConfigurationRegistry registry = new ConfigurationRegistry(List.of(SixthRootConfiguration.KEY), Map.of(), new TestConfigurationStorage(LOCAL), List.of(), List.of(Fourth0PolymorphicConfigurationSchema.class));
    registry.start();
    try {
        registry.getConfiguration(SixthRootConfiguration.KEY).change(c -> c.changePoly(toFirst0Polymorphic(0)).changePolyNamed(c0 -> c0.create("1", toFirst0Polymorphic(1))).changeEntity(c0 -> c0.changePoly(toFirst0Polymorphic(2)).changePolyNamed(c1 -> c1.create("3", toFirst0Polymorphic(3)))).changeEntityNamed(c0 -> c0.create("4", c1 -> c1.changePoly(toFirst0Polymorphic(4)).changePolyNamed(c2 -> c2.create("5", toFirst0Polymorphic(5)))))).get(1, SECONDS);
    } finally {
        registry.stop();
    }
}
Also used : TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) PolymorphicId(org.apache.ignite.configuration.annotation.PolymorphicId) ConfigurationRoot(org.apache.ignite.configuration.annotation.ConfigurationRoot) Consumer(java.util.function.Consumer) NamedConfigValue(org.apache.ignite.configuration.annotation.NamedConfigValue) Test(org.junit.jupiter.api.Test) ConfigValue(org.apache.ignite.configuration.annotation.ConfigValue) List(java.util.List) LOCAL(org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL) PolymorphicConfigInstance(org.apache.ignite.configuration.annotation.PolymorphicConfigInstance) Map(java.util.Map) Config(org.apache.ignite.configuration.annotation.Config) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) PolymorphicConfig(org.apache.ignite.configuration.annotation.PolymorphicConfig) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Value(org.apache.ignite.configuration.annotation.Value) InternalConfiguration(org.apache.ignite.configuration.annotation.InternalConfiguration) Test(org.junit.jupiter.api.Test)

Aggregations

List (java.util.List)5 Map (java.util.Map)5 LOCAL (org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL)5 TestConfigurationStorage (org.apache.ignite.internal.configuration.storage.TestConfigurationStorage)5 Test (org.junit.jupiter.api.Test)5 SECONDS (java.util.concurrent.TimeUnit.SECONDS)4 AfterEach (org.junit.jupiter.api.AfterEach)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 ConfigurationRegistry (org.apache.ignite.internal.configuration.ConfigurationRegistry)3 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)3 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)3 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)3 Config (org.apache.ignite.configuration.annotation.Config)2 ConfigValue (org.apache.ignite.configuration.annotation.ConfigValue)2 ConfigurationRoot (org.apache.ignite.configuration.annotation.ConfigurationRoot)2 NamedConfigValue (org.apache.ignite.configuration.annotation.NamedConfigValue)2 PolymorphicConfig (org.apache.ignite.configuration.annotation.PolymorphicConfig)2 PolymorphicConfigInstance (org.apache.ignite.configuration.annotation.PolymorphicConfigInstance)2 PolymorphicId (org.apache.ignite.configuration.annotation.PolymorphicId)2 Value (org.apache.ignite.configuration.annotation.Value)2