use of org.apache.geode.cache.AttributesMutator in project geode by apache.
the class PRDeltaPropagationDUnitTest method createServerCache.
public static Integer createServerCache(Boolean isListAttach, Boolean isEmpty) throws Exception {
Properties props = new Properties();
new PRDeltaPropagationDUnitTest().createCache(props);
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setConcurrencyChecksEnabled(true);
if (isEmpty.booleanValue()) {
factory.setDataPolicy(DataPolicy.EMPTY);
} else {
factory.setDataPolicy(DataPolicy.REPLICATE);
}
lastKeyReceived = false;
RegionAttributes attrs = factory.create();
deltaPR = cache.createRegion(REGION_NAME, attrs);
AttributesMutator am = deltaPR.getAttributesMutator();
if (isListAttach.booleanValue()) {
am.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
if (event.getNewValue() == null)
isFailed = true;
if (event.getKey().equals(LAST_KEY)) {
lastKeyReceived = true;
}
}
@Override
public void afterUpdate(EntryEvent event) {
if (event.getNewValue() == null)
isFailed = true;
}
});
}
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.AttributesMutator in project geode by apache.
the class WANTestBase method addCacheListenerOnQueueBucketRegion.
private void addCacheListenerOnQueueBucketRegion(String senderId, int numBuckets) {
Set<GatewaySender> senders = cache.getGatewaySenders();
GatewaySender sender = null;
for (GatewaySender s : senders) {
if (s.getId().equals(senderId)) {
sender = s;
break;
}
}
RegionQueue parallelQueue = ((AbstractGatewaySender) sender).getQueues().toArray(new RegionQueue[1])[0];
PartitionedRegion region = (PartitionedRegion) parallelQueue.getRegion();
for (int i = 0; i < numBuckets; i++) {
BucketRegion br = region.getBucketRegion(i);
if (br != null) {
AttributesMutator mutator = br.getAttributesMutator();
CacheListener listener = new QueueListener();
mutator.addCacheListener(listener);
}
}
}
use of org.apache.geode.cache.AttributesMutator in project geode by apache.
the class CacheAdvisorDUnitTest method testNetLoadAdviceWithAttributesMutator.
@Test
public void testNetLoadAdviceWithAttributesMutator() throws Exception {
final String rgnName = getUniqueName();
AttributesFactory fac = new AttributesFactory();
fac.setScope(Scope.DISTRIBUTED_ACK);
RegionAttributes attrs = fac.create();
DistributedRegion rgn = (DistributedRegion) createRegion(rgnName, attrs);
Invoke.invokeInEveryVM(new CacheSerializableRunnable("CachAdvisorTest.testNetLoadAdviceWithAttributesMutator;createRegion") {
public void run2() throws CacheException {
AttributesFactory f = new AttributesFactory();
f.setScope(Scope.DISTRIBUTED_ACK);
createRegion(rgnName, f.create());
}
});
Set expected = new HashSet();
for (int i = 1; i < vms.length; i += 2) {
VM vm = vms[i];
final int numVMsMinusOne = vms.length;
InternalDistributedMember id = ids[i];
expected.add(id);
// final int index = i;
vm.invoke(new CacheSerializableRunnable("CacheAdvisorDUnitTest.testNetLoadAdviceWithAttributesMutator;mutate") {
public void run2() throws CacheException {
Region rgn1 = getRootRegion().getSubregion(rgnName);
assertEquals(numVMsMinusOne, ((DistributedRegion) rgn1).getDistributionAdvisor().adviseGeneric().size());
AttributesMutator mut = rgn1.getAttributesMutator();
mut.setCacheLoader(new CacheLoader() {
public Object load(LoaderHelper helper) throws CacheLoaderException {
return null;
}
public void close() {
}
});
}
});
}
Awaitility.await().pollInterval(10, TimeUnit.MILLISECONDS).pollDelay(10, TimeUnit.MILLISECONDS).atMost(30, TimeUnit.SECONDS).until(() -> assertEquals(expected, rgn.getCacheDistributionAdvisor().adviseNetLoad()));
}
use of org.apache.geode.cache.AttributesMutator in project geode by apache.
the class ForceInvalidateEvictionDUnitTest method removeListener.
private void removeListener(VM vm) {
final String name = getUniqueName();
vm.invoke(new SerializableRunnable() {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(name);
AttributesMutator am = region.getAttributesMutator();
am.initCacheListeners(null);
}
});
}
use of org.apache.geode.cache.AttributesMutator in project geode by apache.
the class SerialGatewaySenderQueue method addCacheListener.
@SuppressWarnings("rawtypes")
public void addCacheListener(CacheListener listener) {
AttributesMutator mutator = this.region.getAttributesMutator();
mutator.addCacheListener(listener);
}
Aggregations