Search in sources :

Example 36 with HazelcastClientInstanceImpl

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

the class SqlConsole method sqlStartingPrompt.

private static String sqlStartingPrompt(HazelcastInstance hz) {
    HazelcastClientInstanceImpl hazelcastClientImpl = getHazelcastClientInstanceImpl(hz);
    ClientClusterService clientClusterService = hazelcastClientImpl.getClientClusterService();
    MCClusterMetadata clusterMetadata = FutureUtil.getValue(getClusterMetadata(hazelcastClientImpl, clientClusterService.getMasterMember()));
    Cluster cluster = hazelcastClientImpl.getCluster();
    Set<Member> members = cluster.getMembers();
    String versionString = "Hazelcast " + clusterMetadata.getMemberVersion();
    return new AttributedStringBuilder().style(AttributedStyle.BOLD.foreground(PRIMARY_COLOR)).append("Connected to ").append(versionString).append(" at ").append(members.iterator().next().getAddress().toString()).append(" (+").append(String.valueOf(members.size() - 1)).append(" more)\n").append("Type 'help' for instructions").toAnsi();
}
Also used : HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) HazelcastCommandLine.getHazelcastClientInstanceImpl(com.hazelcast.client.console.HazelcastCommandLine.getHazelcastClientInstanceImpl) Cluster(com.hazelcast.cluster.Cluster) AttributedStringBuilder(org.jline.utils.AttributedStringBuilder) Member(com.hazelcast.cluster.Member) ClientClusterService(com.hazelcast.client.impl.spi.ClientClusterService) MCClusterMetadata(com.hazelcast.client.impl.management.MCClusterMetadata)

Example 37 with HazelcastClientInstanceImpl

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

the class ClientRegressionWithRealNetworkTest method testNioChannelLeakTest.

@Test
public void testNioChannelLeakTest() {
    ClientConfig config = new ClientConfig();
    config.getConnectionStrategyConfig().setAsyncStart(true).setReconnectMode(ClientConnectionStrategyConfig.ReconnectMode.ASYNC).getConnectionRetryConfig().setInitialBackoffMillis(1).setClusterConnectTimeoutMillis(1000);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(config);
    HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
    TcpClientConnectionManager connectionManager = (TcpClientConnectionManager) clientInstanceImpl.getConnectionManager();
    sleepSeconds(2);
    assertTrueEventually(() -> assertEquals(0, connectionManager.getNetworking().getChannels().size()));
    client.shutdown();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) TcpClientConnectionManager(com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Example 38 with HazelcastClientInstanceImpl

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

the class ClientRegressionWithRealNetworkTest method testConnectionCountAfterClientReconnect.

private void testConnectionCountAfterClientReconnect(String memberAddress, String clientAddress) {
    Config config = new Config();
    config.getNetworkConfig().setPublicAddress(memberAddress);
    HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().addAddress(clientAddress);
    clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
    HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
    HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
    ClientConnectionManager connectionManager = clientInstanceImpl.getConnectionManager();
    assertTrueEventually(() -> assertEquals(1, connectionManager.getActiveConnections().size()));
    ReconnectListener reconnectListener = new ReconnectListener();
    client.getLifecycleService().addLifecycleListener(reconnectListener);
    hazelcastInstance.shutdown();
    assertOpenEventually(reconnectListener.disconnectedLatch);
    Hazelcast.newHazelcastInstance(config);
    assertOpenEventually(reconnectListener.reconnectedLatch);
    assertEquals(1, connectionManager.getActiveConnections().size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) 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) TcpClientConnectionManager(com.hazelcast.client.impl.connection.tcp.TcpClientConnectionManager) ClientConnectionManager(com.hazelcast.client.impl.connection.ClientConnectionManager)

Example 39 with HazelcastClientInstanceImpl

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

the class TcpClientConnectionTest method testAddingConnectionListenerTwice_shouldCauseEventDeliveredTwice.

@Test
public void testAddingConnectionListenerTwice_shouldCauseEventDeliveredTwice() {
    hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    HazelcastClientInstanceImpl clientImpl = ClientTestUtil.getHazelcastClientInstanceImpl(client);
    ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
    final CountingConnectionListener listener = new CountingConnectionListener();
    connectionManager.addConnectionListener(listener);
    connectionManager.addConnectionListener(listener);
    hazelcastFactory.newHazelcastInstance();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() {
            assertEquals(listener.connectionAddedCount.get(), 2);
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) AssertTask(com.hazelcast.test.AssertTask) ClientConnectionManager(com.hazelcast.client.impl.connection.ClientConnectionManager) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 40 with HazelcastClientInstanceImpl

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

the class ClientConfigLoadBalancerTest method shouldCreateCustomLoadBalancerWhenConfigInstanceNotProvidedAndClassNameSpecified.

@Test
public void shouldCreateCustomLoadBalancerWhenConfigInstanceNotProvidedAndClassNameSpecified() {
    hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.setLoadBalancerClassName("com.hazelcast.client.test.CustomLoadBalancer");
    HazelcastInstance instance = hazelcastFactory.newHazelcastClient(clientConfig);
    HazelcastClientInstanceImpl client = ClientTestUtil.getHazelcastClientInstanceImpl(instance);
    LoadBalancer actual = client.getLoadBalancer();
    assertTrue(actual instanceof CustomLoadBalancer);
}
Also used : CustomLoadBalancer(com.hazelcast.client.test.CustomLoadBalancer) HazelcastInstance(com.hazelcast.core.HazelcastInstance) HazelcastClientInstanceImpl(com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl) CustomLoadBalancer(com.hazelcast.client.test.CustomLoadBalancer) LoadBalancer(com.hazelcast.client.LoadBalancer) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

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