Search in sources :

Example 36 with Node

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

the class CacheBackupTest method entrySuccessfullyRetrievedFromBackup.

private void entrySuccessfullyRetrievedFromBackup(int backupCount, boolean sync) {
    final String KEY = "key";
    final String VALUE = "value";
    final int nodeCount = backupCount + 1;
    final TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(nodeCount);
    final HazelcastInstance[] instances = new HazelcastInstance[nodeCount];
    for (int i = 0; i < instances.length; i++) {
        instances[i] = instanceFactory.newHazelcastInstance();
    }
    final HazelcastInstance hz = instances[0];
    final CachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(hz);
    final CacheManager cacheManager = cachingProvider.getCacheManager();
    final String cacheName = randomName();
    final CacheConfig cacheConfig = new CacheConfig().setName(cacheName);
    if (sync) {
        cacheConfig.setBackupCount(backupCount);
    } else {
        cacheConfig.setAsyncBackupCount(backupCount);
    }
    final Cache cache = cacheManager.createCache(cacheName, cacheConfig);
    warmUpPartitions(instances);
    waitAllForSafeState(instances);
    cache.put(KEY, VALUE);
    final Node node = getNode(hz);
    final InternalPartitionService partitionService = node.getPartitionService();
    final int keyPartitionId = partitionService.getPartitionId(KEY);
    for (int i = 1; i <= backupCount; i++) {
        final Node backupNode = getNode(instances[i]);
        final SerializationService serializationService = backupNode.getSerializationService();
        final ICacheService cacheService = backupNode.getNodeEngine().getService(ICacheService.SERVICE_NAME);
        if (sync) {
            checkSavedRecordOnBackup(KEY, VALUE, cacheName, keyPartitionId, serializationService, cacheService);
        } else {
            assertTrueEventually(new AssertTask() {

                @Override
                public void run() throws Exception {
                    checkSavedRecordOnBackup(KEY, VALUE, cacheName, keyPartitionId, serializationService, cacheService);
                }
            });
        }
    }
}
Also used : InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Node(com.hazelcast.instance.Node) SerializationService(com.hazelcast.spi.serialization.SerializationService) HazelcastInstance(com.hazelcast.core.HazelcastInstance) ICacheService(com.hazelcast.cache.impl.ICacheService) CacheManager(javax.cache.CacheManager) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) CacheConfig(com.hazelcast.config.CacheConfig) HazelcastServerCachingProvider(com.hazelcast.cache.impl.HazelcastServerCachingProvider) CachingProvider(javax.cache.spi.CachingProvider) Cache(javax.cache.Cache)

Example 37 with Node

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

the class CacheClearTest method createAndFillEntries.

protected Map<String, String> createAndFillEntries() {
    final int ENTRY_COUNT_PER_PARTITION = 3;
    Node node = getNode(hazelcastInstance);
    int partitionCount = node.getPartitionService().getPartitionCount();
    Map<String, String> entries = new HashMap<String, String>(partitionCount * ENTRY_COUNT_PER_PARTITION);
    for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        for (int i = 0; i < ENTRY_COUNT_PER_PARTITION; i++) {
            String key = generateKeyForPartition(hazelcastInstance, partitionId);
            String value = generateRandomString(16);
            entries.put(key, value);
        }
    }
    return entries;
}
Also used : HashMap(java.util.HashMap) Node(com.hazelcast.instance.Node)

Example 38 with Node

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

the class CachePutAllTest method testPutAll.

@Test
public void testPutAll() {
    ICache<String, String> cache = createCache();
    String cacheName = cache.getName();
    Map<String, String> entries = createAndFillEntries();
    cache.putAll(entries);
    // Verify that put-all 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-all 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);
        }
    }
}
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)

Example 39 with Node

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

the class ClusterShutdownTest method testClusterShutdownWithMultipleMembers.

private void testClusterShutdownWithMultipleMembers(int clusterSize, int nodeCountToTriggerShutdown) {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(clusterSize);
    HazelcastInstance[] instances = factory.newInstances();
    instances[0].getCluster().changeClusterState(ClusterState.PASSIVE);
    Node[] nodes = getNodes(instances);
    final CountDownLatch latch = new CountDownLatch(1);
    for (int i = 0; i < nodeCountToTriggerShutdown; i++) {
        final HazelcastInstance instance = instances[i];
        final Runnable shutdownRunnable = new Runnable() {

            @Override
            public void run() {
                assertOpenEventually(latch);
                instance.getCluster().shutdown();
            }
        };
        new Thread(shutdownRunnable).start();
    }
    latch.countDown();
    assertNodesShutDownEventually(nodes);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Node(com.hazelcast.instance.Node) CountDownLatch(java.util.concurrent.CountDownLatch) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 40 with Node

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

the class ClusterInfoTest method test_start_time_single_node_cluster.

@Test
public void test_start_time_single_node_cluster() throws Exception {
    HazelcastInstance h1 = factory.newHazelcastInstance();
    Node node1 = TestUtil.getNode(h1);
    assertNotEquals(Long.MIN_VALUE, node1.getClusterService().getClusterClock().getClusterStartTime());
}
Also used : 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)

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