Committed by
Gerrit Code Review
Unit tests for the distributed group store.
Change-Id: Ie8f00b9bbc1ba46a6f80e70f63d1fd853d64154b
Showing
5 changed files
with
130 additions
and
80 deletions
1 | +/* | ||
2 | + * Copyright 2015 Open Networking Laboratory | ||
3 | + * | ||
4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | + * you may not use this file except in compliance with the License. | ||
6 | + * You may obtain a copy of the License at | ||
7 | + * | ||
8 | + * http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | + * | ||
10 | + * Unless required by applicable law or agreed to in writing, software | ||
11 | + * distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | + * See the License for the specific language governing permissions and | ||
14 | + * limitations under the License. | ||
15 | + */ | ||
16 | +package org.onosproject.store.cluster.messaging; | ||
17 | + | ||
18 | +import java.util.Set; | ||
19 | +import java.util.concurrent.CompletableFuture; | ||
20 | +import java.util.concurrent.Executor; | ||
21 | +import java.util.concurrent.ExecutorService; | ||
22 | +import java.util.function.Consumer; | ||
23 | +import java.util.function.Function; | ||
24 | + | ||
25 | +import org.onosproject.cluster.NodeId; | ||
26 | + | ||
27 | +/** | ||
28 | + * Testing adapter for the cluster communication service. | ||
29 | + */ | ||
30 | +public class ClusterCommunicationServiceAdapter | ||
31 | + implements ClusterCommunicationService { | ||
32 | + | ||
33 | + @Override | ||
34 | + public void addSubscriber(MessageSubject subject, | ||
35 | + ClusterMessageHandler subscriber, | ||
36 | + ExecutorService executor) { | ||
37 | + } | ||
38 | + | ||
39 | + @Override | ||
40 | + public void removeSubscriber(MessageSubject subject) {} | ||
41 | + | ||
42 | + @Override | ||
43 | + public <M> void broadcast(M message, MessageSubject subject, | ||
44 | + Function<M, byte[]> encoder) { | ||
45 | + } | ||
46 | + | ||
47 | + @Override | ||
48 | + public <M> void broadcastIncludeSelf(M message, | ||
49 | + MessageSubject subject, Function<M, byte[]> encoder) { | ||
50 | + } | ||
51 | + | ||
52 | + @Override | ||
53 | + public <M> CompletableFuture<Void> unicast(M message, MessageSubject subject, | ||
54 | + Function<M, byte[]> encoder, NodeId toNodeId) { | ||
55 | + return null; | ||
56 | + } | ||
57 | + | ||
58 | + @Override | ||
59 | + public <M> void multicast(M message, MessageSubject subject, | ||
60 | + Function<M, byte[]> encoder, Set<NodeId> nodes) { | ||
61 | + } | ||
62 | + | ||
63 | + @Override | ||
64 | + public <M, R> CompletableFuture<R> sendAndReceive(M message, | ||
65 | + MessageSubject subject, Function<M, byte[]> encoder, | ||
66 | + Function<byte[], R> decoder, NodeId toNodeId) { | ||
67 | + return null; | ||
68 | + } | ||
69 | + | ||
70 | + @Override | ||
71 | + public <M, R> void addSubscriber(MessageSubject subject, | ||
72 | + Function<byte[], M> decoder, Function<M, R> handler, | ||
73 | + Function<R, byte[]> encoder, Executor executor) { | ||
74 | + } | ||
75 | + | ||
76 | + @Override | ||
77 | + public <M, R> void addSubscriber(MessageSubject subject, | ||
78 | + Function<byte[], M> decoder, Function<M, CompletableFuture<R>> handler, | ||
79 | + Function<R, byte[]> encoder) { | ||
80 | + } | ||
81 | + | ||
82 | + @Override | ||
83 | + public <M> void addSubscriber(MessageSubject subject, | ||
84 | + Function<byte[], M> decoder, Consumer<M> handler, | ||
85 | + Executor executor) { | ||
86 | + | ||
87 | + } | ||
88 | +} |
... | @@ -91,7 +91,9 @@ public final class TestEventuallyConsistentMap<K, V> extends EventuallyConsisten | ... | @@ -91,7 +91,9 @@ public final class TestEventuallyConsistentMap<K, V> extends EventuallyConsisten |
91 | EventuallyConsistentMapEvent<K, V> addEvent = | 91 | EventuallyConsistentMapEvent<K, V> addEvent = |
92 | new EventuallyConsistentMapEvent<>(mapName, PUT, key, value); | 92 | new EventuallyConsistentMapEvent<>(mapName, PUT, key, value); |
93 | notifyListeners(addEvent); | 93 | notifyListeners(addEvent); |
94 | - peerUpdateFunction.apply(key, value); | 94 | + if (peerUpdateFunction != null) { |
95 | + peerUpdateFunction.apply(key, value); | ||
96 | + } | ||
95 | } | 97 | } |
96 | 98 | ||
97 | @Override | 99 | @Override | ... | ... |
... | @@ -1014,7 +1014,7 @@ public class DistributedGroupStore | ... | @@ -1014,7 +1014,7 @@ public class DistributedGroupStore |
1014 | /** | 1014 | /** |
1015 | * Flattened map key to be used to store group entries. | 1015 | * Flattened map key to be used to store group entries. |
1016 | */ | 1016 | */ |
1017 | - private class GroupStoreMapKey { | 1017 | + protected static class GroupStoreMapKey { |
1018 | private final DeviceId deviceId; | 1018 | private final DeviceId deviceId; |
1019 | 1019 | ||
1020 | public GroupStoreMapKey(DeviceId deviceId) { | 1020 | public GroupStoreMapKey(DeviceId deviceId) { |
... | @@ -1047,7 +1047,7 @@ public class DistributedGroupStore | ... | @@ -1047,7 +1047,7 @@ public class DistributedGroupStore |
1047 | } | 1047 | } |
1048 | } | 1048 | } |
1049 | 1049 | ||
1050 | - private class GroupStoreKeyMapKey extends GroupStoreMapKey { | 1050 | + protected static class GroupStoreKeyMapKey extends GroupStoreMapKey { |
1051 | private final GroupKey appCookie; | 1051 | private final GroupKey appCookie; |
1052 | public GroupStoreKeyMapKey(DeviceId deviceId, | 1052 | public GroupStoreKeyMapKey(DeviceId deviceId, |
1053 | GroupKey appCookie) { | 1053 | GroupKey appCookie) { |
... | @@ -1078,7 +1078,7 @@ public class DistributedGroupStore | ... | @@ -1078,7 +1078,7 @@ public class DistributedGroupStore |
1078 | } | 1078 | } |
1079 | } | 1079 | } |
1080 | 1080 | ||
1081 | - private class GroupStoreIdMapKey extends GroupStoreMapKey { | 1081 | + protected static class GroupStoreIdMapKey extends GroupStoreMapKey { |
1082 | private final GroupId groupId; | 1082 | private final GroupId groupId; |
1083 | public GroupStoreIdMapKey(DeviceId deviceId, | 1083 | public GroupStoreIdMapKey(DeviceId deviceId, |
1084 | GroupId groupId) { | 1084 | GroupId groupId) { | ... | ... |
... | @@ -15,10 +15,22 @@ | ... | @@ -15,10 +15,22 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.store.ecmap; | 16 | package org.onosproject.store.ecmap; |
17 | 17 | ||
18 | -import com.google.common.collect.ComparisonChain; | 18 | +import java.util.ArrayList; |
19 | -import com.google.common.collect.ImmutableList; | 19 | +import java.util.Collection; |
20 | -import com.google.common.collect.ImmutableSet; | 20 | +import java.util.HashMap; |
21 | -import com.google.common.util.concurrent.MoreExecutors; | 21 | +import java.util.HashSet; |
22 | +import java.util.List; | ||
23 | +import java.util.Map; | ||
24 | +import java.util.Objects; | ||
25 | +import java.util.Optional; | ||
26 | +import java.util.Set; | ||
27 | +import java.util.concurrent.CompletableFuture; | ||
28 | +import java.util.concurrent.CountDownLatch; | ||
29 | +import java.util.concurrent.Executor; | ||
30 | +import java.util.concurrent.TimeUnit; | ||
31 | +import java.util.concurrent.atomic.AtomicLong; | ||
32 | +import java.util.function.Consumer; | ||
33 | +import java.util.function.Function; | ||
22 | 34 | ||
23 | import org.junit.After; | 35 | import org.junit.After; |
24 | import org.junit.Before; | 36 | import org.junit.Before; |
... | @@ -32,38 +44,35 @@ import org.onosproject.cluster.NodeId; | ... | @@ -32,38 +44,35 @@ import org.onosproject.cluster.NodeId; |
32 | import org.onosproject.event.AbstractEvent; | 44 | import org.onosproject.event.AbstractEvent; |
33 | import org.onosproject.store.Timestamp; | 45 | import org.onosproject.store.Timestamp; |
34 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; | 46 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; |
35 | -import org.onosproject.store.cluster.messaging.ClusterMessageHandler; | 47 | +import org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter; |
36 | import org.onosproject.store.cluster.messaging.MessageSubject; | 48 | import org.onosproject.store.cluster.messaging.MessageSubject; |
37 | import org.onosproject.store.impl.LogicalTimestamp; | 49 | import org.onosproject.store.impl.LogicalTimestamp; |
38 | -import org.onosproject.store.service.WallClockTimestamp; | ||
39 | import org.onosproject.store.serializers.KryoNamespaces; | 50 | import org.onosproject.store.serializers.KryoNamespaces; |
40 | import org.onosproject.store.serializers.KryoSerializer; | 51 | import org.onosproject.store.serializers.KryoSerializer; |
41 | import org.onosproject.store.service.EventuallyConsistentMap; | 52 | import org.onosproject.store.service.EventuallyConsistentMap; |
42 | import org.onosproject.store.service.EventuallyConsistentMapEvent; | 53 | import org.onosproject.store.service.EventuallyConsistentMapEvent; |
43 | import org.onosproject.store.service.EventuallyConsistentMapListener; | 54 | import org.onosproject.store.service.EventuallyConsistentMapListener; |
55 | +import org.onosproject.store.service.WallClockTimestamp; | ||
44 | 56 | ||
45 | -import java.util.ArrayList; | 57 | +import com.google.common.collect.ComparisonChain; |
46 | -import java.util.Collection; | 58 | +import com.google.common.collect.ImmutableList; |
47 | -import java.util.HashMap; | 59 | +import com.google.common.collect.ImmutableSet; |
48 | -import java.util.HashSet; | 60 | +import com.google.common.util.concurrent.MoreExecutors; |
49 | -import java.util.List; | ||
50 | -import java.util.Map; | ||
51 | -import java.util.Objects; | ||
52 | -import java.util.Optional; | ||
53 | -import java.util.Set; | ||
54 | -import java.util.concurrent.CompletableFuture; | ||
55 | -import java.util.concurrent.CountDownLatch; | ||
56 | -import java.util.concurrent.Executor; | ||
57 | -import java.util.concurrent.ExecutorService; | ||
58 | -import java.util.concurrent.TimeUnit; | ||
59 | -import java.util.concurrent.atomic.AtomicLong; | ||
60 | -import java.util.function.Consumer; | ||
61 | -import java.util.function.Function; | ||
62 | 61 | ||
63 | import static com.google.common.base.Preconditions.checkArgument; | 62 | import static com.google.common.base.Preconditions.checkArgument; |
64 | import static junit.framework.TestCase.assertFalse; | 63 | import static junit.framework.TestCase.assertFalse; |
65 | -import static org.easymock.EasyMock.*; | 64 | +import static org.easymock.EasyMock.anyObject; |
66 | -import static org.junit.Assert.*; | 65 | +import static org.easymock.EasyMock.createMock; |
66 | +import static org.easymock.EasyMock.eq; | ||
67 | +import static org.easymock.EasyMock.expect; | ||
68 | +import static org.easymock.EasyMock.expectLastCall; | ||
69 | +import static org.easymock.EasyMock.replay; | ||
70 | +import static org.easymock.EasyMock.reset; | ||
71 | +import static org.easymock.EasyMock.verify; | ||
72 | +import static org.junit.Assert.assertEquals; | ||
73 | +import static org.junit.Assert.assertNull; | ||
74 | +import static org.junit.Assert.assertTrue; | ||
75 | +import static org.junit.Assert.fail; | ||
67 | 76 | ||
68 | /** | 77 | /** |
69 | * Unit tests for EventuallyConsistentMapImpl. | 78 | * Unit tests for EventuallyConsistentMapImpl. |
... | @@ -697,7 +706,7 @@ public class EventuallyConsistentMapImplTest { | ... | @@ -697,7 +706,7 @@ public class EventuallyConsistentMapImplTest { |
697 | * Sets up a mock ClusterCommunicationService to expect a specific cluster | 706 | * Sets up a mock ClusterCommunicationService to expect a specific cluster |
698 | * message to be broadcast to the cluster. | 707 | * message to be broadcast to the cluster. |
699 | * | 708 | * |
700 | - * @param m message we expect to be sent | 709 | + * @param message message we expect to be sent |
701 | * @param clusterCommunicator a mock ClusterCommunicationService to set up | 710 | * @param clusterCommunicator a mock ClusterCommunicationService to set up |
702 | */ | 711 | */ |
703 | //FIXME rename | 712 | //FIXME rename |
... | @@ -776,56 +785,7 @@ public class EventuallyConsistentMapImplTest { | ... | @@ -776,56 +785,7 @@ public class EventuallyConsistentMapImplTest { |
776 | * events coming in from other instances. | 785 | * events coming in from other instances. |
777 | */ | 786 | */ |
778 | private final class TestClusterCommunicationService | 787 | private final class TestClusterCommunicationService |
779 | - implements ClusterCommunicationService { | 788 | + extends ClusterCommunicationServiceAdapter { |
780 | - | ||
781 | - @Override | ||
782 | - public void addSubscriber(MessageSubject subject, | ||
783 | - ClusterMessageHandler subscriber, | ||
784 | - ExecutorService executor) { | ||
785 | - } | ||
786 | - | ||
787 | - @Override | ||
788 | - public void removeSubscriber(MessageSubject subject) {} | ||
789 | - | ||
790 | - @Override | ||
791 | - public <M> void broadcast(M message, MessageSubject subject, | ||
792 | - Function<M, byte[]> encoder) { | ||
793 | - } | ||
794 | - | ||
795 | - @Override | ||
796 | - public <M> void broadcastIncludeSelf(M message, | ||
797 | - MessageSubject subject, Function<M, byte[]> encoder) { | ||
798 | - } | ||
799 | - | ||
800 | - @Override | ||
801 | - public <M> CompletableFuture<Void> unicast(M message, MessageSubject subject, | ||
802 | - Function<M, byte[]> encoder, NodeId toNodeId) { | ||
803 | - return null; | ||
804 | - } | ||
805 | - | ||
806 | - @Override | ||
807 | - public <M> void multicast(M message, MessageSubject subject, | ||
808 | - Function<M, byte[]> encoder, Set<NodeId> nodes) { | ||
809 | - } | ||
810 | - | ||
811 | - @Override | ||
812 | - public <M, R> CompletableFuture<R> sendAndReceive(M message, | ||
813 | - MessageSubject subject, Function<M, byte[]> encoder, | ||
814 | - Function<byte[], R> decoder, NodeId toNodeId) { | ||
815 | - return null; | ||
816 | - } | ||
817 | - | ||
818 | - @Override | ||
819 | - public <M, R> void addSubscriber(MessageSubject subject, | ||
820 | - Function<byte[], M> decoder, Function<M, R> handler, | ||
821 | - Function<R, byte[]> encoder, Executor executor) { | ||
822 | - } | ||
823 | - | ||
824 | - @Override | ||
825 | - public <M, R> void addSubscriber(MessageSubject subject, | ||
826 | - Function<byte[], M> decoder, Function<M, CompletableFuture<R>> handler, | ||
827 | - Function<R, byte[]> encoder) { | ||
828 | - } | ||
829 | 789 | ||
830 | @Override | 790 | @Override |
831 | public <M> void addSubscriber(MessageSubject subject, | 791 | public <M> void addSubscriber(MessageSubject subject, | ... | ... |
core/store/dist/src/test/java/org/onosproject/store/group/impl/DistributedGroupStoreTest.java
0 → 100644
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment