Skip to content

Commit 67a5f93

Browse files
committed
improve code
1 parent 048e782 commit 67a5f93

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

hugegraph-test/src/main/java/com/baidu/hugegraph/core/RoleElectionStateMachineTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,15 @@
3232
import java.util.concurrent.CountDownLatch;
3333
import java.util.concurrent.locks.LockSupport;
3434

35-
import org.junit.Test;
36-
3735
import com.baidu.hugegraph.election.Config;
38-
import com.baidu.hugegraph.election.RoleTypeData;
39-
import com.baidu.hugegraph.election.RoleTypeDataAdapter;
4036
import com.baidu.hugegraph.election.RoleElectionStateMachine;
4137
import com.baidu.hugegraph.election.RoleElectionStateMachineImpl;
38+
import com.baidu.hugegraph.election.RoleTypeData;
39+
import com.baidu.hugegraph.election.RoleTypeDataAdapter;
4240
import com.baidu.hugegraph.election.StateMachineCallback;
4341
import com.baidu.hugegraph.election.StateMachineContext;
4442
import com.baidu.hugegraph.testutil.Assert;
43+
import org.junit.Test;
4544

4645
public class RoleElectionStateMachineTest {
4746

@@ -150,7 +149,7 @@ public void master(StateMachineContext context) {
150149
if (logRecords.size() > MAX_COUNT) {
151150
context.stateMachine().shutdown();
152151
}
153-
System.out.println("----master " + node);
152+
System.out.println("master node: " + node);
154153
masterNodes.add(node);
155154
}
156155

@@ -196,7 +195,7 @@ public void abdication(StateMachineContext context) {
196195

197196
@Override
198197
public void error(StateMachineContext context, Throwable e) {
199-
System.out.println("----" + context.node() + " " + e.getMessage());
198+
System.out.println("state machine error: node " + context.node() + " message " + e.getMessage());
200199
}
201200
};
202201

@@ -226,18 +225,17 @@ public boolean updateIfNodePresent(RoleTypeData stateData) {
226225
this.epoch = copy.epoch();
227226
Assert.assertNull(value);
228227
metaDataLogs.add(copy);
229-
System.out.println("----1" + copy);
228+
System.out.println("The node " + copy + " become new master:");
230229
return copy;
231230
}
232231

233232
Assert.assertEquals(value.epoch(), copy.epoch());
234233
if (Objects.equals(value.node(), copy.node()) &&
235234
value.clock() <= copy.clock()) {
236-
System.out.println("----2" + copy);
235+
System.out.println("The master node " + copy + " keep heartbeat");
237236
metaDataLogs.add(copy);
238237
if (value.clock() == copy.clock()) {
239-
Exception e = new Exception("eq");
240-
e.printStackTrace();
238+
Assert.fail("Clock must increase when same epoch and node id");
241239
}
242240
return copy;
243241
}

0 commit comments

Comments
 (0)