keith-turner commented on code in PR #5323:
URL: https://github.com/apache/accumulo/pull/5323#discussion_r1951783320


##########
test/src/main/java/org/apache/accumulo/test/TableOperationsIT.java:
##########
@@ -216,6 +218,81 @@ public void createTableWithBadProperties()
         () -> tableOps.setProperty(t0, Property.TABLE_BLOOM_ENABLED.getKey(), 
"foo"));
   }
 
+  @Test
+  public void createTablesWithSameNameInDifferentNamespace() throws Exception {
+    TableOperations tableOps = accumuloClient.tableOperations();
+    String[] names = getUniqueNames(2);
+
+    accumuloClient.namespaceOperations().create("test1");
+    accumuloClient.namespaceOperations().create("test2");
+
+    var tables = Set.of("test1.table1", "test1.table2", "test1.root", 
"test2.table1",
+        "test2.table2", "test2.metadata", "table1", "table2", "metadata");
+
+    for (String table : tables) {
+      tableOps.create(table);
+    }
+
+    assertTrue(accumuloClient.tableOperations().list().containsAll(tables));
+
+    accumuloClient.namespaceOperations().create("test3");
+
+    Set<String> clones = new HashSet<>();
+    for (String table : tables) {
+      if (table.startsWith("test1.")) {
+        var clone = table.replace("test1.", "test3.");
+        tableOps.clone(table, clone, CloneConfiguration.empty());
+        clones.add(clone);
+      }
+    }
+
+    assertTrue(accumuloClient.tableOperations().list().containsAll(tables));
+    assertTrue(accumuloClient.tableOperations().list().containsAll(clones));
+
+    // Rename a table to a tablename that exists in another namespace
+    tableOps.rename("test1.table1", "test1.metadata");
+
+    tables = new HashSet<>(tables);
+    tables.remove("test1.table1");
+    tables.add("test1.metadata");
+
+    assertTrue(accumuloClient.tableOperations().list().containsAll(tables));
+    assertTrue(accumuloClient.tableOperations().list().containsAll(clones));
+    
assertFalse(accumuloClient.tableOperations().list().contains("test1.table"));
+
+    // Read and write data to tables w/ the same name in different namespaces 
to ensure no wires are
+    // crossed.
+    for (var table : Sets.union(tables, clones)) {
+      try (var writer = accumuloClient.createBatchWriter(table)) {
+        Mutation m = new Mutation("self");
+        m.put("table", "name", table);
+        writer.addMutation(m);
+      }
+    }
+
+    for (var table : Sets.union(tables, clones)) {
+      try (var scanner = accumuloClient.createScanner(table)) {
+        var seenValues =
+            scanner.stream().map(e -> 
e.getValue().toString()).collect(Collectors.toSet());
+        assertEquals(Set.of(table), seenValues);
+      }
+    }
+
+    for (var table : Sets.union(tables, clones)) {
+      assertThrows(TableExistsException.class,
+          () -> accumuloClient.tableOperations().create(table));
+    }
+
+    for (var srcTable : List.of("metadata", "test1.table2")) {
+      for (var destTable : Sets.union(tables, clones)) {
+        assertThrows(TableExistsException.class, () -> 
accumuloClient.tableOperations()
+            .clone(srcTable, destTable, CloneConfiguration.empty()));
+      }
+    }
+
+    // TODO test export/import w/ diff table names

Review Comment:
   opened #5326



-- 
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]

Reply via email to