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"));
}
}
}
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);
}
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);
}
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));
}
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));
}
Aggregations