Add GossipLinkStoreTest
Change-Id: If3d9777583a38d911b19bb1bc50212ccb621918a
Showing
7 changed files
with
77 additions
and
56 deletions
| ... | @@ -23,6 +23,7 @@ import java.util.ArrayList; | ... | @@ -23,6 +23,7 @@ import java.util.ArrayList; |
| 23 | import java.util.HashSet; | 23 | import java.util.HashSet; |
| 24 | import java.util.List; | 24 | import java.util.List; |
| 25 | 25 | ||
| 26 | +import static org.junit.Assert.assertEquals; | ||
| 26 | import static org.onlab.onos.net.DeviceId.deviceId; | 27 | import static org.onlab.onos.net.DeviceId.deviceId; |
| 27 | import static org.onlab.onos.net.HostId.hostId; | 28 | import static org.onlab.onos.net.HostId.hostId; |
| 28 | import static org.onlab.onos.net.PortNumber.portNumber; | 29 | import static org.onlab.onos.net.PortNumber.portNumber; |
| ... | @@ -85,4 +86,23 @@ public final class NetTestTools { | ... | @@ -85,4 +86,23 @@ public final class NetTestTools { |
| 85 | return new DefaultPath(PID, links, ids.length); | 86 | return new DefaultPath(PID, links, ids.length); |
| 86 | } | 87 | } |
| 87 | 88 | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * Verifies that Annotations created by merging {@code annotations} is | ||
| 92 | + * equal to actual Annotations. | ||
| 93 | + * | ||
| 94 | + * @param actual Annotations to check | ||
| 95 | + * @param annotations | ||
| 96 | + */ | ||
| 97 | + public static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) { | ||
| 98 | + DefaultAnnotations expected = DefaultAnnotations.builder().build(); | ||
| 99 | + for (SparseAnnotations a : annotations) { | ||
| 100 | + expected = DefaultAnnotations.merge(expected, a); | ||
| 101 | + } | ||
| 102 | + assertEquals(expected.keys(), actual.keys()); | ||
| 103 | + for (String key : expected.keys()) { | ||
| 104 | + assertEquals(expected.value(key), actual.value(key)); | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | + | ||
| 88 | } | 108 | } | ... | ... |
| ... | @@ -122,7 +122,7 @@ public class GossipLinkStore | ... | @@ -122,7 +122,7 @@ public class GossipLinkStore |
| 122 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 122 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 123 | protected ClusterService clusterService; | 123 | protected ClusterService clusterService; |
| 124 | 124 | ||
| 125 | - private static final KryoSerializer SERIALIZER = new KryoSerializer() { | 125 | + protected static final KryoSerializer SERIALIZER = new KryoSerializer() { |
| 126 | @Override | 126 | @Override |
| 127 | protected void setupKryoPool() { | 127 | protected void setupKryoPool() { |
| 128 | serializerPool = KryoNamespace.newBuilder() | 128 | serializerPool = KryoNamespace.newBuilder() | ... | ... |
| 1 | +package org.onlab.onos.store.cluster; | ||
| 2 | + | ||
| 3 | +import java.util.HashMap; | ||
| 4 | +import java.util.Map; | ||
| 5 | +import java.util.Set; | ||
| 6 | + | ||
| 7 | +import org.onlab.onos.cluster.ClusterEventListener; | ||
| 8 | +import org.onlab.onos.cluster.ClusterService; | ||
| 9 | +import org.onlab.onos.cluster.ControllerNode; | ||
| 10 | +import org.onlab.onos.cluster.NodeId; | ||
| 11 | +import org.onlab.onos.cluster.ControllerNode.State; | ||
| 12 | + | ||
| 13 | +import com.google.common.collect.Sets; | ||
| 14 | + | ||
| 15 | +public abstract class StaticClusterService implements ClusterService { | ||
| 16 | + | ||
| 17 | + protected final Map<NodeId, ControllerNode> nodes = new HashMap<>(); | ||
| 18 | + protected final Map<NodeId, ControllerNode.State> nodeStates = new HashMap<>(); | ||
| 19 | + protected ControllerNode localNode; | ||
| 20 | + | ||
| 21 | + @Override | ||
| 22 | + public ControllerNode getLocalNode() { | ||
| 23 | + return localNode; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + @Override | ||
| 27 | + public Set<ControllerNode> getNodes() { | ||
| 28 | + return Sets.newHashSet(nodes.values()); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + @Override | ||
| 32 | + public ControllerNode getNode(NodeId nodeId) { | ||
| 33 | + return nodes.get(nodeId); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + @Override | ||
| 37 | + public State getState(NodeId nodeId) { | ||
| 38 | + return nodeStates.get(nodeId); | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + @Override | ||
| 42 | + public void addListener(ClusterEventListener listener) { | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + @Override | ||
| 46 | + public void removeListener(ClusterEventListener listener) { | ||
| 47 | + } | ||
| 48 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -41,10 +41,8 @@ import org.junit.Before; | ... | @@ -41,10 +41,8 @@ import org.junit.Before; |
| 41 | import org.junit.BeforeClass; | 41 | import org.junit.BeforeClass; |
| 42 | import org.junit.Ignore; | 42 | import org.junit.Ignore; |
| 43 | import org.junit.Test; | 43 | import org.junit.Test; |
| 44 | -import org.onlab.onos.cluster.ClusterEventListener; | ||
| 45 | import org.onlab.onos.cluster.ClusterService; | 44 | import org.onlab.onos.cluster.ClusterService; |
| 46 | import org.onlab.onos.cluster.ControllerNode; | 45 | import org.onlab.onos.cluster.ControllerNode; |
| 47 | -import org.onlab.onos.cluster.ControllerNode.State; | ||
| 48 | import org.onlab.onos.cluster.DefaultControllerNode; | 46 | import org.onlab.onos.cluster.DefaultControllerNode; |
| 49 | import org.onlab.onos.cluster.NodeId; | 47 | import org.onlab.onos.cluster.NodeId; |
| 50 | import org.onlab.onos.mastership.MastershipServiceAdapter; | 48 | import org.onlab.onos.mastership.MastershipServiceAdapter; |
| ... | @@ -65,6 +63,7 @@ import org.onlab.onos.net.device.DeviceStore; | ... | @@ -65,6 +63,7 @@ import org.onlab.onos.net.device.DeviceStore; |
| 65 | import org.onlab.onos.net.device.DeviceStoreDelegate; | 63 | import org.onlab.onos.net.device.DeviceStoreDelegate; |
| 66 | import org.onlab.onos.net.device.PortDescription; | 64 | import org.onlab.onos.net.device.PortDescription; |
| 67 | import org.onlab.onos.net.provider.ProviderId; | 65 | import org.onlab.onos.net.provider.ProviderId; |
| 66 | +import org.onlab.onos.store.cluster.StaticClusterService; | ||
| 68 | import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; | 67 | import org.onlab.onos.store.cluster.messaging.ClusterCommunicationService; |
| 69 | import org.onlab.onos.store.cluster.messaging.ClusterMessage; | 68 | import org.onlab.onos.store.cluster.messaging.ClusterMessage; |
| 70 | import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; | 69 | import org.onlab.onos.store.cluster.messaging.ClusterMessageHandler; |
| ... | @@ -133,6 +132,7 @@ public class GossipDeviceStoreTest { | ... | @@ -133,6 +132,7 @@ public class GossipDeviceStoreTest { |
| 133 | private DeviceClockManager deviceClockManager; | 132 | private DeviceClockManager deviceClockManager; |
| 134 | private DeviceClockService deviceClockService; | 133 | private DeviceClockService deviceClockService; |
| 135 | private ClusterCommunicationService clusterCommunicator; | 134 | private ClusterCommunicationService clusterCommunicator; |
| 135 | + | ||
| 136 | @BeforeClass | 136 | @BeforeClass |
| 137 | public static void setUpBeforeClass() throws Exception { | 137 | public static void setUpBeforeClass() throws Exception { |
| 138 | } | 138 | } |
| ... | @@ -838,45 +838,15 @@ public class GossipDeviceStoreTest { | ... | @@ -838,45 +838,15 @@ public class GossipDeviceStoreTest { |
| 838 | } | 838 | } |
| 839 | } | 839 | } |
| 840 | 840 | ||
| 841 | - private static final class TestClusterService implements ClusterService { | 841 | + private static final class TestClusterService extends StaticClusterService { |
| 842 | - | ||
| 843 | - private final Map<NodeId, ControllerNode> nodes = new HashMap<>(); | ||
| 844 | - private final Map<NodeId, ControllerNode.State> nodeStates = new HashMap<>(); | ||
| 845 | 842 | ||
| 846 | public TestClusterService() { | 843 | public TestClusterService() { |
| 844 | + localNode = ONOS1; | ||
| 847 | nodes.put(NID1, ONOS1); | 845 | nodes.put(NID1, ONOS1); |
| 848 | nodeStates.put(NID1, ACTIVE); | 846 | nodeStates.put(NID1, ACTIVE); |
| 849 | 847 | ||
| 850 | nodes.put(NID2, ONOS2); | 848 | nodes.put(NID2, ONOS2); |
| 851 | nodeStates.put(NID2, ACTIVE); | 849 | nodeStates.put(NID2, ACTIVE); |
| 852 | } | 850 | } |
| 853 | - | ||
| 854 | - @Override | ||
| 855 | - public ControllerNode getLocalNode() { | ||
| 856 | - return GossipDeviceStoreTest.ONOS1; | ||
| 857 | - } | ||
| 858 | - | ||
| 859 | - @Override | ||
| 860 | - public Set<ControllerNode> getNodes() { | ||
| 861 | - return Sets.newHashSet(nodes.values()); | ||
| 862 | - } | ||
| 863 | - | ||
| 864 | - @Override | ||
| 865 | - public ControllerNode getNode(NodeId nodeId) { | ||
| 866 | - return nodes.get(nodeId); | ||
| 867 | - } | ||
| 868 | - | ||
| 869 | - @Override | ||
| 870 | - public State getState(NodeId nodeId) { | ||
| 871 | - return nodeStates.get(nodeId); | ||
| 872 | - } | ||
| 873 | - | ||
| 874 | - @Override | ||
| 875 | - public void addListener(ClusterEventListener listener) { | ||
| 876 | - } | ||
| 877 | - | ||
| 878 | - @Override | ||
| 879 | - public void removeListener(ClusterEventListener listener) { | ||
| 880 | - } | ||
| 881 | } | 851 | } |
| 882 | } | 852 | } | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -23,6 +23,7 @@ import static org.junit.Assert.*; | ... | @@ -23,6 +23,7 @@ import static org.junit.Assert.*; |
| 23 | import static org.onlab.onos.net.Device.Type.SWITCH; | 23 | import static org.onlab.onos.net.Device.Type.SWITCH; |
| 24 | import static org.onlab.onos.net.DeviceId.deviceId; | 24 | import static org.onlab.onos.net.DeviceId.deviceId; |
| 25 | import static org.onlab.onos.net.device.DeviceEvent.Type.*; | 25 | import static org.onlab.onos.net.device.DeviceEvent.Type.*; |
| 26 | +import static org.onlab.onos.net.NetTestTools.assertAnnotationsEquals; | ||
| 26 | 27 | ||
| 27 | import java.util.Arrays; | 28 | import java.util.Arrays; |
| 28 | import java.util.HashMap; | 29 | import java.util.HashMap; |
| ... | @@ -38,7 +39,6 @@ import org.junit.Before; | ... | @@ -38,7 +39,6 @@ import org.junit.Before; |
| 38 | import org.junit.BeforeClass; | 39 | import org.junit.BeforeClass; |
| 39 | import org.junit.Ignore; | 40 | import org.junit.Ignore; |
| 40 | import org.junit.Test; | 41 | import org.junit.Test; |
| 41 | -import org.onlab.onos.net.Annotations; | ||
| 42 | import org.onlab.onos.net.DefaultAnnotations; | 42 | import org.onlab.onos.net.DefaultAnnotations; |
| 43 | import org.onlab.onos.net.Device; | 43 | import org.onlab.onos.net.Device; |
| 44 | import org.onlab.onos.net.DeviceId; | 44 | import org.onlab.onos.net.DeviceId; |
| ... | @@ -56,6 +56,7 @@ import org.onlab.onos.net.provider.ProviderId; | ... | @@ -56,6 +56,7 @@ import org.onlab.onos.net.provider.ProviderId; |
| 56 | 56 | ||
| 57 | import com.google.common.collect.Iterables; | 57 | import com.google.common.collect.Iterables; |
| 58 | import com.google.common.collect.Sets; | 58 | import com.google.common.collect.Sets; |
| 59 | + | ||
| 59 | import org.onlab.packet.ChassisId; | 60 | import org.onlab.packet.ChassisId; |
| 60 | 61 | ||
| 61 | /** | 62 | /** |
| ... | @@ -146,25 +147,6 @@ public class SimpleDeviceStoreTest { | ... | @@ -146,25 +147,6 @@ public class SimpleDeviceStoreTest { |
| 146 | assertEquals(SN, device.serialNumber()); | 147 | assertEquals(SN, device.serialNumber()); |
| 147 | } | 148 | } |
| 148 | 149 | ||
| 149 | - // TODO slice this out somewhere | ||
| 150 | - /** | ||
| 151 | - * Verifies that Annotations created by merging {@code annotations} is | ||
| 152 | - * equal to actual Annotations. | ||
| 153 | - * | ||
| 154 | - * @param actual Annotations to check | ||
| 155 | - * @param annotations | ||
| 156 | - */ | ||
| 157 | - public static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) { | ||
| 158 | - DefaultAnnotations expected = DefaultAnnotations.builder().build(); | ||
| 159 | - for (SparseAnnotations a : annotations) { | ||
| 160 | - expected = DefaultAnnotations.merge(expected, a); | ||
| 161 | - } | ||
| 162 | - assertEquals(expected.keys(), actual.keys()); | ||
| 163 | - for (String key : expected.keys()) { | ||
| 164 | - assertEquals(expected.value(key), actual.value(key)); | ||
| 165 | - } | ||
| 166 | - } | ||
| 167 | - | ||
| 168 | @Test | 150 | @Test |
| 169 | public final void testGetDeviceCount() { | 151 | public final void testGetDeviceCount() { |
| 170 | assertEquals("initialy empty", 0, deviceStore.getDeviceCount()); | 152 | assertEquals("initialy empty", 0, deviceStore.getDeviceCount()); | ... | ... |
| ... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
| 16 | package org.onlab.onos.store.trivial.impl; | 16 | package org.onlab.onos.store.trivial.impl; |
| 17 | 17 | ||
| 18 | import com.google.common.collect.Iterables; | 18 | import com.google.common.collect.Iterables; |
| 19 | + | ||
| 19 | import org.junit.After; | 20 | import org.junit.After; |
| 20 | import org.junit.AfterClass; | 21 | import org.junit.AfterClass; |
| 21 | import org.junit.Before; | 22 | import org.junit.Before; |
| ... | @@ -46,7 +47,7 @@ import static org.junit.Assert.*; | ... | @@ -46,7 +47,7 @@ import static org.junit.Assert.*; |
| 46 | import static org.onlab.onos.net.DeviceId.deviceId; | 47 | import static org.onlab.onos.net.DeviceId.deviceId; |
| 47 | import static org.onlab.onos.net.Link.Type.*; | 48 | import static org.onlab.onos.net.Link.Type.*; |
| 48 | import static org.onlab.onos.net.link.LinkEvent.Type.*; | 49 | import static org.onlab.onos.net.link.LinkEvent.Type.*; |
| 49 | -import static org.onlab.onos.store.trivial.impl.SimpleDeviceStoreTest.assertAnnotationsEquals; | 50 | +import static org.onlab.onos.net.NetTestTools.assertAnnotationsEquals; |
| 50 | 51 | ||
| 51 | /** | 52 | /** |
| 52 | * Test of the simple LinkStore implementation. | 53 | * Test of the simple LinkStore implementation. | ... | ... |
-
Please register or login to post a comment