Search in sources :

Example 11 with EvictionAttributes

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

the class PartitionedRegionEvictionDUnitTest method testEvictionValidationForLRUEntry.

// Test to validate the Eviction Attribute : LRU Check
@Test
public void testEvictionValidationForLRUEntry() {
    final Host host = Host.getHost(0);
    final VM testAccessor = host.getVM(1);
    final VM testDatastore = host.getVM(2);
    final VM firstDatastore = host.getVM(3);
    final String uniqName = getUniqueName();
    final int redundantCopies = 1;
    final int maxEntries = 226;
    final String name = uniqName + "-PR";
    // final int evictionSizeInMB = 200;
    final EvictionAttributes firstEvictionAttrs = EvictionAttributes.createLRUEntryAttributes(maxEntries, EvictionAction.LOCAL_DESTROY);
    // Creating LRU Entry Count Eviction Attribute
    final SerializableRunnable create = new CacheSerializableRunnable("Create Entry LRU with local destroy on a partitioned Region") {

        public void run2() {
            // Assert that LRUEntry maximum can be less than 1 entry per
            // bucket
            // DUnit not required for this test, but its a convenient place
            // to put it.
            {
                final int buks = 11;
                final AttributesFactory factory = new AttributesFactory();
                factory.setOffHeap(isOffHeap());
                factory.setPartitionAttributes(new PartitionAttributesFactory().setTotalNumBuckets(buks).setRedundantCopies(0).create());
                factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes((buks / 2)));
                final PartitionedRegion pr = (PartitionedRegion) createRootRegion(name, factory.create());
                final Integer key = new Integer(1);
                pr.put(key, "testval");
                final BucketRegion b;
                try {
                    b = pr.getDataStore().getInitializedBucketForId(key, new Integer(PartitionedRegionHelper.getHashKey(pr, null, key, null, null)));
                } catch (final ForceReattemptException e) {
                    fail();
                }
                pr.destroyRegion();
            }
            final AttributesFactory factory = new AttributesFactory();
            factory.setOffHeap(isOffHeap());
            factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).create());
            factory.setEvictionAttributes(firstEvictionAttrs);
            final Region pr = createRootRegion(name, factory.create());
            assertNotNull(pr);
        }
    };
    firstDatastore.invoke(create);
    final SerializableRunnable create2 = new SerializableRunnable("Create Entry LRU with Overflow to disk partitioned Region") {

        public void run() {
            final AttributesFactory factory = new AttributesFactory();
            factory.setOffHeap(isOffHeap());
            factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).create());
            // Assert a different algo is invalid
            try {
                getCache().getLogger().info("<ExpectedException action=add>" + "IllegalStateException</ExpectedException>");
                assertTrue(!firstEvictionAttrs.getAlgorithm().isLRUHeap());
                final EvictionAttributes illegalEa = EvictionAttributes.createLRUHeapAttributes(null, firstEvictionAttrs.getAction());
                assertTrue(!firstEvictionAttrs.equals(illegalEa));
                factory.setEvictionAttributes(illegalEa);
                setEvictionPercentage(50);
                createRootRegion(name, factory.create());
                fail("Creating LRU Entry Count Eviction Attribute");
            } catch (final IllegalStateException expected) {
                assertTrue(expected.getMessage().contains(PartitionRegionConfigValidator.EVICTION_ATTRIBUTES_ARE_INCOMPATIBLE_MESSAGE));
            } finally {
                getCache().getLogger().info("<ExpectedException action=remove>" + "IllegalStateException</ExpectedException>");
            }
            // Assert a different action is invalid
            try {
                getCache().getLogger().info("<ExpectedException action=add>" + "IllegalStateException</ExpectedException>");
                assertTrue(firstEvictionAttrs.getAlgorithm().isLRUEntry());
                assertTrue(!firstEvictionAttrs.getAction().isOverflowToDisk());
                final EvictionAttributes illegalEa = EvictionAttributes.createLRUEntryAttributes(firstEvictionAttrs.getMaximum(), EvictionAction.OVERFLOW_TO_DISK);
                assertTrue(!firstEvictionAttrs.equals(illegalEa));
                factory.setEvictionAttributes(illegalEa);
                createRootRegion(name, factory.create());
                fail("Creating LRU Entry Count Eviction Attribute");
            } catch (final IllegalStateException expected) {
                assertTrue(expected.getMessage().contains(PartitionRegionConfigValidator.EVICTION_ATTRIBUTES_ARE_INCOMPATIBLE_MESSAGE));
            } finally {
                getCache().getLogger().info("<ExpectedException action=remove>" + "IllegalStateException</ExpectedException>");
            }
            assertTrue(firstEvictionAttrs.getAlgorithm().isLRUEntry());
            final EvictionAttributes brokenEa = EvictionAttributes.createLRUEntryAttributes(firstEvictionAttrs.getMaximum() + 1, firstEvictionAttrs.getAction());
            assertTrue(!firstEvictionAttrs.equals(brokenEa));
            factory.setEvictionAttributes(brokenEa);
            createRootRegion(name, factory.create());
        }
    };
    testDatastore.invoke(create2);
    testAccessor.invoke(new CacheSerializableRunnable("Create an Accessor with and without eviction attributes") {

        public void run2() throws CacheException {
            final PartitionAttributes pra = new PartitionAttributesFactory().setRedundantCopies(redundantCopies).setLocalMaxMemory(0).create();
            AttributesFactory factory = new AttributesFactory();
            factory.setOffHeap(isOffHeap());
            factory.setPartitionAttributes(pra);
            factory.setEvictionAttributes(firstEvictionAttrs);
            setEvictionPercentage(50);
            Region r1 = createRootRegion(name, factory.create());
            assertNotNull(r1);
            assertEquals(firstEvictionAttrs, r1.getAttributes().getEvictionAttributes());
        }
    });
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Host(org.apache.geode.test.dunit.Host) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 12 with EvictionAttributes

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

the class PartitionedRegionEvictionDUnitTest method testEvictionValidationForLRUAction.

// Test to validate the Eviction Attribute : LRU Action
@Test
public void testEvictionValidationForLRUAction() {
    final Host host = Host.getHost(0);
    final VM testDatastore = host.getVM(2);
    final VM firstDatastore = host.getVM(3);
    final String uniqName = getUniqueName();
    final int redundantCopies = 1;
    final int maxEntries = 226;
    final String name = uniqName + "-PR";
    final EvictionAttributes firstEa = EvictionAttributes.createLRUEntryAttributes(maxEntries, EvictionAction.LOCAL_DESTROY);
    // Creating LRU Entry Count Eviction Attribute : Algorithm :
    // LOCAL_DESTROY
    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).create());
            factory.setEvictionAttributes(firstEa);
            final Region pr = createRootRegion(name, factory.create());
            assertNotNull(pr);
            assertEquals(firstEa, pr.getAttributes().getEvictionAttributes());
        }
    };
    firstDatastore.invoke(create);
    final SerializableRunnable create2 = new SerializableRunnable("Create Entry LRU with Overflow to disk partitioned Region") {

        public void run() {
            final AttributesFactory factory = new AttributesFactory();
            factory.setOffHeap(isOffHeap());
            factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).create());
            // OVERFLOW_TO_DISK // Exception should occur
            try {
                getCache().getLogger().info("<ExpectedException action=add>" + "IllegalStateException</ExpectedException>");
                assertTrue(firstEa.getAlgorithm().isLRUEntry());
                assertTrue(!firstEa.getAction().isOverflowToDisk());
                factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(maxEntries, EvictionAction.OVERFLOW_TO_DISK));
                createRootRegion(name, factory.create());
                fail("Test to validate the Eviction Attribute : LRU Action");
            } catch (final IllegalStateException expected) {
                assertTrue(expected.getMessage().contains(PartitionRegionConfigValidator.EVICTION_ATTRIBUTES_ARE_INCOMPATIBLE_MESSAGE));
            } finally {
                getCache().getLogger().info("<ExpectedException action=remove>" + "IllegalStateException</ExpectedException>");
            }
            // // Exception should occur
            try {
                getCache().getLogger().info("<ExpectedException action=add>" + "IllegalStateException</ExpectedException>");
                assertTrue(firstEa.getAlgorithm().isLRUEntry());
                assertTrue(!firstEa.getAction().isNone());
                factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(maxEntries, EvictionAction.NONE));
                createRootRegion(name, factory.create());
                fail("Test to validate the Eviction Attribute : LRU Action");
            } catch (final IllegalStateException expected) {
                assertTrue(expected.getMessage().contains(PartitionRegionConfigValidator.EVICTION_ATTRIBUTES_ARE_INCOMPATIBLE_MESSAGE));
            } finally {
                getCache().getLogger().info("<ExpectedException action=remove>" + "IllegalStateException</ExpectedException>");
            }
            // Creating LRU Entry Count Eviction Attribute : Action :
            // LOCAL_DESTROY // Exception should not occur
            factory.setEvictionAttributes(firstEa);
            final Region pr = createRootRegion(name, factory.create());
            assertNotNull(pr);
            assertEquals(firstEa, pr.getAttributes().getEvictionAttributes());
        }
    };
    testDatastore.invoke(create2);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 13 with EvictionAttributes

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

the class PartitionedRegionDUnitTestCase method createMultiplePartitionRegion.

/**
   * This function creates multiple partition regions in a VM. The name of the Partition Region will
   * be PRPrefix+index (index starts from startIndexForRegion and ends to endIndexForRegion)
   * 
   * @param PRPrefix : Used in the name of the Partition Region
   * 
   *        These indices Represents range of the Partition Region
   * @param startIndexForRegion :
   * @param endIndexForRegion
   * @param redundancy
   * @param localmaxMemory
   * @param evict
   * @return
   */
public CacheSerializableRunnable createMultiplePartitionRegion(final String PRPrefix, final int startIndexForRegion, final int endIndexForRegion, final int redundancy, final int localmaxMemory, final boolean evict) {
    return new CacheSerializableRunnable("createPrRegions_" + PRPrefix) {

        String innerPRPrefix = PRPrefix;

        int innerStartIndexForRegion = startIndexForRegion;

        int innerEndIndexForRegion = endIndexForRegion;

        int innerRedundancy = redundancy;

        int innerlocalmaxMemory = localmaxMemory;

        public void run2() throws CacheException {
            System.setProperty(PartitionedRegion.RETRY_TIMEOUT_PROPERTY, "20000");
            EvictionAttributes evictionAttrs = evict ? EvictionAttributes.createLRUEntryAttributes(Integer.MAX_VALUE, EvictionAction.LOCAL_DESTROY) : null;
            for (int i = startIndexForRegion; i < endIndexForRegion; i++) {
                Region partitionedregion = getCache().createRegion(innerPRPrefix + i, createRegionAttrsForPR(innerRedundancy, innerlocalmaxMemory, PartitionAttributesFactory.RECOVERY_DELAY_DEFAULT, evictionAttrs));
                getCache().getLogger().info("Successfully created PartitionedRegion = " + partitionedregion);
            }
            System.setProperty(PartitionedRegion.RETRY_TIMEOUT_PROPERTY, Integer.toString(PartitionedRegionHelper.DEFAULT_TOTAL_WAIT_RETRY_ITERATION));
            getCache().getLogger().info("createMultiplePartitionRegion() - Partition Regions Successfully Completed ");
        }
    };
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Region(org.apache.geode.cache.Region)

Example 14 with EvictionAttributes

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

the class PartitionedRegionEvictionDUnitTest method testEvictionValidationForLRUMaximum.

// Test to validate the Eviction Attribute : LRU Maximum
@Test
public void testEvictionValidationForLRUMaximum() {
    final Host host = Host.getHost(0);
    final VM testDatastore = host.getVM(2);
    final VM firstDatastore = host.getVM(3);
    final String uniqName = getUniqueName();
    final int redundantCopies = 1;
    final int maxEntries = 226;
    final String name = uniqName + "-PR";
    final EvictionAttributes firstEvictionAttributes = EvictionAttributes.createLRUEntryAttributes(maxEntries, EvictionAction.LOCAL_DESTROY);
    // Creating LRU Entry Count Eviction Attribute : maxentries : 2
    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).create());
            factory.setEvictionAttributes(firstEvictionAttributes);
            final Region pr = createRootRegion(name, factory.create());
            assertNotNull(pr);
            assertEquals(firstEvictionAttributes, pr.getAttributes().getEvictionAttributes());
        }
    };
    firstDatastore.invoke(create);
    final SerializableRunnable create2 = new SerializableRunnable("Create Entry LRU with Overflow to disk partitioned Region") {

        public void run() {
            final AttributesFactory factory = new AttributesFactory();
            factory.setOffHeap(isOffHeap());
            factory.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(redundantCopies).create());
            final EvictionAttributes ea = EvictionAttributes.createLRUEntryAttributes(firstEvictionAttributes.getMaximum() + 10, firstEvictionAttributes.getAction());
            factory.setEvictionAttributes(ea);
            final Region pr = createRootRegion(name, factory.create());
            assertNotNull(pr);
        }
    };
    testDatastore.invoke(create2);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 15 with EvictionAttributes

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

the class DiskStoreCommandsDUnitTest method createParRegWithPersistence.

private Region<?, ?> createParRegWithPersistence(String regionName, String diskStoreName, String diskDirName) {
    Cache cache = getCache();
    File diskStoreDirFile = new File(diskDirName);
    if (!diskStoreDirFile.exists()) {
        diskStoreDirFile.mkdirs();
    }
    DiskStoreFactory diskStoreFactory = cache.createDiskStoreFactory();
    diskStoreFactory.setDiskDirs(new File[] { diskStoreDirFile });
    diskStoreFactory.setMaxOplogSize(1);
    diskStoreFactory.setAllowForceCompaction(true);
    diskStoreFactory.setAutoCompact(false);
    diskStoreFactory.create(diskStoreName);
    /****
     * Eviction Attributes
     */
    EvictionAttributes ea = EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK);
    RegionFactory regionFactory = cache.createRegionFactory();
    regionFactory.setDiskStoreName(diskStoreName);
    regionFactory.setDiskSynchronous(true);
    regionFactory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
    regionFactory.setScope(Scope.DISTRIBUTED_ACK);
    regionFactory.setEvictionAttributes(ea);
    return regionFactory.create(regionName);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) RegionFactory(org.apache.geode.cache.RegionFactory) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) Cache(org.apache.geode.cache.Cache) InternalCache(org.apache.geode.internal.cache.InternalCache)

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