vldpyatkov commented on a change in pull request #441:
URL: https://github.com/apache/ignite-3/pull/441#discussion_r752402116
##########
File path:
modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItTablesApiTest.java
##########
@@ -104,97 +114,308 @@
/** Cluster nodes. */
private List<Ignite> clusterNodes;
-
+
/**
* Before each.
*/
@BeforeEach
void beforeEach(TestInfo testInfo) throws Exception {
String metastorageNodeName = IgniteTestUtils.testNodeName(testInfo, 0);
-
+
clusterNodes = IntStream.range(0,
nodesBootstrapCfg.size()).mapToObj(value -> {
String nodeName = IgniteTestUtils.testNodeName(testInfo,
value);
-
+
return IgnitionManager.start(
nodeName,
nodesBootstrapCfg.get(value).apply(metastorageNodeName),
workDir.resolve(nodeName));
}
).collect(Collectors.toList());
}
-
+
/**
* After each.
*/
@AfterEach
void afterEach() throws Exception {
IgniteUtils.closeAll(ItUtils.reverse(clusterNodes));
}
+
+ /**
+ * Trys to create a table which is already created.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testTableAlreadyCreated() throws Exception {
+ clusterNodes.forEach(ign ->
assertNull(ign.tables().table(TABLE_NAME)));
+
+ Ignite ignite0 = clusterNodes.get(0);
+
+ Table tbl = createTable(ignite0, SCHEMA, SHORT_TABLE_NAME);
+
+ assertThrows(TableAlreadyExistsException.class,
+ () -> createTable(ignite0, SCHEMA, SHORT_TABLE_NAME));
+
+ assertEquals(tbl, createTableIfNotExists(ignite0, SCHEMA,
SHORT_TABLE_NAME));
+ }
/**
- * Checks that if a table would be created/dropped into any cluster node,
this is visible to all other nodes.
+ * Trys to create a table which is already created from lagged node.
*
* @throws Exception If failed.
*/
@Test
- public void testCreateDropTable() throws Exception {
+ @Disabled("IGNITE-15891 Configuration use local state cache internally,
but have to look at consensus")
+ 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 =
WatchListenerInhibitor.metastorageEventsInhibitor(ignite1);
+ WatchListenerInhibitor ignite1Inhibitor =
metastorageEventsInhibitor(ignite1);
ignite1Inhibitor.startInhibit();
- Table table = createTable(clusterNodes.get(0), SCHEMA,
SHORT_TABLE_NAME);
+ createTable(ignite0, SCHEMA, SHORT_TABLE_NAME);
+
+ CompletableFuture createTblFut = CompletableFuture.runAsync(() ->
createTable(ignite1, SCHEMA, SHORT_TABLE_NAME));
+ CompletableFuture createTblIfNotExistsFut = CompletableFuture
+ .runAsync(() -> createTableIfNotExists(ignite1, SCHEMA,
SHORT_TABLE_NAME));
- IgniteUuid tblId = ((TableImpl) table).tableId();
+ 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));
+ }
+
+ /**
+ * Trys to create an index which is already created.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testAddIndex() throws Exception {
+ clusterNodes.forEach(ign ->
assertNull(ign.tables().table(TABLE_NAME)));
+
+ Ignite ignite0 = clusterNodes.get(0);
+
+ createTable(ignite0, SCHEMA, SHORT_TABLE_NAME);
+
+ addIndex(ignite0, SCHEMA, SHORT_TABLE_NAME);
+
+ assertThrows(IndexAlreadyExistsException.class,
+ () -> addIndex(ignite0, SCHEMA, SHORT_TABLE_NAME));
+
+ addIndexIfNotExists(ignite0, SCHEMA, SHORT_TABLE_NAME);
+ }
+
+ /**
+ * Trys to create an index which is already created from lagged node.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ @Disabled("IGNITE-15891 Configuration use local state cache internally,
but have to look at consensus")
+ 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);
+ }
+
+ /**
+ * Trys to create a column which is already created.
+ *
+ * @throws Exception If failed.
+ */
+ @Test
+ public void testAddColumn() throws Exception {
+ clusterNodes.forEach(ign ->
assertNull(ign.tables().table(TABLE_NAME)));
+
+ Ignite ignite0 = clusterNodes.get(0);
+
+ createTable(ignite0, SCHEMA, SHORT_TABLE_NAME);
+
+ addColumn(ignite0, SCHEMA, SHORT_TABLE_NAME);
Review comment:
Do you see an issue in delete column implementation?
It just a demonstration.
##########
File path:
modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ItTablesApiTest.java
##########
@@ -204,12 +425,135 @@ public void testCreateDropTable() throws Exception {
*/
protected Table createTable(Ignite node, String schemaName, String
shortTableName) {
return node.tables().createTable(
- schemaName + "." + shortTableName, tblCh ->
convert(SchemaBuilders.tableBuilder(schemaName, shortTableName).columns(
- SchemaBuilders.column("key",
ColumnType.INT64).asNonNull().build(),
- SchemaBuilders.column("valInt",
ColumnType.INT32).asNullable().build(),
- SchemaBuilders.column("valStr",
ColumnType.string()).withDefaultValueExpression("default").build()
+ schemaName + "." + shortTableName,
+ tblCh -> convert(SchemaBuilders.tableBuilder(schemaName,
shortTableName).columns(
+ SchemaBuilders.column("key",
ColumnType.INT64).asNonNull().build(),
+ SchemaBuilders.column("valInt",
ColumnType.INT32).asNullable().build(),
+ SchemaBuilders.column("valStr", ColumnType.string())
+ .withDefaultValueExpression("default").build()
+ ).withPrimaryKey("key").build(),
+ tblCh).changeReplicas(2).changePartitions(10)
+ );
+ }
+
+ /**
+ * Adds an index if it does not exist.
+ *
+ * @param node Cluster node.
+ * @param schemaName Schema name.
+ * @param shortTableName Table name.
+ */
+ protected Table createTableIfNotExists(Ignite node, String schemaName,
String shortTableName) {
+ return node.tables().createTableIfNotExists(
+ schemaName + "." + shortTableName,
+ tblCh -> convert(SchemaBuilders.tableBuilder(schemaName,
shortTableName).columns(
+ SchemaBuilders.column("key",
ColumnType.INT64).asNonNull().build(),
+ SchemaBuilders.column("valInt",
ColumnType.INT32).asNullable().build(),
+ SchemaBuilders.column("valStr", ColumnType.string())
+ .withDefaultValueExpression("default").build()
).withPrimaryKey("key").build(),
tblCh).changeReplicas(2).changePartitions(10)
);
}
+
+ /**
+ * Adds an index.
+ *
+ * @param node Cluster node.
+ * @param schemaName Schema name.
+ * @param shortTableName Table name.
+ */
+ protected void addColumn(Ignite node, String schemaName, String
shortTableName) {
+ ColumnDefinition col = SchemaBuilders.column("valStrNew",
ColumnType.string()).asNullable()
+ .withDefaultValueExpression("default").build();
+
+ addColumnInternal(node, schemaName, shortTableName, col);
+ }
+
+ /**
+ * Adds a column according to the column definition.
+ *
+ * @param node Ignite node.
+ * @param schemaName Schema name.
+ * @param shortTableName Table name.
+ * @param colDefinition Column defenition.
+ */
+ private void addColumnInternal(Ignite node, String schemaName, String
shortTableName, ColumnDefinition colDefinition) {
+ node.tables().alterTable(
+ schemaName + "." + shortTableName,
Review comment:
I think we must do it. But it is not a part of the issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]