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;
}
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());
}
}
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());
}
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());
}
}
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);
});
}
Aggregations