You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by as...@apache.org on 2021/01/22 08:59:47 UTC
[ignite-3] branch ignite-13885 updated: IGNITE-13885 Bugfixing.
This is an automated email from the ASF dual-hosted git repository.
ascherbakov pushed a commit to branch ignite-13885
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/ignite-13885 by this push:
new fbd7d2d IGNITE-13885 Bugfixing.
fbd7d2d is described below
commit fbd7d2d9f1ee807c5e0f929ab178e002e85e160e
Author: Alexey Scherbakov <al...@gmail.com>
AuthorDate: Fri Jan 22 11:59:32 2021 +0300
IGNITE-13885 Bugfixing.
---
.../alipay/sofa/jraft/counter/CounterExampleTest.java | 7 ++++---
.../com/alipay/sofa/jraft/counter/CounterServer.java | 17 +++++++++--------
.../test/java/com/alipay/sofa/jraft/test/TestUtils.java | 6 +++---
3 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/modules/raft/src/test/java/com/alipay/sofa/jraft/counter/CounterExampleTest.java b/modules/raft/src/test/java/com/alipay/sofa/jraft/counter/CounterExampleTest.java
index d03c2f2..81d378e 100644
--- a/modules/raft/src/test/java/com/alipay/sofa/jraft/counter/CounterExampleTest.java
+++ b/modules/raft/src/test/java/com/alipay/sofa/jraft/counter/CounterExampleTest.java
@@ -58,7 +58,6 @@ public class CounterExampleTest {
@Test
public void testCounter() throws IOException, InterruptedException, TimeoutException, RemotingException {
-
try {
String initConfStr = "127.0.0.1:8080,127.0.0.1:8081,127.0.0.1:8082";
@@ -69,7 +68,9 @@ public class CounterExampleTest {
CounterServer node1 = CounterServer.start(dataPath, groupId, "127.0.0.1:8081", initConfStr);
CounterServer node2 = CounterServer.start(dataPath, groupId, "127.0.0.1:8082", initConfStr);
- Thread.sleep(3000);
+ LOG.info("Waiting for leader election");
+
+ Thread.sleep(2000);
// Create client.
final Configuration conf = new Configuration();
@@ -87,7 +88,7 @@ public class CounterExampleTest {
final PeerId leader = RouteTable.getInstance().selectLeader(groupId);
System.out.println("Leader is " + leader);
- final int n = 1;
+ final int n = 1000;
final CountDownLatch latch = new CountDownLatch(n);
final long start = System.currentTimeMillis();
for (int i = 0; i < n; i++) {
diff --git a/modules/raft/src/test/java/com/alipay/sofa/jraft/counter/CounterServer.java b/modules/raft/src/test/java/com/alipay/sofa/jraft/counter/CounterServer.java
index e6fa618..9461ceb 100644
--- a/modules/raft/src/test/java/com/alipay/sofa/jraft/counter/CounterServer.java
+++ b/modules/raft/src/test/java/com/alipay/sofa/jraft/counter/CounterServer.java
@@ -116,14 +116,10 @@ public class CounterServer {
public static CounterServer start(String dataPath, String groupId, String serverIdStr, String initConfStr) throws IOException {
final NodeOptions nodeOptions = new NodeOptions();
- // 为了测试,调整 snapshot 间隔等参数
- // 设置选举超时时间为 1 秒
+
nodeOptions.setElectionTimeoutMs(1000);
- // 关闭 CLI 服务。
nodeOptions.setDisableCli(false);
- // 每隔30秒做一次 snapshot
nodeOptions.setSnapshotIntervalSecs(30);
- // 解析参数
final PeerId serverId = new PeerId();
if (!serverId.parse(serverIdStr)) {
throw new IllegalArgumentException("Fail to parse serverId:" + serverIdStr);
@@ -132,11 +128,16 @@ public class CounterServer {
if (!initConf.parse(initConfStr)) {
throw new IllegalArgumentException("Fail to parse initConf:" + initConfStr);
}
- // 设置初始集群配置
nodeOptions.setInitialConf(initConf);
- // 启动
- final CounterServer counterServer = new CounterServer(dataPath, groupId, serverId, nodeOptions);
+ File serverData = new File(dataPath, serverIdStr.replaceAll("\\W+", ""));
+
+ if (!serverData.exists()) {
+ if (!serverData.mkdirs())
+ throw new IllegalArgumentException("Failed to create server data path:" + serverData);
+ }
+
+ final CounterServer counterServer = new CounterServer(serverData.getPath(), groupId, serverId, nodeOptions);
System.out.println("Started counter server at port:"
+ counterServer.getNode().getNodeId().getPeerId().getPort());
diff --git a/modules/raft/src/test/java/com/alipay/sofa/jraft/test/TestUtils.java b/modules/raft/src/test/java/com/alipay/sofa/jraft/test/TestUtils.java
index 4bd1926..b41f44f 100644
--- a/modules/raft/src/test/java/com/alipay/sofa/jraft/test/TestUtils.java
+++ b/modules/raft/src/test/java/com/alipay/sofa/jraft/test/TestUtils.java
@@ -67,9 +67,9 @@ public class TestUtils {
}
public static String mkTempDir() {
- String userDirectory = System.getProperty("user.dir");
- // String tmpDir = System.getProperty("java.io.tmpdir", "/tmp");
- return Paths.get(userDirectory, "jraft_test_" + System.nanoTime()).toString();
+ String dir = System.getProperty("user.dir");
+ //String dir = System.getProperty("java.io.tmpdir", "/tmp");
+ return Paths.get(dir, "jraft_test_" + System.nanoTime()).toString();
}
public static LogEntry mockEntry(final int index, final int term) {