ctubbsii commented on code in PR #5919:
URL: https://github.com/apache/accumulo/pull/5919#discussion_r2380030487


##########
test/src/main/java/org/apache/accumulo/test/VolumeChooserIT.java:
##########
@@ -132,194 +137,177 @@ public void configure(MiniAccumuloConfigImpl cfg, 
Configuration hadoopCoreSite)
 
   }
 
-  public static void addSplits(AccumuloClient accumuloClient, String tableName)
-      throws TableNotFoundException, AccumuloException, 
AccumuloSecurityException {
-    // Add 10 splits to the table
-    SortedSet<Text> partitions = new TreeSet<>();
-    for (String s : alpha_rows) {
-      partitions.add(new Text(s));
-    }
-    accumuloClient.tableOperations().addSplits(tableName, partitions);
-  }
-
-  public static void writeAndReadData(AccumuloClient accumuloClient, String 
tableName)
-      throws Exception {
-    writeDataToTable(accumuloClient, tableName, alpha_rows);
-
-    // Write the data to disk, read it back
-    accumuloClient.tableOperations().flush(tableName, null, null, true);
-    try (Scanner scanner = accumuloClient.createScanner(tableName, 
Authorizations.EMPTY)) {
-      int i = 0;
-      for (Entry<Key,Value> entry : scanner) {
-        assertEquals(alpha_rows[i++], entry.getKey().getRow().toString(),
-            "Data read is not data written");
-      }
-    }
-  }
+  static TableId createAndVerifyTable(AccumuloClient client, String tableName,
+      SortedSet<Text> splits, boolean flush) throws Exception {
+    // create the table
+    var ntc = new NewTableConfiguration().withSplits(splits);
+    client.tableOperations().create(tableName, ntc);
 
-  public static void writeDataToTable(AccumuloClient accumuloClient, String 
tableName,
-      String[] rows) throws Exception {
-    // Write some data to the table
-    try (BatchWriter bw = accumuloClient.createBatchWriter(tableName)) {
-      for (String s : rows) {
-        Mutation m = new Mutation(new Text(s));
+    // write some data
+    try (BatchWriter bw = client.createBatchWriter(tableName)) {
+      for (Text row : alpha_rows) {
+        Mutation m = new Mutation(row);
         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);
+    // optionally, flush before verification
+    if (flush) {
+      client.tableOperations().flush(tableName, null, null, true);
+    }
+
+    // verify it can be read back
+    try (Scanner scanner = client.createScanner(tableName, 
Authorizations.EMPTY)) {
+      var row_iter = alpha_rows.iterator();
       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(row_iter.next(), entry.getKey().getRow(), "Data read is 
not data written");
       }
     }
-    assertEquals(volumes.size(), volumesSeen.size(),
-        "Did not see all the volumes. volumes: " + volumes + " volumes seen: " 
+ volumesSeen);
-    assertEquals(26, fileCount, "Wrong number of files");
+    return TableId.of(client.tableOperations().tableIdMap().get(tableName));
   }
 
-  private void configureNamespace(AccumuloClient accumuloClient, String 
volumeChooserClassName,
-      String configuredVolumes, String namespace) throws Exception {
-    accumuloClient.namespaceOperations().create(namespace);
-    // Set properties on the namespace
-    accumuloClient.namespaceOperations().setProperty(namespace, 
PERTABLE_CHOOSER_PROP,
-        volumeChooserClassName);
-    accumuloClient.namespaceOperations().setProperty(namespace, 
PREFERRED_CHOOSER_PROP,
-        configuredVolumes);
+  private void createNamespaceWithPreferredChooser(AccumuloClient client, 
String namespace,
+      Path preferredVolume) throws Exception {
+    client.namespaceOperations().create(namespace);
+    client.namespaceOperations().setProperty(namespace, PERTABLE_CHOOSER_PROP,
+        PreferredVolumeChooser.class.getName());
+    if (preferredVolume != null) {
+      client.namespaceOperations().setProperty(namespace, 
PREFERRED_CHOOSER_PROP,
+          preferredVolume.toString());
+    }
   }
 
-  private void verifyVolumesForWritesToNewTable(AccumuloClient accumuloClient, 
String myNamespace,
-      String expectedVolumes) throws Exception {
-    String tableName = myNamespace + ".1";
-
-    accumuloClient.tableOperations().create(tableName);
-    TableId tableID = 
TableId.of(accumuloClient.tableOperations().tableIdMap().get(tableName));
+  private void createNamespaceWithRandomChooser(AccumuloClient client, String 
namespace)
+      throws Exception {
+    client.namespaceOperations().create(namespace);
+    client.namespaceOperations().setProperty(namespace, PERTABLE_CHOOSER_PROP,
+        RandomVolumeChooser.class.getName());
+    // The random volume chooser should ignore this property
+    client.namespaceOperations().setProperty(namespace, 
PREFERRED_CHOOSER_PROP, "ignored");
+  }
 
-    // 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);
+  private void createTableAndVerifyVolumesUsed(AccumuloClient client, String 
namespace,
+      Path... expectedVolumes) throws Exception {
+    String tableName = namespace + ".1";
+    TableId tableID = createAndVerifyTable(client, tableName, alpha_rows, 
true);
+
+    // Verify the new files are written only to the expected volumes
+    Set<String> allTableFiles = 
getServerContext().getAmple().readTablets().forTable(tableID)
+        .fetch(ColumnType.FILES).build().stream().flatMap(tm -> 
tm.getFiles().stream())

Review Comment:
   fixed



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