|
32 | 32 | import java.util.concurrent.CountDownLatch; |
33 | 33 | import java.util.concurrent.locks.LockSupport; |
34 | 34 |
|
35 | | -import org.junit.Test; |
36 | | - |
37 | 35 | import com.baidu.hugegraph.election.Config; |
38 | | -import com.baidu.hugegraph.election.RoleTypeData; |
39 | | -import com.baidu.hugegraph.election.RoleTypeDataAdapter; |
40 | 36 | import com.baidu.hugegraph.election.RoleElectionStateMachine; |
41 | 37 | import com.baidu.hugegraph.election.RoleElectionStateMachineImpl; |
| 38 | +import com.baidu.hugegraph.election.RoleTypeData; |
| 39 | +import com.baidu.hugegraph.election.RoleTypeDataAdapter; |
42 | 40 | import com.baidu.hugegraph.election.StateMachineCallback; |
43 | 41 | import com.baidu.hugegraph.election.StateMachineContext; |
44 | 42 | import com.baidu.hugegraph.testutil.Assert; |
| 43 | +import org.junit.Test; |
45 | 44 |
|
46 | 45 | public class RoleElectionStateMachineTest { |
47 | 46 |
|
@@ -150,7 +149,7 @@ public void master(StateMachineContext context) { |
150 | 149 | if (logRecords.size() > MAX_COUNT) { |
151 | 150 | context.stateMachine().shutdown(); |
152 | 151 | } |
153 | | - System.out.println("----master " + node); |
| 152 | + System.out.println("master node: " + node); |
154 | 153 | masterNodes.add(node); |
155 | 154 | } |
156 | 155 |
|
@@ -196,7 +195,7 @@ public void abdication(StateMachineContext context) { |
196 | 195 |
|
197 | 196 | @Override |
198 | 197 | 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()); |
200 | 199 | } |
201 | 200 | }; |
202 | 201 |
|
@@ -226,18 +225,17 @@ public boolean updateIfNodePresent(RoleTypeData stateData) { |
226 | 225 | this.epoch = copy.epoch(); |
227 | 226 | Assert.assertNull(value); |
228 | 227 | metaDataLogs.add(copy); |
229 | | - System.out.println("----1" + copy); |
| 228 | + System.out.println("The node " + copy + " become new master:"); |
230 | 229 | return copy; |
231 | 230 | } |
232 | 231 |
|
233 | 232 | Assert.assertEquals(value.epoch(), copy.epoch()); |
234 | 233 | if (Objects.equals(value.node(), copy.node()) && |
235 | 234 | value.clock() <= copy.clock()) { |
236 | | - System.out.println("----2" + copy); |
| 235 | + System.out.println("The master node " + copy + " keep heartbeat"); |
237 | 236 | metaDataLogs.add(copy); |
238 | 237 | 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"); |
241 | 239 | } |
242 | 240 | return copy; |
243 | 241 | } |
|
0 commit comments