Search in sources :

Example 1 with EvictionAttributes

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

the class CqQueryUsingPoolDUnitTest method createServer.

public void createServer(VM server, final int thePort, final boolean eviction, final MirrorType mirrorType) {
    SerializableRunnable createServer = new CacheSerializableRunnable("Create Cache Server") {

        @Override
        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Create Cache Server. ###");
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.DISTRIBUTED_ACK);
            factory.setMirrorType(mirrorType);
            // setting the eviction attributes.
            if (eviction) {
                EvictionAttributes evictAttrs = EvictionAttributes.createLRUEntryAttributes(100000, EvictionAction.OVERFLOW_TO_DISK);
                factory.setEvictionAttributes(evictAttrs);
            }
            for (int i = 0; i < regions.length; i++) {
                createRegion(regions[i], factory.createRegionAttributes());
            }
            try {
                startBridgeServer(thePort, true);
            } catch (Exception ex) {
                Assert.fail("While starting CacheServer", ex);
            }
        }
    };
    server.invoke(createServer);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CqExistsException(org.apache.geode.cache.query.CqExistsException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) RMIException(org.apache.geode.test.dunit.RMIException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 2 with EvictionAttributes

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

the class CqQueryDUnitTest method createServer.

public void createServer(VM server, final int thePort, final boolean eviction, final MirrorType mirrorType) {
    SerializableRunnable createServer = new CacheSerializableRunnable("Create Cache Server") {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Create Cache Server. ###");
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.DISTRIBUTED_ACK);
            factory.setMirrorType(mirrorType);
            // setting the eviction attributes.
            if (eviction) {
                EvictionAttributes evictAttrs = EvictionAttributes.createLRUEntryAttributes(100000, EvictionAction.OVERFLOW_TO_DISK);
                factory.setEvictionAttributes(evictAttrs);
            }
            for (int i = 0; i < regions.length; i++) {
                createRegion(regions[i], factory.createRegionAttributes());
            }
            Wait.pause(2000);
            try {
                startBridgeServer(thePort, true);
            } catch (Exception ex) {
                Assert.fail("While starting CacheServer", ex);
            }
            Wait.pause(2000);
        }
    };
    server.invoke(createServer);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CqExistsException(org.apache.geode.cache.query.CqExistsException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqClosedException(org.apache.geode.cache.query.CqClosedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 3 with EvictionAttributes

use of org.apache.geode.cache.EvictionAttributes 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 4 with EvictionAttributes

use of org.apache.geode.cache.EvictionAttributes 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 5 with EvictionAttributes

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

the class CqDataDUnitTest method testCQWithEviction.

/**
   * Test for CQ when entries are evicted from region.
   * 
   * @throws Exception
   */
@Test
public void testCQWithEviction() throws Exception {
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM client = host.getVM(2);
    final int evictionThreshold = 1;
    server1.invoke(new CacheSerializableRunnable("Create Cache Server") {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Create Cache Server. ###");
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.DISTRIBUTED_ACK);
            factory.setDataPolicy(DataPolicy.REPLICATE);
            // factory.setMirrorType(MirrorType.NONE);
            // setting the eviction attributes.
            EvictionAttributes evictAttrs = EvictionAttributes.createLRUEntryAttributes(evictionThreshold, EvictionAction.OVERFLOW_TO_DISK);
            factory.setEvictionAttributes(evictAttrs);
            for (int i = 0; i < cqDUnitTest.regions.length; i++) {
                Region region = createRegion(cqDUnitTest.regions[i], factory.createRegionAttributes());
                // Set CacheListener.
                region.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(LogWriterUtils.getLogWriter()));
            }
            Wait.pause(2000);
            try {
                cqDUnitTest.startBridgeServer(0, true);
            } catch (Exception ex) {
                Assert.fail("While starting CacheServer", ex);
            }
            Wait.pause(2000);
        }
    });
    final int port1 = server1.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server1.getHost());
    cqDUnitTest.createClient(client, port1, host0);
    // Create CQs.
    cqDUnitTest.createCQ(client, "testCQWithEviction_0", cqDUnitTest.cqs[0]);
    final int size = 10;
    // CREATE VALUES.
    cqDUnitTest.createValues(server1, cqDUnitTest.regions[0], size);
    cqDUnitTest.executeCQ(client, "testCQWithEviction_0", false, "CqException");
    Wait.pause(1 * 1000);
    // Update VALUES.
    cqDUnitTest.createValues(server1, cqDUnitTest.regions[0], size);
    for (int i = 1; i <= size; i++) {
        cqDUnitTest.waitForUpdated(client, "testCQWithEviction_0", cqDUnitTest.KEY + i);
    }
    cqDUnitTest.validateCQ(client, "testCQWithEviction_0", cqDUnitTest.noTest, 0, 10, 0);
    // Close.
    cqDUnitTest.closeClient(client);
    cqDUnitTest.closeServer(server1);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) CertifiableTestCacheListener(org.apache.geode.cache30.CertifiableTestCacheListener) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) CacheException(org.apache.geode.cache.CacheException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

EvictionAttributes (org.apache.geode.cache.EvictionAttributes)41 AttributesFactory (org.apache.geode.cache.AttributesFactory)25 Region (org.apache.geode.cache.Region)24 Test (org.junit.Test)24 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)21 RegionAttributes (org.apache.geode.cache.RegionAttributes)17 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)13 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)12 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)11 Host (org.apache.geode.test.dunit.Host)10 VM (org.apache.geode.test.dunit.VM)10 Cache (org.apache.geode.cache.Cache)9 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)9 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8 DiskWriteAttributesFactory (org.apache.geode.cache.DiskWriteAttributesFactory)7 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)6 LocalRegion (org.apache.geode.internal.cache.LocalRegion)6 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)6 ClientCacheCreation (org.apache.geode.internal.cache.xmlcache.ClientCacheCreation)6 File (java.io.File)5