use of org.apache.geode.cache.SubscriptionAttributes in project geode by apache.
the class PRDeltaPropagationDUnitTest method createClientCache.
public static void createClientCache(Integer port1, Boolean subscriptionEnable, Boolean isEmpty, Boolean isCq) throws Exception {
PRDeltaPropagationDUnitTest test = new PRDeltaPropagationDUnitTest();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
test.createCache(props);
lastKeyReceived = false;
queryUpdateExecuted = false;
queryDestroyExecuted = false;
notADeltaInstanceObj = false;
isFailed = false;
procced = false;
numValidCqEvents = 0;
PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer("localhost", port1).setSubscriptionEnabled(true).setSubscriptionRedundancy(0).setThreadLocalConnections(true).setMinConnections(6).setReadTimeout(20000).setPingInterval(10000).setRetryAttempts(5).create("PRDeltaPropagationDUnitTestPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setConcurrencyChecksEnabled(true);
if (isEmpty.booleanValue()) {
factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
factory.setDataPolicy(DataPolicy.EMPTY);
}
factory.setPoolName(p.getName());
factory.setCloningEnabled(false);
factory.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
if (LAST_KEY.equals(event.getKey())) {
lastKeyReceived = true;
}
}
});
RegionAttributes attrs = factory.create();
deltaPR = cache.createRegion(REGION_NAME, attrs);
if (subscriptionEnable.booleanValue()) {
deltaPR.registerInterest("ALL_KEYS");
}
pool = p;
if (isCq.booleanValue()) {
CqAttributesFactory cqf = new CqAttributesFactory();
CqListenerAdapter cqlist = new CqListenerAdapter() {
@Override
@SuppressWarnings("synthetic-access")
public void onEvent(CqEvent cqEvent) {
if (LAST_KEY.equals(cqEvent.getKey().toString())) {
lastKeyReceived = true;
} else if (!(cqEvent.getNewValue() instanceof Delta)) {
notADeltaInstanceObj = true;
} else if (cqEvent.getQueryOperation().isUpdate() && cqEvent.getBaseOperation().isUpdate() && DELTA_KEY.equals(cqEvent.getKey().toString())) {
queryUpdateExecuted = true;
} else if (cqEvent.getQueryOperation().isDestroy() && cqEvent.getBaseOperation().isUpdate() && DELTA_KEY.equals(cqEvent.getKey().toString())) {
queryDestroyExecuted = true;
}
if (forOldNewCQVarification) {
if (DELTA_KEY.equals(cqEvent.getKey().toString())) {
if (numValidCqEvents == 0 && ((DeltaTestImpl) cqEvent.getNewValue()).getIntVar() == 8) {
procced = true;
} else if (procced && numValidCqEvents == 1 && ((DeltaTestImpl) cqEvent.getNewValue()).getIntVar() == 10) {
// this tell us that every thing is fine
isFailed = true;
}
}
}
numValidCqEvents++;
}
};
cqf.addCqListener(cqlist);
CqAttributes cqa = cqf.create();
CqQuery cq = cache.getQueryService().newCq("CQ_Delta", CQ, cqa);
cq.execute();
}
}
use of org.apache.geode.cache.SubscriptionAttributes in project geode by apache.
the class ClientToServerDeltaDUnitTest method createServerCache.
/*
* create server cache
*/
public static Integer createServerCache(Boolean attachListener, Boolean isEmpty, Boolean clone, Boolean enableDelta) throws Exception {
// for validation
updates = 0;
create = 0;
firstUpdate = null;
secondUpdate = null;
error = false;
Properties props = new Properties();
props.setProperty(DELTA_PROPAGATION, enableDelta.toString());
new ClientToServerDeltaDUnitTest().createCache(props);
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setConcurrencyChecksEnabled(true);
if (isEmpty) {
factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
factory.setDataPolicy(DataPolicy.EMPTY);
} else {
factory.setDataPolicy(DataPolicy.REPLICATE);
}
factory.setCloningEnabled(clone);
RegionAttributes attrs = factory.create();
region = cache.createRegion(REGION_NAME, attrs);
AttributesMutator am = region.getAttributesMutator();
if (attachListener) {
am.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
create++;
}
@Override
public void afterUpdate(EntryEvent event) {
switch(updates) {
case 0:
// first delta
validateUpdates(event, firstUpdate, "FIRST");
updates++;
break;
case 1:
// combine delta
validateUpdates(event, firstUpdate, "FIRST");
validateUpdates(event, secondUpdate, "SECOND");
updates++;
break;
default:
break;
}
}
});
} else if (!isEmpty) {
am.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
switch(create) {
case 1:
validateUpdates(event, firstUpdate, "FIRST");
create++;
break;
case 2:
validateUpdates(event, secondUpdate, "SECOND");
create++;
break;
default:
create++;
break;
}
}
});
}
CacheServer server = cache.addCacheServer();
int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
server.setPort(port);
// ensures updates to be sent instead of invalidations
server.setNotifyBySubscription(true);
server.start();
return new Integer(server.getPort());
}
use of org.apache.geode.cache.SubscriptionAttributes in project geode by apache.
the class PartitionedRegionEvictionDUnitTest method testEntryLRUDeadlock.
/**
* Test that gets do not need to acquire a lock on the region entry when LRU is enabled. This is
* bug 42265
*/
@Test
public void testEntryLRUDeadlock() {
final Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
final VM vm1 = host.getVM(1);
final String uniqName = getUniqueName();
final int redundantCopies = 0;
final int maxBuckets = 8;
final int maxEntries = 16;
final String name = uniqName + "-PR";
final int extraEntries = 4;
// final int heapPercentage = 66;
// final int evictorInterval = 100;
final SerializableRunnable create = new CacheSerializableRunnable("Create Entry LRU with local destroy on a partitioned Region") {
public void run2() {
final AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setTotalNumBuckets(maxBuckets).create());
factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(maxEntries, EvictionAction.LOCAL_DESTROY));
final PartitionedRegion pr = (PartitionedRegion) createRootRegion(name, factory.create());
assertNotNull(pr);
}
};
vm0.invoke(create);
final SerializableRunnable create2 = new SerializableRunnable("Create Entry LRU with local destroy on a partitioned Region") {
public void run() {
try {
final AttributesFactory factory = new AttributesFactory();
factory.setOffHeap(isOffHeap());
factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setLocalMaxMemory(0).setTotalNumBuckets(maxBuckets).create());
factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(maxEntries));
factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
// this listener will cause a deadlock if the get ends up
// locking the entry.
factory.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
Region region = event.getRegion();
Object key = event.getKey();
region.get(key);
}
});
final PartitionedRegion pr = (PartitionedRegion) createRootRegion(name, factory.create());
assertNotNull(pr);
} catch (final CacheException ex) {
Assert.fail("While creating Partitioned region", ex);
}
}
};
vm1.invoke(create2);
final SerializableRunnable doPuts = new SerializableRunnable("Do Puts") {
public void run() {
final PartitionedRegion pr = (PartitionedRegion) getRootRegion(name);
assertNotNull(pr);
for (int counter = 0; counter <= maxEntries + extraEntries; counter++) {
pr.put(new Integer(counter), "value");
}
}
};
vm0.invoke(doPuts);
}
use of org.apache.geode.cache.SubscriptionAttributes in project geode by apache.
the class ClientServerForceInvalidateDUnitTest method createClientCache.
public static void createClientCache(String h, int port1, int port2, boolean empty, boolean concurrenctChecksEnabled) throws Exception {
AbstractRegionMap.FORCE_INVALIDATE_EVENT = true;
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
Cache cache = new ClientServerForceInvalidateDUnitTest().createCacheV(props);
PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(h, port1).addServer(h, port2).setSubscriptionEnabled(true).setThreadLocalConnections(true).setReadTimeout(1000).setSocketBufferSize(32768).setMinConnections(3).setSubscriptionRedundancy(-1).setPingInterval(2000).create("ClientServerForceInvalidateDUnitTestPool");
RegionFactory<String, String> factory = cache.createRegionFactory();
if (empty) {
factory.setDataPolicy(DataPolicy.EMPTY);
factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
} else {
factory.setDataPolicy(DataPolicy.NORMAL);
}
factory.setPoolName(p.getName());
factory.setConcurrencyChecksEnabled(concurrenctChecksEnabled);
region1 = factory.create(REGION_NAME1);
region1.registerInterest("ALL_KEYS", InterestResultPolicy.NONE, false, false);
region1.getAttributesMutator().addCacheListener(new ClientListener());
assertNotNull(region1);
with().pollDelay(1, TimeUnit.MILLISECONDS).pollInterval(1, TimeUnit.SECONDS).await().atMost(60, TimeUnit.SECONDS).until(() -> poolReady(p));
}
use of org.apache.geode.cache.SubscriptionAttributes in project geode by apache.
the class PartitionedRegionDUnitTest method testRegionInvalidationWithAdjunctMessages.
/**
* Bug #47235 concerns assertion failures being thrown when there is a member that receives
* adjunct messages (as in a WAN gateway, a peer with clients, etc).
*/
@Test
public void testRegionInvalidationWithAdjunctMessages() throws Exception {
final String name = getUniqueName();
VM vm1 = Host.getHost(0).getVM(1);
Cache cache = getCache();
RegionFactory fact = getCache().createRegionFactory(RegionShortcut.PARTITION);
Region pr = fact.create(name + "Region");
pr.put("Object1", "Value1");
vm1.invoke(new SerializableRunnable("create PR") {
@Override
public void run() {
RegionFactory fact = getCache().createRegionFactory(RegionShortcut.PARTITION);
fact.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
fact.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterInvalidate(EntryEvent event) {
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("afterInvalidate invoked with " + event);
InvalidateInvoked = true;
}
});
fact.create(name + "Region");
}
});
try {
pr.invalidateRegion();
assertTrue("vm1 should have invoked the listener for an invalidateRegion operation", (Boolean) vm1.invoke(new SerializableCallable("getStatus") {
public Object call() {
return InvalidateInvoked;
}
}));
} finally {
disconnectAllFromDS();
}
}
Aggregations