Search in sources :

Example 1 with IgniteImpl

use of org.apache.ignite.internal.app.IgniteImpl in project ignite-3 by apache.

the class ItDataSchemaSyncTest method test.

/**
 * The test executes various operation over the lagging node.
 * The operations can be executed only the node overtakes a distributed cluster state.
 */
@Test
public void test() throws Exception {
    Ignite ignite0 = clusterNodes.get(0);
    final IgniteImpl ignite1 = (IgniteImpl) clusterNodes.get(1);
    createTable(ignite0, SCHEMA, SHORT_TABLE_NAME);
    TableImpl table = (TableImpl) ignite0.tables().table(TABLE_NAME);
    assertEquals(1, table.schemaView().schema().version());
    for (int i = 0; i < 10; i++) {
        table.recordView().insert(null, Tuple.create().set("key", (long) i).set("valInt", i).set("valStr", "str_" + i));
    }
    WatchListenerInhibitor listenerInhibitor = WatchListenerInhibitor.metastorageEventsInhibitor(ignite1);
    listenerInhibitor.startInhibit();
    ColumnDefinition columnDefinition = SchemaBuilders.column("valStr2", ColumnType.string()).withDefaultValueExpression("default").build();
    ignite0.tables().alterTable(TABLE_NAME, tblChanger -> tblChanger.changeColumns(cols -> cols.create(columnDefinition.name(), colChg -> convert(columnDefinition, colChg))));
    for (Ignite node : clusterNodes) {
        if (node == ignite1) {
            continue;
        }
        TableImpl tableOnNode = (TableImpl) node.tables().table(TABLE_NAME);
        IgniteTestUtils.waitForCondition(() -> tableOnNode.schemaView().lastSchemaVersion() == 2, 10_000);
    }
    TableImpl table1 = (TableImpl) ignite1.tables().table(TABLE_NAME);
    for (int i = 10; i < 20; i++) {
        table.recordView().insert(null, Tuple.create().set("key", (long) i).set("valInt", i).set("valStr", "str_" + i).set("valStr2", "str2_" + i));
    }
    final CompletableFuture insertFut = IgniteTestUtils.runAsync(() -> table1.recordView().insert(null, Tuple.create().set("key", 0L).set("valInt", 0).set("valStr", "str_" + 0).set("valStr2", "str2_" + 0)));
    final CompletableFuture getFut = IgniteTestUtils.runAsync(() -> {
        table1.recordView().get(null, Tuple.create().set("key", 10L));
    });
    final CompletableFuture checkDefaultFut = IgniteTestUtils.runAsync(() -> {
        assertEquals("default", table1.recordView().get(null, Tuple.create().set("key", 0L)).value("valStr2"));
    });
    assertEquals(1, table1.schemaView().lastSchemaVersion());
    assertFalse(getFut.isDone());
    assertFalse(insertFut.isDone());
    assertFalse(checkDefaultFut.isDone());
    listenerInhibitor.stopInhibit();
    getFut.get(10, TimeUnit.SECONDS);
    insertFut.get(10, TimeUnit.SECONDS);
    checkDefaultFut.get(10, TimeUnit.SECONDS);
    for (Ignite node : clusterNodes) {
        Table tableOnNode = node.tables().table(TABLE_NAME);
        for (int i = 0; i < 20; i++) {
            Tuple row = tableOnNode.recordView().get(null, Tuple.create().set("key", (long) i));
            assertNotNull(row);
            assertEquals(i, row.intValue("valInt"));
            assertEquals("str_" + i, row.value("valStr"));
            assertEquals(i < 10 ? "default" : ("str2_" + i), row.value("valStr2"));
        }
    }
}
Also used : IgniteImpl(org.apache.ignite.internal.app.IgniteImpl) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) BeforeEach(org.junit.jupiter.api.BeforeEach) SchemaConfigurationConverter.convert(org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter.convert) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) WatchListenerInhibitor(org.apache.ignite.internal.test.WatchListenerInhibitor) Lists(com.google.common.collect.Lists) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) TableImpl(org.apache.ignite.internal.table.TableImpl) Map(java.util.Map) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) ColumnDefinition(org.apache.ignite.schema.definition.ColumnDefinition) Ignite(org.apache.ignite.Ignite) ColumnType(org.apache.ignite.schema.definition.ColumnType) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) IgnitionManager(org.apache.ignite.IgnitionManager) IgniteTestUtils(org.apache.ignite.internal.testframework.IgniteTestUtils) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest) SchemaBuilders(org.apache.ignite.schema.SchemaBuilders) WorkDirectoryExtension(org.apache.ignite.internal.testframework.WorkDirectoryExtension) Table(org.apache.ignite.table.Table) Tuple(org.apache.ignite.table.Tuple) CompletableFuture(java.util.concurrent.CompletableFuture) Table(org.apache.ignite.table.Table) IgniteImpl(org.apache.ignite.internal.app.IgniteImpl) TableImpl(org.apache.ignite.internal.table.TableImpl) Ignite(org.apache.ignite.Ignite) WatchListenerInhibitor(org.apache.ignite.internal.test.WatchListenerInhibitor) Tuple(org.apache.ignite.table.Tuple) ColumnDefinition(org.apache.ignite.schema.definition.ColumnDefinition) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 2 with IgniteImpl

use of org.apache.ignite.internal.app.IgniteImpl in project ignite-3 by apache.

the class PlatformTestNodeRunner method main.

/**
 * Entry point.
 *
 * @param args Args.
 */
public static void main(String[] args) throws Exception {
    System.out.println("Starting test node runner...");
    for (int i = 0; i < args.length; i++) {
        System.out.println("Arg " + i + ": " + args[i]);
    }
    if (args.length > 0 && "dry-run".equals(args[0])) {
        System.out.println("Dry run succeeded.");
        return;
    }
    IgniteUtils.deleteIfExists(BASE_PATH);
    Files.createDirectories(BASE_PATH);
    List<Ignite> startedNodes = new ArrayList<>();
    nodesBootstrapCfg.forEach((nodeName, configStr) -> startedNodes.add(IgnitionManager.start(nodeName, configStr, BASE_PATH.resolve(nodeName))));
    var keyCol = "key";
    var valCol = "val";
    TableDefinition schTbl = SchemaBuilders.tableBuilder(SCHEMA_NAME, TABLE_NAME).columns(SchemaBuilders.column(keyCol, ColumnType.INT64).build(), SchemaBuilders.column(valCol, ColumnType.string()).asNullable(true).build()).withPrimaryKey(keyCol).build();
    startedNodes.get(0).tables().createTable(schTbl.canonicalName(), tblCh -> SchemaConfigurationConverter.convert(schTbl, tblCh).changeReplicas(1).changePartitions(10));
    String ports = startedNodes.stream().map(n -> String.valueOf(getPort((IgniteImpl) n))).collect(Collectors.joining(","));
    System.out.println("THIN_CLIENT_PORTS=" + ports);
    Thread.sleep(RUN_TIME_MINUTES * 60_000);
    System.out.println("Exiting after " + RUN_TIME_MINUTES + " minutes.");
}
Also used : IgniteImpl(org.apache.ignite.internal.app.IgniteImpl) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Files(java.nio.file.Files) SchemaConfigurationConverter(org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter) Ignite(org.apache.ignite.Ignite) ColumnType(org.apache.ignite.schema.definition.ColumnType) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) IgnitionManager(org.apache.ignite.IgnitionManager) List(java.util.List) Map(java.util.Map) IgniteUtils(org.apache.ignite.internal.util.IgniteUtils) SchemaBuilders(org.apache.ignite.schema.SchemaBuilders) Path(java.nio.file.Path) IgniteImpl(org.apache.ignite.internal.app.IgniteImpl) ArrayList(java.util.ArrayList) TableDefinition(org.apache.ignite.schema.definition.TableDefinition) Ignite(org.apache.ignite.Ignite)

Example 3 with IgniteImpl

use of org.apache.ignite.internal.app.IgniteImpl in project ignite-3 by apache.

the class ItIgniteNodeRestartTest method twoCustomPropertiesTest.

/**
 * Checks that the only one non-default property overwrites after another configuration is passed on the node restart.
 */
@Test
public void twoCustomPropertiesTest(TestInfo testInfo) {
    String nodeName = testNodeName(testInfo, 3344);
    String startCfg = "network: {\n" + "  port:3344,\n" + "  nodeFinder: {netClusterNodes:[ \"localhost:3344\" ]}\n" + "}";
    IgniteImpl ignite = (IgniteImpl) IgnitionManager.start(nodeName, startCfg, workDir);
    assertEquals(3344, ignite.nodeConfiguration().getConfiguration(NetworkConfiguration.KEY).port().value());
    assertArrayEquals(new String[] { "localhost:3344" }, ignite.nodeConfiguration().getConfiguration(NetworkConfiguration.KEY).nodeFinder().netClusterNodes().value());
    IgnitionManager.stop(ignite.name());
    ignite = (IgniteImpl) IgnitionManager.start(nodeName, "network.nodeFinder.netClusterNodes=[ \"localhost:3344\", \"localhost:3343\" ]", workDir);
    assertEquals(3344, ignite.nodeConfiguration().getConfiguration(NetworkConfiguration.KEY).port().value());
    assertArrayEquals(new String[] { "localhost:3344", "localhost:3343" }, ignite.nodeConfiguration().getConfiguration(NetworkConfiguration.KEY).nodeFinder().netClusterNodes().value());
    IgnitionManager.stop(ignite.name());
}
Also used : IgniteImpl(org.apache.ignite.internal.app.IgniteImpl) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 4 with IgniteImpl

use of org.apache.ignite.internal.app.IgniteImpl in project ignite-3 by apache.

the class ItIgniteNodeRestartTest method emptyNodeTest.

/**
 * Restarts empty node.
 */
@Test
public void emptyNodeTest(TestInfo testInfo) {
    String nodeName = testNodeName(testInfo, DEFAULT_NODE_PORT);
    IgniteImpl ignite = (IgniteImpl) IgnitionManager.start(nodeName, null, workDir);
    int nodePort = ignite.nodeConfiguration().getConfiguration(NetworkConfiguration.KEY).port().value();
    assertEquals(DEFAULT_NODE_PORT, nodePort);
    IgnitionManager.stop(ignite.name());
    ignite = (IgniteImpl) IgnitionManager.start(nodeName, null, workDir);
    nodePort = ignite.nodeConfiguration().getConfiguration(NetworkConfiguration.KEY).port().value();
    assertEquals(DEFAULT_NODE_PORT, nodePort);
    IgnitionManager.stop(ignite.name());
}
Also used : IgniteImpl(org.apache.ignite.internal.app.IgniteImpl) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 5 with IgniteImpl

use of org.apache.ignite.internal.app.IgniteImpl in project ignite-3 by apache.

the class ItIgniteNodeRestartTest method changeConfigurationOnStartTest.

/**
 * Restarts a node with changing configuration.
 */
@Test
public void changeConfigurationOnStartTest(TestInfo testInfo) {
    String nodeName = testNodeName(testInfo, DEFAULT_NODE_PORT);
    IgniteImpl ignite = (IgniteImpl) IgnitionManager.start(nodeName, null, workDir);
    int nodePort = ignite.nodeConfiguration().getConfiguration(NetworkConfiguration.KEY).port().value();
    assertEquals(DEFAULT_NODE_PORT, nodePort);
    IgnitionManager.stop(ignite.name());
    int newPort = 3322;
    String updateCfg = "network.port=" + newPort;
    ignite = (IgniteImpl) IgnitionManager.start(nodeName, updateCfg, workDir);
    nodePort = ignite.nodeConfiguration().getConfiguration(NetworkConfiguration.KEY).port().value();
    assertEquals(newPort, nodePort);
    IgnitionManager.stop(ignite.name());
}
Also used : IgniteImpl(org.apache.ignite.internal.app.IgniteImpl) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Aggregations

IgniteImpl (org.apache.ignite.internal.app.IgniteImpl)5 IgniteAbstractTest (org.apache.ignite.internal.testframework.IgniteAbstractTest)4 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Map (java.util.Map)2 Ignite (org.apache.ignite.Ignite)2 IgnitionManager (org.apache.ignite.IgnitionManager)2 IgniteUtils (org.apache.ignite.internal.util.IgniteUtils)2 SchemaBuilders (org.apache.ignite.schema.SchemaBuilders)2 ColumnType (org.apache.ignite.schema.definition.ColumnType)2 TableDefinition (org.apache.ignite.schema.definition.TableDefinition)2 Lists (com.google.common.collect.Lists)1 InetSocketAddress (java.net.InetSocketAddress)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1