Skip to content

Commit

Permalink
Make test time limitation work stable (#379)
Browse files Browse the repository at this point in the history
* done?

* config temporarily commit

* Revert "config temporarily commit"

This reverts commit ef0b002.

* add comment
  • Loading branch information
liyuheng55555 committed Nov 16, 2023
1 parent e7d5e46 commit bbf690d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 63 deletions.
3 changes: 2 additions & 1 deletion configuration/conf/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
# verificationQueryMode 单数据库正确性查询模式,需要配置 FILE_PATH 以及 DATA_SET
# BENCHMARK_WORK_MODE=testWithDefaultPath

# 限制测试最长耗时,设置为0表示无限制,单位为ms
# 对于数据写入或查询,限制最长耗时,设置为0表示无限制,单位为ms
# 此参数不限制预先注册元数据的耗时
# TEST_MAX_TIME=0

# 是否启动Benchmark统计模块
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import cn.edu.tsinghua.iot.benchmark.client.DataClient;
import cn.edu.tsinghua.iot.benchmark.client.SchemaClient;
import cn.edu.tsinghua.iot.benchmark.client.TimeClient;
import cn.edu.tsinghua.iot.benchmark.client.operation.Operation;
import cn.edu.tsinghua.iot.benchmark.conf.Config;
import cn.edu.tsinghua.iot.benchmark.conf.ConfigDescriptor;
Expand All @@ -35,6 +34,8 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.ExecutorService;
Expand Down Expand Up @@ -75,26 +76,38 @@ public void run() {
}
dataClients.add(client);
}
TimeClient timeClient = new TimeClient(dataClients);
timeClient.start();
for (DataClient client : dataClients) {
executorService.submit(client);
}
setTimeLimitTask();
start = System.nanoTime();
executorService.shutdown();
try {
// wait for all dataClients finish test
dataDownLatch.await();
if (timeClient.isAlive()) {
timeClient.interrupt();
}
} catch (InterruptedException e) {
LOGGER.error("Exception occurred during waiting for all threads finish.", e);
Thread.currentThread().interrupt();
}
postCheck();
}

private void setTimeLimitTask() {
if (config.getTEST_MAX_TIME() != 0) {
TimerTask stopAllDataClient =
new TimerTask() {
@Override
public void run() {
LOGGER.info(
"It has been tested for {} ms, start to stop all dataClients.",
config.getTEST_MAX_TIME());
dataClients.forEach(DataClient::stopClient);
}
};
new Timer().schedule(stopAllDataClient, config.getTEST_MAX_TIME());
}
}

protected abstract void postCheck();

/** Clean up data */
Expand Down

0 comments on commit bbf690d

Please sign in to comment.