use of com.hazelcast.core.InitialMembershipEvent in project hazelcast by hazelcast.
the class ClusterMembershipTest method assertInitialMembershipEvent.
public void assertInitialMembershipEvent(EventObject e, Member... expectedMembers) {
assertTrue(e instanceof InitialMembershipEvent);
InitialMembershipEvent initialMembershipEvent = (InitialMembershipEvent) e;
Set<Member> foundMembers = initialMembershipEvent.getMembers();
assertEquals(new HashSet<Member>(Arrays.asList(expectedMembers)), foundMembers);
}
use of com.hazelcast.core.InitialMembershipEvent in project hazelcast by hazelcast.
the class MembershipListenerTest method initialMemberEvents_whenAddedViaConfig.
@Test
public void initialMemberEvents_whenAddedViaConfig() throws InterruptedException {
hazelcastFactory.newHazelcastInstance();
hazelcastFactory.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
final InitialMemberShipEventLogger listener = new InitialMemberShipEventLogger();
clientConfig.addListenerConfig(new ListenerConfig().setImplementation(listener));
hazelcastFactory.newHazelcastClient(clientConfig);
EventObject eventObject = listener.events.poll(ASSERT_TRUE_EVENTUALLY_TIMEOUT, TimeUnit.SECONDS);
assertInstanceOf(InitialMembershipEvent.class, eventObject);
InitialMembershipEvent event = (InitialMembershipEvent) eventObject;
assertEquals(2, event.getMembers().size());
assertEquals(0, listener.events.size());
}
use of com.hazelcast.core.InitialMembershipEvent in project hazelcast by hazelcast.
the class MembershipListenerTest method givenMixOfListenerExists_whenConnect_thenCallInitialMembershipListener.
@Test
public void givenMixOfListenerExists_whenConnect_thenCallInitialMembershipListener() throws Exception {
hazelcastFactory.newHazelcastInstance();
final ClientConfig config = new ClientConfig();
// first add bunch of *regular* MembershipListener. They do not implement InitialMembershipListener
config.addListenerConfig(new ListenerConfig().setImplementation(new MemberShipEventLogger()));
config.addListenerConfig(new ListenerConfig().setImplementation(new MemberShipEventLogger()));
config.addListenerConfig(new ListenerConfig().setImplementation(new MemberShipEventLogger()));
// now add an InitialMembershipListener
// if there is an exception thrown during event delivery to regular listeners
// then no event will likely be delivered to InitialMemberShipEventLogger
final InitialMemberShipEventLogger initialListener = new InitialMemberShipEventLogger();
config.addListenerConfig(new ListenerConfig().setImplementation(initialListener));
//connect to a grid
hazelcastFactory.newHazelcastClient(config);
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals("Expecting one event", 1, initialListener.events.size());
InitialMembershipEvent event = (InitialMembershipEvent) initialListener.events.getLast();
assertEquals(1, event.getMembers().size());
}
});
}
use of com.hazelcast.core.InitialMembershipEvent in project hazelcast by hazelcast.
the class MembershipListenerTest method initialMemberEvents_whenAddedAfterClientStarted.
@Test
public void initialMemberEvents_whenAddedAfterClientStarted() throws InterruptedException {
hazelcastFactory.newHazelcastInstance();
hazelcastFactory.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
final InitialMemberShipEventLogger listener = new InitialMemberShipEventLogger();
client.getCluster().addMembershipListener(listener);
EventObject eventObject = listener.events.poll(ASSERT_TRUE_EVENTUALLY_TIMEOUT, TimeUnit.SECONDS);
assertInstanceOf(InitialMembershipEvent.class, eventObject);
InitialMembershipEvent event = (InitialMembershipEvent) eventObject;
assertEquals(2, event.getMembers().size());
assertEquals(0, listener.events.size());
}
use of com.hazelcast.core.InitialMembershipEvent in project hazelcast by hazelcast.
the class ClientClusterServiceImpl method initMembershipListener.
private void initMembershipListener(MembershipListener listener) {
if (listener instanceof InitialMembershipListener) {
Cluster cluster = client.getCluster();
Collection<Member> memberCollection = members.get().values();
LinkedHashSet<Member> members = new LinkedHashSet<Member>(memberCollection);
InitialMembershipEvent event = new InitialMembershipEvent(cluster, members);
((InitialMembershipListener) listener).init(event);
}
}
Aggregations