Search in sources :

Example 1 with RegionAttributes

use of org.apache.geode.cache.RegionAttributes 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();
    }
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) DeltaTestImpl(org.apache.geode.DeltaTestImpl) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) CqListenerAdapter(org.apache.geode.cache.util.CqListenerAdapter) 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) CqEvent(org.apache.geode.cache.query.CqEvent) Delta(org.apache.geode.Delta) CqAttributes(org.apache.geode.cache.query.CqAttributes) EntryEvent(org.apache.geode.cache.EntryEvent) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqQuery(org.apache.geode.cache.query.CqQuery) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 2 with RegionAttributes

use of org.apache.geode.cache.RegionAttributes in project geode by apache.

the class LuceneRegionListener method beforeCreate.

@Override
public RegionAttributes beforeCreate(Region parent, String regionName, RegionAttributes attrs, InternalRegionArguments internalRegionArgs) {
    RegionAttributes updatedRA = attrs;
    String path = parent == null ? "/" + regionName : parent.getFullPath() + "/" + regionName;
    if (path.equals(this.regionPath)) {
        if (!attrs.getDataPolicy().withPartitioning()) {
            // replicated region
            throw new UnsupportedOperationException("Lucene indexes on replicated regions are not supported");
        }
        // For now we cannot support eviction with local destroy.
        // Eviction with overflow to disk still needs to be supported
        EvictionAttributes evictionAttributes = attrs.getEvictionAttributes();
        EvictionAlgorithm evictionAlgorithm = evictionAttributes.getAlgorithm();
        if (evictionAlgorithm != EvictionAlgorithm.NONE && evictionAttributes.getAction().isLocalDestroy()) {
            throw new UnsupportedOperationException("Lucene indexes on regions with eviction and action local destroy are not supported");
        }
        String aeqId = LuceneServiceImpl.getUniqueIndexName(this.indexName, this.regionPath);
        if (!attrs.getAsyncEventQueueIds().contains(aeqId)) {
            AttributesFactory af = new AttributesFactory(attrs);
            af.addAsyncEventQueueId(aeqId);
            updatedRA = af.create();
        }
        // Add index creation profile
        internalRegionArgs.addCacheServiceProfile(new LuceneIndexCreationProfile(this.indexName, this.regionPath, this.fields, this.analyzer, this.fieldAnalyzers));
        luceneIndex = this.service.beforeDataRegionCreated(this.indexName, this.regionPath, attrs, this.analyzer, this.fieldAnalyzers, aeqId, this.fields);
        // Add internal async event id
        internalRegionArgs.addInternalAsyncEventQueueId(aeqId);
    }
    return updatedRA;
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) EvictionAlgorithm(org.apache.geode.cache.EvictionAlgorithm)

Example 3 with RegionAttributes

use of org.apache.geode.cache.RegionAttributes in project geode by apache.

the class CacheClientNotifierDUnitTest method checkCacheServer.

private void checkCacheServer(VM vm, final int serverPort, final boolean withCSC, final int capacity) {
    SerializableRunnable checkCacheServer = new SerializableRunnable() {

        @Override
        public void run() throws Exception {
            List<CacheServer> cacheServers = ((GemFireCacheImpl) cache).getCacheServersAndGatewayReceiver();
            CacheServerImpl server = null;
            for (CacheServer cs : cacheServers) {
                if (cs.getPort() == serverPort) {
                    server = (CacheServerImpl) cs;
                    break;
                }
            }
            assertNotNull(server);
            CacheClientNotifier ccn = server.getAcceptor().getCacheClientNotifier();
            HAContainerRegion haContainer = (HAContainerRegion) ccn.getHaContainer();
            if (server.getAcceptor().isGatewayReceiver()) {
                assertNull(haContainer);
                return;
            }
            Region internalRegion = haContainer.getMapForTest();
            RegionAttributes ra = internalRegion.getAttributes();
            EvictionAttributes ea = ra.getEvictionAttributes();
            if (withCSC) {
                assertNotNull(ea);
                assertEquals(capacity, ea.getMaximum());
                assertEquals(EvictionAction.OVERFLOW_TO_DISK, ea.getAction());
            } else {
                assertNull(ea);
            }
        }
    };
    vm.invoke(checkCacheServer);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) RegionAttributes(org.apache.geode.cache.RegionAttributes) HAContainerRegion(org.apache.geode.internal.cache.ha.HAContainerRegion) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) CacheServer(org.apache.geode.cache.server.CacheServer) Region(org.apache.geode.cache.Region) HAContainerRegion(org.apache.geode.internal.cache.ha.HAContainerRegion) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl)

Example 4 with RegionAttributes

use of org.apache.geode.cache.RegionAttributes in project geode by apache.

the class TestClientIdsDUnitTest method createServerCache.

private int createServerCache() throws IOException {
    Cache cache = this.managementTestRule.getCache();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
    CacheServer cacheServer = cache.addCacheServer();
    cacheServer.setPort(0);
    cacheServer.setNotifyBySubscription(true);
    cacheServer.start();
    return cacheServer.getPort();
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheServer(org.apache.geode.cache.server.CacheServer) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache)

Example 5 with RegionAttributes

use of org.apache.geode.cache.RegionAttributes in project geode by apache.

the class JUnit4CacheTestCase method createRegion.

public final Region createRegion(final String name, final String rootName, final RegionAttributes attributes) throws CacheException {
    Region root = getRootRegion(rootName);
    if (root == null) {
        // don't put listeners on root region
        RegionAttributes rootAttrs = attributes;
        AttributesFactory fac = new AttributesFactory(attributes);
        ExpirationAttributes expiration = ExpirationAttributes.DEFAULT;
        // fac.setCacheListener(null);
        fac.setCacheLoader(null);
        fac.setCacheWriter(null);
        fac.setPoolName(null);
        fac.setPartitionAttributes(null);
        fac.setRegionTimeToLive(expiration);
        fac.setEntryTimeToLive(expiration);
        fac.setRegionIdleTimeout(expiration);
        fac.setEntryIdleTimeout(expiration);
        rootAttrs = fac.create();
        root = createRootRegion(rootName, rootAttrs);
    }
    InternalRegionArguments internalArgs = getInternalRegionArguments();
    if (internalArgs == null) {
        return root.createSubregion(name, attributes);
    } else {
        try {
            LocalRegion lr = (LocalRegion) root;
            return lr.createSubregion(name, attributes, internalArgs);
        } catch (IOException ioe) {
            AssertionError assErr = new AssertionError("unexpected exception");
            assErr.initCause(ioe);
            throw assErr;
        } catch (ClassNotFoundException cnfe) {
            AssertionError assErr = new AssertionError("unexpected exception");
            assErr.initCause(cnfe);
            throw assErr;
        }
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) InternalRegionArguments(org.apache.geode.internal.cache.InternalRegionArguments) LocalRegion(org.apache.geode.internal.cache.LocalRegion) IOException(java.io.IOException) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes)

Aggregations

RegionAttributes (org.apache.geode.cache.RegionAttributes)590 AttributesFactory (org.apache.geode.cache.AttributesFactory)471 Region (org.apache.geode.cache.Region)256 Test (org.junit.Test)251 Properties (java.util.Properties)158 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)128 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)126 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)118 LocalRegion (org.apache.geode.internal.cache.LocalRegion)112 Cache (org.apache.geode.cache.Cache)99 VM (org.apache.geode.test.dunit.VM)93 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)93 Host (org.apache.geode.test.dunit.Host)89 HashSet (java.util.HashSet)80 CacheException (org.apache.geode.cache.CacheException)65 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)62 CacheServer (org.apache.geode.cache.server.CacheServer)60 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)59 ArrayList (java.util.ArrayList)57 PartitionAttributesImpl (org.apache.geode.internal.cache.PartitionAttributesImpl)56