Search in sources :

Example 11 with ICacheRecordStore

use of com.hazelcast.cache.impl.ICacheRecordStore 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)

Example 12 with ICacheRecordStore

use of com.hazelcast.cache.impl.ICacheRecordStore in project hazelcast by hazelcast.

the class CacheBackupTest method checkSavedRecordOnBackup.

private void checkSavedRecordOnBackup(String key, String expectedValue, String cacheName, int keyPartitionId, SerializationService serializationService, ICacheService cacheService) {
    ICacheRecordStore recordStore = cacheService.getRecordStore("/hz/" + cacheName, keyPartitionId);
    assertNotNull(recordStore);
    assertEquals(expectedValue, serializationService.toObject(recordStore.get(serializationService.toData(key), null)));
}
Also used : ICacheRecordStore(com.hazelcast.cache.impl.ICacheRecordStore)

Aggregations

ICacheRecordStore (com.hazelcast.cache.impl.ICacheRecordStore)12 ICacheService (com.hazelcast.cache.impl.ICacheService)9 Data (com.hazelcast.nio.serialization.Data)5 QuickTest (com.hazelcast.test.annotation.QuickTest)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Node (com.hazelcast.instance.Node)3 InternalPartitionService (com.hazelcast.internal.partition.InternalPartitionService)3 SerializationService (com.hazelcast.spi.serialization.SerializationService)3 ParallelTest (com.hazelcast.test.annotation.ParallelTest)3 CacheRecordStore (com.hazelcast.cache.impl.CacheRecordStore)1 CacheRecord (com.hazelcast.cache.impl.record.CacheRecord)1 CacheConfig (com.hazelcast.config.CacheConfig)1 MetaDataGenerator (com.hazelcast.internal.nearcache.impl.invalidation.MetaDataGenerator)1 NodeEngine (com.hazelcast.spi.NodeEngine)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 CacheLoaderException (javax.cache.integration.CacheLoaderException)1