Ayaka Koshibe

term-related test additions

Change-Id: I9359ab9a53d73a216a83732612a54154b9655c8c
...@@ -31,6 +31,9 @@ public final class MastershipTerm { ...@@ -31,6 +31,9 @@ public final class MastershipTerm {
31 31
32 @Override 32 @Override
33 public boolean equals(Object other) { 33 public boolean equals(Object other) {
34 + if (this == other) {
35 + return true;
36 + }
34 if (other instanceof MastershipTerm) { 37 if (other instanceof MastershipTerm) {
35 MastershipTerm that = (MastershipTerm) other; 38 MastershipTerm that = (MastershipTerm) other;
36 if (!this.master.equals(that.master)) { 39 if (!this.master.equals(that.master)) {
......
...@@ -11,6 +11,7 @@ import org.onlab.onos.cluster.ControllerNode; ...@@ -11,6 +11,7 @@ import org.onlab.onos.cluster.ControllerNode;
11 import org.onlab.onos.cluster.ControllerNode.State; 11 import org.onlab.onos.cluster.ControllerNode.State;
12 import org.onlab.onos.cluster.DefaultControllerNode; 12 import org.onlab.onos.cluster.DefaultControllerNode;
13 import org.onlab.onos.cluster.MastershipService; 13 import org.onlab.onos.cluster.MastershipService;
14 +import org.onlab.onos.cluster.MastershipTermService;
14 import org.onlab.onos.cluster.NodeId; 15 import org.onlab.onos.cluster.NodeId;
15 import org.onlab.onos.event.impl.TestEventDispatcher; 16 import org.onlab.onos.event.impl.TestEventDispatcher;
16 import org.onlab.onos.net.DeviceId; 17 import org.onlab.onos.net.DeviceId;
...@@ -100,6 +101,20 @@ public class MastershipManagerTest { ...@@ -100,6 +101,20 @@ public class MastershipManagerTest {
100 assertEquals("should be two devices:", 2, mgr.getDevicesOf(NID_LOCAL).size()); 101 assertEquals("should be two devices:", 2, mgr.getDevicesOf(NID_LOCAL).size());
101 } 102 }
102 103
104 + @Test
105 + public void termService() {
106 + MastershipTermService ts = mgr.requestTermService();
107 +
108 + //term = 0 for both
109 + mgr.setRole(NID_LOCAL, DEV_MASTER, MASTER);
110 + assertEquals("inconsistent term: ", 0, ts.getMastershipTerm(DEV_MASTER).termNumber());
111 +
112 + //hand devices to NID_LOCAL and back: term = 2
113 + mgr.setRole(NID_OTHER, DEV_MASTER, MASTER);
114 + mgr.setRole(NID_LOCAL, DEV_MASTER, MASTER);
115 + assertEquals("inconsistent terms: ", 2, ts.getMastershipTerm(DEV_MASTER).termNumber());
116 + }
117 +
103 private final class TestClusterService implements ClusterService { 118 private final class TestClusterService implements ClusterService {
104 119
105 ControllerNode local = new DefaultControllerNode(NID_LOCAL, LOCALHOST); 120 ControllerNode local = new DefaultControllerNode(NID_LOCAL, LOCALHOST);
......