This is an automated email from the ASF dual-hosted git repository.

domgarguilo pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/accumulo-testing.git


The following commit(s) were added to refs/heads/2.1 by this push:
     new 9bf9f84  Misc improvements (#303)
9bf9f84 is described below

commit 9bf9f84d2bb14a6641390aa587e3e3921acd9c08
Author: Dom G. <[email protected]>
AuthorDate: Thu Oct 30 12:15:11 2025 -0400

    Misc improvements (#303)
    
    * use of try-with-resources to replace manual closing of resources in 
TableOp.java
    * simplified logic in a few spots
---
 .../testing/continuous/ContinuousScanner.java      |  7 ++-
 .../testing/randomwalk/security/TableOp.java       | 60 +++++++---------------
 .../randomwalk/security/WalkingSecurity.java       | 15 ++----
 3 files changed, 29 insertions(+), 53 deletions(-)

diff --git 
a/src/main/java/org/apache/accumulo/testing/continuous/ContinuousScanner.java 
b/src/main/java/org/apache/accumulo/testing/continuous/ContinuousScanner.java
index 0a65e35..dff77c3 100644
--- 
a/src/main/java/org/apache/accumulo/testing/continuous/ContinuousScanner.java
+++ 
b/src/main/java/org/apache/accumulo/testing/continuous/ContinuousScanner.java
@@ -62,8 +62,11 @@ public class ContinuousScanner {
 
           long t1 = System.currentTimeMillis();
 
-          long count = scanner.stream()
-              .peek(entry -> ContinuousWalk.validate(entry.getKey(), 
entry.getValue())).count();
+          long count = 0;
+          for (var entry : scanner) {
+            ContinuousWalk.validate(entry.getKey(), entry.getValue());
+            count++;
+          }
 
           long t2 = System.currentTimeMillis();
 
diff --git 
a/src/main/java/org/apache/accumulo/testing/randomwalk/security/TableOp.java 
b/src/main/java/org/apache/accumulo/testing/randomwalk/security/TableOp.java
index cadfbae..e5c25d1 100644
--- a/src/main/java/org/apache/accumulo/testing/randomwalk/security/TableOp.java
+++ b/src/main/java/org/apache/accumulo/testing/randomwalk/security/TableOp.java
@@ -20,7 +20,6 @@ package org.apache.accumulo.testing.randomwalk.security;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 
-import java.util.Iterator;
 import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.SortedSet;
@@ -91,13 +90,10 @@ public class TableOp extends Test {
           boolean ambiguousAuths =
               WalkingSecurity.get(state, 
env).ambiguousAuthorizations(client.whoami());
 
-          Scanner scan = null;
-          try {
-            scan = client.createScanner(tableName, 
secOps.getUserAuthorizations(client.whoami()));
+          try (Scanner scan =
+              client.createScanner(tableName, 
secOps.getUserAuthorizations(client.whoami()))) {
             int seen = 0;
-            Iterator<Entry<Key,Value>> iter = scan.iterator();
-            while (iter.hasNext()) {
-              Entry<Key,Value> entry = iter.next();
+            for (Entry<Key,Value> entry : scan) {
               Key k = entry.getKey();
               seen++;
               if (!auths.contains(k.getColumnVisibilityData()) && 
!ambiguousAuths)
@@ -156,12 +152,6 @@ public class TableOp extends Test {
             }
 
             throw new AccumuloException("Unexpected exception!", re);
-          } finally {
-            if (scan != null) {
-              scan.close();
-              scan = null;
-            }
-
           }
 
           break;
@@ -183,20 +173,10 @@ public class TableOp extends Test {
             m.put(new Text(), new Text(), new ColumnVisibility(s),
                 new Value("value".getBytes(UTF_8)));
           }
-          BatchWriter writer = null;
-          try {
-            try {
-              writer = client.createBatchWriter(tableName,
-                  new 
BatchWriterConfig().setMaxMemory(9000l).setMaxWriteThreads(1));
-            } catch (TableNotFoundException tnfe) {
-              if (tableExists)
-                throw new AccumuloException("Table didn't exist when it should 
have: " + tableName);
-              return;
-            }
-            boolean works = true;
+          try (BatchWriter writer = client.createBatchWriter(tableName,
+              new 
BatchWriterConfig().setMaxMemory(9000L).setMaxWriteThreads(1))) {
             try {
               writer.addMutation(m);
-              writer.close();
             } catch (MutationsRejectedException mre) {
               if (mre.getSecurityErrorCodes().size() == 1) {
                 // TabletServerBatchWriter will log the error automatically so 
make sure its the
@@ -212,14 +192,12 @@ public class TableOp extends Test {
               throw new AccumuloException("Unexpected 
MutationsRejectedException in TableOp.WRITE",
                   mre);
             }
-            if (works)
-              for (String s : WalkingSecurity.get(state, env).getAuthsArray())
-                WalkingSecurity.get(state, env).increaseAuthMap(s, 1);
-          } finally {
-            if (writer != null) {
-              writer.close();
-              writer = null;
-            }
+            for (String s : WalkingSecurity.get(state, env).getAuthsArray())
+              WalkingSecurity.get(state, env).increaseAuthMap(s, 1);
+          } catch (TableNotFoundException tnfe) {
+            if (tableExists)
+              throw new AccumuloException("Table didn't exist when it should 
have: " + tableName);
+            return;
           }
           break;
         case BULK_IMPORT:
@@ -229,16 +207,16 @@ public class TableOp extends Test {
             Key k = new Key(key, "", "", s);
             keys.add(k);
           }
-          Path dir = new Path("/tmp", "bulk_" + UUID.randomUUID().toString());
-          Path fail = new Path(dir.toString() + "_fail");
           FileSystem fs = WalkingSecurity.get(state, env).getFs();
-          RFileWriter rFileWriter =
-              RFile.newWriter().to(dir + 
"/securityBulk.rf").withFileSystem(fs).build();
-          rFileWriter.startDefaultLocalityGroup();
+          Path dir = new Path("/tmp", "bulk_" + UUID.randomUUID());
+          Path fail = new Path(dir + "_fail");
           fs.mkdirs(fail);
-          for (Key k : keys)
-            rFileWriter.append(k, new Value("Value".getBytes(UTF_8)));
-          rFileWriter.close();
+          try (RFileWriter rFileWriter =
+              RFile.newWriter().to(dir + 
"/securityBulk.rf").withFileSystem(fs).build()) {
+            rFileWriter.startDefaultLocalityGroup();
+            for (Key k : keys)
+              rFileWriter.append(k, new Value("Value".getBytes(UTF_8)));
+          }
           try {
             
tableOps.importDirectory(dir.toString()).to(tableName).tableTime(true).load();
           } catch (TableNotFoundException tnfe) {
diff --git 
a/src/main/java/org/apache/accumulo/testing/randomwalk/security/WalkingSecurity.java
 
b/src/main/java/org/apache/accumulo/testing/randomwalk/security/WalkingSecurity.java
index fc87203..7b8f291 100644
--- 
a/src/main/java/org/apache/accumulo/testing/randomwalk/security/WalkingSecurity.java
+++ 
b/src/main/java/org/apache/accumulo/testing/randomwalk/security/WalkingSecurity.java
@@ -273,10 +273,10 @@ public class WalkingSecurity {
   public boolean inAmbiguousZone(String userName, TablePermission tp) {
     if (tp.equals(TablePermission.READ) || tp.equals(TablePermission.WRITE)) {
       Long setTime = state.getLong("Tab-" + userName + '-' + tp.name() + '-' + 
"time");
-      if (setTime == null)
+      if (setTime == null) {
         throw new RuntimeException("Tab-" + userName + '-' + tp.name() + '-' + 
"time is null");
-      if (System.currentTimeMillis() < (setTime + 1000))
-        return true;
+      }
+      return System.currentTimeMillis() < (setTime + 1000);
     }
     return false;
   }
@@ -291,19 +291,14 @@ public class WalkingSecurity {
   }
 
   public void increaseAuthMap(String s, int increment) {
-    Integer curVal = getAuthsMap().get(s);
-    if (curVal == null) {
-      curVal = Integer.valueOf(0);
-      getAuthsMap().put(s, curVal);
-    }
-    curVal += increment;
+    getAuthsMap().merge(s, increment, Integer::sum);
   }
 
   public FileSystem getFs() {
     FileSystem fs = null;
     try {
       fs = (FileSystem) state.get(filesystem);
-    } catch (RuntimeException re) {}
+    } catch (RuntimeException ignored) {}
 
     if (fs == null) {
       try {

Reply via email to