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 0a65e351..dff77c31 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 static void main(String[] args) throws Exception { 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 cadfbaec..e5c25d1b 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 @@ 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 void visit(State state, RandWalkEnv env, Properties props) throws Excepti 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> iter = scan.iterator(); - while (iter.hasNext()) { - Entry entry = iter.next(); + for (Entry entry : scan) { Key k = entry.getKey(); seen++; if (!auths.contains(k.getColumnVisibilityData()) && !ambiguousAuths) @@ -156,12 +152,6 @@ public void visit(State state, RandWalkEnv env, Properties props) throws Excepti } throw new AccumuloException("Unexpected exception!", re); - } finally { - if (scan != null) { - scan.close(); - scan = null; - } - } break; @@ -183,20 +173,10 @@ public void visit(State state, RandWalkEnv env, Properties props) throws Excepti 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 void visit(State state, RandWalkEnv env, Properties props) throws Excepti 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 void visit(State state, RandWalkEnv env, Properties props) throws Excepti 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 fc87203b..7b8f291e 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 String[] getAuthsArray() { 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 String getLastKey() { } 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 {