Search in sources :

Example 6 with BackupAccessor

use of com.hazelcast.test.backup.BackupAccessor in project hazelcast by hazelcast.

the class CacheExpirationTest method test_whenEntryIsAccessedBackupIsNotCleaned.

@Test
public void test_whenEntryIsAccessedBackupIsNotCleaned() {
    CacheConfig<Integer, Integer> cacheConfig = createCacheConfig(new HazelcastExpiryPolicy(THREE_SECONDS, Duration.ETERNAL, THREE_SECONDS));
    Cache<Integer, Integer> cache = createCache(cacheConfig);
    for (int i = 0; i < KEY_RANGE; i++) {
        cache.put(i, i);
        cache.get(i);
    }
    sleepAtLeastSeconds(3);
    for (int i = 1; i < CLUSTER_SIZE; i++) {
        BackupAccessor backupAccessor = TestBackupUtils.newCacheAccessor(instances, cache.getName(), i);
        for (int j = 0; j < KEY_RANGE; j++) {
            assertEquals(i, backupAccessor.get(i));
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BackupAccessor(com.hazelcast.test.backup.BackupAccessor) HazelcastExpiryPolicy(com.hazelcast.cache.HazelcastExpiryPolicy) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 7 with BackupAccessor

use of com.hazelcast.test.backup.BackupAccessor in project hazelcast by hazelcast.

the class CacheExpirationTest method test_whenEntryIsRemovedBackupIsCleaned.

@Test
public void test_whenEntryIsRemovedBackupIsCleaned() {
    int ttlSeconds = 3;
    Duration duration = new Duration(TimeUnit.SECONDS, ttlSeconds);
    HazelcastExpiryPolicy expiryPolicy = new HazelcastExpiryPolicy(duration, duration, duration);
    CacheConfig<Integer, Integer> cacheConfig = createCacheConfig(expiryPolicy);
    Cache<Integer, Integer> cache = createCache(cacheConfig);
    for (int i = 0; i < KEY_RANGE; i++) {
        cache.put(i, i);
    }
    for (int i = 0; i < KEY_RANGE; i++) {
        cache.remove(i, i);
    }
    for (int i = 1; i < CLUSTER_SIZE; i++) {
        BackupAccessor backupAccessor = TestBackupUtils.newCacheAccessor(instances, cache.getName(), i);
        assertBackupSizeEventually(0, backupAccessor);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BackupAccessor(com.hazelcast.test.backup.BackupAccessor) Duration(javax.cache.expiry.Duration) HazelcastExpiryPolicy(com.hazelcast.cache.HazelcastExpiryPolicy) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 8 with BackupAccessor

use of com.hazelcast.test.backup.BackupAccessor in project hazelcast by hazelcast.

the class CacheExpirationStressTest method assertRecords.

protected void assertRecords(final HazelcastInstance[] instances) {
    for (int i = 1; i < instances.length; i++) {
        BackupAccessor backupAccessor = TestBackupUtils.newCacheAccessor(instances, cacheNameWithPrefix, i);
        assertBackupSizeEventually(0, backupAccessor);
    }
    for (int i = 0; i < instances.length; i++) {
        final int index = i;
        assertEqualsEventually(() -> instances[index].getCacheManager().getCache(cacheName).size(), 0);
    }
    instances[0].getCacheManager().getCache(cacheName).destroy();
}
Also used : BackupAccessor(com.hazelcast.test.backup.BackupAccessor)

Aggregations

BackupAccessor (com.hazelcast.test.backup.BackupAccessor)8 HazelcastExpiryPolicy (com.hazelcast.cache.HazelcastExpiryPolicy)6 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)6 QuickTest (com.hazelcast.test.annotation.QuickTest)6 Test (org.junit.Test)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 ICache (com.hazelcast.cache.ICache)2 CacheConfig (com.hazelcast.config.CacheConfig)2 Cache (javax.cache.Cache)1 Duration (javax.cache.expiry.Duration)1