Search in sources :

Example 1 with WatchListenerInhibitor

use of org.apache.ignite.internal.test.WatchListenerInhibitor 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 WatchListenerInhibitor

use of org.apache.ignite.internal.test.WatchListenerInhibitor in project ignite-3 by apache.

the class ItTablesApiTest method testAddIndexFromLaggedNode.

/**
 * Tries to create an index which is already created from lagged node.
 *
 * @throws Exception If failed.
 */
@Test
public void testAddIndexFromLaggedNode() throws Exception {
    clusterNodes.forEach(ign -> assertNull(ign.tables().table(TABLE_NAME)));
    Ignite ignite0 = clusterNodes.get(0);
    createTable(ignite0, SCHEMA, SHORT_TABLE_NAME);
    Ignite ignite1 = clusterNodes.get(1);
    WatchListenerInhibitor ignite1Inhibitor = metastorageEventsInhibitor(ignite1);
    ignite1Inhibitor.startInhibit();
    addIndex(ignite0, SCHEMA, SHORT_TABLE_NAME);
    CompletableFuture addIndesFut = CompletableFuture.runAsync(() -> addIndex(ignite1, SCHEMA, SHORT_TABLE_NAME));
    CompletableFuture addIndesIfNotExistsFut = CompletableFuture.runAsync(() -> addIndexIfNotExists(ignite1, SCHEMA, SHORT_TABLE_NAME));
    for (Ignite ignite : clusterNodes) {
        if (ignite != ignite1) {
            assertThrows(IndexAlreadyExistsException.class, () -> addIndex(ignite, SCHEMA, SHORT_TABLE_NAME));
            addIndexIfNotExists(ignite, SCHEMA, SHORT_TABLE_NAME);
        }
    }
    assertFalse(addIndesFut.isDone());
    assertFalse(addIndesIfNotExistsFut.isDone());
    ignite1Inhibitor.stopInhibit();
    assertThrows(IndexAlreadyExistsException.class, () -> {
        try {
            addIndesFut.get(10, TimeUnit.SECONDS);
        } catch (ExecutionException e) {
            throw e.getCause();
        }
    });
    addIndesIfNotExistsFut.get(10, TimeUnit.SECONDS);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Ignite(org.apache.ignite.Ignite) WatchListenerInhibitor(org.apache.ignite.internal.test.WatchListenerInhibitor) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 3 with WatchListenerInhibitor

use of org.apache.ignite.internal.test.WatchListenerInhibitor in project ignite-3 by apache.

the class ItTablesApiTest method testAddColumnFromLaggedNode.

/**
 * Tries to create a column which is already created from lagged node.
 *
 * @throws Exception If failed.
 */
@Test
public void testAddColumnFromLaggedNode() throws Exception {
    clusterNodes.forEach(ign -> assertNull(ign.tables().table(TABLE_NAME)));
    Ignite ignite0 = clusterNodes.get(0);
    createTable(ignite0, SCHEMA, SHORT_TABLE_NAME);
    Ignite ignite1 = clusterNodes.get(1);
    WatchListenerInhibitor ignite1Inhibitor = metastorageEventsInhibitor(ignite1);
    ignite1Inhibitor.startInhibit();
    addColumn(ignite0, SCHEMA, SHORT_TABLE_NAME);
    CompletableFuture addColFut = CompletableFuture.runAsync(() -> addColumn(ignite1, SCHEMA, SHORT_TABLE_NAME));
    CompletableFuture addColIfNotExistsFut = CompletableFuture.runAsync(() -> addColumnIfNotExists(ignite1, SCHEMA, SHORT_TABLE_NAME));
    for (Ignite ignite : clusterNodes) {
        if (ignite != ignite1) {
            assertThrows(ColumnAlreadyExistsException.class, () -> addColumn(ignite, SCHEMA, SHORT_TABLE_NAME));
            addColumnIfNotExists(ignite, SCHEMA, SHORT_TABLE_NAME);
        }
    }
    assertFalse(addColFut.isDone());
    assertFalse(addColIfNotExistsFut.isDone());
    ignite1Inhibitor.stopInhibit();
    assertThrows(ColumnAlreadyExistsException.class, () -> {
        try {
            addColFut.get(10, TimeUnit.SECONDS);
        } catch (ExecutionException e) {
            throw e.getCause();
        }
    });
    addColIfNotExistsFut.get(10, TimeUnit.SECONDS);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Ignite(org.apache.ignite.Ignite) WatchListenerInhibitor(org.apache.ignite.internal.test.WatchListenerInhibitor) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 4 with WatchListenerInhibitor

use of org.apache.ignite.internal.test.WatchListenerInhibitor in project ignite-3 by apache.

the class ItTablesApiTest method testTableAlreadyCreatedFromLaggedNode.

/**
 * Tries to create a table which is already created from lagged node.
 *
 * @throws Exception If failed.
 */
@Test
public void testTableAlreadyCreatedFromLaggedNode() throws Exception {
    clusterNodes.forEach(ign -> assertNull(ign.tables().table(TABLE_NAME)));
    Ignite ignite0 = clusterNodes.get(0);
    Ignite ignite1 = clusterNodes.get(1);
    WatchListenerInhibitor ignite1Inhibitor = metastorageEventsInhibitor(ignite1);
    ignite1Inhibitor.startInhibit();
    createTable(ignite0, SCHEMA, SHORT_TABLE_NAME);
    CompletableFuture createTblFut = CompletableFuture.runAsync(() -> createTable(ignite1, SCHEMA, SHORT_TABLE_NAME));
    CompletableFuture createTblIfNotExistsFut = CompletableFuture.supplyAsync(() -> createTableIfNotExists(ignite1, SCHEMA, SHORT_TABLE_NAME));
    for (Ignite ignite : clusterNodes) {
        if (ignite != ignite1) {
            assertThrows(TableAlreadyExistsException.class, () -> createTable(ignite, SCHEMA, SHORT_TABLE_NAME));
            assertNotNull(createTableIfNotExists(ignite, SCHEMA, SHORT_TABLE_NAME));
        }
    }
    assertFalse(createTblFut.isDone());
    assertFalse(createTblIfNotExistsFut.isDone());
    ignite1Inhibitor.stopInhibit();
    assertThrows(TableAlreadyExistsException.class, () -> {
        try {
            createTblFut.get(10, TimeUnit.SECONDS);
        } catch (ExecutionException e) {
            throw e.getCause();
        }
    });
    assertNotNull(createTblIfNotExistsFut.get(10, TimeUnit.SECONDS));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Ignite(org.apache.ignite.Ignite) WatchListenerInhibitor(org.apache.ignite.internal.test.WatchListenerInhibitor) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Example 5 with WatchListenerInhibitor

use of org.apache.ignite.internal.test.WatchListenerInhibitor in project ignite-3 by apache.

the class ItTablesApiTest method testGetTableFromLaggedNode.

/**
 * Test scenario when we have lagged node, and tables with the same name are deleted and created again.
 *
 * @throws Exception If failed.
 */
@Test
public void testGetTableFromLaggedNode() throws Exception {
    clusterNodes.forEach(ign -> assertNull(ign.tables().table(TABLE_NAME)));
    Ignite ignite0 = clusterNodes.get(0);
    Ignite ignite1 = clusterNodes.get(1);
    Table tbl = createTable(ignite0, SCHEMA, SHORT_TABLE_NAME);
    Tuple tableKey = Tuple.create().set("key", 123L);
    Tuple value = Tuple.create().set("valInt", 1234).set("valStr", "some string row");
    tbl.keyValueView().put(null, tableKey, value);
    assertEquals(value, tbl.keyValueView().get(null, tableKey));
    assertEquals(value, ignite1.tables().table(TABLE_NAME).keyValueView().get(null, tableKey));
    WatchListenerInhibitor ignite1Inhibitor = metastorageEventsInhibitor(ignite1);
    ignite1Inhibitor.startInhibit();
    Tuple otherValue = Tuple.create().set("valInt", 12345).set("valStr", "some other string row");
    tbl.keyValueView().put(null, tableKey, otherValue);
    assertEquals(otherValue, tbl.keyValueView().get(null, tableKey));
    ignite1Inhibitor.stopInhibit();
    assertEquals(otherValue, ignite1.tables().table(TABLE_NAME).keyValueView().get(null, tableKey));
}
Also used : Table(org.apache.ignite.table.Table) Ignite(org.apache.ignite.Ignite) WatchListenerInhibitor(org.apache.ignite.internal.test.WatchListenerInhibitor) Tuple(org.apache.ignite.table.Tuple) Test(org.junit.jupiter.api.Test) IgniteAbstractTest(org.apache.ignite.internal.testframework.IgniteAbstractTest)

Aggregations

Ignite (org.apache.ignite.Ignite)6 WatchListenerInhibitor (org.apache.ignite.internal.test.WatchListenerInhibitor)6 IgniteAbstractTest (org.apache.ignite.internal.testframework.IgniteAbstractTest)6 Test (org.junit.jupiter.api.Test)6 CompletableFuture (java.util.concurrent.CompletableFuture)4 ExecutionException (java.util.concurrent.ExecutionException)3 Table (org.apache.ignite.table.Table)3 TableImpl (org.apache.ignite.internal.table.TableImpl)2 Tuple (org.apache.ignite.table.Tuple)2 Lists (com.google.common.collect.Lists)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 TimeUnit (java.util.concurrent.TimeUnit)1 IgnitionManager (org.apache.ignite.IgnitionManager)1 IgniteImpl (org.apache.ignite.internal.app.IgniteImpl)1 SchemaConfigurationConverter.convert (org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter.convert)1 IgniteTablesInternal (org.apache.ignite.internal.table.IgniteTablesInternal)1