Search in sources :

Example 1 with Client

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

the class TimedMemberStateFactory method createMemberState.

private void createMemberState(TimedMemberState timedMemberState, MemberStateImpl memberState, Collection<StatisticsAwareService> services) {
    Node node = instance.node;
    HashSet<ClientEndPointDTO> serializableClientEndPoints = new HashSet<ClientEndPointDTO>();
    for (Client client : instance.node.clientEngine.getClients()) {
        serializableClientEndPoints.add(new ClientEndPointDTO(client));
    }
    memberState.setClients(serializableClientEndPoints);
    Address thisAddress = node.getThisAddress();
    memberState.setAddress(thisAddress.getHost() + ":" + thisAddress.getPort());
    TimedMemberStateFactoryHelper.registerJMXBeans(instance, memberState);
    MemberPartitionStateImpl memberPartitionState = (MemberPartitionStateImpl) memberState.getMemberPartitionState();
    InternalPartitionService partitionService = node.getPartitionService();
    IPartition[] partitions = partitionService.getPartitions();
    List<Integer> partitionList = memberPartitionState.getPartitions();
    for (IPartition partition : partitions) {
        if (partition.isLocal()) {
            partitionList.add(partition.getPartitionId());
        }
    }
    memberPartitionState.setMigrationQueueSize(partitionService.getMigrationQueueSize());
    memberPartitionState.setMemberStateSafe(memberStateSafe);
    memberState.setLocalMemoryStats(getMemoryStats());
    memberState.setOperationStats(getOperationStats());
    TimedMemberStateFactoryHelper.createRuntimeProps(memberState);
    createMemState(timedMemberState, memberState, services);
    createNodeState(memberState);
    createHotRestartState(memberState);
    createClusterHotRestartStatus(memberState);
    createWanSyncState(memberState);
}
Also used : Address(com.hazelcast.nio.Address) ClientEndPointDTO(com.hazelcast.internal.management.dto.ClientEndPointDTO) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.Node) MemberPartitionStateImpl(com.hazelcast.monitor.impl.MemberPartitionStateImpl) Client(com.hazelcast.core.Client) IPartition(com.hazelcast.spi.partition.IPartition) HashSet(java.util.HashSet)

Example 2 with Client

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

the class ClientConnectionTest method testWithLegalAndIllegalAddressTogether.

@Test
public void testWithLegalAndIllegalAddressTogether() {
    String illegalAddress = randomString();
    HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
    ClientConfig config = new ClientConfig();
    config.setProperty(ClientProperty.SHUFFLE_MEMBER_LIST.getName(), "false");
    config.getNetworkConfig().addAddress(illegalAddress).addAddress("localhost");
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(config);
    Collection<Client> connectedClients = server.getClientService().getConnectedClients();
    assertEquals(connectedClients.size(), 1);
    Client serverSideClientInfo = connectedClients.iterator().next();
    assertEquals(serverSideClientInfo.getUuid(), client.getLocalEndpoint().getUuid());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientConfig(com.hazelcast.client.config.ClientConfig) Client(com.hazelcast.core.Client) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with Client

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

the class ClientConnectionTest method testMemberConnectionOrder.

@Test
public void testMemberConnectionOrder() {
    HazelcastInstance server1 = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance server2 = hazelcastFactory.newHazelcastInstance();
    ClientConfig config = new ClientConfig();
    config.setProperty(ClientProperty.SHUFFLE_MEMBER_LIST.getName(), "false");
    config.getNetworkConfig().setSmartRouting(false);
    InetSocketAddress socketAddress1 = server1.getCluster().getLocalMember().getSocketAddress();
    InetSocketAddress socketAddress2 = server2.getCluster().getLocalMember().getSocketAddress();
    config.getNetworkConfig().addAddress(socketAddress1.getHostName() + ":" + socketAddress1.getPort()).addAddress(socketAddress2.getHostName() + ":" + socketAddress2.getPort());
    hazelcastFactory.newHazelcastClient(config);
    Collection<Client> connectedClients1 = server1.getClientService().getConnectedClients();
    assertEquals(connectedClients1.size(), 1);
    Collection<Client> connectedClients2 = server2.getClientService().getConnectedClients();
    assertEquals(connectedClients2.size(), 0);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InetSocketAddress(java.net.InetSocketAddress) ClientConfig(com.hazelcast.client.config.ClientConfig) Client(com.hazelcast.core.Client) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with Client

use of com.hazelcast.core.Client in project neo4j by neo4j.

the class HazelcastClientTest method shouldRegisterReadReplicaInTopology.

@Test
public void shouldRegisterReadReplicaInTopology() throws Throwable {
    // given
    com.hazelcast.core.Cluster cluster = mock(Cluster.class);
    Set<Member> members = asSet(makeMember(1));
    when(cluster.getMembers()).thenReturn(members);
    Endpoint endpoint = mock(Endpoint.class);
    when(endpoint.getUuid()).thenReturn("12345");
    Client client = mock(Client.class);
    final String clientId = "12345";
    when(client.getUuid()).thenReturn(clientId);
    ClientService clientService = mock(ClientService.class);
    when(clientService.getConnectedClients()).thenReturn(asSet(client));
    HazelcastMap hazelcastMap = new HazelcastMap();
    HazelcastMultiMap hazelcastMultiMap = new HazelcastMultiMap();
    HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
    when(hazelcastInstance.getAtomicReference(anyString())).thenReturn(mock(IAtomicReference.class));
    when(hazelcastInstance.getMap(anyString())).thenReturn(hazelcastMap);
    when(hazelcastInstance.getMultiMap(anyString())).thenReturn(hazelcastMultiMap);
    when(hazelcastInstance.getLocalEndpoint()).thenReturn(endpoint);
    when(hazelcastInstance.getExecutorService(anyString())).thenReturn(new StubExecutorService());
    when(hazelcastInstance.getCluster()).thenReturn(cluster);
    when(hazelcastInstance.getClientService()).thenReturn(clientService);
    HazelcastConnector connector = mock(HazelcastConnector.class);
    when(connector.connectToHazelcast()).thenReturn(hazelcastInstance);
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    HazelcastClient hazelcastClient = new HazelcastClient(connector, jobScheduler, NullLogProvider.getInstance(), config(), myself);
    // when
    hazelcastClient.start();
    jobScheduler.runJob();
    // then
    assertEquals(1, hazelcastMap.size());
}
Also used : ClientService(com.hazelcast.core.ClientService) Matchers.anyString(org.mockito.Matchers.anyString) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Endpoint(com.hazelcast.core.Endpoint) IAtomicReference(com.hazelcast.core.IAtomicReference) Cluster(com.hazelcast.core.Cluster) Client(com.hazelcast.core.Client) Member(com.hazelcast.core.Member) Test(org.junit.Test)

Example 5 with Client

use of com.hazelcast.core.Client in project neo4j by neo4j.

the class HazelcastClientTest method shouldRemoveReadReplicasOnGracefulShutdown.

@Test
public void shouldRemoveReadReplicasOnGracefulShutdown() throws Throwable {
    // given
    com.hazelcast.core.Cluster cluster = mock(Cluster.class);
    Set<Member> members = asSet(makeMember(1));
    when(cluster.getMembers()).thenReturn(members);
    Endpoint endpoint = mock(Endpoint.class);
    when(endpoint.getUuid()).thenReturn("12345");
    Client client = mock(Client.class);
    final String clientId = "12345";
    when(client.getUuid()).thenReturn(clientId);
    ClientService clientService = mock(ClientService.class);
    when(clientService.getConnectedClients()).thenReturn(asSet(client));
    HazelcastMap hazelcastMap = new HazelcastMap();
    HazelcastInstance hazelcastInstance = mock(HazelcastInstance.class);
    when(hazelcastInstance.getAtomicReference(anyString())).thenReturn(mock(IAtomicReference.class));
    when(hazelcastInstance.getMap(anyString())).thenReturn(hazelcastMap);
    when(hazelcastInstance.getMultiMap(anyString())).thenReturn(new HazelcastMultiMap());
    when(hazelcastInstance.getLocalEndpoint()).thenReturn(endpoint);
    when(hazelcastInstance.getExecutorService(anyString())).thenReturn(new StubExecutorService());
    when(hazelcastInstance.getCluster()).thenReturn(cluster);
    when(hazelcastInstance.getClientService()).thenReturn(clientService);
    HazelcastConnector connector = mock(HazelcastConnector.class);
    when(connector.connectToHazelcast()).thenReturn(hazelcastInstance);
    OnDemandJobScheduler jobScheduler = new OnDemandJobScheduler();
    HazelcastClient hazelcastClient = new HazelcastClient(connector, jobScheduler, NullLogProvider.getInstance(), config(), myself);
    hazelcastClient.start();
    jobScheduler.runJob();
    // when
    hazelcastClient.stop();
    // then
    assertEquals(0, hazelcastMap.size());
}
Also used : ClientService(com.hazelcast.core.ClientService) Matchers.anyString(org.mockito.Matchers.anyString) OnDemandJobScheduler(org.neo4j.test.OnDemandJobScheduler) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Endpoint(com.hazelcast.core.Endpoint) IAtomicReference(com.hazelcast.core.IAtomicReference) Cluster(com.hazelcast.core.Cluster) Client(com.hazelcast.core.Client) Member(com.hazelcast.core.Member) Test(org.junit.Test)

Aggregations

Client (com.hazelcast.core.Client)5 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 Test (org.junit.Test)4 ClientConfig (com.hazelcast.client.config.ClientConfig)2 ClientService (com.hazelcast.core.ClientService)2 Cluster (com.hazelcast.core.Cluster)2 Endpoint (com.hazelcast.core.Endpoint)2 IAtomicReference (com.hazelcast.core.IAtomicReference)2 Member (com.hazelcast.core.Member)2 ParallelTest (com.hazelcast.test.annotation.ParallelTest)2 QuickTest (com.hazelcast.test.annotation.QuickTest)2 Matchers.anyString (org.mockito.Matchers.anyString)2 OnDemandJobScheduler (org.neo4j.test.OnDemandJobScheduler)2 Node (com.hazelcast.instance.Node)1 ClientEndPointDTO (com.hazelcast.internal.management.dto.ClientEndPointDTO)1 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)1 MemberPartitionStateImpl (com.hazelcast.monitor.impl.MemberPartitionStateImpl)1 Address (com.hazelcast.nio.Address)1 IPartition (com.hazelcast.spi.partition.IPartition)1 InetSocketAddress (java.net.InetSocketAddress)1