Search in sources :

Example 26 with EvictionAttributes

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

the class IndexCommandsDUnitTest method createParRegWithPersistence.

private Region<?, ?> createParRegWithPersistence(String regionName, String diskStoreName, String diskDirName) {
    Cache cache = getCache();
    File diskStoreDirFile = new File(diskDirName);
    diskStoreDirFile.deleteOnExit();
    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_PARTITION);
    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)

Example 27 with EvictionAttributes

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

the class MemberCommandsDUnitTest method createPartitionedRegion.

private void createPartitionedRegion(String regionName) {
    final Cache cache = getCache();
    // Create the data region
    RegionFactory<String, Integer> dataRegionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
    dataRegionFactory.setConcurrencyLevel(4);
    EvictionAttributes ea = EvictionAttributes.createLIFOEntryAttributes(100, EvictionAction.LOCAL_DESTROY);
    dataRegionFactory.setEvictionAttributes(ea);
    dataRegionFactory.setEnableAsyncConflation(true);
    FixedPartitionAttributes fpa = FixedPartitionAttributes.createFixedPartition("Par1", true);
    PartitionAttributes pa = new PartitionAttributesFactory().setLocalMaxMemory(100).setRecoveryDelay(2).setTotalMaxMemory(200).setRedundantCopies(1).addFixedPartitionAttributes(fpa).create();
    dataRegionFactory.setPartitionAttributes(pa);
    dataRegionFactory.create(regionName);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) Cache(org.apache.geode.cache.Cache)

Example 28 with EvictionAttributes

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

the class QueryMonitorDUnitTest method createRegion.

private void createRegion(final boolean eviction, final String dirName) {
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    // setting the eviction attributes.
    if (eviction) {
        File[] f = new File[1];
        f[0] = new File(dirName);
        f[0].mkdir();
        DiskStoreFactory dsf = GemFireCacheImpl.getInstance().createDiskStoreFactory();
        DiskStore ds1 = dsf.setDiskDirs(f).create("ds1");
        factory.setDiskStoreName("ds1");
        EvictionAttributes evictAttrs = EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK);
        factory.setEvictionAttributes(evictAttrs);
    }
    // Create region
    createRegion(exampleRegionName, factory.create());
    createRegion(exampleRegionName2, factory.create());
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) EvictionAttributes(org.apache.geode.cache.EvictionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory)

Example 29 with EvictionAttributes

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

the class HARegionJUnitTest method testEventIdSetForEvictDestroy.

/**
   * Test to verify event id exists when evict destroy happens.
   */
@Test
public void testEventIdSetForEvictDestroy() throws Exception {
    AttributesFactory factory = new AttributesFactory();
    factory.setCacheListener(new CacheListenerAdapter() {

        public void afterDestroy(EntryEvent event) {
            assertTrue("eventId has not been set for " + event, ((EntryEventImpl) event).getEventId() != null);
        }
    });
    EvictionAttributes evAttr = EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.LOCAL_DESTROY);
    factory.setEvictionAttributes(evAttr);
    RegionAttributes attrs = factory.createRegionAttributes();
    Region region = cache.createVMRegion("TEST_REGION", attrs);
    region.put("key1", "value1");
    region.put("key2", "value2");
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) RegionAttributes(org.apache.geode.cache.RegionAttributes) EntryEvent(org.apache.geode.cache.EntryEvent) HARegion(org.apache.geode.internal.cache.HARegion) Region(org.apache.geode.cache.Region) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 30 with EvictionAttributes

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

the class CacheXml66DUnitTest method testDiskStoreValidation.

@Test
public void testDiskStoreValidation() throws Exception {
    CacheCreation cache = new CacheCreation();
    DiskStoreFactory dsf = cache.createDiskStoreFactory();
    DiskStore ds1 = dsf.create(getUniqueName());
    RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    attrs.setScope(Scope.DISTRIBUTED_ACK);
    attrs.setDataPolicy(DataPolicy.REPLICATE);
    attrs.setDiskStoreName(getUniqueName());
    RegionCreation root;
    try {
        root = (RegionCreation) cache.createRegion("root", attrs);
        fail("Expected IllegalStateException to be thrown");
    } catch (IllegalStateException e) {
        assertTrue(e.getMessage().contains(LocalizedStrings.DiskStore_IS_USED_IN_NONPERSISTENT_REGION.toLocalizedString()));
    }
    EvictionAttributes ea = EvictionAttributes.createLRUEntryAttributes(1000, EvictionAction.OVERFLOW_TO_DISK);
    attrs.setEvictionAttributes(ea);
    root = (RegionCreation) cache.createRegion("root", attrs);
    File dir = new File("testDiskStoreValidation");
    dir.mkdir();
    dir.deleteOnExit();
    File[] dirs2 = new File[] { dir, new File("").getAbsoluteFile() };
    try {
        AttributesFactory factory = new AttributesFactory();
        factory.setDiskDirs(dirs2);
        factory.setDiskStoreName(getUniqueName());
        RegionAttributes ra = factory.create();
        fail("Expected IllegalStateException to be thrown");
    } catch (IllegalStateException e) {
        assertTrue(e.getMessage().contains(LocalizedStrings.DiskStore_Deprecated_API_0_Cannot_Mix_With_DiskStore_1.toLocalizedString("setDiskDirs or setDiskWriteAttributes", getUniqueName())));
    }
    try {
        AttributesFactory factory = new AttributesFactory();
        factory.setDiskStoreName(getUniqueName());
        factory.setDiskDirs(dirs2);
        RegionAttributes ra = factory.create();
        fail("Expected IllegalStateException to be thrown");
    } catch (IllegalStateException e) {
        assertTrue(e.getMessage().contains(LocalizedStrings.DiskStore_Deprecated_API_0_Cannot_Mix_With_DiskStore_1.toLocalizedString("setDiskDirs", getUniqueName())));
    }
    testXml(cache);
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) EvictionAttributes(org.apache.geode.cache.EvictionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) DiskWriteAttributesFactory(org.apache.geode.cache.DiskWriteAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) RegionCreation(org.apache.geode.internal.cache.xmlcache.RegionCreation) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) Test(org.junit.Test)

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