Search in sources :

Example 71 with Node

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

the class InternalCacheRecordStoreTest method batchEventMapShouldBeCleanedAfterRemoveAll.

/**
 * Test for issue: https://github.com/hazelcast/hazelcast/issues/6618
 */
@Test
public void batchEventMapShouldBeCleanedAfterRemoveAll() {
    String cacheName = randomString();
    CacheConfig<Integer, String> config = createCacheConfig();
    CacheFromDifferentNodesTest.SimpleEntryListener<Integer, String> listener = new CacheFromDifferentNodesTest.SimpleEntryListener<Integer, String>();
    MutableCacheEntryListenerConfiguration<Integer, String> listenerConfiguration = new MutableCacheEntryListenerConfiguration<Integer, String>(FactoryBuilder.factoryOf(listener), null, true, true);
    config.addCacheEntryListenerConfiguration(listenerConfiguration);
    Cache<Integer, String> cache = cacheManager.createCache(cacheName, config);
    assertNotNull(cache);
    Integer key = 1;
    String value = "value";
    cache.put(key, value);
    HazelcastInstance instance = ((HazelcastCacheManager) cacheManager).getHazelcastInstance();
    int partitionId = instance.getPartitionService().getPartition(key).getPartitionId();
    cache.removeAll();
    Node node = getNode(instance);
    assertNotNull(node);
    ICacheService cacheService = node.getNodeEngine().getService(ICacheService.SERVICE_NAME);
    AbstractCacheRecordStore recordStore = (AbstractCacheRecordStore) cacheService.getRecordStore("/hz/" + cacheName, partitionId);
    assertEquals(0, recordStore.batchEvent.size());
}
Also used : MutableCacheEntryListenerConfiguration(javax.cache.configuration.MutableCacheEntryListenerConfiguration) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) HazelcastInstance(com.hazelcast.core.HazelcastInstance) CacheFromDifferentNodesTest(com.hazelcast.cache.CacheFromDifferentNodesTest) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) CacheFromDifferentNodesTest(com.hazelcast.cache.CacheFromDifferentNodesTest)

Example 72 with Node

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

the class InternalCacheRecordStoreTest method ownerStateShouldBeUpdatedAfterMigration.

/**
 * Test for issue: https://github.com/hazelcast/hazelcast/issues/6983
 */
@Test
public void ownerStateShouldBeUpdatedAfterMigration() throws Exception {
    HazelcastCacheManager hzCacheManager = (HazelcastCacheManager) cacheManager;
    HazelcastInstance instance1 = hzCacheManager.getHazelcastInstance();
    Node node1 = getNode(instance1);
    NodeEngineImpl nodeEngine1 = node1.getNodeEngine();
    InternalPartitionService partitionService1 = nodeEngine1.getPartitionService();
    int partitionCount = partitionService1.getPartitionCount();
    String cacheName = randomName();
    CacheConfig cacheConfig = new CacheConfig().setName(cacheName);
    Cache<String, String> cache = cacheManager.createCache(cacheName, cacheConfig);
    String fullCacheName = hzCacheManager.getCacheNameWithPrefix(cacheName);
    for (int i = 0; i < partitionCount; i++) {
        String key = generateKeyForPartition(instance1, i);
        cache.put(key, "Value");
    }
    for (int i = 0; i < partitionCount; i++) {
        verifyPrimaryState(node1, fullCacheName, i, true);
    }
    HazelcastInstance instance2 = getHazelcastInstance();
    Node node2 = getNode(instance2);
    warmUpPartitions(instance1, instance2);
    waitAllForSafeState(instance1, instance2);
    for (int i = 0; i < partitionCount; i++) {
        boolean ownedByNode1 = partitionService1.isPartitionOwner(i);
        if (ownedByNode1) {
            verifyPrimaryState(node1, fullCacheName, i, true);
            verifyPrimaryState(node2, fullCacheName, i, false);
        } else {
            verifyPrimaryState(node1, fullCacheName, i, false);
            verifyPrimaryState(node2, fullCacheName, i, true);
        }
    }
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) HazelcastCacheManager(com.hazelcast.cache.HazelcastCacheManager) HazelcastInstance(com.hazelcast.core.HazelcastInstance) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) CacheConfig(com.hazelcast.config.CacheConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) CacheFromDifferentNodesTest(com.hazelcast.cache.CacheFromDifferentNodesTest)

Example 73 with Node

use of com.hazelcast.instance.impl.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();
    assertClusterSize(2, h1, h2);
    int numberOfClients = 6;
    for (int i = 0; i < numberOfClients; i++) {
        factory.newHazelcastClient();
    }
    Node node = getNode(h1);
    Map<String, Long> clientStats = node.clientEngine.getActiveClientsInCluster();
    assertEquals(numberOfClients, clientStats.get(ConnectionType.JAVA_CLIENT).intValue());
    assertNull(clientStats.get(ConnectionType.CPP_CLIENT));
    assertNull(clientStats.get(ConnectionType.CSHARP_CLIENT));
    assertNull(clientStats.get(ConnectionType.NODEJS_CLIENT));
    assertNull(clientStats.get(ConnectionType.PYTHON_CLIENT));
    assertNull(clientStats.get(ConnectionType.GO_CLIENT));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.impl.Node) Accessors.getNode(com.hazelcast.test.Accessors.getNode) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 74 with Node

use of com.hazelcast.instance.impl.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 = getNode(instance);
    Operation operation = new GetConnectedClientsOperation();
    OperationService operationService = node.nodeEngine.getOperationService();
    Future<Map<String, String>> future = operationService.invokeOnTarget(ClientEngineImpl.SERVICE_NAME, operation, node.address);
    Map<String, String> clients = future.get();
    assertEquals(0, clients.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.impl.Node) Accessors.getNode(com.hazelcast.test.Accessors.getNode) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) Operation(com.hazelcast.spi.impl.operationservice.Operation) GetConnectedClientsOperation(com.hazelcast.client.impl.operations.GetConnectedClientsOperation) OperationService(com.hazelcast.spi.impl.operationservice.OperationService) Map(java.util.Map) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 75 with Node

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

the class ListenerLeakTest method testMultiMapEntryListeners.

@Test
public void testMultiMapEntryListeners() {
    Collection<Node> nodes = createNodes();
    HazelcastInstance client = newHazelcastClient();
    MultiMap multiMap = client.getMultiMap(randomString());
    UUID id = multiMap.addEntryListener(mock(EntryListener.class), false);
    Collection<ClientConnectionRegistration> registrations = getClientEventRegistrations(client, id);
    assertTrue(multiMap.removeEntryListener(id));
    assertNoLeftOver(nodes, client, id, registrations);
}
Also used : MultiMap(com.hazelcast.multimap.MultiMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) UUID(java.util.UUID) EntryListener(com.hazelcast.core.EntryListener) ClientConnectionRegistration(com.hazelcast.client.impl.spi.impl.listener.ClientConnectionRegistration) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Aggregations

Node (com.hazelcast.instance.impl.Node)144 Accessors.getNode (com.hazelcast.test.Accessors.getNode)84 HazelcastInstance (com.hazelcast.core.HazelcastInstance)68 Test (org.junit.Test)60 QuickTest (com.hazelcast.test.annotation.QuickTest)57 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)44 Config (com.hazelcast.config.Config)22 Address (com.hazelcast.cluster.Address)20 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)19 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)13 UUID (java.util.UUID)13 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)12 SerializationService (com.hazelcast.internal.serialization.SerializationService)12 ILogger (com.hazelcast.logging.ILogger)10 MapService (com.hazelcast.map.impl.MapService)10 ClientConnectionRegistration (com.hazelcast.client.impl.spi.impl.listener.ClientConnectionRegistration)9 Operation (com.hazelcast.spi.impl.operationservice.Operation)9 HashMap (java.util.HashMap)9 Data (com.hazelcast.internal.serialization.Data)8 MapServiceContext (com.hazelcast.map.impl.MapServiceContext)8