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


##########
test/src/main/java/org/apache/accumulo/test/VolumeChooserIT.java:
##########
@@ -296,35 +242,37 @@ public void twoTablesPreferredVolumeChooser() throws 
Exception {
   @Test
   public void twoTablesRandomVolumeChooser() throws Exception {
     log.info("Starting twoTablesRandomVolumeChooser()");
+    var namespace1 = "ns_" + getUniqueNames(2)[0];
+    var namespace2 = "ns_" + getUniqueNames(2)[1];
 
     // Create namespace
     try (AccumuloClient client = 
Accumulo.newClient().from(getClientProperties()).build()) {
-      createAndVerify(client, namespace1, v1 + "," + v2 + "," + v3);
-      createAndVerify(client, namespace2, v1 + "," + v2 + "," + v3);
+      client.namespaceOperations().create(namespace1);
+      client.namespaceOperations().setProperty(namespace1, 
PERTABLE_CHOOSER_PROP,
+          RandomVolumeChooser.class.getName());
+      verifyVolumesForWritesToNewTable(client, namespace1, join(v1, v2, v3));
+      client.namespaceOperations().create(namespace2);
+      client.namespaceOperations().setProperty(namespace2, 
PERTABLE_CHOOSER_PROP,
+          RandomVolumeChooser.class.getName());
+      verifyVolumesForWritesToNewTable(client, namespace2, join(v1, v2, v3));
     }
   }
 
-  private void createAndVerify(AccumuloClient client, String ns, String 
expectedVolumes)
-      throws Exception {
-    client.namespaceOperations().create(ns);
-
-    // Set properties on the namespace
-    client.namespaceOperations().setProperty(ns, PERTABLE_CHOOSER_PROP,
-        RandomVolumeChooser.class.getName());
-
-    verifyVolumesForWritesToNewTable(client, ns, expectedVolumes);
-  }
-
   // Test that uses 2 tables with 10 split points each. The first uses the 
RandomVolumeChooser and
   // the second uses the StaticVolumeChooser to choose volumes.

Review Comment:
   This comment mentioning `StaticVolumeChooser` is incorrect.



##########
test/src/main/java/org/apache/accumulo/test/VolumeChooserIT.java:
##########
@@ -165,126 +157,80 @@ public static void writeAndReadData(AccumuloClient 
accumuloClient, String tableN
     }
   }
 
-  public static void writeDataToTable(AccumuloClient accumuloClient, String 
tableName,
-      String[] rows) throws Exception {
+  static void writeDataToTable(AccumuloClient accumuloClient, String 
tableName) throws Exception {
     // Write some data to the table
     try (BatchWriter bw = accumuloClient.createBatchWriter(tableName)) {
-      for (String s : rows) {
+      for (String s : alpha_rows) {
         Mutation m = new Mutation(new Text(s));
         m.put(EMPTY, EMPTY, EMPTY_VALUE);
         bw.addMutation(m);
       }
     }
   }
 
-  public static void verifyVolumes(AccumuloClient accumuloClient, Range 
tableRange, String vol)
-      throws Exception {
-    // Verify the new files are written to the Volumes specified
-    ArrayList<String> volumes = new ArrayList<>();
-    Collections.addAll(volumes, vol.split(","));
-
-    TreeSet<String> volumesSeen = new TreeSet<>();
-    int fileCount = 0;
-    try (Scanner scanner =
-        accumuloClient.createScanner(SystemTables.METADATA.tableName(), 
Authorizations.EMPTY)) {
-      scanner.setRange(tableRange);
-      scanner.fetchColumnFamily(DataFileColumnFamily.NAME);
-      for (Entry<Key,Value> entry : scanner) {
-        boolean inVolume = false;
-        for (String volume : volumes) {
-          if (entry.getKey().getColumnQualifier().toString().contains(volume)) 
{
-            volumesSeen.add(volume);
-            inVolume = true;
-          }
-        }
-        assertTrue(inVolume,
-            "Data not written to the correct volumes.  " + 
entry.getKey().getColumnQualifier());
-        fileCount++;
-      }
-    }
-    assertEquals(volumes.size(), volumesSeen.size(),
-        "Did not see all the volumes. volumes: " + volumes + " volumes seen: " 
+ volumesSeen);
-    assertEquals(26, fileCount, "Wrong number of files");
-  }
-
-  public static void verifyNoVolumes(AccumuloClient accumuloClient, Range 
tableRange)
-      throws Exception {
-    try (Scanner scanner =
-        accumuloClient.createScanner(SystemTables.METADATA.tableName(), 
Authorizations.EMPTY)) {
-      scanner.setRange(tableRange);
-      scanner.fetchColumnFamily(DataFileColumnFamily.NAME);
-      for (Entry<Key,Value> entry : scanner) {
-        fail("Data incorrectly written to " + 
entry.getKey().getColumnQualifier());
-      }
-    }
-  }
-
-  private void configureNamespace(AccumuloClient accumuloClient, String 
volumeChooserClassName,
-      String configuredVolumes, String namespace) throws Exception {
+  private void configurePreferred(AccumuloClient accumuloClient, String 
namespace,
+      Path... configuredVolumes) throws Exception {
     accumuloClient.namespaceOperations().create(namespace);
     // Set properties on the namespace
     accumuloClient.namespaceOperations().setProperty(namespace, 
PERTABLE_CHOOSER_PROP,
-        volumeChooserClassName);
+        PreferredVolumeChooser.class.getName());
     accumuloClient.namespaceOperations().setProperty(namespace, 
PREFERRED_CHOOSER_PROP,
-        configuredVolumes);
+        join(configuredVolumes));
   }
 
-  private void verifyVolumesForWritesToNewTable(AccumuloClient accumuloClient, 
String myNamespace,
+  private void verifyVolumesForWritesToNewTable(AccumuloClient client, String 
myNamespace,
       String expectedVolumes) throws Exception {
     String tableName = myNamespace + ".1";
 
-    accumuloClient.tableOperations().create(tableName);
-    TableId tableID = 
TableId.of(accumuloClient.tableOperations().tableIdMap().get(tableName));
-
-    // Add 10 splits to the table
-    addSplits(accumuloClient, tableName);
-    // Write some data to the table
-    writeAndReadData(accumuloClient, tableName);
-    // Verify the new files are written to the Volumes specified
-    verifyVolumes(accumuloClient, TabletsSection.getRange(tableID), 
expectedVolumes);
-  }
-
-  public static void verifyWaLogVolumes(AccumuloClient accumuloClient, Range 
tableRange, String vol)
-      throws TableNotFoundException {
+    TableId tableID = createPresplitTable(client, tableName);
+    client.tableOperations().flush(tableName, null, null, true);
+    verifyTableContents(client, tableName);
     // Verify the new files are written to the Volumes specified
     ArrayList<String> volumes = new ArrayList<>();
-    Collections.addAll(volumes, vol.split(","));
+    Collections.addAll(volumes, expectedVolumes.split(","));
 
     TreeSet<String> volumesSeen = new TreeSet<>();
+    int fileCount = 0;
     try (Scanner scanner =
-        accumuloClient.createScanner(SystemTables.METADATA.tableName(), 
Authorizations.EMPTY)) {
-      scanner.setRange(tableRange);
-      scanner.fetchColumnFamily(LogColumnFamily.NAME);
+        client.createScanner(SystemTables.METADATA.tableName(), 
Authorizations.EMPTY)) {
+      scanner.setRange(TabletsSection.getRange(tableID));
+      scanner.fetchColumnFamily(DataFileColumnFamily.NAME);

Review Comment:
   Could use Ample for this code.  That would make it easier to extract the 
file path from the json in the qualifier.  Currently the String.contains call 
runs against the json which has some other stuff besides the file path, so that 
increases the chance of an odd false positive in the test.  Alternatively could 
use StoredTableFile on the qualifier to parse the json and extract the path.



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