This is an automated email from the ASF dual-hosted git repository.
runzhiwang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ratis.git
The following commit(s) were added to refs/heads/master by this push:
new 9b1d2c1 RATIS-1075. Classes that implement AutoCloseable should call
"close()" when it should be terminated (#208)
9b1d2c1 is described below
commit 9b1d2c18f5677f3d443344e69f98e6c3ac953835
Author: Rui Wang <[email protected]>
AuthorDate: Thu Sep 24 22:58:10 2020 -0700
RATIS-1075. Classes that implement AutoCloseable should call "close()" when
it should be terminated (#208)
* RATIS-1075. Class that implements AutoCloseable should call "close()"
when it should be terminated
* fixup! use try-with-resources
* address more cases
* fixup! fix test
* fixup! fix test
* fixup! fix test
---
.../ratis/logservice/tool/VerificationTool.java | 74 +++++++++++-----------
1 file changed, 38 insertions(+), 36 deletions(-)
diff --git
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/tool/VerificationTool.java
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/tool/VerificationTool.java
index 0c778df..bed16ef 100644
---
a/ratis-logservice/src/main/java/org/apache/ratis/logservice/tool/VerificationTool.java
+++
b/ratis-logservice/src/main/java/org/apache/ratis/logservice/tool/VerificationTool.java
@@ -113,7 +113,7 @@ public class VerificationTool {
public static final String LOG_NAME_PREFIX = "testlog";
public static final String MESSAGE_PREFIX = "message";
- public static void main(String[] args) throws IOException {
+ public static void main(String[] args) throws Exception {
VerificationTool tool = new VerificationTool();
JCommander jc = JCommander.newBuilder()
.addObject(tool)
@@ -124,59 +124,61 @@ public class VerificationTool {
return;
}
System.out.println(tool.metaQuorum);
- LogServiceClient client = new LogServiceClient(tool.metaQuorum);
- ExecutorService executor = Executors.newCachedThreadPool();
- List<Future<?>> futures = new ArrayList<Future<?>>(tool.numLogs);
-
- if (tool.write) {
- LOG.info("Executing parallel writes");
- // Delete any logs that already exist first
- final Set<LogName> logsInSystem = new HashSet<>();
- List<LogInfo> listOfLogs = client.listLogs();
- for (LogInfo logInfo : listOfLogs) {
- logsInSystem.add(logInfo.getLogName());
- }
+ try (LogServiceClient client = new LogServiceClient(tool.metaQuorum)) {
+ ExecutorService executor = Executors.newCachedThreadPool();
+ List<Future<?>> futures = new ArrayList<Future<?>>(tool.numLogs);
+
+ if (tool.write) {
+ LOG.info("Executing parallel writes");
+ // Delete any logs that already exist first
+ final Set<LogName> logsInSystem = new HashSet<>();
+ List<LogInfo> listOfLogs = client.listLogs();
+ for (LogInfo logInfo : listOfLogs) {
+ logsInSystem.add(logInfo.getLogName());
+ }
- LOG.info("Observed logs already in system: {}", logsInSystem);
- for (int i = 0; i < tool.numLogs; i++) {
+ LOG.info("Observed logs already in system: {}", logsInSystem);
+ for (int i = 0; i < tool.numLogs; i++) {
LogName logName = getLogName(i);
if (logsInSystem.contains(logName)) {
- LOG.info("Deleting {}", logName);
- client.deleteLog(logName);
+ LOG.info("Deleting {}", logName);
+ client.deleteLog(logName);
}
- }
+ }
- // First write batch entries to log.
- if(tool.batchSize > 0) {
+ // First write batch entries to log.
+ if(tool.batchSize > 0) {
// Compute the number of batches to write given the batch size.
int numBatches = tool.numRecords / tool.batchSize;
for (int i = 0; i < tool.numLogs; i++) {
- BatchWriter writer = new BatchWriter(getLogName(i), client,
tool.numRecords,
- tool.logFrequency, tool.recordSize, tool.batchSize,
numBatches);
- futures.add(executor.submit(writer));
+ BatchWriter writer = new BatchWriter(getLogName(i), client,
tool.numRecords,
+ tool.logFrequency, tool.recordSize, tool.batchSize,
numBatches);
+ futures.add(executor.submit(writer));
}
- } else {
+ } else {
// Write single entries to log.
for (int i = 0; i < tool.numLogs; i++) {
- BulkWriter writer = new BulkWriter(getLogName(i), client,
tool.numRecords,
- tool.logFrequency, tool.recordSize);
- futures.add(executor.submit(writer));
+ BulkWriter writer = new BulkWriter(getLogName(i), client,
tool.numRecords,
+ tool.logFrequency, tool.recordSize);
+ futures.add(executor.submit(writer));
}
+ }
+ waitForCompletion(futures);
}
- waitForCompletion(futures);
- }
- if (tool.read) {
- LOG.info("Executing parallel reads");
- futures = new ArrayList<Future<?>>(tool.numLogs);
- for (int i = 0; i < tool.numLogs; i++) {
+ if (tool.read) {
+ LOG.info("Executing parallel reads");
+ futures = new ArrayList<Future<?>>(tool.numLogs);
+ for (int i = 0; i < tool.numLogs; i++) {
BulkReader reader = new BulkReader(getLogName(i), client,
tool.numRecords, tool.logFrequency,
- tool.recordSize);
+ tool.recordSize);
futures.add(executor.submit(reader));
+ }
+ waitForCompletion(futures);
}
- waitForCompletion(futures);
+ executor.shutdownNow();
}
- executor.shutdownNow();
+
}
private static LogName getLogName(int id) {