Package com.hazelcast.core

Examples of com.hazelcast.core.ClientService


    @Test(expected = NullPointerException.class)
    public void testAddClientListener_whenListenerIsNull(){
        HazelcastInstance instance = Hazelcast.newHazelcastInstance();

        ClientService clientService = instance.getClientService();
        clientService.addClientListener(null);
    }
View Full Code Here


    @Test(expected = NullPointerException.class)
    public void testRemoveClientListener_whenIdIsNull(){
        HazelcastInstance instance = Hazelcast.newHazelcastInstance();

        ClientService clientService = instance.getClientService();
        clientService.removeClientListener(null);
    }
View Full Code Here

    @Test
    public void testRemoveClientListener_whenListenerAlreadyRemoved(){
        HazelcastInstance instance = Hazelcast.newHazelcastInstance();

        ClientService clientService = instance.getClientService();
        ClientListener clientListener = mock(ClientListener.class);
        String id = clientService.addClientListener(clientListener);

        // first time remove
        clientService.removeClientListener(id);

        // second time remove
        clientService.removeClientListener(id);
    }
View Full Code Here

    @Test
    public void testRemoveClientListener_whenNonExistingId(){
        HazelcastInstance instance = Hazelcast.newHazelcastInstance();

        ClientService clientService = instance.getClientService();

        clientService.removeClientListener("foobar");
    }
View Full Code Here

        final HazelcastInstance instance = Hazelcast.newHazelcastInstance();

        final HazelcastInstance client1 = HazelcastClient.newHazelcastClient();
        final HazelcastInstance client2 = HazelcastClient.newHazelcastClient();

        final ClientService clientService = instance.getClientService();
        final Collection<Client> connectedClients = clientService.getConnectedClients();
        assertEquals(2, connectedClients.size());

        final String uuid1 = client1.getLocalEndpoint().getUuid();
        final String uuid2 = client2.getLocalEndpoint().getUuid();
        for (Client connectedClient : connectedClients) {
View Full Code Here

    }

    @Test
    public void testClientListener() throws InterruptedException {
        final HazelcastInstance instance = Hazelcast.newHazelcastInstance();
        final ClientService clientService = instance.getClientService();
        final CountDownLatch latchAdd = new CountDownLatch(2);
        final CountDownLatch latchRemove = new CountDownLatch(2);
        final AtomicInteger totalAdd = new AtomicInteger(0);

        final ClientListener clientListener = new ClientListener() {
            @Override
            public void clientConnected(Client client) {
                totalAdd.incrementAndGet();
                latchAdd.countDown();
            }

            @Override
            public void clientDisconnected(Client client) {
                latchRemove.countDown();
            }
        };
        final String id = clientService.addClientListener(clientListener);

        final HazelcastInstance client1 = HazelcastClient.newHazelcastClient();
        final HazelcastInstance client2 = HazelcastClient.newHazelcastClient();

        client1.getLifecycleService().shutdown();
        client2.getLifecycleService().shutdown();

        assertTrue(latchAdd.await(6, TimeUnit.SECONDS));
        assertTrue(latchRemove.await(6, TimeUnit.SECONDS));

        assertTrue(clientService.removeClientListener(id));

        assertFalse(clientService.removeClientListener("foo"));

        assertEquals(0, clientService.getConnectedClients().size());

        final HazelcastInstance client3 = HazelcastClient.newHazelcastClient();

        assertTrueEventually(new AssertTask() {
            @Override
            public void run() throws Exception {
                assertEquals(1, clientService.getConnectedClients().size());
            }
        }, 4);

        assertEquals(2, totalAdd.get());
    }
View Full Code Here

    public void testClientListenerForBothNodes() {
        final HazelcastInstance instance1 = Hazelcast.newHazelcastInstance();
        final HazelcastInstance instance2 = Hazelcast.newHazelcastInstance();
        final ClientConnectedListenerLatch clientListenerLatch = new ClientConnectedListenerLatch(2);

        final ClientService clientService1 = instance1.getClientService();
        clientService1.addClientListener(clientListenerLatch);
        final ClientService clientService2 = instance2.getClientService();
        clientService2.addClientListener(clientListenerLatch);

        final HazelcastInstance client = HazelcastClient.newHazelcastClient();
        final String instance1Key = generateKeyOwnedBy(instance1);
        final String instance2Key = generateKeyOwnedBy(instance2);
View Full Code Here

TOP

Related Classes of com.hazelcast.core.ClientService

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.