Search in sources :

Example 61 with Node

use of com.hazelcast.instance.Node in project hazelcast by hazelcast.

the class Invocation_NetworkSplitTest method testWaitingInvocations_whenNodeSplitFromCluster.

private void testWaitingInvocations_whenNodeSplitFromCluster(SplitAction splitAction) throws Exception {
    Config config = createConfig();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    HazelcastInstance hz3 = factory.newHazelcastInstance(config);
    Node node1 = TestUtil.getNode(hz1);
    Node node2 = TestUtil.getNode(hz2);
    Node node3 = TestUtil.getNode(hz3);
    warmUpPartitions(hz1, hz2, hz3);
    int partitionId = getPartitionId(hz2);
    NodeEngineImpl nodeEngine3 = node3.getNodeEngine();
    OperationService operationService3 = nodeEngine3.getOperationService();
    Operation op = new AlwaysBlockingOperation();
    Future<Object> future = operationService3.invokeOnPartition("", op, partitionId);
    // just wait a little to make sure
    // operation is landed on wait-queue
    sleepSeconds(1);
    // execute the given split action
    splitAction.run(node1, node2, node3);
    // Let node3 detect the split and merge it back to other two.
    ClusterServiceImpl clusterService3 = node3.getClusterService();
    clusterService3.merge(node1.address);
    assertClusterSizeEventually(3, hz1);
    assertClusterSizeEventually(3, hz2);
    assertClusterSizeEventually(3, hz3);
    try {
        future.get(1, TimeUnit.MINUTES);
        fail("Future.get() should fail with a MemberLeftException!");
    } catch (MemberLeftException e) {
        // expected
        EmptyStatement.ignore(e);
    } catch (Exception e) {
        fail(e.getClass().getName() + ": " + e.getMessage());
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) BlockingOperation(com.hazelcast.spi.BlockingOperation) Operation(com.hazelcast.spi.Operation) TimeoutException(java.util.concurrent.TimeoutException) MemberLeftException(com.hazelcast.core.MemberLeftException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) MemberLeftException(com.hazelcast.core.MemberLeftException)

Example 62 with Node

use of com.hazelcast.instance.Node in project hazelcast by hazelcast.

the class ConnectedClientOperationTest method testNumberOfConnectedClients.

@Test
public void testNumberOfConnectedClients() throws Exception {
    HazelcastInstance h1 = factory.newHazelcastInstance();
    HazelcastInstance h2 = factory.newHazelcastInstance();
    assertClusterSizeEventually(2, h1);
    assertClusterSizeEventually(2, h2);
    int numberOfClients = 6;
    for (int i = 0; i < numberOfClients; i++) {
        factory.newHazelcastClient();
    }
    Node node = TestUtil.getNode(h1);
    Map<ClientType, Integer> clientStats = node.clientEngine.getConnectedClientStats();
    assertEquals(numberOfClients, clientStats.get(ClientType.JAVA).intValue());
    assertEquals(0, clientStats.get(ClientType.CPP).intValue());
    assertEquals(0, clientStats.get(ClientType.CSHARP).intValue());
    assertEquals(0, clientStats.get(ClientType.NODEJS).intValue());
    assertEquals(0, clientStats.get(ClientType.PYTHON).intValue());
    assertEquals(0, clientStats.get(ClientType.OTHER).intValue());
}
Also used : ClientType(com.hazelcast.core.ClientType) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.Node) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 63 with Node

use of com.hazelcast.instance.Node in project hazelcast by hazelcast.

the class ConnectedClientOperationTest method testGetConnectedClientsOperation_WhenZeroClientConnects.

@Test
public void testGetConnectedClientsOperation_WhenZeroClientConnects() throws Exception {
    HazelcastInstance instance = factory.newHazelcastInstance();
    Node node = TestUtil.getNode(instance);
    Operation operation = new GetConnectedClientsOperation();
    OperationService operationService = node.nodeEngine.getOperationService();
    Future<Map<String, ClientType>> future = operationService.invokeOnTarget(ClientEngineImpl.SERVICE_NAME, operation, node.address);
    Map<String, ClientType> clients = future.get();
    assertEquals(0, clients.size());
}
Also used : ClientType(com.hazelcast.core.ClientType) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.Node) Operation(com.hazelcast.spi.Operation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) OperationService(com.hazelcast.spi.OperationService) Map(java.util.Map) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 64 with Node

use of com.hazelcast.instance.Node in project hazelcast by hazelcast.

the class NodeQueryCacheContext method flushPublishersOnNodeShutdown.

/**
     * This is a best effort approach; there is no guarantee that events in publishers internal buffers will be fired,
     * {@link com.hazelcast.spi.EventService} can drop them.
     */
private void flushPublishersOnNodeShutdown() {
    Node node = ((NodeEngineImpl) this.nodeEngine).getNode();
    LifecycleServiceImpl lifecycleService = node.hazelcastInstance.getLifecycleService();
    lifecycleService.addLifecycleListener(new LifecycleListener() {

        @Override
        public void stateChanged(LifecycleEvent event) {
            if (SHUTTING_DOWN == event.getState()) {
                publisherContext.flush();
            }
        }
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Node(com.hazelcast.instance.Node) LifecycleEvent(com.hazelcast.core.LifecycleEvent) LifecycleListener(com.hazelcast.core.LifecycleListener) LifecycleServiceImpl(com.hazelcast.instance.LifecycleServiceImpl)

Example 65 with Node

use of com.hazelcast.instance.Node in project hazelcast by hazelcast.

the class CacheClearTest method testClear.

@Test
public void testClear() {
    ICache<String, String> cache = createCache();
    String cacheName = cache.getName();
    Map<String, String> entries = createAndFillEntries();
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        cache.put(entry.getKey(), entry.getValue());
    }
    // Verify that put works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        String expectedValue = entries.get(key);
        String actualValue = cache.get(key);
        assertEquals(expectedValue, actualValue);
    }
    Node node = getNode(hazelcastInstance);
    InternalPartitionService partitionService = node.getPartitionService();
    SerializationService serializationService = node.getSerializationService();
    // Verify that backup of put works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        String expectedValue = entries.get(key);
        Data keyData = serializationService.toData(key);
        int keyPartitionId = partitionService.getPartitionId(keyData);
        for (int i = 0; i < INSTANCE_COUNT; i++) {
            Node n = getNode(hazelcastInstances[i]);
            ICacheService cacheService = n.getNodeEngine().getService(ICacheService.SERVICE_NAME);
            ICacheRecordStore recordStore = cacheService.getRecordStore("/hz/" + cacheName, keyPartitionId);
            assertNotNull(recordStore);
            String actualValue = serializationService.toObject(recordStore.get(keyData, null));
            assertEquals(expectedValue, actualValue);
        }
    }
    cache.clear();
    // Verify that clear works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        String actualValue = cache.get(key);
        assertNull(actualValue);
    }
    // Verify that backup of clear works
    for (Map.Entry<String, String> entry : entries.entrySet()) {
        String key = entry.getKey();
        Data keyData = serializationService.toData(key);
        int keyPartitionId = partitionService.getPartitionId(keyData);
        for (int i = 0; i < INSTANCE_COUNT; i++) {
            Node n = getNode(hazelcastInstances[i]);
            ICacheService cacheService = n.getNodeEngine().getService(ICacheService.SERVICE_NAME);
            ICacheRecordStore recordStore = cacheService.getRecordStore("/hz/" + cacheName, keyPartitionId);
            assertNotNull(recordStore);
            String actualValue = serializationService.toObject(recordStore.get(keyData, null));
            assertNull(actualValue);
        }
    }
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) ICacheService(com.hazelcast.cache.impl.ICacheService) Node(com.hazelcast.instance.Node) SerializationService(com.hazelcast.spi.serialization.SerializationService) Data(com.hazelcast.nio.serialization.Data) ICacheRecordStore(com.hazelcast.cache.impl.ICacheRecordStore) HashMap(java.util.HashMap) Map(java.util.Map) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Node (com.hazelcast.instance.Node)131 HazelcastInstance (com.hazelcast.core.HazelcastInstance)60 Test (org.junit.Test)50 QuickTest (com.hazelcast.test.annotation.QuickTest)45 ParallelTest (com.hazelcast.test.annotation.ParallelTest)42 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)21 ClientEventRegistration (com.hazelcast.client.spi.impl.listener.ClientEventRegistration)18 Address (com.hazelcast.nio.Address)17 Config (com.hazelcast.config.Config)14 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)13 ILogger (com.hazelcast.logging.ILogger)10 Data (com.hazelcast.nio.serialization.Data)10 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)10 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)9 StringUtil.bytesToString (com.hazelcast.util.StringUtil.bytesToString)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ClusterService (com.hazelcast.internal.cluster.ClusterService)7 SerializationService (com.hazelcast.spi.serialization.SerializationService)7 ItemListener (com.hazelcast.core.ItemListener)6 Operation (com.hazelcast.spi.Operation)6