Search in sources :

Example 26 with LocalRegion

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

the class RegionTestCase method testEntryTtl3.

/**
   * Configure entry expiration with a ttl time. Create an entry and records its scheduled
   * expiration time. Then mutate the region expiration configuration and confirm that the entry's
   * expiration time is rescheduled.
   */
@Test
public void testEntryTtl3() {
    final String name = this.getUniqueName();
    // test no longer waits for this expiration to happen
    // ms
    final int timeout1 = 500 * 1000;
    // ms
    final int timeout2 = 2000 * 1000;
    final String key1 = "KEY1";
    final String value1 = "VALUE1";
    AttributesFactory factory = new AttributesFactory(getRegionAttributes());
    ExpirationAttributes expire1 = new ExpirationAttributes(timeout1, ExpirationAction.INVALIDATE);
    factory.setEntryTimeToLive(expire1);
    factory.setStatisticsEnabled(true);
    TestCacheListener list = new TestCacheListener() {

        public void afterCreate2(EntryEvent e) {
        }

        public void afterUpdate2(EntryEvent e) {
        }

        public void afterInvalidate2(EntryEvent e) {
            eventCount++;
        }
    };
    eventCount = 0;
    factory.addCacheListener(list);
    RegionAttributes attrs = factory.create();
    LocalRegion region;
    System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
    try {
        region = (LocalRegion) createRegion(name, attrs);
    } finally {
        System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
    }
    region.create(key1, value1);
    EntryExpiryTask eet = region.getEntryExpiryTask(key1);
    final long firstExpiryTime = eet.getExpirationTime();
    AttributesMutator mutt = region.getAttributesMutator();
    ExpirationAttributes expire2 = new ExpirationAttributes(timeout2, ExpirationAction.INVALIDATE);
    mutt.setEntryTimeToLive(expire2);
    eet = region.getEntryExpiryTask(key1);
    final long secondExpiryTime = eet.getExpirationTime();
    if ((secondExpiryTime - firstExpiryTime) <= 0) {
        fail("expiration time should have been greater after changing region config from 500 to 2000. firstExpiryTime=" + firstExpiryTime + " secondExpiryTime=" + secondExpiryTime);
    }
    // now set back to be more recent
    mutt = region.getAttributesMutator();
    ExpirationAttributes expire3 = new ExpirationAttributes(timeout1, ExpirationAction.INVALIDATE);
    mutt.setEntryTimeToLive(expire3);
    eet = region.getEntryExpiryTask(key1);
    final long thirdExpiryTime = eet.getExpirationTime();
    assertEquals(firstExpiryTime, thirdExpiryTime);
    // confirm that it still has not expired
    assertEquals(0, eventCount);
    // now set it to a really short time and make sure it expires immediately
    Wait.waitForExpiryClockToChange(region);
    final Region.Entry entry = region.getEntry(key1);
    mutt = region.getAttributesMutator();
    ExpirationAttributes expire4 = new ExpirationAttributes(1, ExpirationAction.INVALIDATE);
    mutt.setEntryTimeToLive(expire4);
    WaitCriterion wc = new WaitCriterion() {

        public boolean done() {
            return fetchEntryValue(entry) == null;
        }

        public String description() {
            return "entry never became invalid";
        }
    };
    Wait.waitForCriterion(wc, 10 * 1000, 10, true);
    WaitCriterion waitForEventCountToBeOne = new WaitCriterion() {

        public boolean done() {
            return eventCount == 1;
        }

        public String description() {
            return "eventCount never became 1";
        }
    };
    Wait.waitForCriterion(waitForEventCountToBeOne, 10 * 1000, 10, true);
    eventCount = 0;
}
Also used : EntryExpiryTask(org.apache.geode.internal.cache.EntryExpiryTask) RegionAttributes(org.apache.geode.cache.RegionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) AttributesFactory(org.apache.geode.cache.AttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Entry(org.apache.geode.cache.Region.Entry) EntryEvent(org.apache.geode.cache.EntryEvent) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) AttributesMutator(org.apache.geode.cache.AttributesMutator) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 27 with LocalRegion

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

the class SingleHopGetAllPutAllDUnitTest method verifyMetadata.

private static void verifyMetadata() {
    Region region = cache.getRegion(PartitionedRegionName);
    ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    cms.getClientPRMetadata((LocalRegion) region);
    final Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
    WaitCriterion wc = new WaitCriterion() {

        public boolean done() {
            return (regionMetaData.size() == 1);
        }

        public String description() {
            return "Region metadat size is not 1. Exisitng size of regionMetaData is " + regionMetaData.size();
        }
    };
    Wait.waitForCriterion(wc, 5000, 200, true);
    assertTrue(regionMetaData.containsKey(region.getFullPath()));
    final ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
    wc = new WaitCriterion() {

        public boolean done() {
            return (prMetaData.getBucketServerLocationsMap_TEST_ONLY().size() == 13);
        }

        public String description() {
            return "Bucket server location map size is not 13. Exisitng size is :" + prMetaData.getBucketServerLocationsMap_TEST_ONLY().size();
        }
    };
    Wait.waitForCriterion(wc, 5000, 200, true);
    for (Entry entry : prMetaData.getBucketServerLocationsMap_TEST_ONLY().entrySet()) {
        assertEquals(2, ((List) entry.getValue()).size());
    }
}
Also used : Entry(java.util.Map.Entry) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor)

Example 28 with LocalRegion

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

the class Bug43684DUnitTest method verifyResponse.

public static void verifyResponse(Integer size) throws Exception {
    LocalRegion r = (LocalRegion) cache.getRegion(REGION_NAME);
    assertEquals(size.intValue(), r.size());
}
Also used : LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Example 29 with LocalRegion

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

the class Bug43684DUnitTest method getLocally.

public static void getLocally() throws Exception {
    LocalRegion r = (LocalRegion) cache.getRegion(REGION_NAME);
    for (int i = 0; i < numBuckets; i++) {
        RegionEntry e = r.getRegionEntry("KEY_" + i);
        cache.getLoggerI18n().info(LocalizedStrings.DEBUG, e._getValue());
    }
}
Also used : RegionEntry(org.apache.geode.internal.cache.RegionEntry) LocalRegion(org.apache.geode.internal.cache.LocalRegion)

Example 30 with LocalRegion

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

the class ClientServerMiscBCDUnitTest method testSubscriptionWithCurrentServerAndOldClients.

@Test
public void testSubscriptionWithCurrentServerAndOldClients() throws Exception {
    // start server first
    int serverPort = initServerCache(true);
    VM client1 = Host.getHost(0).getVM(testVersion, 1);
    VM client2 = Host.getHost(0).getVM(testVersion, 3);
    String hostname = NetworkUtils.getServerHostName(Host.getHost(0));
    client1.invoke("create client1 cache", () -> {
        createClientCache(hostname, serverPort);
        populateCache();
        registerInterest();
    });
    client2.invoke("create client2 cache", () -> {
        Pool ignore = createClientCache(hostname, serverPort);
    });
    client2.invoke("putting data in client2", () -> putForClient());
    // client1 will receive client2's updates asynchronously
    client1.invoke(() -> {
        Region r2 = getCache().getRegion(REGION_NAME2);
        MemberIDVerifier verifier = (MemberIDVerifier) ((LocalRegion) r2).getCacheListener();
        Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> verifier.eventReceived);
    });
    // client2's update should have included a memberID - GEODE-2954
    client1.invoke(() -> {
        Region r2 = getCache().getRegion(REGION_NAME2);
        MemberIDVerifier verifier = (MemberIDVerifier) ((LocalRegion) r2).getCacheListener();
        assertFalse(verifier.memberIDNotReceived);
    });
}
Also used : VM(org.apache.geode.test.dunit.VM) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Pool(org.apache.geode.cache.client.Pool) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) BackwardCompatibilityTest(org.apache.geode.test.junit.categories.BackwardCompatibilityTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

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