@Test
public void testTwoMemberMapSizes() {
// start the first member
HazelcastInstance h1 = Hazelcast.newHazelcastInstance(null);
// get the map and put 1000 entries
Map map1 = h1.getMap("testmap");
for (int i = 0; i < 1000; i++) {
map1.put(i, "value" + i);
}
// check the map size
assertEquals(1000, map1.size());
// start the second member
HazelcastInstance h2 = Hazelcast.newHazelcastInstance(null);
// get the same map from the second member
Map map2 = h2.getMap("testmap");
// check the size of map2
assertEquals(1000, map2.size());
// check the size of map1 again
assertEquals(1000, map1.size());
}
The following assert fails:
assertEquals(1000, map2.size());
Because map2.size() is 0, and indeed, if adding:
assertEquals(h1.getCluster(), h2.getCluster());
it fails because the clusters are not equal…
I am running this on a plain JUnit test without any other configurations. I did notice however the following warning in trace, which I am not sure if is the cause:
WARNING: [10.130.79.32]:5702 [dev] Config seed port is 5701 and cluster size is 1. Some of the ports seem occupied!
The full trace:
Feb 28, 2014 6:00:35 PM com.hazelcast.config.XmlConfigBuilder
INFO: Looking for hazelcast.xml config file in classpath.
Feb 28, 2014 6:00:35 PM com.hazelcast.config.XmlConfigBuilder
WARNING: Could not find hazelcast.xml in classpath.
Hazelcast will use hazelcast-default.xml config file in jar.
Feb 28, 2014 6:00:35 PM com.hazelcast.config.XmlConfigBuilder
INFO: Using configuration file file:/Users/myuser/.m2/repository/com/hazelcast/hazelcast/3.1.6/hazelcast-3.1.6.jar!/hazelcast-default.xml in the classpath.
Feb 28, 2014 6:00:36 PM com.hazelcast.instance.DefaultAddressPicker
INFO: Prefer IPv4 stack is true.
Feb 28, 2014 6:00:36 PM com.hazelcast.instance.DefaultAddressPicker
INFO: Picked Address[10.130.79.32]:5701, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0%0,localport=5701], bind any local is true
Feb 28, 2014 6:00:36 PM com.hazelcast.system
INFO: [10.130.79.32]:5701 [dev] Hazelcast Community Edition 3.1.6 (20140221) starting at Address[10.130.79.32]:5701
Feb 28, 2014 6:00:36 PM com.hazelcast.system
INFO: [10.130.79.32]:5701 [dev] Copyright (C) 2008-2013 Hazelcast.com
Feb 28, 2014 6:00:36 PM com.hazelcast.instance.Node
INFO: [10.130.79.32]:5701 [dev] Creating MulticastJoiner
Feb 28, 2014 6:00:36 PM com.hazelcast.core.LifecycleService
INFO: [10.130.79.32]:5701 [dev] Address[10.130.79.32]:5701 is STARTING
Feb 28, 2014 6:00:41 PM com.hazelcast.cluster.MulticastJoiner
INFO: [10.130.79.32]:5701 [dev]
Members [1] {
Member [10.130.79.32]:5701 this
}
Feb 28, 2014 6:00:41 PM com.hazelcast.core.LifecycleService
INFO: [10.130.79.32]:5701 [dev] Address[10.130.79.32]:5701 is STARTED
Feb 28, 2014 6:00:41 PM com.hazelcast.partition.PartitionService
INFO: [10.130.79.32]:5701 [dev] Initializing cluster partition table first arrangement...
Feb 28, 2014 6:00:41 PM com.hazelcast.config.XmlConfigBuilder
INFO: Looking for hazelcast.xml config file in classpath.
Feb 28, 2014 6:00:41 PM com.hazelcast.config.XmlConfigBuilder
WARNING: Could not find hazelcast.xml in classpath.
Hazelcast will use hazelcast-default.xml config file in jar.
Feb 28, 2014 6:00:41 PM com.hazelcast.config.XmlConfigBuilder
INFO: Using configuration file file:/Users/myuser/.m2/repository/com/hazelcast/hazelcast/3.1.6/hazelcast-3.1.6.jar!/hazelcast-default.xml in the classpath.
Feb 28, 2014 6:00:41 PM com.hazelcast.instance.DefaultAddressPicker
INFO: Prefer IPv4 stack is true.
Feb 28, 2014 6:00:41 PM com.hazelcast.instance.DefaultAddressPicker
INFO: Picked Address[10.130.79.32]:5702, using socket ServerSocket[addr=/0:0:0:0:0:0:0:0%0,localport=5702], bind any local is true
Feb 28, 2014 6:00:41 PM com.hazelcast.system
INFO: [10.130.79.32]:5702 [dev] Hazelcast Community Edition 3.1.6 (20140221) starting at Address[10.130.79.32]:5702
Feb 28, 2014 6:00:41 PM com.hazelcast.system
INFO: [10.130.79.32]:5702 [dev] Copyright (C) 2008-2013 Hazelcast.com
Feb 28, 2014 6:00:41 PM com.hazelcast.instance.Node
INFO: [10.130.79.32]:5702 [dev] Creating MulticastJoiner
Feb 28, 2014 6:00:41 PM com.hazelcast.core.LifecycleService
INFO: [10.130.79.32]:5702 [dev] Address[10.130.79.32]:5702 is STARTING
Feb 28, 2014 6:00:47 PM com.hazelcast.cluster.MulticastJoiner
INFO: [10.130.79.32]:5702 [dev]
Members [1] {
Member [10.130.79.32]:5702 this
}
Feb 28, 2014 6:00:47 PM com.hazelcast.instance.Node
WARNING: [10.130.79.32]:5702 [dev] Config seed port is 5701 and cluster size is 1. Some of the ports seem occupied!
Feb 28, 2014 6:00:47 PM com.hazelcast.core.LifecycleService
INFO: [10.130.79.32]:5702 [dev] Address[10.130.79.32]:5702 is STARTED
Feb 28, 2014 6:00:47 PM com.hazelcast.partition.PartitionService
INFO: [10.130.79.32]:5702 [dev] Initializing cluster partition table first arrangement...
java.lang.AssertionError:
Expected :1000
Actual :0
<Click to see difference>
at org.junit.Assert.fail(Assert.java:93)
at org.junit.Assert.failNotEquals(Assert.java:647)
at org.junit.Assert.assertEquals(Assert.java:128)
at org.junit.Assert.assertEquals(Assert.java:472)
at org.junit.Assert.assertEquals(Assert.java:456)
at com.mypackage.HazelcastTest.testTwoMemberMapSizes(HazelcastTest.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63)
Disconnected from the target VM, address: '127.0.0.1:62239', transport: 'socket'
Process finished with exit code 255
Any idea?
Yuval