Search in sources :

Example 1 with BackupAccessor

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

the class CacheExpirationTest method test_whenEntryIsRemovedBackupIsCleaned_eternalDuration.

@Test
public void test_whenEntryIsRemovedBackupIsCleaned_eternalDuration() {
    CacheConfig<Integer, Integer> cacheConfig = createCacheConfig(new HazelcastExpiryPolicy(Duration.ETERNAL, Duration.ETERNAL, Duration.ETERNAL));
    Cache<Integer, Integer> cache = createCache(cacheConfig);
    for (int i = 0; i < KEY_RANGE; i++) {
        cache.put(i, i);
        cache.remove(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) HazelcastExpiryPolicy(com.hazelcast.cache.HazelcastExpiryPolicy) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 2 with BackupAccessor

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

the class CacheExpirationTest method testBackupsAreEmptyAfterExpiration.

@Test
public void testBackupsAreEmptyAfterExpiration() {
    SimpleExpiryListener listener = new SimpleExpiryListener();
    CacheConfig cacheConfig = createCacheConfig(new HazelcastExpiryPolicy(100, 100, 100), listener);
    Cache cache = createCache(cacheConfig);
    for (int i = 0; i < KEY_RANGE; i++) {
        cache.put(i, i);
    }
    assertEqualsEventually(KEY_RANGE, listener.getExpirationCount());
    for (int i = 1; i < CLUSTER_SIZE; i++) {
        BackupAccessor backupAccessor = TestBackupUtils.newCacheAccessor(instances, cache.getName(), i);
        assertBackupSizeEventually(0, backupAccessor);
    }
}
Also used : BackupAccessor(com.hazelcast.test.backup.BackupAccessor) CacheConfig(com.hazelcast.config.CacheConfig) HazelcastExpiryPolicy(com.hazelcast.cache.HazelcastExpiryPolicy) Cache(javax.cache.Cache) ICache(com.hazelcast.cache.ICache) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 3 with BackupAccessor

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

the class ExtendedCacheExpirationTest method test_backupOperationAppliesDefaultExpiryPolicy.

@Test
public void test_backupOperationAppliesDefaultExpiryPolicy() {
    HazelcastExpiryPolicy defaultExpiryPolicy = new HazelcastExpiryPolicy(THREE_SECONDS, Duration.ZERO, Duration.ZERO);
    CacheConfig cacheConfig = createCacheConfig(defaultExpiryPolicy);
    ICache cache = createCache(cacheConfig);
    int keyCount = 100;
    for (int i = 0; i < keyCount; i++) {
        cache.put(i, i);
    }
    // Check if all backup entries have applied the default expiry policy
    for (int i = 1; i < CLUSTER_SIZE; i++) {
        BackupAccessor backupAccessor = TestBackupUtils.newCacheAccessor(instances, cache.getName(), i);
        for (int j = 0; j < keyCount; j++) {
            TestBackupUtils.assertExpirationTimeExistsEventually(j, backupAccessor);
        }
    }
    // terminate other nodes than number zero to cause backup promotion at the 0th member
    for (int i = 1; i < CLUSTER_SIZE; i++) {
        getNode(instances[i]).shutdown(true);
    }
    assertTrueEventually(() -> {
        for (int i = 0; i < keyCount; i++) {
            assertNull(cache.get(i));
        }
    });
}
Also used : BackupAccessor(com.hazelcast.test.backup.BackupAccessor) ICache(com.hazelcast.cache.ICache) HazelcastExpiryPolicy(com.hazelcast.cache.HazelcastExpiryPolicy) CacheConfig(com.hazelcast.config.CacheConfig) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 4 with BackupAccessor

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

the class CacheExpirationTest method test_whenEntryIsUpdatedBackupIsNotCleaned.

@Test
public void test_whenEntryIsUpdatedBackupIsNotCleaned() {
    CacheConfig<Integer, Integer> cacheConfig = createCacheConfig(new HazelcastExpiryPolicy(THREE_SECONDS, THREE_SECONDS, Duration.ETERNAL));
    Cache<Integer, Integer> cache = createCache(cacheConfig);
    for (int i = 0; i < KEY_RANGE; i++) {
        cache.put(i, i);
        cache.put(i, i);
    }
    cache.put(1, 1);
    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 5 with BackupAccessor

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

the class MapExpirationStressTest method assertRecords.

protected void assertRecords(final HazelcastInstance[] instances) {
    for (int i = 1; i < instances.length; i++) {
        BackupAccessor backupAccessor = TestBackupUtils.newCacheAccessor(instances, mapName, i);
        assertBackupSizeEventually(0, backupAccessor);
    }
    for (int i = 0; i < instances.length; i++) {
        final int index = i;
        assertEqualsEventually(() -> instances[index].getMap(mapName).size(), 0);
    }
    instances[0].getMap(mapName).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