Search in sources :

Example 21 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class TestHazelcastFactory method newHazelcastClient.

public HazelcastInstance newHazelcastClient(ClientConfig config) {
    if (!mockNetwork) {
        return HazelcastClient.newHazelcastClient(config);
    }
    if (config == null) {
        config = new XmlClientConfigBuilder().build();
    }
    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    HazelcastClientProxy proxy;
    try {
        if (tccl == ClassLoader.getSystemClassLoader()) {
            Thread.currentThread().setContextClassLoader(HazelcastClient.class.getClassLoader());
        }
        ClientConnectionManagerFactory clientConnectionManagerFactory = clientRegistry.createClientServiceFactory("127.0.0.1", CLIENT_PORTS);
        AddressProvider testAddressProvider = createAddressProvider(config);
        HazelcastClientInstanceImpl client = new HazelcastClientInstanceImpl(config, clientConnectionManagerFactory, testAddressProvider);
        client.start();
        clients.add(client);
        OutOfMemoryErrorDispatcher.registerClient(client);
        proxy = new HazelcastClientProxy(client);
    } finally {
        Thread.currentThread().setContextClassLoader(tccl);
    }
    return proxy;
}
Also used : AddressProvider(com.hazelcast.client.connection.AddressProvider) XmlClientConfigBuilder(com.hazelcast.client.config.XmlClientConfigBuilder) ClientConnectionManagerFactory(com.hazelcast.client.impl.ClientConnectionManagerFactory) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) HazelcastClient(com.hazelcast.client.HazelcastClient) HazelcastClientProxy(com.hazelcast.client.impl.HazelcastClientProxy)

Example 22 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class ClientTestSupport method blockMessagesFromInstance.

/**
     * Blocks incoming messages to client from given instance
     */
protected void blockMessagesFromInstance(HazelcastInstance instance, HazelcastInstance client) {
    HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
    ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
    Address address = instance.getCluster().getLocalMember().getAddress();
    ((TestClientRegistry.MockClientConnectionManager) connectionManager).blockFrom(address);
}
Also used : Address(com.hazelcast.nio.Address) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) ClientConnectionManager(com.hazelcast.client.connection.ClientConnectionManager)

Example 23 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class ClientHeartbeatTest method testAddingListenerToNewConnectionFailedBecauseOfHeartbeat.

@Test
public void testAddingListenerToNewConnectionFailedBecauseOfHeartbeat() throws Exception {
    hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setProperty(ClientProperty.HEARTBEAT_TIMEOUT.getName(), "4000");
    clientConfig.setProperty(ClientProperty.HEARTBEAT_INTERVAL.getName(), "1000");
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
    final ClientListenerService clientListenerService = clientInstanceImpl.getListenerService();
    final CountDownLatch blockIncoming = new CountDownLatch(1);
    final CountDownLatch heartbeatStopped = new CountDownLatch(1);
    final CountDownLatch onListenerRegister = new CountDownLatch(2);
    clientInstanceImpl.getConnectionManager().addConnectionHeartbeatListener(new ConnectionHeartbeatListener() {

        @Override
        public void heartbeatResumed(Connection connection) {
        }

        @Override
        public void heartbeatStopped(Connection connection) {
            heartbeatStopped.countDown();
        }
    });
    clientListenerService.registerListener(createPartitionLostListenerCodec(), new EventHandler() {

        AtomicInteger count = new AtomicInteger(0);

        @Override
        public void handle(Object event) {
        }

        @Override
        public void beforeListenerRegister() {
            if (count.incrementAndGet() == 2) {
                try {
                    blockIncoming.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }

        @Override
        public void onListenerRegister() {
            onListenerRegister.countDown();
        }
    });
    HazelcastInstance hazelcastInstance2 = hazelcastFactory.newHazelcastInstance();
    assertSizeEventually(2, clientInstanceImpl.getConnectionManager().getActiveConnections());
    blockMessagesFromInstance(hazelcastInstance2, client);
    assertOpenEventually(heartbeatStopped);
    blockIncoming.countDown();
    unblockMessagesFromInstance(hazelcastInstance2, client);
    assertOpenEventually(onListenerRegister);
}
Also used : ClientListenerService(com.hazelcast.client.spi.ClientListenerService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Connection(com.hazelcast.nio.Connection) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) EventHandler(com.hazelcast.client.spi.EventHandler) ConnectionHeartbeatListener(com.hazelcast.client.spi.impl.ConnectionHeartbeatListener) ClientConfig(com.hazelcast.client.config.ClientConfig) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 24 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class AbstractListenersOnReconnectTest method getClientEventRegistrations.

private Collection<ClientEventRegistration> getClientEventRegistrations(HazelcastInstance client, String id) {
    HazelcastClientInstanceImpl clientImpl = ClientTestUtil.getHazelcastClientInstanceImpl(client);
    ClientListenerServiceImpl listenerService = (ClientListenerServiceImpl) clientImpl.getListenerService();
    return listenerService.getActiveRegistrations(id);
}
Also used : ClientListenerServiceImpl(com.hazelcast.client.spi.impl.listener.ClientListenerServiceImpl) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl)

Example 25 with HazelcastClientInstanceImpl

use of com.hazelcast.client.impl.HazelcastClientInstanceImpl in project hazelcast by hazelcast.

the class AbstractListenersOnReconnectTest method testListenersTerminateRandomNode.

private void testListenersTerminateRandomNode() {
    setupListener();
    terminateRandomNode();
    HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
    final CountDownLatch memberAddedLatch = new CountDownLatch(1);
    clientInstanceImpl.getClientClusterService().addMembershipListener(new MembershipListener() {

        @Override
        public void memberAdded(MembershipEvent membershipEvent) {
            memberAddedLatch.countDown();
        }

        @Override
        public void memberRemoved(MembershipEvent membershipEvent) {
        }

        @Override
        public void memberAttributeChanged(MemberAttributeEvent memberAttributeEvent) {
        }
    });
    factory.newHazelcastInstance();
    assertOpenEventually(memberAddedLatch);
    validateRegistrationsAndListenerFunctionality();
}
Also used : MemberAttributeEvent(com.hazelcast.core.MemberAttributeEvent) MembershipEvent(com.hazelcast.core.MembershipEvent) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) CountDownLatch(java.util.concurrent.CountDownLatch) MembershipListener(com.hazelcast.core.MembershipListener)

Aggregations

HazelcastClientInstanceImpl (com.hazelcast.client.impl.HazelcastClientInstanceImpl)40 HazelcastInstance (com.hazelcast.core.HazelcastInstance)15 Address (com.hazelcast.nio.Address)14 Test (org.junit.Test)12 ParallelTest (com.hazelcast.test.annotation.ParallelTest)11 QuickTest (com.hazelcast.test.annotation.QuickTest)11 ClientConnectionManager (com.hazelcast.client.connection.ClientConnectionManager)10 ClientInvocation (com.hazelcast.client.spi.impl.ClientInvocation)9 CountDownLatch (java.util.concurrent.CountDownLatch)9 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)7 ClientInvocationFuture (com.hazelcast.client.spi.impl.ClientInvocationFuture)7 HazelcastClientProxy (com.hazelcast.client.impl.HazelcastClientProxy)6 Connection (com.hazelcast.nio.Connection)6 ClientConfig (com.hazelcast.client.config.ClientConfig)5 ClientTestUtil.getHazelcastClientInstanceImpl (com.hazelcast.client.impl.ClientTestUtil.getHazelcastClientInstanceImpl)5 LifecycleEvent (com.hazelcast.core.LifecycleEvent)5 LifecycleListener (com.hazelcast.core.LifecycleListener)5 ClientConnection (com.hazelcast.client.connection.nio.ClientConnection)4 AssertTask (com.hazelcast.test.AssertTask)4 CacheException (javax.cache.CacheException)4