Search in sources :

Example 1 with TestConfigurationStorage

use of org.apache.ignite.internal.configuration.storage.TestConfigurationStorage in project ignite-3 by apache.

the class SchemaConfigurationConverterTest method createRegistry.

/**
 * Prepare configuration registry for test.
 *
 * @throws ExecutionException If failed.
 * @throws InterruptedException If failed.
 */
@BeforeEach
public void createRegistry() throws ExecutionException, InterruptedException {
    confRegistry = new ConfigurationRegistry(List.of(TablesConfiguration.KEY, DataStorageConfiguration.KEY), Map.of(TableValidator.class, Set.of(TableValidatorImpl.INSTANCE)), new TestConfigurationStorage(DISTRIBUTED), List.of(), List.of(HashIndexConfigurationSchema.class, SortedIndexConfigurationSchema.class, PartialIndexConfigurationSchema.class, RocksDbDataRegionConfigurationSchema.class));
    confRegistry.start();
    tblBuilder = SchemaBuilders.tableBuilder("SNAME", "TNAME").columns(SchemaBuilders.column("COL1", ColumnType.DOUBLE).build(), SchemaBuilders.column("COL2", ColumnType.DOUBLE).build(), SchemaBuilders.column("A", ColumnType.INT8).build(), SchemaBuilders.column("B", ColumnType.INT8).build(), SchemaBuilders.column("C", ColumnType.INT8).build()).withPrimaryKey("COL1");
    TableDefinition tbl = tblBuilder.build();
    confRegistry.getConfiguration(TablesConfiguration.KEY).change(ch -> SchemaConfigurationConverter.createTable(tbl, ch).changeTables(tblsCh -> tblsCh.createOrUpdate(tbl.canonicalName(), tblCh -> tblCh.changeReplicas(1)))).get();
}
Also used : TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) HashIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.HashIndexConfigurationSchema) SortedIndexDefinitionBuilder(org.apache.ignite.schema.definition.builder.SortedIndexDefinitionBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach) IndexColumnDefinition(org.apache.ignite.schema.definition.index.IndexColumnDefinition) SortOrder(org.apache.ignite.schema.definition.index.SortOrder) HashIndexDefinition(org.apache.ignite.schema.definition.index.HashIndexDefinition) DISTRIBUTED(org.apache.ignite.configuration.annotation.ConfigurationType.DISTRIBUTED) TableConfiguration(org.apache.ignite.configuration.schemas.table.TableConfiguration) PartialIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.PartialIndexConfigurationSchema) SortedIndexConfigurationSchema(org.apache.ignite.configuration.schemas.table.SortedIndexConfigurationSchema) HashIndexDefinitionBuilder(org.apache.ignite.schema.definition.builder.HashIndexDefinitionBuilder) Disabled(org.junit.jupiter.api.Disabled) Map(java.util.Map) RocksDbDataRegionConfigurationSchema(org.apache.ignite.configuration.schemas.store.RocksDbDataRegionConfigurationSchema) SortedIndexDefinition(org.apache.ignite.schema.definition.index.SortedIndexDefinition) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IndexDefinition(org.apache.ignite.schema.definition.index.IndexDefinition) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Collection(java.util.Collection) DataStorageConfiguration(org.apache.ignite.configuration.schemas.store.DataStorageConfiguration) TablesConfiguration(org.apache.ignite.configuration.schemas.table.TablesConfiguration) PartialIndexDefinition(org.apache.ignite.schema.definition.index.PartialIndexDefinition) Set(java.util.Set) PartialIndexDefinitionBuilder(org.apache.ignite.schema.definition.builder.PartialIndexDefinitionBuilder) TableValidator(org.apache.ignite.configuration.schemas.table.TableValidator) ColumnType(org.apache.ignite.schema.definition.ColumnType) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) TableDefinitionBuilder(org.apache.ignite.schema.definition.builder.TableDefinitionBuilder) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) ConfigurationRegistry(org.apache.ignite.internal.configuration.ConfigurationRegistry) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) SchemaBuilders(org.apache.ignite.schema.SchemaBuilders) Collections(java.util.Collections) ConfigurationRegistry(org.apache.ignite.internal.configuration.ConfigurationRegistry) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with TestConfigurationStorage

use of org.apache.ignite.internal.configuration.storage.TestConfigurationStorage 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 3 with TestConfigurationStorage

use of org.apache.ignite.internal.configuration.storage.TestConfigurationStorage 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 4 with TestConfigurationStorage

use of org.apache.ignite.internal.configuration.storage.TestConfigurationStorage in project ignite-3 by apache.

the class ClusterServiceTestUtils method clusterService.

/**
 * Creates a cluster service and required node configuration manager beneath it. Populates node configuration with specified port.
 * Manages configuration manager lifecycle: on cluster service start starts node configuration manager, on cluster service stop - stops
 * node configuration manager.
 *
 * @param testInfo                 Test info.
 * @param port                     Local port.
 * @param nodeFinder               Node finder.
 * @param clusterSvcFactory        Cluster service factory.
 */
public static ClusterService clusterService(TestInfo testInfo, int port, NodeFinder nodeFinder, TestScaleCubeClusterServiceFactory clusterSvcFactory) {
    var registry = new MessageSerializationRegistryImpl();
    REGISTRY_INITIALIZERS.forEach(c -> {
        try {
            c.invoke(c.getDeclaringClass(), registry);
        } catch (Throwable e) {
            throw new RuntimeException("Failed to invoke registry initializer", e);
        }
    });
    var ctx = new ClusterLocalConfiguration(testNodeName(testInfo, port), registry);
    ConfigurationManager nodeConfigurationMgr = new ConfigurationManager(Collections.singleton(NetworkConfiguration.KEY), Map.of(), new TestConfigurationStorage(ConfigurationType.LOCAL), List.of(), List.of());
    NetworkConfiguration configuration = nodeConfigurationMgr.configurationRegistry().getConfiguration(NetworkConfiguration.KEY);
    var bootstrapFactory = new NettyBootstrapFactory(configuration, ctx.getName());
    var clusterSvc = clusterSvcFactory.createClusterService(ctx, configuration, bootstrapFactory);
    assert nodeFinder instanceof StaticNodeFinder : "Only StaticNodeFinder is supported at the moment";
    return new ClusterService() {

        @Override
        public TopologyService topologyService() {
            return clusterSvc.topologyService();
        }

        @Override
        public MessagingService messagingService() {
            return clusterSvc.messagingService();
        }

        @Override
        public ClusterLocalConfiguration localConfiguration() {
            return clusterSvc.localConfiguration();
        }

        @Override
        public boolean isStopped() {
            return clusterSvc.isStopped();
        }

        @Override
        public void start() {
            nodeConfigurationMgr.start();
            NetworkConfiguration configuration = nodeConfigurationMgr.configurationRegistry().getConfiguration(NetworkConfiguration.KEY);
            configuration.change(netCfg -> netCfg.changePort(port).changeNodeFinder(c -> c.changeType(NodeFinderType.STATIC.toString()).changeNetClusterNodes(nodeFinder.findNodes().stream().map(NetworkAddress::toString).toArray(String[]::new)))).join();
            bootstrapFactory.start();
            clusterSvc.start();
        }

        @Override
        public void stop() {
            try {
                clusterSvc.stop();
                bootstrapFactory.stop();
                nodeConfigurationMgr.stop();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
}
Also used : IntStream(java.util.stream.IntStream) ClassGraph(io.github.classgraph.ClassGraph) NodeFinderType(org.apache.ignite.configuration.schemas.network.NodeFinderType) NettyBootstrapFactory(org.apache.ignite.network.NettyBootstrapFactory) ConfigurationType(org.apache.ignite.configuration.annotation.ConfigurationType) IgniteTestUtils.testNodeName(org.apache.ignite.internal.testframework.IgniteTestUtils.testNodeName) Collectors.toUnmodifiableList(java.util.stream.Collectors.toUnmodifiableList) ArrayList(java.util.ArrayList) TestScaleCubeClusterServiceFactory(org.apache.ignite.network.scalecube.TestScaleCubeClusterServiceFactory) NetworkConfiguration(org.apache.ignite.configuration.schemas.network.NetworkConfiguration) Map(java.util.Map) NodeFinder(org.apache.ignite.network.NodeFinder) ScanResult(io.github.classgraph.ScanResult) Method(java.lang.reflect.Method) MessagingService(org.apache.ignite.network.MessagingService) MessageSerializationRegistryInitializer(org.apache.ignite.network.serialization.MessageSerializationRegistryInitializer) TopologyService(org.apache.ignite.network.TopologyService) ClusterLocalConfiguration(org.apache.ignite.network.ClusterLocalConfiguration) ClassInfo(io.github.classgraph.ClassInfo) ConfigurationManager(org.apache.ignite.internal.configuration.ConfigurationManager) TestInfo(org.junit.jupiter.api.TestInfo) NetworkAddress(org.apache.ignite.network.NetworkAddress) List(java.util.List) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) MessageSerializationRegistry(org.apache.ignite.network.serialization.MessageSerializationRegistry) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) ClusterService(org.apache.ignite.network.ClusterService) NetworkMessagesSerializationRegistryInitializer(org.apache.ignite.internal.network.NetworkMessagesSerializationRegistryInitializer) MessageSerializationRegistryImpl(org.apache.ignite.network.MessageSerializationRegistryImpl) Collections(java.util.Collections) StaticNodeFinder(org.apache.ignite.network.StaticNodeFinder) TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) NettyBootstrapFactory(org.apache.ignite.network.NettyBootstrapFactory) ClusterService(org.apache.ignite.network.ClusterService) MessageSerializationRegistryImpl(org.apache.ignite.network.MessageSerializationRegistryImpl) NetworkConfiguration(org.apache.ignite.configuration.schemas.network.NetworkConfiguration) ClusterLocalConfiguration(org.apache.ignite.network.ClusterLocalConfiguration) ConfigurationManager(org.apache.ignite.internal.configuration.ConfigurationManager)

Example 5 with TestConfigurationStorage

use of org.apache.ignite.internal.configuration.storage.TestConfigurationStorage in project ignite-3 by apache.

the class ConfigurationListenerTest method before.

/**
 * Before each.
 */
@BeforeEach
public void before() {
    storage = new TestConfigurationStorage(LOCAL);
    registry = new ConfigurationRegistry(List.of(ParentConfiguration.KEY), Map.of(), storage, List.of(InternalChildConfigurationSchema.class), List.of(StringPolyConfigurationSchema.class, LongPolyConfigurationSchema.class));
    registry.start();
    registry.initializeDefaults();
    config = registry.getConfiguration(ParentConfiguration.KEY);
}
Also used : TestConfigurationStorage(org.apache.ignite.internal.configuration.storage.TestConfigurationStorage) ConfigurationRegistry(org.apache.ignite.internal.configuration.ConfigurationRegistry) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

TestConfigurationStorage (org.apache.ignite.internal.configuration.storage.TestConfigurationStorage)15 Test (org.junit.jupiter.api.Test)9 List (java.util.List)7 Map (java.util.Map)7 ConfigurationRegistry (org.apache.ignite.internal.configuration.ConfigurationRegistry)7 BeforeEach (org.junit.jupiter.api.BeforeEach)6 LOCAL (org.apache.ignite.configuration.annotation.ConfigurationType.LOCAL)5 AfterEach (org.junit.jupiter.api.AfterEach)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5 SECONDS (java.util.concurrent.TimeUnit.SECONDS)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 ConfigValue (org.apache.ignite.configuration.annotation.ConfigValue)3 Value (org.apache.ignite.configuration.annotation.Value)3 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)3 Collections (java.util.Collections)2 Config (org.apache.ignite.configuration.annotation.Config)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