Search in sources :

Example 26 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class ConnectedClientOperationTest method testGetConnectedClientsOperation_WhenMoreThanZeroClientConnects.

@Test
public void testGetConnectedClientsOperation_WhenMoreThanZeroClientConnects() throws Exception {
    HazelcastInstance instance = factory.newHazelcastInstance();
    factory.newHazelcastClient();
    factory.newHazelcastClient();
    Node node = TestUtil.getNode(instance);
    Operation operation = new GetConnectedClientsOperation();
    OperationService operationService = node.nodeEngine.getOperationService();
    Future<Map<String, ClientType>> future = operationService.invokeOnTarget(ClientEngineImpl.SERVICE_NAME, operation, node.address);
    Map<String, ClientType> clients = future.get();
    assertEquals(2, clients.size());
}
Also used : ClientType(com.hazelcast.core.ClientType) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.Node) Operation(com.hazelcast.spi.Operation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) OperationService(com.hazelcast.spi.OperationService) Map(java.util.Map) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 27 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class MembershipListenerTest method whenMemberAdded_thenMemberAddedEvent.

@Test
public void whenMemberAdded_thenMemberAddedEvent() throws Exception {
    final HazelcastInstance server1 = hazelcastFactory.newHazelcastInstance();
    final MemberShipEventLogger listener = new MemberShipEventLogger();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    client.getCluster().addMembershipListener(listener);
    //start a second server and verify that the listener receives it.
    final HazelcastInstance server2 = hazelcastFactory.newHazelcastInstance();
    //verify that the listener receives member added event.
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertNotEquals("Expecting one or more events", 0, listener.events.size());
            MembershipEvent event = (MembershipEvent) listener.events.getLast();
            assertEquals("Last event should be member added", MembershipEvent.MEMBER_ADDED, event.getEventType());
            assertEquals(server2.getCluster().getLocalMember(), event.getMember());
            assertEquals(getMembers(server1, server2), event.getMembers());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InitialMembershipEvent(com.hazelcast.core.InitialMembershipEvent) MembershipEvent(com.hazelcast.core.MembershipEvent) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 28 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class MembershipListenerTest method removedNullListener_thenException.

@Test(expected = NullPointerException.class)
public void removedNullListener_thenException() throws Exception {
    hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    assertFalse(client.getCluster().removeMembershipListener(null));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 29 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class MembershipListenerTest method removedPhantomListener_thenFalse.

@Test
public void removedPhantomListener_thenFalse() throws Exception {
    hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    assertFalse(client.getCluster().removeMembershipListener(randomString()));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 30 with HazelcastInstance

use of com.hazelcast.core.HazelcastInstance in project hazelcast by hazelcast.

the class MembershipListenerTest method addNullListener_thenException.

@Test(expected = java.lang.NullPointerException.class)
public void addNullListener_thenException() throws Exception {
    hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    client.getCluster().addMembershipListener(null);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

HazelcastInstance (com.hazelcast.core.HazelcastInstance)2077 Test (org.junit.Test)1684 QuickTest (com.hazelcast.test.annotation.QuickTest)1466 ParallelTest (com.hazelcast.test.annotation.ParallelTest)1389 Config (com.hazelcast.config.Config)815 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)665 AssertTask (com.hazelcast.test.AssertTask)263 MapConfig (com.hazelcast.config.MapConfig)254 CountDownLatch (java.util.concurrent.CountDownLatch)251 NightlyTest (com.hazelcast.test.annotation.NightlyTest)230 MapStoreConfig (com.hazelcast.config.MapStoreConfig)169 IMap (com.hazelcast.core.IMap)145 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)144 ClientConfig (com.hazelcast.client.config.ClientConfig)137 Before (org.junit.Before)111 NearCacheConfig (com.hazelcast.config.NearCacheConfig)106 Member (com.hazelcast.core.Member)96 Map (java.util.Map)96 SlowTest (com.hazelcast.test.annotation.SlowTest)94 SqlPredicate (com.hazelcast.query.SqlPredicate)83