Yuta HIGUCHI

Fixing DeviceManagerTest

Change-Id: I9431f40e0cb733f59041790af1ee54d1813f117d
1 package org.onlab.onos.net.device.impl; 1 package org.onlab.onos.net.device.impl;
2 2
3 import com.google.common.collect.Sets; 3 import com.google.common.collect.Sets;
4 +
4 import org.junit.After; 5 import org.junit.After;
5 import org.junit.Before; 6 import org.junit.Before;
6 import org.junit.Ignore; 7 import org.junit.Ignore;
7 import org.junit.Test; 8 import org.junit.Test;
9 +import org.onlab.onos.cluster.ClusterEventListener;
10 +import org.onlab.onos.cluster.ClusterService;
11 +import org.onlab.onos.cluster.ControllerNode;
12 +import org.onlab.onos.cluster.DefaultControllerNode;
8 import org.onlab.onos.cluster.MastershipServiceAdapter; 13 import org.onlab.onos.cluster.MastershipServiceAdapter;
14 +import org.onlab.onos.cluster.MastershipTerm;
15 +import org.onlab.onos.cluster.MastershipTermService;
9 import org.onlab.onos.cluster.NodeId; 16 import org.onlab.onos.cluster.NodeId;
17 +import org.onlab.onos.cluster.ControllerNode.State;
10 import org.onlab.onos.event.Event; 18 import org.onlab.onos.event.Event;
11 import org.onlab.onos.event.impl.TestEventDispatcher; 19 import org.onlab.onos.event.impl.TestEventDispatcher;
12 import org.onlab.onos.net.Device; 20 import org.onlab.onos.net.Device;
...@@ -27,7 +35,9 @@ import org.onlab.onos.net.device.DeviceService; ...@@ -27,7 +35,9 @@ import org.onlab.onos.net.device.DeviceService;
27 import org.onlab.onos.net.device.PortDescription; 35 import org.onlab.onos.net.device.PortDescription;
28 import org.onlab.onos.net.provider.AbstractProvider; 36 import org.onlab.onos.net.provider.AbstractProvider;
29 import org.onlab.onos.net.provider.ProviderId; 37 import org.onlab.onos.net.provider.ProviderId;
38 +import org.onlab.onos.store.ClockProviderService;
30 import org.onlab.onos.store.trivial.impl.SimpleDeviceStore; 39 import org.onlab.onos.store.trivial.impl.SimpleDeviceStore;
40 +import org.onlab.packet.IpPrefix;
31 41
32 import java.util.ArrayList; 42 import java.util.ArrayList;
33 import java.util.Iterator; 43 import java.util.Iterator;
...@@ -56,6 +66,8 @@ public class DeviceManagerTest { ...@@ -56,6 +66,8 @@ public class DeviceManagerTest {
56 private static final PortNumber P1 = PortNumber.portNumber(1); 66 private static final PortNumber P1 = PortNumber.portNumber(1);
57 private static final PortNumber P2 = PortNumber.portNumber(2); 67 private static final PortNumber P2 = PortNumber.portNumber(2);
58 private static final PortNumber P3 = PortNumber.portNumber(3); 68 private static final PortNumber P3 = PortNumber.portNumber(3);
69 + private static final NodeId NID_LOCAL = new NodeId("local");
70 + private static final IpPrefix LOCALHOST = IpPrefix.valueOf("127.0.0.1");
59 71
60 private DeviceManager mgr; 72 private DeviceManager mgr;
61 73
...@@ -75,6 +87,8 @@ public class DeviceManagerTest { ...@@ -75,6 +87,8 @@ public class DeviceManagerTest {
75 mgr.store = new SimpleDeviceStore(); 87 mgr.store = new SimpleDeviceStore();
76 mgr.eventDispatcher = new TestEventDispatcher(); 88 mgr.eventDispatcher = new TestEventDispatcher();
77 mgr.mastershipService = new TestMastershipService(); 89 mgr.mastershipService = new TestMastershipService();
90 + mgr.clusterService = new TestClusterService();
91 + mgr.clockProviderService = new TestClockProviderService();
78 mgr.activate(); 92 mgr.activate();
79 93
80 service.addListener(listener); 94 service.addListener(listener);
...@@ -273,6 +287,59 @@ public class DeviceManagerTest { ...@@ -273,6 +287,59 @@ public class DeviceManagerTest {
273 public MastershipRole requestRoleFor(DeviceId deviceId) { 287 public MastershipRole requestRoleFor(DeviceId deviceId) {
274 return MastershipRole.MASTER; 288 return MastershipRole.MASTER;
275 } 289 }
290 +
291 + @Override
292 + public MastershipTermService requestTermService() {
293 + return new MastershipTermService() {
294 + @Override
295 + public MastershipTerm getMastershipTerm(DeviceId deviceId) {
296 + // FIXME: just returning something not null
297 + return MastershipTerm.of(NID_LOCAL, 1);
298 + }
299 + };
300 + }
301 + }
302 +
303 + // code clone
304 + private final class TestClusterService implements ClusterService {
305 +
306 + ControllerNode local = new DefaultControllerNode(NID_LOCAL, LOCALHOST);
307 +
308 + @Override
309 + public ControllerNode getLocalNode() {
310 + return local;
311 + }
312 +
313 + @Override
314 + public Set<ControllerNode> getNodes() {
315 + return null;
276 } 316 }
277 317
318 + @Override
319 + public ControllerNode getNode(NodeId nodeId) {
320 + return null;
321 + }
322 +
323 + @Override
324 + public State getState(NodeId nodeId) {
325 + return null;
326 + }
327 +
328 + @Override
329 + public void addListener(ClusterEventListener listener) {
330 + }
331 +
332 + @Override
333 + public void removeListener(ClusterEventListener listener) {
334 + }
335 + }
336 +
337 + private final class TestClockProviderService implements
338 + ClockProviderService {
339 +
340 + @Override
341 + public void setMastershipTerm(DeviceId deviceId, MastershipTerm term) {
342 + // TODO Auto-generated method stub
343 + }
344 + }
278 } 345 }
......