Search in sources :

Example 21 with AttributesMutator

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());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) RegionAttributes(org.apache.geode.cache.RegionAttributes) EntryEvent(org.apache.geode.cache.EntryEvent) CacheServer(org.apache.geode.cache.server.CacheServer) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) AttributesMutator(org.apache.geode.cache.AttributesMutator)

Example 22 with AttributesMutator

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);
        }
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) BucketRegion(org.apache.geode.internal.cache.BucketRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RegionQueue(org.apache.geode.internal.cache.RegionQueue) CacheListener(org.apache.geode.cache.CacheListener) AttributesMutator(org.apache.geode.cache.AttributesMutator)

Example 23 with AttributesMutator

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()));
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheException(org.apache.geode.cache.CacheException) LoaderHelper(org.apache.geode.cache.LoaderHelper) AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) CacheLoader(org.apache.geode.cache.CacheLoader) HashSet(java.util.HashSet) AttributesMutator(org.apache.geode.cache.AttributesMutator) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 24 with AttributesMutator

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);
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) AttributesMutator(org.apache.geode.cache.AttributesMutator)

Example 25 with AttributesMutator

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);
}
Also used : AttributesMutator(org.apache.geode.cache.AttributesMutator)

Aggregations

AttributesMutator (org.apache.geode.cache.AttributesMutator)37 Region (org.apache.geode.cache.Region)24 Test (org.junit.Test)19 LocalRegion (org.apache.geode.internal.cache.LocalRegion)18 AttributesFactory (org.apache.geode.cache.AttributesFactory)16 RegionAttributes (org.apache.geode.cache.RegionAttributes)13 EntryEvent (org.apache.geode.cache.EntryEvent)11 ExpirationAttributes (org.apache.geode.cache.ExpirationAttributes)11 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)11 Properties (java.util.Properties)8 CacheException (org.apache.geode.cache.CacheException)8 CacheLoader (org.apache.geode.cache.CacheLoader)8 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8 HashSet (java.util.HashSet)7 Set (java.util.Set)7 LoaderHelper (org.apache.geode.cache.LoaderHelper)7 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)7 AbstractRegion (org.apache.geode.internal.cache.AbstractRegion)7 CacheListener (org.apache.geode.cache.CacheListener)6 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)6