Search in sources :

Example 6 with Node

use of com.hazelcast.instance.impl.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 = createServerCachingProvider(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.impl.Node) Accessors.getNode(com.hazelcast.test.Accessors.getNode) SerializationService(com.hazelcast.internal.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) CachingProvider(javax.cache.spi.CachingProvider) CacheTestSupport.createServerCachingProvider(com.hazelcast.cache.CacheTestSupport.createServerCachingProvider) Cache(javax.cache.Cache)

Example 7 with Node

use of com.hazelcast.instance.impl.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) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node)

Example 8 with Node

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

the class CacheLoadAllTest method createAndFillEntries.

private 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 = getValueOfKey(key);
            entries.put(key, value);
        }
    }
    return entries;
}
Also used : HashMap(java.util.HashMap) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node)

Example 9 with Node

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

the class CacheLoadAllTest method testLoadAll.

@Test
public void testLoadAll() throws InterruptedException {
    ICache<String, String> cache = createCache();
    String cacheName = cache.getName();
    Map<String, String> entries = createAndFillEntries();
    final CountDownLatch latch = new CountDownLatch(1);
    cache.loadAll(entries.keySet(), true, new CompletionListener() {

        @Override
        public void onCompletion() {
            latch.countDown();
        }

        @Override
        public void onException(Exception e) {
            latch.countDown();
        }
    });
    assertTrue(latch.await(60, TimeUnit.SECONDS));
    // Verify that load-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 load-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 : CompletionListener(javax.cache.integration.CompletionListener) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) Accessors.getNode(com.hazelcast.test.Accessors.getNode) Node(com.hazelcast.instance.impl.Node) SerializationService(com.hazelcast.internal.serialization.SerializationService) Data(com.hazelcast.internal.serialization.Data) ICacheRecordStore(com.hazelcast.cache.impl.ICacheRecordStore) CountDownLatch(java.util.concurrent.CountDownLatch) CacheLoaderException(javax.cache.integration.CacheLoaderException) ICacheService(com.hazelcast.cache.impl.ICacheService) HashMap(java.util.HashMap) Map(java.util.Map) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 10 with Node

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

the class ConnectedClientOperationTest method testGetConnectedClientsOperation_WhenMoreThanZeroClientConnects.

@Test
public void testGetConnectedClientsOperation_WhenMoreThanZeroClientConnects() throws Exception {
    HazelcastInstance instance = factory.newHazelcastInstance();
    factory.newHazelcastClient();
    factory.newHazelcastClient();
    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(2, 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)

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