use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class ClusterShutdownTest method testClusterShutdownWithMultipleMembers.
private void testClusterShutdownWithMultipleMembers(int clusterSize, int nodeCountToTriggerShutdown) {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(clusterSize);
HazelcastInstance[] instances = factory.newInstances();
instances[0].getCluster().changeClusterState(ClusterState.PASSIVE);
Node[] nodes = getNodes(instances);
final CountDownLatch latch = new CountDownLatch(1);
for (int i = 0; i < nodeCountToTriggerShutdown; i++) {
final HazelcastInstance instance = instances[i];
final Runnable shutdownRunnable = new Runnable() {
@Override
public void run() {
assertOpenEventually(latch);
instance.getCluster().shutdown();
}
};
new Thread(shutdownRunnable).start();
}
latch.countDown();
assertNodesShutDownEventually(nodes);
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class JoinStressTest method testJoincompletesCorrectlyWhenMultipleNodesStartedParallel.
@Test
public void testJoincompletesCorrectlyWhenMultipleNodesStartedParallel() throws Exception {
int count = 10;
final TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(count);
final HazelcastInstance[] instances = new HazelcastInstance[count];
final CountDownLatch latch = new CountDownLatch(count);
for (int i = 0; i < count; i++) {
final int index = i;
new Thread(new Runnable() {
@Override
public void run() {
instances[index] = factory.newHazelcastInstance();
latch.countDown();
}
}).start();
}
assertOpenEventually(latch);
for (int i = 0; i < count; i++) {
assertClusterSize(count, instances[i]);
}
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class ClusterMembershipTest method testMembershipListener.
@Test
public void testMembershipListener() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance hz1 = factory.newHazelcastInstance();
MembershipListenerImpl listener = new MembershipListenerImpl();
hz1.getCluster().addMembershipListener(listener);
//start a second instance
HazelcastInstance hz2 = factory.newHazelcastInstance();
assertEventuallySizeAtLeast(listener.events, 1);
assertMembershipAddedEvent(listener.events.get(0), hz2.getCluster().getLocalMember(), hz1.getCluster().getLocalMember(), hz2.getCluster().getLocalMember());
//terminate the second instance
Member member2 = hz2.getCluster().getLocalMember();
hz2.shutdown();
assertEventuallySizeAtLeast(listener.events, 2);
assertMembershipRemovedEvent(listener.events.get(1), member2, hz1.getCluster().getLocalMember());
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class ClusterMembershipTest method testNodesAbleToJoinFromMultipleThreads_whenPostJoinOperationPresent.
@Test
public void testNodesAbleToJoinFromMultipleThreads_whenPostJoinOperationPresent() throws InterruptedException {
final int instanceCount = 6;
final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(instanceCount);
final Config config = new Config();
config.setProperty(GroupProperty.WAIT_SECONDS_BEFORE_JOIN.getName(), "0");
final String mapName = randomMapName();
// index config is added since it was blocking post join operations.
config.getMapConfig(mapName).addMapIndexConfig(new MapIndexConfig("name", false));
final CountDownLatch latch = new CountDownLatch(instanceCount);
for (int i = 0; i < instanceCount; i++) {
executorService.execute(new Runnable() {
public void run() {
HazelcastInstance hz = factory.newHazelcastInstance(config);
hz.getMap(mapName);
latch.countDown();
}
});
}
assertOpenEventually(latch);
Collection<HazelcastInstance> instances = factory.getAllHazelcastInstances();
for (HazelcastInstance instance : instances) {
assertClusterSize(instanceCount, instance);
}
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class ClusterMembershipTest method testRemoveMembershipListener.
@Test
public void testRemoveMembershipListener() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
HazelcastInstance hz1 = factory.newHazelcastInstance();
Cluster cluster = hz1.getCluster();
MembershipListener membershipListener = mock(MembershipListener.class);
String id = cluster.addMembershipListener(membershipListener);
boolean removed = cluster.removeMembershipListener(id);
assertTrue(removed);
// now we add a member
HazelcastInstance hz2 = factory.newHazelcastInstance();
// and verify that the listener isn't called.
verify(membershipListener, never()).memberAdded(any(MembershipEvent.class));
}
Aggregations