Search in sources :

Example 71 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class PersistentRVVRecoveryDUnitTest method testLotsOfTombstonesExpiration.

/**
   * Test that we correctly recover and expire recovered tombstones, with compaction enabled.
   * 
   * This test differs from above test in that we need to make sure tombstones start expiring based
   * on their original time-stamp, NOT the time-stamp assigned during scheduling for expiration
   * after recovery.
   */
@Ignore
@Test
public void testLotsOfTombstonesExpiration() throws Throwable {
    Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    vm0.invoke(new CacheSerializableRunnable("") {

        @Override
        public void run2() throws CacheException {
            long replicatedTombstoneTomeout = TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT;
            int expiriredTombstoneLimit = TombstoneService.EXPIRED_TOMBSTONE_LIMIT;
            try {
                LocalRegion region = createRegion(vm0);
                int initialCount = getTombstoneCount(region);
                assertEquals(0, initialCount);
                final int entryCount = 20;
                for (int i = 0; i < entryCount; i++) {
                    region.put(i, new byte[100]);
                    // destroy each entry.
                    region.destroy(i);
                }
                assertEquals(entryCount, getTombstoneCount(region));
                // roll to a new oplog
                region.getDiskStore().forceRoll();
                // Force a compaction. This should do nothing, because
                // The tombstones are not garbage, so only 50% of the oplog
                // is garbage (the creates).
                region.getDiskStore().forceCompaction();
                assertEquals(0, region.getDiskStore().numCompactableOplogs());
                assertEquals(entryCount, getTombstoneCount(region));
                getCache().close();
                // We should wait for timeout time so that tomstones are expired
                // right away when they are gIId based on their original timestamp.
                Wait.pause((int) TEST_REPLICATED_TOMBSTONE_TIMEOUT);
                TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT = TEST_REPLICATED_TOMBSTONE_TIMEOUT;
                TombstoneService.EXPIRED_TOMBSTONE_LIMIT = entryCount;
                // Do region GII
                region = createRegion(vm0);
                assertEquals(entryCount, getTombstoneCount(region));
                getCache().getLogger().fine("Waiting for maximumSleepTime ms");
                // maximumSleepTime+500 in TombstoneSweeper GC thread
                Wait.pause(10000);
                // Tombstones should have been expired and garbage collected by now by
                // TombstoneService.
                assertEquals(0, getTombstoneCount(region));
                // This should compact some oplogs
                region.getDiskStore().forceCompaction();
                assertEquals(0, region.getDiskStore().numCompactableOplogs());
                // Test after restart the tombstones are still missing
                getCache().close();
                region = createRegion(vm0);
                assertEquals(0, getTombstoneCount(region));
                // We should have an oplog available for compaction, because the
                // tombstones
                // were garbage collected
                assertEquals(0, region.getDiskStore().numCompactableOplogs());
                GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
                cache.close();
            } finally {
                TombstoneService.REPLICATE_TOMBSTONE_TIMEOUT = replicatedTombstoneTomeout;
                TombstoneService.EXPIRED_TOMBSTONE_LIMIT = expiriredTombstoneLimit;
            }
        }
    });
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Host(org.apache.geode.test.dunit.Host) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Ignore(org.junit.Ignore) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 72 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class HAInterestTestCase method stopSecondaryAndRegisterK1AndK2AndVerifyResponse.

/**
   * returns the secondary that was stopped
   */
public static VM stopSecondaryAndRegisterK1AndK2AndVerifyResponse() {
    LocalRegion r = (LocalRegion) cache.getRegion(Region.SEPARATOR + REGION_NAME);
    assertNotNull(r);
    ServerRegionProxy srp = new ServerRegionProxy(r);
    WaitCriterion wc = new WaitCriterion() {

        @Override
        public boolean done() {
            return pool.getConnectedServerCount() == 3;
        }

        @Override
        public String description() {
            return "Never got three connected servers";
        }
    };
    Wait.waitForCriterion(wc, TIMEOUT_MILLIS, INTERVAL_MILLIS, true);
    // close secondary EP
    VM result = getBackupVM();
    result.invoke(() -> HAInterestTestCase.stopServer());
    List list = new ArrayList();
    list.add(k1);
    list.add(k2);
    List serverKeys = srp.registerInterest(list, InterestType.KEY, InterestResultPolicy.KEYS, false, r.getAttributes().getDataPolicy().ordinal);
    assertNotNull(serverKeys);
    List resultKeys = (List) serverKeys.get(0);
    assertEquals(2, resultKeys.size());
    assertTrue(resultKeys.contains(k1));
    assertTrue(resultKeys.contains(k2));
    return result;
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) VM(org.apache.geode.test.dunit.VM) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Example 73 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class HAInterestTestCase method registerK1AndK2OnPrimaryAndSecondaryAndVerifyResponse.

public static void registerK1AndK2OnPrimaryAndSecondaryAndVerifyResponse() {
    ServerLocation primary = pool.getPrimary();
    ServerLocation secondary = (ServerLocation) pool.getRedundants().get(0);
    LocalRegion r = (LocalRegion) cache.getRegion(Region.SEPARATOR + REGION_NAME);
    assertNotNull(r);
    ServerRegionProxy srp = new ServerRegionProxy(r);
    List list = new ArrayList();
    list.add(k1);
    list.add(k2);
    // Primary server
    List serverKeys1 = srp.registerInterestOn(primary, list, InterestType.KEY, InterestResultPolicy.KEYS, false, r.getAttributes().getDataPolicy().ordinal);
    assertNotNull(serverKeys1);
    // expect serverKeys in response from primary
    List resultKeys = (List) serverKeys1.get(0);
    assertEquals(2, resultKeys.size());
    assertTrue(resultKeys.contains(k1));
    assertTrue(resultKeys.contains(k2));
    // Secondary server
    List serverKeys2 = srp.registerInterestOn(secondary, list, InterestType.KEY, InterestResultPolicy.KEYS, false, r.getAttributes().getDataPolicy().ordinal);
    // if the list is null then it is empty
    if (serverKeys2 != null) {
        // no serverKeys in response from secondary
        assertTrue(serverKeys2.isEmpty());
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Example 74 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class HAInterestTestCase method stopPrimaryAndUnregisterRegisterK1.

public static void stopPrimaryAndUnregisterRegisterK1() {
    LocalRegion r = (LocalRegion) cache.getRegion(Region.SEPARATOR + REGION_NAME);
    assertNotNull(r);
    ServerRegionProxy srp = new ServerRegionProxy(r);
    WaitCriterion wc = new WaitCriterion() {

        @Override
        public boolean done() {
            return pool.getConnectedServerCount() == 3;
        }

        @Override
        public String description() {
            return "connected server count never became 3";
        }
    };
    Wait.waitForCriterion(wc, TIMEOUT_MILLIS, INTERVAL_MILLIS, true);
    // close primaryEP
    getPrimaryVM().invoke(() -> HAInterestTestCase.stopServer());
    List list = new ArrayList();
    list.add(k1);
    srp.unregisterInterest(list, InterestType.KEY, false, false);
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Example 75 with LocalRegion

use of org.apache.geode.internal.cache.LocalRegion in project geode by apache.

the class FilterProfileIntegrationJUnitTest method testFilterProfile.

@Test
public void testFilterProfile() throws Exception {
    Cache cache = CacheUtils.getCache();
    try {
        createLocalRegion();
        LocalRegion region = (LocalRegion) cache.getRegion(regionName);
        final FilterProfile filterProfile = new FilterProfile(region);
        filterProfile.registerClientInterest("clientId", ".*", InterestType.REGULAR_EXPRESSION, false);
        final FilterProfileTestHook hook = new FilterProfileTestHook();
        FilterProfile.testHook = hook;
        new Thread(new Runnable() {

            public void run() {
                while (hook.getCount() != 1) {
                }
                filterProfile.unregisterClientInterest("clientId", ".*", InterestType.REGULAR_EXPRESSION);
            }
        }).start();
        filterProfile.hasAllKeysInterestFor("clientId");
    } finally {
        cache.getDistributedSystem().disconnect();
        cache.close();
    }
}
Also used : FilterProfile(org.apache.geode.internal.cache.FilterProfile) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Cache(org.apache.geode.cache.Cache) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

LocalRegion (org.apache.geode.internal.cache.LocalRegion)243 Test (org.junit.Test)103 Region (org.apache.geode.cache.Region)70 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)54 IOException (java.io.IOException)50 AttributesFactory (org.apache.geode.cache.AttributesFactory)42 VM (org.apache.geode.test.dunit.VM)39 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)38 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)37 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)34 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)34 Cache (org.apache.geode.cache.Cache)31 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)31 Host (org.apache.geode.test.dunit.Host)31 Iterator (java.util.Iterator)29 QueryService (org.apache.geode.cache.query.QueryService)29 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)27 CancelException (org.apache.geode.CancelException)26 CacheException (org.apache.geode.cache.CacheException)26 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)25