use of org.apache.geode.cache.AttributesMutator in project geode by apache.
the class ClientServerCCEDUnitTest method testClientDoesNotExpireEntryPrematurely.
@Test
public void testClientDoesNotExpireEntryPrematurely() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final String name = this.getUniqueName() + "Region";
final String key = "testKey";
int port = createServerRegion(vm0, name, true);
vm0.invoke(new SerializableCallable("create old entry") {
public Object call() throws Exception {
LocalRegion r = (LocalRegion) basicGetCache().getRegion(name);
r.put(key, "value");
AbstractRegionEntry entry = (AbstractRegionEntry) r.basicGetEntry(key);
// set an old timestamp in the entry - thirty minutes ago
entry.getVersionStamp().setVersionTimeStamp(System.currentTimeMillis() - 1800000L);
return null;
}
});
createClientRegion(vm1, name, port, true, ClientRegionShortcut.CACHING_PROXY, false);
vm1.invoke(new SerializableCallable("fetch entry and validate") {
public Object call() throws Exception {
final Long[] expirationTimeMillis = new Long[1];
int expirationSeconds = 15;
LocalRegion r = (LocalRegion) basicGetCache().getRegion(name);
AttributesMutator mutator = r.getAttributesMutator();
mutator.setEntryIdleTimeout(new ExpirationAttributes(expirationSeconds, ExpirationAction.LOCAL_DESTROY));
mutator.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterDestroy(EntryEvent event) {
expirationTimeMillis[0] = System.currentTimeMillis();
}
});
// fetch the entry from the server and make sure it doesn't expire early
if (!r.containsKey(key)) {
r.get(key);
}
final long expirationTime = System.currentTimeMillis() + (expirationSeconds * 1000);
Awaitility.await("waiting for object to expire").atMost(expirationSeconds * 2, TimeUnit.SECONDS).until(() -> {
return expirationTimeMillis[0] != null;
});
disconnectFromDS();
assertTrue("entry expired " + (expirationTime - expirationTimeMillis[0]) + " milliseconds early", expirationTimeMillis[0] >= expirationTime);
return null;
}
});
vm0.invoke(new SerializableRunnable() {
public void run() {
disconnectFromDS();
}
});
}
use of org.apache.geode.cache.AttributesMutator in project geode by apache.
the class RegionReliabilityTestCase method testFullAccessWithLocalRegionExpiration.
/**
* Tests affect of FULL_ACCESS on local region expiration actions.
*/
@Test
public void testFullAccessWithLocalRegionExpiration() throws Exception {
final String name = this.getUniqueName();
final String roleA = name + "-A";
final String[] requiredRoles = { roleA };
Set requiredRolesSet = new HashSet();
for (int i = 0; i < requiredRoles.length; i++) {
requiredRolesSet.add(InternalRole.getRole(requiredRoles[i]));
}
assertEquals(requiredRoles.length, requiredRolesSet.size());
// connect controller to system...
Properties config = new Properties();
config.setProperty(ROLES, "");
getSystem(config);
getCache();
// create region in controller...
MembershipAttributes ra = new MembershipAttributes(requiredRoles, LossAction.FULL_ACCESS, ResumptionAction.NONE);
AttributesFactory fac = new AttributesFactory();
fac.setMembershipAttributes(ra);
fac.setScope(getRegionScope());
fac.setStatisticsEnabled(true);
RegionAttributes attr = fac.create();
final Region region = createExpiryRootRegion(name, attr);
// wait for memberTimeout to expire
waitForMemberTimeout();
AttributesMutator mutator = region.getAttributesMutator();
mutator.setRegionTimeToLive(new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
waitForRegionDestroy(region);
}
use of org.apache.geode.cache.AttributesMutator in project geode by apache.
the class RegionReliabilityTestCase method testNoAccessWithLocalRegionExpiration.
/**
* Tests affect of NO_ACCESS on local region expiration actions.
*/
@Test
public void testNoAccessWithLocalRegionExpiration() throws Exception {
final String name = this.getUniqueName();
final String roleA = name + "-A";
// assign names to 4 vms...
final String[] requiredRoles = { roleA };
Set requiredRolesSet = new HashSet();
for (int i = 0; i < requiredRoles.length; i++) {
requiredRolesSet.add(InternalRole.getRole(requiredRoles[i]));
}
assertEquals(requiredRoles.length, requiredRolesSet.size());
// connect controller to system...
Properties config = new Properties();
config.setProperty(ROLES, "");
getSystem(config);
getCache();
// create region in controller...
MembershipAttributes ra = new MembershipAttributes(requiredRoles, LossAction.NO_ACCESS, ResumptionAction.NONE);
AttributesFactory fac = new AttributesFactory();
fac.setMembershipAttributes(ra);
fac.setScope(getRegionScope());
fac.setStatisticsEnabled(true);
RegionAttributes attr = fac.create();
final Region region = createExpiryRootRegion(name, attr);
// wait for memberTimeout to expire
waitForMemberTimeout();
AttributesMutator mutator = region.getAttributesMutator();
mutator.setRegionTimeToLive(new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
// sleep and make sure region does not expire
sleep(200);
assertFalse(region.isDestroyed());
// create region in vm1
Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("Create Region") {
public void run2() throws CacheException {
createConnection(new String[] { roleA });
AttributesFactory fac = new AttributesFactory();
fac.setScope(getRegionScope());
RegionAttributes attr = fac.create();
createRootRegion(name, attr);
}
});
waitForRegionDestroy(region);
}
use of org.apache.geode.cache.AttributesMutator in project geode by apache.
the class EventIdOptimizationDUnitTest method verifyEventIdsOnClient2.
/**
* Waits for the listener to receive all events and validates that no exception occurred in client
*/
public static void verifyEventIdsOnClient2() {
await("Waiting for proceedForValidation to be true").atMost(2, MINUTES).until(() -> proceedForValidation);
LogWriterUtils.getLogWriter().info("Starting validation on client2");
if (validationFailed) {
fail("\n The following eventIds recieved by client2 were not present in the eventId array sent by client1 \n" + failureMsg);
}
LogWriterUtils.getLogWriter().info("Validation complete on client2, goin to unregister listeners");
Region region = cache.getRegion(Region.SEPARATOR + REGION_NAME);
if (region != null && !region.isDestroyed()) {
try {
AttributesMutator mutator = region.getAttributesMutator();
mutator.initCacheListeners(null);
} catch (RegionDestroyedException ignore) {
}
}
for (int i = 0; i < eventIds.length; i++) {
region = cache.getRegion(Region.SEPARATOR + REGION_NAME + i);
if (region != null && !region.isDestroyed()) {
try {
AttributesMutator mutator = region.getAttributesMutator();
mutator.initCacheListeners(null);
} catch (RegionDestroyedException ignore) {
}
}
}
LogWriterUtils.getLogWriter().info("Test completed, Unregistered the listeners");
}
use of org.apache.geode.cache.AttributesMutator in project geode by apache.
the class IndexMaintenanceJUnitTest method testIndexMaintenanceOnCacheLoadedData.
/**
* Tests Index maintenance on data loaded via cache loader
*/
@Test
public void testIndexMaintenanceOnCacheLoadedData() {
try {
IndexManager.TEST_RANGEINDEX_ONLY = true;
Cache cache = CacheUtils.getCache();
qs = cache.getQueryService();
region = CacheUtils.createRegion("portfolio1", null);
AttributesMutator am = region.getAttributesMutator();
am.setCacheLoader(new CacheLoader() {
public Object load(LoaderHelper helper) throws CacheLoaderException {
String key = (String) helper.getKey();
Portfolio p = new Portfolio(Integer.parseInt(key));
return p;
}
public void close() {
// TODO Auto-generated method stub
}
});
Index i1 = qs.createIndex("indx1", IndexType.FUNCTIONAL, "pf.getID()", "/portfolio1 pf");
List keys = new ArrayList();
keys.add("1");
keys.add("2");
keys.add("3");
keys.add("4");
region.getAll(keys);
} catch (Exception e) {
CacheUtils.getLogger().error(e);
fail(e.toString());
}
}
Aggregations