DomGarguilo commented on code in PR #5525:
URL: https://github.com/apache/accumulo/pull/5525#discussion_r2072070556


##########
test/src/main/java/org/apache/accumulo/test/IteratorEnvIT.java:
##########
@@ -227,43 +253,134 @@ public void testCompact(String tableName,
     writeData(tableName);
 
     IteratorSetting cfg = new IteratorSetting(1, iteratorClass);
-    cfg.addOption("expected.table.id", 
client.tableOperations().tableIdMap().get(tableName));
+    cfg.addOption(EXPECTED_TABLE_ID_OPT, 
client.tableOperations().tableIdMap().get(tableName));
     CompactionConfig config = new CompactionConfig();
     config.setIterators(Collections.singletonList(cfg));
     client.tableOperations().compact(tableName, config);
+
+    try (Scanner scan = client.createScanner(tableName)) {
+      validateScanner(scan);
+    }
   }
 
   public void testMinCompact(String tableName,
       Class<? extends SortedKeyValueIterator<Key,Value>> iteratorClass) throws 
Exception {
     writeData(tableName);
 
     IteratorSetting cfg = new IteratorSetting(1, iteratorClass);
-    cfg.addOption("expected.table.id", 
client.tableOperations().tableIdMap().get(tableName));
+    cfg.addOption(EXPECTED_TABLE_ID_OPT, 
client.tableOperations().tableIdMap().get(tableName));
 
     client.tableOperations().attachIterator(tableName, cfg, 
EnumSet.of(IteratorScope.minc));
 
-    client.tableOperations().flush(tableName);
+    client.tableOperations().flush(tableName, null, null, true);
+
+    try (Scanner scan = client.createScanner(tableName)) {
+      validateScanner(scan);
+    }
+  }
+
+  private void testRFileScan(Class<? extends 
SortedKeyValueIterator<Key,Value>> iteratorClass)
+      throws Exception {
+    TreeMap<Key,Value> data = createTestData();
+    var fs = FileSystem.getLocal(new Configuration());
+    String rFilePath = createRFile(fs, data);
+
+    IteratorSetting cfg = new IteratorSetting(1, iteratorClass);
+
+    try (Scanner scan = RFile.newScanner().from(rFilePath).withFileSystem(fs)
+        .withTableProperties(getTableConfig().getProperties()).build()) {
+      scan.addScanIterator(cfg);
+      validateScanner(scan);
+    }
+  }
+
+  public void testOfflineScan(String tableName,
+      Class<? extends SortedKeyValueIterator<Key,Value>> iteratorClass) throws 
Exception {
+    writeData(tableName);
+
+    TableId tableId = 
TableId.of(client.tableOperations().tableIdMap().get(tableName));
+    client.tableOperations().offline(tableName, true);
+
+    IteratorSetting cfg = new IteratorSetting(1, iteratorClass);
+    cfg.addOption(EXPECTED_TABLE_ID_OPT, tableId.canonical());
+
+    try (OfflineScanner scan =
+        new OfflineScanner((ClientContext) client, tableId, 
Authorizations.EMPTY)) {
+      scan.addScanIterator(cfg);
+      validateScanner(scan);
+    }
+  }
+
+  public void testClientSideScan(String tableName,
+      Class<? extends SortedKeyValueIterator<Key,Value>> iteratorClass) throws 
Exception {
+    writeData(tableName);
+
+    IteratorSetting cfg = new IteratorSetting(1, iteratorClass);
+    cfg.addOption(EXPECTED_TABLE_ID_OPT, 
client.tableOperations().tableIdMap().get(tableName));
+
+    try (Scanner scan = client.createScanner(tableName);
+        var clientIterScan = new ClientSideIteratorScanner(scan)) {
+      clientIterScan.addScanIterator(cfg);
+      validateScanner(clientIterScan);
+    }
+  }
+
+  private TreeMap<Key,Value> createTestData() {
+    TreeMap<Key,Value> testData = new TreeMap<>();
+
+    // Write data that we do not expect to be filtered out
+    testData.put(new Key("row1", GOOD_COL_FAM, "cq1"), new Value("val1"));
+    testData.put(new Key("row2", GOOD_COL_FAM, "cq1"), new Value("val2"));
+    testData.put(new Key("row3", GOOD_COL_FAM, "cq1"), new Value("val3"));
+    // Write data that we expect to be filtered out
+    testData.put(new Key("row4", BAD_COL_FAM, "badcq"), new Value("val1"));
+    testData.put(new Key("row5", BAD_COL_FAM, "badcq"), new Value("val2"));
+    testData.put(new Key("row6", BAD_COL_FAM, "badcq"), new Value("val3"));
+
+    return testData;
+  }
+
+  private void validateScanner(Scanner scan) {
+    // Ensure the bad cf was filtered out to ensure init() and testEnv() were 
called
+    int numElts = 0;
+    for (var e : scan) {
+      numElts++;
+      assertEquals(GOOD_COL_FAM, e.getKey().getColumnFamily().toString());
+    }
+    assertEquals(3, numElts);
+  }
+
+  private String createRFile(FileSystem fs, TreeMap<Key,Value> data) throws 
Exception {
+    File dir = new File(System.getProperty("user.dir") + 
"/target/rfilescan-iterenv-test");
+    assertTrue(dir.mkdirs());
+    String filePath = dir.getAbsolutePath() + "/test.rf";
+
+    try (RFileWriter writer = 
RFile.newWriter().to(filePath).withFileSystem(fs).build()) {
+      writer.append(data.entrySet());
+    }
+
+    fs.deleteOnExit(new Path(dir.getAbsolutePath()));

Review Comment:
   This could be a good spot for Junits `@TempDir` potentially. Doesn't make a 
big difference but it'll do the setup and cleanup for us. 
   
   You would just need to add to the top:
   ```java
     @TempDir
     private static File tempDir;
   ```
   ```suggestion
       File testFile = new File(tempDir, "test.rf");
       String filePath = testFile.getAbsolutePath();
   
       try (RFileWriter writer = 
RFile.newWriter().to(filePath).withFileSystem(fs).build()) {
         writer.append(data.entrySet());
       }
       
   ```



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