keith-turner commented on code in PR #87:
URL: https://github.com/apache/accumulo-proxy/pull/87#discussion_r2291738808


##########
src/test/java/org/apache/accumulo/proxy/its/SimpleProxyBase.java:
##########
@@ -2315,6 +2319,76 @@ public void testCompactionSelector() throws Exception {
     assertEquals(1, countFiles(tableNames[1]), messagePrefix + tableNames[2]);
   }
 
+  /**
+   * Retrieves the collective size of all the files in a table.
+   */
+  private long getFileSizes(ServerContext ctx, String tableName) {
+    TableId tableId = 
TableId.of(ctx.tableOperations().tableIdMap().get(tableName));
+    var tabletsMetadata = 
ctx.getAmple().readTablets().forTable(tableId).build();
+    return tabletsMetadata.stream().flatMap(tm -> 
tm.getFiles().stream()).mapToLong(stf -> {
+      try {
+        return FileSystem.getLocal(new 
Configuration()).getFileStatus(stf.getPath()).getLen();
+      } catch (IOException e) {
+        throw new UncheckedIOException(e);
+      }
+    }).sum();
+  }
+
+  /**
+   * Testing the functionality for the CompactionConfigurer by testing an 
implementation of it. The
+   * implementation being tested is the CompressionConfigurer.
+   */
+  @Test
+  public void testCompactionConfigurer() throws Exception {
+    // Delete the table to start fresh
+    client.deleteTable(sharedSecret, tableName);
+    // Create two tables
+    final String[] tableNames = getUniqueNameArray(2);
+    for (String tableName : tableNames) {
+      client.createTable(sharedSecret, tableName, true, TimeType.MILLIS);
+      client.setTableProperty(sharedSecret, tableName, 
"table.file.compress.type", "none");
+    }
+
+    // Create data to add to the tables
+    Map<ByteBuffer,List<ColumnUpdate>> mutation = new HashMap<>();
+    byte[] data = new byte[100000];
+    Arrays.fill(data, (byte) 65);
+    for (int i = 0; i < 10; i++) {
+      String row = String.format("%09d", i);
+      ColumnUpdate columnUpdate = new ColumnUpdate(s2bb("big"), s2bb("files"));
+      columnUpdate.setDeleteCell(false);
+      columnUpdate.setValue(data);
+      mutation.put(s2bb(row), List.of(columnUpdate));
+    }
+    for (String tableName : tableNames) {
+      client.updateAndFlush(sharedSecret, tableName, mutation);
+      client.flushTable(sharedSecret, tableName, null, null, true);
+    }
+
+    // Checking the sizes of the files before compaction
+    for (String tableName : tableNames) {
+      long sizes = getFileSizes(getCluster().getServerContext(), tableName);
+      assertTrue(sizes > data.length * 10.0 && sizes < data.length * 11.0);
+    }
+
+    // Create a PluginConfig for the CompressionConfigurer
+    PluginConfig configurerCompact = new 
PluginConfig(CompressionConfigurer.class.getName(),
+        Map.of(CompressionConfigurer.LARGE_FILE_COMPRESSION_THRESHOLD, 
data.length + "",
+            CompressionConfigurer.LARGE_FILE_COMPRESSION_TYPE, "gz"));
+
+    // Compacting the tables one with the Configurer, one without
+    client.compactTable(sharedSecret, tableNames[0], null, null, null, true, 
true, null,
+        configurerCompact);
+    client.compactTable(sharedSecret, tableNames[1], null, null, null, true, 
true, null, null);
+
+    // Checking to see that the data sizes are the appropriate size. Based on 
the data, it will be
+    // significantly smaller with compression
+    long sizes1 = getFileSizes(getCluster().getServerContext(), tableNames[0]);
+    long sizes2 = getFileSizes(getCluster().getServerContext(), tableNames[1]);
+    assertTrue(sizes1 < data.length);
+    assertTrue(sizes1 < sizes2, "Size1 is " + sizes1 + ", size2 is " + sizes2);

Review Comment:
   Could add a third check of sizes2.
   
   ```
   assertTrue(sizes2 > data.length * 10.0 && sizes2 < data.length * 11.0);
   ```



-- 
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: notifications-unsubscr...@accumulo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to