Search in sources :

Example 6 with HazelcastClientInstanceImpl

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

the class TcpClientConnectionTest method destroyConnection_whenDestroyedMultipleTimes_thenListenerRemoveCalledOnce.

@Test
public void destroyConnection_whenDestroyedMultipleTimes_thenListenerRemoveCalledOnce() {
    HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    HazelcastClientInstanceImpl clientImpl = ClientTestUtil.getHazelcastClientInstanceImpl(client);
    ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
    final CountingConnectionListener listener = new CountingConnectionListener();
    connectionManager.addConnectionListener(listener);
    UUID serverUuid = server.getCluster().getLocalMember().getUuid();
    final Connection connectionToServer = connectionManager.getConnection(serverUuid);
    ReconnectListener reconnectListener = new ReconnectListener();
    clientImpl.getLifecycleService().addLifecycleListener(reconnectListener);
    connectionToServer.close(null, null);
    assertOpenEventually(reconnectListener.reconnectedLatch);
    connectionToServer.close(null, null);
    assertEqualsEventually(() -> listener.connectionRemovedCount.get(), 1);
    sleepMillis(100);
    assertEquals("connection removed should be called only once", 1, listener.connectionRemovedCount.get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Connection(com.hazelcast.internal.nio.Connection) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) UUID(java.util.UUID) ClientConnectionManager(com.hazelcast.client.impl.connection.ClientConnectionManager) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with HazelcastClientInstanceImpl

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

the class ClientRegressionWithRealNetworkTest method testListenersAfterClientDisconnected.

private void testListenersAfterClientDisconnected(String memberAddress, String clientAddress) {
    Config config = new Config();
    int heartBeatSeconds = 6;
    config.getNetworkConfig().setPublicAddress(memberAddress);
    config.setProperty(ClusterProperty.CLIENT_HEARTBEAT_TIMEOUT_SECONDS.getName(), Integer.toString(heartBeatSeconds));
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    ClientConfig clientConfig = new ClientConfig();
    ClientNetworkConfig networkConfig = clientConfig.getNetworkConfig();
    networkConfig.addAddress(clientAddress);
    clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    IMap<Integer, Integer> map = client.getMap("test");
    AtomicInteger eventCount = new AtomicInteger(0);
    map.addEntryListener((EntryAddedListener<Object, Object>) event -> eventCount.incrementAndGet(), false);
    assertTrueEventually(() -> {
        HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
        int size = clientInstanceImpl.getConnectionManager().getActiveConnections().size();
        assertEquals(1, size);
    });
    hazelcastInstance.shutdown();
    sleepAtLeastSeconds(2 * heartBeatSeconds);
    Hazelcast.newHazelcastInstance(config);
    assertTrueEventually(() -> {
        map.remove(1);
        map.put(1, 2);
        assertNotEquals(0, eventCount.get());
    });
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) Address(com.hazelcast.cluster.Address) ClientTestSupport(com.hazelcast.client.test.ClientTestSupport) QuickTest(com.hazelcast.test.annotation.QuickTest) RunWith(org.junit.runner.RunWith) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HazelcastSerialClassRunner(com.hazelcast.test.HazelcastSerialClassRunner) ClientProperty(com.hazelcast.client.properties.ClientProperty) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) ExecutorService(java.util.concurrent.ExecutorService) Config(com.hazelcast.config.Config) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AddressProvider(com.hazelcast.client.impl.connection.AddressProvider) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest) UUID(java.util.UUID) TcpClientConnectionManager(com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager) Category(org.junit.experimental.categories.Category) AddressHelper(com.hazelcast.client.util.AddressHelper) Executors(java.util.concurrent.Executors) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) EntryAddedListener(com.hazelcast.map.listener.EntryAddedListener) ClusterProperty(com.hazelcast.spi.properties.ClusterProperty) CountDownLatch(java.util.concurrent.CountDownLatch) Addresses(com.hazelcast.client.impl.connection.Addresses) ClientConnectionStrategyConfig(com.hazelcast.client.config.ClientConnectionStrategyConfig) Assert.assertNull(org.junit.Assert.assertNull) Hazelcast(com.hazelcast.core.Hazelcast) Assert.assertEquals(org.junit.Assert.assertEquals) ClientConnectionManager(com.hazelcast.client.impl.connection.ClientConnectionManager) IMap(com.hazelcast.map.IMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig) Config(com.hazelcast.config.Config) ClientConnectionStrategyConfig(com.hazelcast.client.config.ClientConnectionStrategyConfig) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientConfig(com.hazelcast.client.config.ClientConfig) ClientNetworkConfig(com.hazelcast.client.config.ClientNetworkConfig)

Example 8 with HazelcastClientInstanceImpl

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

the class ClientSplitBrainTest method testClientEngineCleanup_AfterMergeFromSplitBrain.

@Test
public void testClientEngineCleanup_AfterMergeFromSplitBrain() {
    Config config = new Config();
    config.setProperty(ClusterProperty.MERGE_FIRST_RUN_DELAY_SECONDS.getName(), "10");
    config.setProperty(ClusterProperty.MERGE_NEXT_RUN_DELAY_SECONDS.getName(), "10");
    config.setProperty(ClusterProperty.MAX_NO_HEARTBEAT_SECONDS.getName(), "5");
    config.setProperty(ClusterProperty.HEARTBEAT_INTERVAL_SECONDS.getName(), "1");
    TestHazelcastFactory hazelcastFactory = new TestHazelcastFactory();
    HazelcastInstance h1 = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    HazelcastInstance h2 = hazelcastFactory.newHazelcastInstance(config);
    HazelcastInstance h3 = hazelcastFactory.newHazelcastInstance(config);
    HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
    assertSizeEventually(3, clientInstanceImpl.getConnectionManager().getActiveConnections());
    blockCommunicationBetween(h1, h2);
    blockCommunicationBetween(h1, h3);
    // make sure that cluster is split as [ 1 ] , [ 2 , 3 ]
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertEquals(2, h2.getCluster().getMembers().size());
            assertEquals(2, h3.getCluster().getMembers().size());
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertEquals(1, h1.getCluster().getMembers().size());
        }
    });
    // open communication back for nodes to merge
    unblockCommunicationBetween(h1, h2);
    unblockCommunicationBetween(h1, h3);
    // wait for cluster is merged back
    assertClusterSizeEventually(3, h1, h2, h3);
    // wait for client to connect back to all nodes
    assertSizeEventually(3, clientInstanceImpl.getConnectionManager().getActiveConnections());
    // verify endpoints are cleared
    ClientEngineImpl clientEngineImpl1 = getClientEngineImpl(h1);
    ClientEngineImpl clientEngineImpl2 = getClientEngineImpl(h2);
    ClientEngineImpl clientEngineImpl3 = getClientEngineImpl(h3);
    assertEquals(1, clientEngineImpl1.getClientEndpointCount());
    assertEquals(1, clientEngineImpl2.getClientEndpointCount());
    assertEquals(1, clientEngineImpl3.getClientEndpointCount());
    hazelcastFactory.shutdownAll();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientEngineImpl(com.hazelcast.client.impl.ClientEngineImpl) Accessors.getClientEngineImpl(com.hazelcast.test.Accessors.getClientEngineImpl) ClientConfig(com.hazelcast.client.config.ClientConfig) Config(com.hazelcast.config.Config) TestHazelcastFactory(com.hazelcast.client.test.TestHazelcastFactory) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) AssertTask(com.hazelcast.test.AssertTask) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 9 with HazelcastClientInstanceImpl

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

the class ClientProtocolTest method testUnsupportedClientMessage.

@Test(expected = UnsupportedOperationException.class)
public void testUnsupportedClientMessage() {
    hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
    ClientMessage s = MapSizeCodec.encodeRequest("mapName");
    int undefinedMessageType = -1;
    s.setMessageType(undefinedMessageType);
    ClientInvocation invocation = new ClientInvocation(clientImpl, s, "mapName");
    try {
        invocation.invoke().get();
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientInvocation(com.hazelcast.client.impl.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with HazelcastClientInstanceImpl

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

the class ClientCacheClearTest method registerInvalidationListener.

private void registerInvalidationListener(EventHandler handler, String nameWithPrefix) {
    ListenerMessageCodec listenerCodec = createInvalidationListenerCodec(nameWithPrefix);
    HazelcastClientProxy hzClient = (HazelcastClientProxy) client;
    final HazelcastClientInstanceImpl clientInstance = hzClient.client;
    clientInstance.getListenerService().registerListener(listenerCodec, handler);
}
Also used : ListenerMessageCodec(com.hazelcast.client.impl.spi.impl.ListenerMessageCodec) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) HazelcastClientProxy(com.hazelcast.client.impl.clientside.HazelcastClientProxy)

Aggregations

HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)59 Test (org.junit.Test)24 HazelcastInstance (com.hazelcast.core.HazelcastInstance)23 QuickTest (com.hazelcast.test.annotation.QuickTest)23 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)21 ClientMessage (com.hazelcast.client.impl.protocol.ClientMessage)19 ClientInvocation (com.hazelcast.client.impl.spi.impl.ClientInvocation)15 UUID (java.util.UUID)14 ClientConfig (com.hazelcast.client.config.ClientConfig)11 ClientConnectionManager (com.hazelcast.client.impl.connection.ClientConnectionManager)9 HazelcastClientProxy (com.hazelcast.client.impl.clientside.HazelcastClientProxy)7 ClientEngineImpl (com.hazelcast.client.impl.ClientEngineImpl)6 UuidUtil.newUnsecureUUID (com.hazelcast.internal.util.UuidUtil.newUnsecureUUID)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 TcpClientConnectionManager (com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager)4 Address (com.hazelcast.cluster.Address)4 SessionExpiredException (com.hazelcast.cp.internal.session.SessionExpiredException)4 Accessors.getClientEngineImpl (com.hazelcast.test.Accessors.getClientEngineImpl)4 LoadBalancer (com.hazelcast.client.LoadBalancer)3 MCClusterMetadata (com.hazelcast.client.impl.management.MCClusterMetadata)3