Search in sources :

Example 1 with ClientEngineImpl

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

the class ClientReAuthOperation method run.

@Override
public void run() throws Exception {
    ClientEngineImpl engine = getService();
    String memberUuid = getCallerUuid();
    if (!engine.trySetLastAuthenticationCorrelationId(clientUuid, authCorrelationId)) {
        String message = "Server already processed a newer authentication from client with uuid " + clientUuid + ". Not applying requested ownership change to " + memberUuid;
        getLogger().info(message);
        throw new AuthenticationException(message);
    }
    Set<ClientEndpoint> endpoints = engine.getEndpointManager().getEndpoints(clientUuid);
    for (ClientEndpoint endpoint : endpoints) {
        ClientPrincipal principal = new ClientPrincipal(clientUuid, memberUuid);
        endpoint.authenticated(principal);
    }
    String previousMemberUuid = engine.addOwnershipMapping(clientUuid, memberUuid);
    clientDisconnectOperationRun = previousMemberUuid == null;
}
Also used : ClientEngineImpl(com.hazelcast.client.impl.ClientEngineImpl) AuthenticationException(com.hazelcast.client.AuthenticationException) ClientEndpoint(com.hazelcast.client.ClientEndpoint) ClientPrincipal(com.hazelcast.client.impl.client.ClientPrincipal)

Example 2 with ClientEngineImpl

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

the class ClientOwnershipTest method test_clientOwnedByMember.

@Test
public void test_clientOwnedByMember() {
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    String instanceUuid = instance.getLocalEndpoint().getUuid();
    String clientUuid = client.getLocalEndpoint().getUuid();
    ClientEngineImpl clientEngine = getClientEngineImpl(instance);
    assertEquals(instanceUuid, clientEngine.getOwnerUuid(clientUuid));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientEngineImpl(com.hazelcast.client.impl.ClientEngineImpl) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 3 with ClientEngineImpl

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

the class ClientOwnershipTest method test_ownerShip_afterClusterRestart.

@Test
public void test_ownerShip_afterClusterRestart() {
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.getNetworkConfig().setConnectionAttemptLimit(Integer.MAX_VALUE);
    final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
    instance.shutdown();
    final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
    // wait for client to connect to node
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(1, client.getCluster().getMembers().size());
            assertEquals(1, instance2.getCluster().getMembers().size());
        }
    });
    final String instanceUuid = instance2.getLocalEndpoint().getUuid();
    final ClientEngineImpl clientEngine2 = getClientEngineImpl(instance2);
    final String clientUuid = client.getLocalEndpoint().getUuid();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(instanceUuid, clientEngine2.getOwnerUuid(clientUuid));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientEngineImpl(com.hazelcast.client.impl.ClientEngineImpl) AssertTask(com.hazelcast.test.AssertTask) ClientConfig(com.hazelcast.client.config.ClientConfig) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 4 with ClientEngineImpl

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

the class ClientOwnershipTest method test_clientOwnedInfoPropagatedToAllMembers.

@Test
public void test_clientOwnedInfoPropagatedToAllMembers() {
    HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
    final String instanceUuid = instance1.getLocalEndpoint().getUuid();
    final String clientUuid = client.getLocalEndpoint().getUuid();
    final ClientEngineImpl clientEngine1 = getClientEngineImpl(instance1);
    final ClientEngineImpl clientEngine2 = getClientEngineImpl(instance2);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(instanceUuid, clientEngine1.getOwnerUuid(clientUuid));
            assertEquals(instanceUuid, clientEngine2.getOwnerUuid(clientUuid));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientEngineImpl(com.hazelcast.client.impl.ClientEngineImpl) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 5 with ClientEngineImpl

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

the class ClientOwnershipTest method test_ownerShipRemoved_afterClientDies.

@Test
public void test_ownerShipRemoved_afterClientDies() {
    HazelcastInstance instance1 = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();
    final String instanceUuid = instance1.getLocalEndpoint().getUuid();
    final String clientUuid = client.getLocalEndpoint().getUuid();
    final ClientEngineImpl clientEngine1 = getClientEngineImpl(instance1);
    final ClientEngineImpl clientEngine2 = getClientEngineImpl(instance2);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(instanceUuid, clientEngine1.getOwnerUuid(clientUuid));
            assertEquals(instanceUuid, clientEngine2.getOwnerUuid(clientUuid));
        }
    });
    client.shutdown();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(null, clientEngine1.getOwnerUuid(clientUuid));
            assertEquals(null, clientEngine2.getOwnerUuid(clientUuid));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ClientEngineImpl(com.hazelcast.client.impl.ClientEngineImpl) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ClientEngineImpl (com.hazelcast.client.impl.ClientEngineImpl)20 HazelcastInstance (com.hazelcast.core.HazelcastInstance)16 Test (org.junit.Test)16 QuickTest (com.hazelcast.test.annotation.QuickTest)15 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)9 Accessors.getClientEngineImpl (com.hazelcast.test.Accessors.getClientEngineImpl)8 ClientConfig (com.hazelcast.client.config.ClientConfig)6 HazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.HazelcastClientInstanceImpl)6 AssertTask (com.hazelcast.test.AssertTask)6 ParallelTest (com.hazelcast.test.annotation.ParallelTest)6 UUID (java.util.UUID)4 ClientEndpoint (com.hazelcast.client.ClientEndpoint)2 ClientEndpoint (com.hazelcast.client.impl.ClientEndpoint)2 ClientStatistics (com.hazelcast.client.impl.statistics.ClientStatistics)2 Consumer (java.util.function.Consumer)2 AuthenticationException (com.hazelcast.client.AuthenticationException)1 ClientEndpointManagerImpl (com.hazelcast.client.impl.ClientEndpointManagerImpl)1 ClientEndpointStatisticsManagerImpl (com.hazelcast.client.impl.ClientEndpointStatisticsManagerImpl)1 ClientPrincipal (com.hazelcast.client.impl.client.ClientPrincipal)1 ClientTestUtil.getHazelcastClientInstanceImpl (com.hazelcast.client.impl.clientside.ClientTestUtil.getHazelcastClientInstanceImpl)1