This is an automated email from the ASF dual-hosted git repository. jmanno pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo-testing.git
The following commit(s) were added to refs/heads/main by this push: new 0a50e1f Some minor code cleanup throughout accumulo-testing (#176) 0a50e1f is described below commit 0a50e1f4d93c135c9cbae90b20628bd48c52e583 Author: Jeffrey Manno <jeffreymann...@gmail.com> AuthorDate: Tue Dec 7 10:02:12 2021 -0500 Some minor code cleanup throughout accumulo-testing (#176) --- bin/mapred | 3 +- .../java/org/apache/accumulo/testing/TestEnv.java | 2 +- .../testing/continuous/UndefinedAnalyzer.java | 4 +- .../org/apache/accumulo/testing/gcs/Collector.java | 2 +- .../org/apache/accumulo/testing/gcs/Generator.java | 2 +- .../org/apache/accumulo/testing/gcs/Mutator.java | 2 +- .../apache/accumulo/testing/gcs/Persistence.java | 6 +- .../org/apache/accumulo/testing/gcs/Verifier.java | 2 +- .../accumulo/testing/healthprobe/Monitor.java | 11 ++-- .../apache/accumulo/testing/ingest/TestIngest.java | 17 ++---- .../accumulo/testing/ingest/VerifyIngest.java | 2 +- .../testing/performance/tests/GroupCommitPT.java | 14 ++--- .../performance/tests/YieldingScanExecutorPT.java | 5 +- .../testing/performance/util/TestExecutor.java | 4 +- .../accumulo/testing/randomwalk/Framework.java | 2 +- .../apache/accumulo/testing/randomwalk/Module.java | 69 ++++++++++------------ .../apache/accumulo/testing/randomwalk/State.java | 10 ++-- .../accumulo/testing/randomwalk/bulk/Verify.java | 2 +- .../testing/randomwalk/concurrent/BatchWrite.java | 5 +- .../testing/randomwalk/concurrent/BulkImport.java | 7 +-- .../testing/randomwalk/concurrent/CreateTable.java | 2 +- .../testing/randomwalk/conditional/Verify.java | 3 +- .../accumulo/testing/randomwalk/image/Commit.java | 2 +- .../testing/randomwalk/image/ImageFixture.java | 6 +- .../accumulo/testing/randomwalk/image/TableOp.java | 2 +- .../accumulo/testing/randomwalk/image/Verify.java | 2 +- .../testing/randomwalk/multitable/Commit.java | 2 +- .../randomwalk/multitable/MultiTableFixture.java | 6 +- .../randomwalk/security/WalkingSecurity.java | 11 ++-- .../testing/randomwalk/sequential/BatchVerify.java | 9 +-- .../testing/randomwalk/sequential/Commit.java | 2 +- .../randomwalk/sequential/MapRedVerifyTool.java | 2 +- .../randomwalk/sequential/SequentialFixture.java | 4 +- .../testing/randomwalk/shard/CloneIndex.java | 2 +- .../accumulo/testing/randomwalk/shard/Grep.java | 9 ++- .../testing/randomwalk/shard/SortTool.java | 8 +-- .../org/apache/accumulo/testing/stress/Scan.java | 4 +- 37 files changed, 106 insertions(+), 141 deletions(-) diff --git a/bin/mapred b/bin/mapred index 269c729..33cb8d2 100755 --- a/bin/mapred +++ b/bin/mapred @@ -16,7 +16,6 @@ # limitations under the License. bin_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) -at_home=$( cd "$( dirname "$bin_dir" )" && pwd ) source "${bin_dir}/build" function print_usage() { @@ -55,7 +54,7 @@ export CLASSPATH="$TEST_JAR_PATH:$HADOOP_API_JAR:$HADOOP_RUNTIME_JAR:$CLASSPATH" if [ -n "$HADOOP_HOME" ]; then export HADOOP_USE_CLIENT_CLASSLOADER=true - "$HADOOP_HOME"/bin/yarn jar "$TEST_JAR_PATH" "$mr_main" "$TEST_PROPS" "$ACCUMULO_CLIENT_PROPS" "${@:2}" + "$HADOOP_HOME"/bin/yarn jar "$TEST_JAR_PATH" "$mr_main" "$TEST_PROPS" "$ACCUMULO_CLIENT_PROPS" "${@:2}" else echo "Hadoop must be installed and HADOOP_HOME must be set!" exit 1 diff --git a/src/main/java/org/apache/accumulo/testing/TestEnv.java b/src/main/java/org/apache/accumulo/testing/TestEnv.java index d395ad4..18f6afc 100644 --- a/src/main/java/org/apache/accumulo/testing/TestEnv.java +++ b/src/main/java/org/apache/accumulo/testing/TestEnv.java @@ -33,7 +33,7 @@ import org.apache.hadoop.conf.Configuration; public class TestEnv implements AutoCloseable { protected final Properties testProps; - private String clientPropsPath; + private final String clientPropsPath; private final Properties clientProps; private AccumuloClient client = null; private Configuration hadoopConfig = null; diff --git a/src/main/java/org/apache/accumulo/testing/continuous/UndefinedAnalyzer.java b/src/main/java/org/apache/accumulo/testing/continuous/UndefinedAnalyzer.java index 61d28ea..00bbe56 100644 --- a/src/main/java/org/apache/accumulo/testing/continuous/UndefinedAnalyzer.java +++ b/src/main/java/org/apache/accumulo/testing/continuous/UndefinedAnalyzer.java @@ -319,8 +319,8 @@ public class UndefinedAnalyzer { if (ta == null) logger.debug("{} {} {} {} {}", undefinedNode.undef, undefinedNode.ref, uuid, t1, t2); else - logger.debug("{} {} {} {} {}", undefinedNode.undef, undefinedNode.ref, ta.tablet, - ta.server, uuid, t1, t2); + logger.debug("{} {} {} {} {} {} {}", undefinedNode.undef, undefinedNode.ref, + ta.tablet, ta.server, uuid, t1, t2); } } else { diff --git a/src/main/java/org/apache/accumulo/testing/gcs/Collector.java b/src/main/java/org/apache/accumulo/testing/gcs/Collector.java index 628f286..042b8bd 100644 --- a/src/main/java/org/apache/accumulo/testing/gcs/Collector.java +++ b/src/main/java/org/apache/accumulo/testing/gcs/Collector.java @@ -23,7 +23,7 @@ import java.util.function.Consumer; public class Collector { Persistence persistence; - private int batchSize; + private final int batchSize; public Collector(GcsEnv gcsEnv) { this.persistence = new Persistence(gcsEnv); diff --git a/src/main/java/org/apache/accumulo/testing/gcs/Generator.java b/src/main/java/org/apache/accumulo/testing/gcs/Generator.java index e5c6a12..31b9a07 100644 --- a/src/main/java/org/apache/accumulo/testing/gcs/Generator.java +++ b/src/main/java/org/apache/accumulo/testing/gcs/Generator.java @@ -40,7 +40,7 @@ public class Generator { Random rand = new Random(); - private Persistence persistence; + private final Persistence persistence; public Generator(GcsEnv gcsEnv) { this.persistence = new Persistence(gcsEnv); diff --git a/src/main/java/org/apache/accumulo/testing/gcs/Mutator.java b/src/main/java/org/apache/accumulo/testing/gcs/Mutator.java index d4cb3e3..2bb4db3 100644 --- a/src/main/java/org/apache/accumulo/testing/gcs/Mutator.java +++ b/src/main/java/org/apache/accumulo/testing/gcs/Mutator.java @@ -18,5 +18,5 @@ package org.apache.accumulo.testing.gcs; public interface Mutator { - public void run(Persistence p); + void run(Persistence p); } diff --git a/src/main/java/org/apache/accumulo/testing/gcs/Persistence.java b/src/main/java/org/apache/accumulo/testing/gcs/Persistence.java index 7638c6f..213e8fa 100644 --- a/src/main/java/org/apache/accumulo/testing/gcs/Persistence.java +++ b/src/main/java/org/apache/accumulo/testing/gcs/Persistence.java @@ -48,9 +48,9 @@ import com.google.common.hash.Hashing; public class Persistence { - private BatchWriter writer; - private String table; - private AccumuloClient client; + private final BatchWriter writer; + private final String table; + private final AccumuloClient client; Persistence(GcsEnv env) { this.client = env.getAccumuloClient(); diff --git a/src/main/java/org/apache/accumulo/testing/gcs/Verifier.java b/src/main/java/org/apache/accumulo/testing/gcs/Verifier.java index 1cdda76..7de7f2d 100644 --- a/src/main/java/org/apache/accumulo/testing/gcs/Verifier.java +++ b/src/main/java/org/apache/accumulo/testing/gcs/Verifier.java @@ -28,7 +28,7 @@ import java.util.TreeSet; public class Verifier { Persistence persistence; - private int batchSize; + private final int batchSize; public Verifier(GcsEnv gcsEnv) { this.persistence = new Persistence(gcsEnv); diff --git a/src/main/java/org/apache/accumulo/testing/healthprobe/Monitor.java b/src/main/java/org/apache/accumulo/testing/healthprobe/Monitor.java index a1d097e..9681655 100644 --- a/src/main/java/org/apache/accumulo/testing/healthprobe/Monitor.java +++ b/src/main/java/org/apache/accumulo/testing/healthprobe/Monitor.java @@ -20,7 +20,6 @@ import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterrup import java.util.ArrayList; import java.util.Collections; -import java.util.Iterator; import java.util.List; import java.util.Map.Entry; import java.util.Random; @@ -111,7 +110,6 @@ public class Monitor { int count = 0; while (rowIter.hasNext()) { - Iterator<Entry<Key,Value>> itr = rowIter.next(); count++; if (count >= numberOfRows) { break; @@ -125,20 +123,19 @@ public class Monitor { if (cacheTablets) { Locations locations = tops.locate(table, Collections.singleton(new Range())); - tablets = new ArrayList<TabletId>(locations.groupByTablet().keySet()); + tablets = new ArrayList<>(locations.groupByTablet().keySet()); cacheTablets = false; } int index = r.nextInt(tablets.size()); - TabletId tabletId = tablets.get(index); - return tabletId; + return tablets.get(index); } /* * These interfaces + implementations are used to determine how many times the scanner should look * up a random tablet and scan it. */ - static interface LoopControl { - public boolean keepScanning(); + interface LoopControl { + boolean keepScanning(); } // Does a finite number of iterations diff --git a/src/main/java/org/apache/accumulo/testing/ingest/TestIngest.java b/src/main/java/org/apache/accumulo/testing/ingest/TestIngest.java index 0cd0024..ad3cf1c 100644 --- a/src/main/java/org/apache/accumulo/testing/ingest/TestIngest.java +++ b/src/main/java/org/apache/accumulo/testing/ingest/TestIngest.java @@ -153,8 +153,8 @@ public class TestIngest { return bytevals; } - private static byte[] ROW_PREFIX = "row_".getBytes(UTF_8); - private static byte[] COL_PREFIX = "col_".getBytes(UTF_8); + private static final byte[] ROW_PREFIX = "row_".getBytes(UTF_8); + private static final byte[] COL_PREFIX = "col_".getBytes(UTF_8); public static Text generateRow(int rowid, int startRow) { return new Text(FastFormat.toZeroPaddedString(rowid + startRow, 10, 10, ROW_PREFIX)); @@ -196,7 +196,7 @@ public class TestIngest { public static void ingest(AccumuloClient client, FileSystem fs, Opts opts, Configuration conf) throws IOException, AccumuloException, AccumuloSecurityException, TableNotFoundException, - MutationsRejectedException, TableExistsException { + TableExistsException { long stopTime; byte[][] bytevals = generateValues(opts.dataSize); @@ -245,11 +245,7 @@ public class TestIngest { key.setTimestamp(startTime); } - if (opts.delete) { - key.setDeleted(true); - } else { - key.setDeleted(false); - } + key.setDeleted(opts.delete); bytesWritten += key.getSize(); @@ -334,9 +330,8 @@ public class TestIngest { elapsed); } - public static void ingest(AccumuloClient c, Opts opts, Configuration conf) - throws MutationsRejectedException, IOException, AccumuloException, AccumuloSecurityException, - TableNotFoundException, TableExistsException { + public static void ingest(AccumuloClient c, Opts opts, Configuration conf) throws IOException, + AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException { ingest(c, FileSystem.get(conf), opts, conf); } } diff --git a/src/main/java/org/apache/accumulo/testing/ingest/VerifyIngest.java b/src/main/java/org/apache/accumulo/testing/ingest/VerifyIngest.java index d7c36de..849904c 100644 --- a/src/main/java/org/apache/accumulo/testing/ingest/VerifyIngest.java +++ b/src/main/java/org/apache/accumulo/testing/ingest/VerifyIngest.java @@ -101,7 +101,7 @@ public class VerifyIngest { Range range = new Range(startKey, startKey.followingKey(PartialKey.ROW_COLFAM_COLQUAL)); scanner.setRange(range); - byte[] val = null; // t.get(rowKey, column); + byte[] val = null; Iterator<Entry<Key,Value>> iter = scanner.iterator(); diff --git a/src/main/java/org/apache/accumulo/testing/performance/tests/GroupCommitPT.java b/src/main/java/org/apache/accumulo/testing/performance/tests/GroupCommitPT.java index 1d9c130..0f084ca 100644 --- a/src/main/java/org/apache/accumulo/testing/performance/tests/GroupCommitPT.java +++ b/src/main/java/org/apache/accumulo/testing/performance/tests/GroupCommitPT.java @@ -48,14 +48,14 @@ public class GroupCommitPT implements PerformanceTest { private static final int NUM_FLUSHES = 1024; static Mutation createRandomMutation(Random rand) { - byte row[] = new byte[16]; + byte[] row = new byte[16]; rand.nextBytes(row); Mutation m = new Mutation(row); - byte cq[] = new byte[8]; - byte val[] = new byte[16]; + byte[] cq = new byte[8]; + byte[] val = new byte[16]; for (int i = 0; i < 3; i++) { rand.nextBytes(cq); @@ -68,8 +68,8 @@ public class GroupCommitPT implements PerformanceTest { static class WriteTask implements Runnable { - private int batchSize; - private BatchWriter bw; + private final int batchSize; + private final BatchWriter bw; private volatile int written = 0; WriteTask(BatchWriter bw, int numMutations) throws Exception { @@ -153,7 +153,7 @@ public class GroupCommitPT implements PerformanceTest { "The number of times each thread will flush its batch writer. The flushes are spread evenly between mutations."); // number of threads to run for each test - int tests[] = new int[] {1, 2, 4, 8, 16, 32, 64}; + int[] tests = new int[] {1, 2, 4, 8, 16, 32, 64}; // run warm up test for (int numThreads : tests) { @@ -174,7 +174,7 @@ public class GroupCommitPT implements PerformanceTest { Preconditions.checkArgument(NUM_MUTATIONS % numThreads == 0); // presplit tablet to allow more concurrency to tablet in memory map updates, so this does not - // impeded write ahead log appends. + // impede write ahead log appends. NewTableConfiguration ntc = new NewTableConfiguration(); SortedSet<Text> splits = new TreeSet<>(); for (int s = 16; s < 256; s += 16) { diff --git a/src/main/java/org/apache/accumulo/testing/performance/tests/YieldingScanExecutorPT.java b/src/main/java/org/apache/accumulo/testing/performance/tests/YieldingScanExecutorPT.java index 310c971..f05e491 100644 --- a/src/main/java/org/apache/accumulo/testing/performance/tests/YieldingScanExecutorPT.java +++ b/src/main/java/org/apache/accumulo/testing/performance/tests/YieldingScanExecutorPT.java @@ -23,7 +23,6 @@ import java.util.LongSummaryStatistics; import java.util.Map; import java.util.Map.Entry; import java.util.Random; -import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -187,7 +186,6 @@ public class YieldingScanExecutorPT implements PerformanceTest { scanner.addScanIterator(is); - // scanner.setExecutionHints(hints); for (Iterator<Entry<Key,Value>> iter = scanner.iterator(); iter.hasNext(); iter.next()) { count++; if (stop.get()) { @@ -200,8 +198,7 @@ public class YieldingScanExecutorPT implements PerformanceTest { return count; } - private LongSummaryStatistics runShortScans(Environment env, String tableName, int numScans) - throws InterruptedException, ExecutionException { + private LongSummaryStatistics runShortScans(Environment env, String tableName, int numScans) { try (TestExecutor<Long> executor = new TestExecutor<>(NUM_SHORT_SCANS_THREADS)) { Random rand = new Random(); diff --git a/src/main/java/org/apache/accumulo/testing/performance/util/TestExecutor.java b/src/main/java/org/apache/accumulo/testing/performance/util/TestExecutor.java index 42b95d0..a2b5b95 100644 --- a/src/main/java/org/apache/accumulo/testing/performance/util/TestExecutor.java +++ b/src/main/java/org/apache/accumulo/testing/performance/util/TestExecutor.java @@ -28,8 +28,8 @@ import java.util.concurrent.Future; import java.util.stream.Stream; public class TestExecutor<T> implements Iterable<T>, AutoCloseable { - private ExecutorService es; - private List<Future<T>> futures = new ArrayList<>(); + private final ExecutorService es; + private final List<Future<T>> futures = new ArrayList<>(); public TestExecutor(int numThreads) { es = Executors.newFixedThreadPool(numThreads); diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/Framework.java b/src/main/java/org/apache/accumulo/testing/randomwalk/Framework.java index a055ad1..3250053 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/Framework.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/Framework.java @@ -25,7 +25,7 @@ import org.slf4j.LoggerFactory; public class Framework { private static final Logger log = LoggerFactory.getLogger(Framework.class); - private HashMap<String,Node> nodes = new HashMap<>(); + private final HashMap<String,Node> nodes = new HashMap<>(); private static final Framework INSTANCE = new Framework(); /** diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/Module.java b/src/main/java/org/apache/accumulo/testing/randomwalk/Module.java index 0137c4c..8341af3 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/Module.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/Module.java @@ -28,7 +28,6 @@ import java.util.Properties; import java.util.Random; import java.util.Set; import java.util.TreeSet; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.FutureTask; @@ -57,7 +56,7 @@ public class Module extends Node { private static final Logger log = LoggerFactory.getLogger(Module.class); - private class Dummy extends Node { + private static class Dummy extends Node { String name; @@ -133,17 +132,17 @@ public class Module extends Node { } } - private HashMap<String,Node> nodes = new HashMap<>(); - private HashMap<String,Properties> localProps = new HashMap<>(); + private final HashMap<String,Node> nodes = new HashMap<>(); + private final HashMap<String,Properties> localProps = new HashMap<>(); - private class Edge { + private static class Edge { String nodeId; int weight; } - private class AdjList { + private static class AdjList { - private List<Edge> edges = new ArrayList<>(); + private final List<Edge> edges = new ArrayList<>(); private int totalWeight = 0; private Random rand = new Random(); @@ -184,9 +183,9 @@ public class Module extends Node { } } - private HashMap<String,String> prefixes = new HashMap<>(); - private HashMap<String,AdjList> adjMap = new HashMap<>(); - private HashMap<String,Set<String>> aliasMap = new HashMap<>(); + private final HashMap<String,String> prefixes = new HashMap<>(); + private final HashMap<String,AdjList> adjMap = new HashMap<>(); + private final HashMap<String,Set<String>> aliasMap = new HashMap<>(); private final String id; private String initNodeId; private Fixture fixture = null; @@ -295,18 +294,13 @@ public class Module extends Node { // Wrap the visit of the next node in the module in a // callable that returns a thrown exception - FutureTask<Exception> task = new FutureTask<>(new Callable<Exception>() { - - @Override - public Exception call() throws Exception { - try { - nextNode.visit(state, env, nodeProps); - return null; - } catch (Exception e) { - return e; - } + FutureTask<Exception> task = new FutureTask<>(() -> { + try { + nextNode.visit(state, env, nodeProps); + return null; + } catch (Exception e) { + return e; } - }); // Run the task (should execute immediately) @@ -400,21 +394,18 @@ public class Module extends Node { */ private void startTimer(final Node initNode) { runningLong.set(false); - timer = new Thread(new Runnable() { - @Override - public void run() { - try { - systemTime = System.currentTimeMillis(); - Thread.sleep(time); - } catch (InterruptedException ie) { - return; - } - long timeSinceLastProgress = System.currentTimeMillis() - initNode.lastProgress(); - if (timeSinceLastProgress > time) { - log.warn("Node " + initNode + " has been running for " + timeSinceLastProgress / 1000.0 - + " seconds. You may want to look into it."); - runningLong.set(true); - } + timer = new Thread(() -> { + try { + systemTime = System.currentTimeMillis(); + Thread.sleep(time); + } catch (InterruptedException ie) { + return; + } + long timeSinceLastProgress = System.currentTimeMillis() - initNode.lastProgress(); + if (timeSinceLastProgress > time) { + log.warn("Node " + initNode + " has been running for " + timeSinceLastProgress / 1000.0 + + " seconds. You may want to look into it."); + runningLong.set(true); } }); initNode.makingProgress(); @@ -464,14 +455,14 @@ public class Module extends Node { // check if id indicates dummy node if (id.equalsIgnoreCase("END") || id.startsWith("dummy")) { - if (nodes.containsKey(id) == false) { + if (!nodes.containsKey(id)) { nodes.put(id, new Dummy(id)); } return nodes.get(id); } if (id.startsWith("alias")) { - if (nodes.containsKey(id) == false) { + if (!nodes.containsKey(id)) { nodes.put(id, new Alias(id)); } return nodes.get(id); @@ -515,7 +506,7 @@ public class Module extends Node { private void loadFromXml() throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder docbuilder; - Document d = null; + Document d; // set the schema SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/State.java b/src/main/java/org/apache/accumulo/testing/randomwalk/State.java index 2e4f634..6cdba29 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/State.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/State.java @@ -26,10 +26,10 @@ import java.util.Random; */ public class State { - private HashMap<String,Object> stateMap = new HashMap<>(); - private List<String> tables = new ArrayList<>(); - private List<String> namespaces = new ArrayList<>(); - private List<String> users = new ArrayList<>(); + private final HashMap<String,Object> stateMap = new HashMap<>(); + private final List<String> tables = new ArrayList<>(); + private final List<String> namespaces = new ArrayList<>(); + private final List<String> users = new ArrayList<>(); private Random random = new Random(); /** @@ -83,7 +83,7 @@ public class State { * if state object is not present */ public Object get(String key) { - if (stateMap.containsKey(key) == false) { + if (!stateMap.containsKey(key)) { throw new RuntimeException("State does not contain " + key); } return stateMap.get(key); diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/bulk/Verify.java b/src/main/java/org/apache/accumulo/testing/randomwalk/bulk/Verify.java index 552adbc..387e356 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/bulk/Verify.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/bulk/Verify.java @@ -42,7 +42,7 @@ import com.beust.jcommander.Parameter; public class Verify extends Test { - private static byte[] zero = new byte[] {'0'}; + private static final byte[] zero = new byte[] {'0'}; @Override public void visit(State state, RandWalkEnv env, Properties props) throws Exception { diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/BatchWrite.java b/src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/BatchWrite.java index b22ff8a..fc2c6a1 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/BatchWrite.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/BatchWrite.java @@ -43,8 +43,7 @@ public class BatchWrite extends Test { String tableName = state.getRandomTableName(); try { - BatchWriter bw = client.createBatchWriter(tableName, new BatchWriterConfig()); - try { + try (BatchWriter bw = client.createBatchWriter(tableName, new BatchWriterConfig())) { int numRows = rand.nextInt(100000); for (int i = 0; i < numRows; i++) { Mutation m = new Mutation(String.format("%016x", rand.nextLong() & 0x7fffffffffffffffl)); @@ -55,8 +54,6 @@ public class BatchWrite extends Test { bw.addMutation(m); } - } finally { - bw.close(); } log.debug("Wrote to " + tableName); diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/BulkImport.java b/src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/BulkImport.java index b3ebe27..b23bde5 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/BulkImport.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/BulkImport.java @@ -104,9 +104,8 @@ public class BulkImport extends Test { fs.mkdirs(new Path(bulkDir + "_f")); try { - BatchWriter bw = new RFileBatchWriter(env.getHadoopConfiguration(), fs, - bulkDir + "/file01.rf"); - try { + try (BatchWriter bw = new RFileBatchWriter(env.getHadoopConfiguration(), fs, + bulkDir + "/file01.rf")) { TreeSet<Long> rows = new TreeSet<>(); int numRows = rand.nextInt(100000); for (int i = 0; i < numRows; i++) { @@ -122,8 +121,6 @@ public class BulkImport extends Test { bw.addMutation(m); } - } finally { - bw.close(); } client.tableOperations().importDirectory(bulkDir).to(tableName).tableTime(rand.nextBoolean()) diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/CreateTable.java b/src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/CreateTable.java index fb6bfa0..1b79d7f 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/CreateTable.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/concurrent/CreateTable.java @@ -45,7 +45,7 @@ public class CreateTable extends Test { else throw e; } catch (IllegalArgumentException e) { - log.debug("Create: " + e.toString()); + log.debug("Create: " + e); } catch (AccumuloSecurityException e) { log.debug("Could not create table: " + e); } diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/conditional/Verify.java b/src/main/java/org/apache/accumulo/testing/randomwalk/conditional/Verify.java index d3b89d9..3189cae 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/conditional/Verify.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/conditional/Verify.java @@ -23,7 +23,6 @@ import org.apache.accumulo.core.client.AccumuloClient; import org.apache.accumulo.core.client.IsolatedScanner; import org.apache.accumulo.core.client.IteratorSetting; import org.apache.accumulo.core.client.Scanner; -import org.apache.accumulo.core.client.TableNotFoundException; import org.apache.accumulo.core.data.Key; import org.apache.accumulo.core.data.Range; import org.apache.accumulo.core.data.Value; @@ -51,7 +50,7 @@ public class Verify extends Test { } private void verifyBank(String table, AccumuloClient client, String row, int numAccts) - throws TableNotFoundException, Exception { + throws Exception { log.debug("Verifying bank " + row); int count = 0; diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/image/Commit.java b/src/main/java/org/apache/accumulo/testing/randomwalk/image/Commit.java index f3e4318..e5e1aba 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/image/Commit.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/image/Commit.java @@ -30,7 +30,7 @@ public class Commit extends Test { log.debug("Committed " + state.getLong("numWrites") + " writes. Total writes: " + state.getLong("totalWrites")); - state.set("numWrites", Long.valueOf(0)); + state.set("numWrites", 0L); } } diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/image/ImageFixture.java b/src/main/java/org/apache/accumulo/testing/randomwalk/image/ImageFixture.java index 02c7add..28cf33e 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/image/ImageFixture.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/image/ImageFixture.java @@ -86,9 +86,9 @@ public class ImageFixture extends Fixture { log.debug("Configured locality groups for " + imageTableName + " groups = " + groups); } - state.set("numWrites", Long.valueOf(0)); - state.set("totalWrites", Long.valueOf(0)); - state.set("verified", Integer.valueOf(0)); + state.set("numWrites", 0L); + state.set("totalWrites", 0L); + state.set("verified", 0); state.set("lastIndexRow", new Text("")); } diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/image/TableOp.java b/src/main/java/org/apache/accumulo/testing/randomwalk/image/TableOp.java index e4cf731..cdf0442 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/image/TableOp.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/image/TableOp.java @@ -46,7 +46,7 @@ public class TableOp extends Test { // check if chosen table exists AccumuloClient client = env.getAccumuloClient(); TableOperations tableOps = client.tableOperations(); - if (tableOps.exists(tableName) == false) { + if (!tableOps.exists(tableName)) { log.error("Table " + tableName + " does not exist!"); return; } diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/image/Verify.java b/src/main/java/org/apache/accumulo/testing/randomwalk/image/Verify.java index 5b45027..8787469 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/image/Verify.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/image/Verify.java @@ -102,7 +102,7 @@ public class Verify extends Test { Iterator<Entry<Key,Value>> scanIter = scanner.iterator(); - if (scanIter.hasNext() == false) { + if (!scanIter.hasNext()) { log.error("Found row(" + row + ") in " + indexTableName + " but not " + imageTableName); return; } diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/multitable/Commit.java b/src/main/java/org/apache/accumulo/testing/randomwalk/multitable/Commit.java index b8dbe1d..0a65e33 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/multitable/Commit.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/multitable/Commit.java @@ -34,7 +34,7 @@ public class Commit extends Test { log.debug("Committed " + numWrites + " writes. Total writes: " + totalWrites); state.set("totalWrites", totalWrites); - state.set("numWrites", Long.valueOf(0)); + state.set("numWrites", 0L); } } diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/multitable/MultiTableFixture.java b/src/main/java/org/apache/accumulo/testing/randomwalk/multitable/MultiTableFixture.java index 0549bca..68c4cee 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/multitable/MultiTableFixture.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/multitable/MultiTableFixture.java @@ -39,9 +39,9 @@ public class MultiTableFixture extends Fixture { state.set("tableNamePrefix", String.format("multi_%s_%s_%d", hostname, env.getPid(), System.currentTimeMillis())); - state.set("nextId", Integer.valueOf(0)); - state.set("numWrites", Long.valueOf(0)); - state.set("totalWrites", Long.valueOf(0)); + state.set("nextId", 0); + state.set("numWrites", 0L); + state.set("totalWrites", 0L); state.set("tableList", new CopyOnWriteArrayList<String>()); state.set("fs", FileSystem.get(new Configuration())); } 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 9d81b00..6fe575a 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 @@ -38,8 +38,8 @@ import org.slf4j.LoggerFactory; * */ public class WalkingSecurity { - State state = null; - RandWalkEnv env = null; + State state; + RandWalkEnv env; private static final Logger log = LoggerFactory.getLogger(WalkingSecurity.class); private static final String tableName = "SecurityTableName"; @@ -85,9 +85,7 @@ public class WalkingSecurity { Long setTime = state.getLong("Auths-" + userName + '-' + "time"); if (setTime == null) throw new RuntimeException("Auths-" + userName + '-' + "time is null"); - if (System.currentTimeMillis() < (setTime + 1000)) - return true; - return false; + return System.currentTimeMillis() < (setTime + 1000); } public void createUser(String principal, AuthenticationToken token) @@ -116,8 +114,7 @@ public class WalkingSecurity { public boolean hasSystemPermission(String user, SystemPermission permission) throws AccumuloSecurityException { - boolean res = Boolean.parseBoolean(state.getString("Sys-" + user + '-' + permission.name())); - return res; + return Boolean.parseBoolean(state.getString("Sys-" + user + '-' + permission.name())); } public boolean hasTablePermission(String user, String table, TablePermission permission) diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/BatchVerify.java b/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/BatchVerify.java index badef95..f9fb92e 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/BatchVerify.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/BatchVerify.java @@ -51,10 +51,9 @@ public class BatchVerify extends Test { } AccumuloClient client = env.getAccumuloClient(); - BatchScanner scanner = client.createBatchScanner(state.getString("seqTableName"), - new Authorizations(), 2); - try { + try (BatchScanner scanner = client.createBatchScanner(state.getString("seqTableName"), + new Authorizations(), 2)) { int count = 0; List<Range> ranges = new ArrayList<>(); while (count < numVerify) { @@ -109,7 +108,7 @@ public class BatchVerify extends Test { while (curKey < i) { log.error("extra key " + curKey); - if (iterator.hasNext() == false) { + if (!iterator.hasNext()) { done = true; break; } @@ -129,8 +128,6 @@ public class BatchVerify extends Test { } log.debug("verify is now complete"); - } finally { - scanner.close(); } } } diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/Commit.java b/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/Commit.java index 316c650..35c8b7d 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/Commit.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/Commit.java @@ -31,7 +31,7 @@ public class Commit extends Test { log.debug("Committed " + state.getLong("numWrites") + " writes. Total writes: " + state.getLong("totalWrites")); - state.set("numWrites", Long.valueOf(0)); + state.set("numWrites", 0L); } } diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/MapRedVerifyTool.java b/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/MapRedVerifyTool.java index f1e560c..090095b 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/MapRedVerifyTool.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/MapRedVerifyTool.java @@ -43,7 +43,7 @@ public class MapRedVerifyTool extends Configured implements Tool { public static class SeqMapClass extends Mapper<Key,Value,NullWritable,IntWritable> { @Override public void map(Key row, Value data, Context output) throws IOException, InterruptedException { - Integer num = Integer.valueOf(row.getRow().toString()); + int num = Integer.parseInt(row.getRow().toString()); output.write(NullWritable.get(), new IntWritable(num)); } } diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/SequentialFixture.java b/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/SequentialFixture.java index 937458a..251ab36 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/SequentialFixture.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/sequential/SequentialFixture.java @@ -51,8 +51,8 @@ public class SequentialFixture extends Fixture { } client.tableOperations().setProperty(seqTableName, "table.scan.max.memory", "1K"); - state.set("numWrites", Long.valueOf(0)); - state.set("totalWrites", Long.valueOf(0)); + state.set("numWrites", 0L); + state.set("totalWrites", 0L); } @Override diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/shard/CloneIndex.java b/src/main/java/org/apache/accumulo/testing/randomwalk/shard/CloneIndex.java index 334beae..9daaf13 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/shard/CloneIndex.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/shard/CloneIndex.java @@ -36,7 +36,7 @@ public class CloneIndex extends Test { env.getAccumuloClient().tableOperations().flush(indexTableName, null, null, true); long t2 = System.currentTimeMillis(); env.getAccumuloClient().tableOperations().clone(indexTableName, tmpIndexTableName, false, - new HashMap<String,String>(), new HashSet<String>()); + new HashMap<>(), new HashSet<>()); long t3 = System.currentTimeMillis(); log.debug("Cloned " + tmpIndexTableName + " from " + indexTableName + " flush: " + (t2 - t1) diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/shard/Grep.java b/src/main/java/org/apache/accumulo/testing/randomwalk/shard/Grep.java index 519bf5a..acbbcb4 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/shard/Grep.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/shard/Grep.java @@ -88,13 +88,12 @@ public class Grep extends Test { bs.close(); if (!documentsFoundInIndex.equals(documentsFoundByGrep)) { - throw new Exception( - "Set of documents found not equal for words " + Arrays.asList(words).toString() + " " - + documentsFoundInIndex + " " + documentsFoundByGrep); + throw new Exception("Set of documents found not equal for words " + Arrays.toString(words) + + " " + documentsFoundInIndex + " " + documentsFoundByGrep); } - log.debug("Grep and index agree " + Arrays.asList(words).toString() + " " - + documentsFoundInIndex.size()); + log.debug( + "Grep and index agree " + Arrays.toString(words) + " " + documentsFoundInIndex.size()); } diff --git a/src/main/java/org/apache/accumulo/testing/randomwalk/shard/SortTool.java b/src/main/java/org/apache/accumulo/testing/randomwalk/shard/SortTool.java index 91ff5eb..c87e665 100644 --- a/src/main/java/org/apache/accumulo/testing/randomwalk/shard/SortTool.java +++ b/src/main/java/org/apache/accumulo/testing/randomwalk/shard/SortTool.java @@ -31,10 +31,10 @@ import org.slf4j.LoggerFactory; public class SortTool extends Configured implements Tool { protected final Logger log = LoggerFactory.getLogger(this.getClass()); - private String outputDir; - private String seqFile; - private String splitFile; - private Collection<Text> splits; + private final String outputDir; + private final String seqFile; + private final String splitFile; + private final Collection<Text> splits; public SortTool(String seqFile, String outputDir, String splitFile, Collection<Text> splits) { this.outputDir = outputDir; diff --git a/src/main/java/org/apache/accumulo/testing/stress/Scan.java b/src/main/java/org/apache/accumulo/testing/stress/Scan.java index 93dfb2a..56ce66d 100644 --- a/src/main/java/org/apache/accumulo/testing/stress/Scan.java +++ b/src/main/java/org/apache/accumulo/testing/stress/Scan.java @@ -91,8 +91,8 @@ public class Scan { * These interfaces + implementations are used to determine how many times the scanner should look * up a random tablet and scan it. */ - static interface LoopControl { - public boolean keepScanning(); + interface LoopControl { + boolean keepScanning(); } // Does a finite number of iterations