use etc/hazelcast.xml + modifications when creating HZ for testing
Change-Id: I92d554d2e8c696780c3a2fab2accdab396a3805b
Showing
5 changed files
with
68 additions
and
28 deletions
... | @@ -44,6 +44,13 @@ | ... | @@ -44,6 +44,13 @@ |
44 | <version>${project.version}</version> | 44 | <version>${project.version}</version> |
45 | <scope>test</scope> | 45 | <scope>test</scope> |
46 | </dependency> | 46 | </dependency> |
47 | + <dependency> | ||
48 | + <groupId>org.onlab.onos</groupId> | ||
49 | + <artifactId>onos-core-store</artifactId> | ||
50 | + <version>${project.version}</version> | ||
51 | + <classifier>tests</classifier> | ||
52 | + <scope>test</scope> | ||
53 | + </dependency> | ||
47 | 54 | ||
48 | <dependency> | 55 | <dependency> |
49 | <groupId>org.apache.felix</groupId> | 56 | <groupId>org.apache.felix</groupId> | ... | ... |
... | @@ -33,20 +33,18 @@ import org.onlab.onos.net.provider.ProviderId; | ... | @@ -33,20 +33,18 @@ import org.onlab.onos.net.provider.ProviderId; |
33 | import org.onlab.onos.store.common.StoreService; | 33 | import org.onlab.onos.store.common.StoreService; |
34 | import org.onlab.onos.store.device.impl.DistributedDeviceStore; | 34 | import org.onlab.onos.store.device.impl.DistributedDeviceStore; |
35 | import org.onlab.onos.store.impl.StoreManager; | 35 | import org.onlab.onos.store.impl.StoreManager; |
36 | +import org.onlab.onos.store.impl.TestStoreManager; | ||
36 | 37 | ||
37 | import java.util.ArrayList; | 38 | import java.util.ArrayList; |
38 | import java.util.Iterator; | 39 | import java.util.Iterator; |
39 | import java.util.List; | 40 | import java.util.List; |
40 | import java.util.Set; | 41 | import java.util.Set; |
41 | -import java.util.UUID; | ||
42 | - | ||
43 | import static org.junit.Assert.*; | 42 | import static org.junit.Assert.*; |
44 | import static org.onlab.onos.net.Device.Type.SWITCH; | 43 | import static org.onlab.onos.net.Device.Type.SWITCH; |
45 | import static org.onlab.onos.net.DeviceId.deviceId; | 44 | import static org.onlab.onos.net.DeviceId.deviceId; |
46 | import static org.onlab.onos.net.device.DeviceEvent.Type.*; | 45 | import static org.onlab.onos.net.device.DeviceEvent.Type.*; |
47 | 46 | ||
48 | -// FIXME This test is painfully slow starting up Hazelcast on each test cases, | 47 | +// FIXME This test is slow starting up Hazelcast on each test cases. |
49 | -// turning it off in repository for now. | ||
50 | // FIXME DistributedDeviceStore should have it's own test cases. | 48 | // FIXME DistributedDeviceStore should have it's own test cases. |
51 | 49 | ||
52 | /** | 50 | /** |
... | @@ -84,17 +82,8 @@ public class DistributedDeviceManagerTest { | ... | @@ -84,17 +82,8 @@ public class DistributedDeviceManagerTest { |
84 | service = mgr; | 82 | service = mgr; |
85 | admin = mgr; | 83 | admin = mgr; |
86 | registry = mgr; | 84 | registry = mgr; |
87 | - // FIXME should be reading the hazelcast.xml | 85 | + // TODO should find a way to clean Hazelcast instance without shutdown. |
88 | - Config config = new Config(); | 86 | + Config config = TestStoreManager.getTestConfig(); |
89 | - // avoid accidentally joining other cluster | ||
90 | - config.getGroupConfig().setName(UUID.randomUUID().toString()); | ||
91 | - // quickly form single node cluster | ||
92 | - config.getNetworkConfig().getJoin() | ||
93 | - .getTcpIpConfig() | ||
94 | - .setEnabled(true).setConnectionTimeoutSeconds(0); | ||
95 | - config.getNetworkConfig().getJoin() | ||
96 | - .getMulticastConfig() | ||
97 | - .setEnabled(false); | ||
98 | 87 | ||
99 | storeManager = new TestStoreManager(Hazelcast.newHazelcastInstance(config)); | 88 | storeManager = new TestStoreManager(Hazelcast.newHazelcastInstance(config)); |
100 | storeManager.activate(); | 89 | storeManager.activate(); |
... | @@ -288,18 +277,8 @@ public class DistributedDeviceManagerTest { | ... | @@ -288,18 +277,8 @@ public class DistributedDeviceManagerTest { |
288 | } | 277 | } |
289 | } | 278 | } |
290 | 279 | ||
291 | - private class TestStoreManager extends StoreManager { | ||
292 | - TestStoreManager(HazelcastInstance instance) { | ||
293 | - this.instance = instance; | ||
294 | - } | ||
295 | - | ||
296 | - @Override | ||
297 | - public void activate() { | ||
298 | - setupKryoPool(); | ||
299 | - } | ||
300 | - } | ||
301 | - | ||
302 | private static class TestMastershipService extends MastershipServiceAdapter { | 280 | private static class TestMastershipService extends MastershipServiceAdapter { |
281 | + | ||
303 | @Override | 282 | @Override |
304 | public MastershipRole getLocalRole(DeviceId deviceId) { | 283 | public MastershipRole getLocalRole(DeviceId deviceId) { |
305 | return MastershipRole.MASTER; | 284 | return MastershipRole.MASTER; |
... | @@ -315,5 +294,4 @@ public class DistributedDeviceManagerTest { | ... | @@ -315,5 +294,4 @@ public class DistributedDeviceManagerTest { |
315 | return MastershipRole.MASTER; | 294 | return MastershipRole.MASTER; |
316 | } | 295 | } |
317 | } | 296 | } |
318 | - | ||
319 | } | 297 | } | ... | ... |
... | @@ -110,6 +110,7 @@ public class DistributedDeviceStore | ... | @@ -110,6 +110,7 @@ public class DistributedDeviceStore |
110 | 110 | ||
111 | @Deactivate | 111 | @Deactivate |
112 | public void deactivate() { | 112 | public void deactivate() { |
113 | + | ||
113 | log.info("Stopped"); | 114 | log.info("Stopped"); |
114 | } | 115 | } |
115 | 116 | ... | ... |
... | @@ -45,7 +45,7 @@ import java.util.HashMap; | ... | @@ -45,7 +45,7 @@ import java.util.HashMap; |
45 | @Service | 45 | @Service |
46 | public class StoreManager implements StoreService { | 46 | public class StoreManager implements StoreService { |
47 | 47 | ||
48 | - private static final String HAZELCAST_XML_FILE = "etc/hazelcast.xml"; | 48 | + protected static final String HAZELCAST_XML_FILE = "etc/hazelcast.xml"; |
49 | 49 | ||
50 | private final Logger log = LoggerFactory.getLogger(getClass()); | 50 | private final Logger log = LoggerFactory.getLogger(getClass()); |
51 | 51 | ... | ... |
1 | +package org.onlab.onos.store.impl; | ||
2 | + | ||
3 | +import java.io.FileNotFoundException; | ||
4 | +import java.util.UUID; | ||
5 | + | ||
6 | +import com.hazelcast.config.Config; | ||
7 | +import com.hazelcast.config.FileSystemXmlConfig; | ||
8 | +import com.hazelcast.core.HazelcastInstance; | ||
9 | + | ||
10 | +/** | ||
11 | + * Dummy StoreManager to use specified Hazelcast instance. | ||
12 | + */ | ||
13 | +public class TestStoreManager extends StoreManager { | ||
14 | + | ||
15 | + /** | ||
16 | + * Gets the Hazelcast Config for testing. | ||
17 | + * | ||
18 | + * @return | ||
19 | + */ | ||
20 | + public static Config getTestConfig() { | ||
21 | + Config config; | ||
22 | + try { | ||
23 | + config = new FileSystemXmlConfig(HAZELCAST_XML_FILE); | ||
24 | + } catch (FileNotFoundException e) { | ||
25 | + // falling back to default | ||
26 | + config = new Config(); | ||
27 | + } | ||
28 | + // avoid accidentally joining other cluster | ||
29 | + config.getGroupConfig().setName(UUID.randomUUID().toString()); | ||
30 | + // quickly form single node cluster | ||
31 | + config.getNetworkConfig().getJoin() | ||
32 | + .getTcpIpConfig() | ||
33 | + .setEnabled(true).setConnectionTimeoutSeconds(0); | ||
34 | + config.getNetworkConfig().getJoin() | ||
35 | + .getMulticastConfig() | ||
36 | + .setEnabled(false); | ||
37 | + return config; | ||
38 | + } | ||
39 | + | ||
40 | + /** | ||
41 | + * Constructor. | ||
42 | + * | ||
43 | + * @param instance Hazelast instance to return on #getHazelcastInstance() | ||
44 | + */ | ||
45 | + public TestStoreManager(HazelcastInstance instance) { | ||
46 | + this.instance = instance; | ||
47 | + } | ||
48 | + | ||
49 | + // Hazelcast setup removed from original code. | ||
50 | + @Override | ||
51 | + public void activate() { | ||
52 | + setupKryoPool(); | ||
53 | + } | ||
54 | +} |
-
Please register or login to post a comment