Committed by
Gerrit Code Review
Added an adapter for PersistenceService to be used in unit tests
Change-Id: Ided127f848b97632b021ea1f1c88d912fe28492c
Showing
4 changed files
with
99 additions
and
7 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.persistence; | ||
17 | + | ||
18 | +import org.onosproject.persistence.PersistenceService; | ||
19 | +import org.onosproject.persistence.PersistentMapBuilder; | ||
20 | +import org.onosproject.persistence.PersistentSetBuilder; | ||
21 | + | ||
22 | +/** | ||
23 | + * Adapter for PersistenceService. | ||
24 | + */ | ||
25 | +public class PersistenceServiceAdapter implements PersistenceService { | ||
26 | + | ||
27 | + @Override | ||
28 | + public <K, V> PersistentMapBuilder<K, V> persistentMapBuilder() { | ||
29 | + return null; | ||
30 | + } | ||
31 | + | ||
32 | + @Override | ||
33 | + public <E> PersistentSetBuilder<E> persistentSetBuilder() { | ||
34 | + return null; | ||
35 | + } | ||
36 | +} |
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.persistence; | ||
17 | + | ||
18 | +import java.util.Map; | ||
19 | + | ||
20 | +import org.onosproject.persistence.PersistentMapBuilder; | ||
21 | +import org.onosproject.persistence.PersistentSetBuilder; | ||
22 | +import org.onosproject.store.service.Serializer; | ||
23 | + | ||
24 | +import com.google.common.collect.Maps; | ||
25 | + | ||
26 | +/** | ||
27 | + * PersistenceService that produces in memory maps for use in unit testing. | ||
28 | + */ | ||
29 | +public class TestPersistenceService extends PersistenceServiceAdapter { | ||
30 | + @Override | ||
31 | + public <K, V> PersistentMapBuilder<K, V> persistentMapBuilder() { | ||
32 | + return new TestPersistentMapBuilder<K, V>(); | ||
33 | + } | ||
34 | + | ||
35 | + @Override | ||
36 | + public <E> PersistentSetBuilder<E> persistentSetBuilder() { | ||
37 | + throw new UnsupportedOperationException(); | ||
38 | + } | ||
39 | + | ||
40 | + private static class TestPersistentMapBuilder<K, V> implements PersistentMapBuilder<K, V> { | ||
41 | + | ||
42 | + @Override | ||
43 | + public PersistentMapBuilder<K, V> withName(String name) { | ||
44 | + return this; | ||
45 | + } | ||
46 | + | ||
47 | + @Override | ||
48 | + public PersistentMapBuilder<K, V> withSerializer(Serializer serializer) { | ||
49 | + return this; | ||
50 | + } | ||
51 | + | ||
52 | + @Override | ||
53 | + public Map<K, V> build() { | ||
54 | + return Maps.newConcurrentMap(); | ||
55 | + } | ||
56 | + } | ||
57 | +} |
... | @@ -42,12 +42,13 @@ import org.onosproject.cluster.ControllerNode; | ... | @@ -42,12 +42,13 @@ import org.onosproject.cluster.ControllerNode; |
42 | import org.onosproject.cluster.DefaultControllerNode; | 42 | import org.onosproject.cluster.DefaultControllerNode; |
43 | import org.onosproject.cluster.NodeId; | 43 | import org.onosproject.cluster.NodeId; |
44 | import org.onosproject.event.AbstractEvent; | 44 | import org.onosproject.event.AbstractEvent; |
45 | -import org.onosproject.persistence.impl.PersistenceManager; | 45 | +import org.onosproject.persistence.PersistenceService; |
46 | import org.onosproject.store.Timestamp; | 46 | import org.onosproject.store.Timestamp; |
47 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; | 47 | import org.onosproject.store.cluster.messaging.ClusterCommunicationService; |
48 | import org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter; | 48 | import org.onosproject.store.cluster.messaging.ClusterCommunicationServiceAdapter; |
49 | import org.onosproject.store.cluster.messaging.MessageSubject; | 49 | import org.onosproject.store.cluster.messaging.MessageSubject; |
50 | import org.onosproject.store.impl.LogicalTimestamp; | 50 | import org.onosproject.store.impl.LogicalTimestamp; |
51 | +import org.onosproject.store.persistence.TestPersistenceService; | ||
51 | import org.onosproject.store.serializers.KryoNamespaces; | 52 | import org.onosproject.store.serializers.KryoNamespaces; |
52 | import org.onosproject.store.serializers.KryoSerializer; | 53 | import org.onosproject.store.serializers.KryoSerializer; |
53 | import org.onosproject.store.service.EventuallyConsistentMap; | 54 | import org.onosproject.store.service.EventuallyConsistentMap; |
... | @@ -82,7 +83,7 @@ public class EventuallyConsistentMapImplTest { | ... | @@ -82,7 +83,7 @@ public class EventuallyConsistentMapImplTest { |
82 | 83 | ||
83 | private EventuallyConsistentMap<String, String> ecMap; | 84 | private EventuallyConsistentMap<String, String> ecMap; |
84 | 85 | ||
85 | - private PersistenceManager persistenceService; | 86 | + private PersistenceService persistenceService; |
86 | private ClusterService clusterService; | 87 | private ClusterService clusterService; |
87 | private ClusterCommunicationService clusterCommunicator; | 88 | private ClusterCommunicationService clusterCommunicator; |
88 | private SequentialClockService<String, String> clockService; | 89 | private SequentialClockService<String, String> clockService; |
... | @@ -138,8 +139,7 @@ public class EventuallyConsistentMapImplTest { | ... | @@ -138,8 +139,7 @@ public class EventuallyConsistentMapImplTest { |
138 | 139 | ||
139 | clusterCommunicator = createMock(ClusterCommunicationService.class); | 140 | clusterCommunicator = createMock(ClusterCommunicationService.class); |
140 | 141 | ||
141 | - persistenceService = new PersistenceManager(); | 142 | + persistenceService = new TestPersistenceService(); |
142 | - persistenceService.activate(); | ||
143 | // Add expectation for adding cluster message subscribers which | 143 | // Add expectation for adding cluster message subscribers which |
144 | // delegate to our ClusterCommunicationService implementation. This | 144 | // delegate to our ClusterCommunicationService implementation. This |
145 | // allows us to get a reference to the map's internal cluster message | 145 | // allows us to get a reference to the map's internal cluster message | ... | ... |
... | @@ -46,9 +46,8 @@ import static org.slf4j.LoggerFactory.getLogger; | ... | @@ -46,9 +46,8 @@ import static org.slf4j.LoggerFactory.getLogger; |
46 | @Service | 46 | @Service |
47 | public class PersistenceManager implements PersistenceService { | 47 | public class PersistenceManager implements PersistenceService { |
48 | 48 | ||
49 | - private static final String DATABASE_PATH = "../data/localDB"; | 49 | + private static final String DATABASE_PATH = System.getProperty("karaf.data", "./data/localDB"); |
50 | - | 50 | + private static final String ENCLOSING_FOLDER = System.getProperty("karaf.data", "./data"); |
51 | - private static final String ENCLOSING_FOLDER = "../data"; | ||
52 | 51 | ||
53 | static final String MAP_PREFIX = "map:"; | 52 | static final String MAP_PREFIX = "map:"; |
54 | 53 | ... | ... |
-
Please register or login to post a comment