Search in sources :

Example 91 with AttributesFactory

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

the class DistTXExpiryJUnitTest method createCache.

@Override
protected void createCache() throws CacheException {
    Properties p = new Properties();
    // loner
    p.setProperty(MCAST_PORT, "0");
    p.setProperty(ConfigurationProperties.DISTRIBUTED_TRANSACTIONS, "true");
    this.cache = (GemFireCacheImpl) CacheFactory.create(DistributedSystem.connect(p));
    AttributesFactory af = new AttributesFactory();
    af.setScope(Scope.DISTRIBUTED_NO_ACK);
    this.txMgr = this.cache.getCacheTransactionManager();
    assert (this.txMgr.isDistributed());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties)

Example 92 with AttributesFactory

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

the class DeltaPropagationDUnitTest method createDurableCacheClient.

public static void createDurableCacheClient(Pool poolAttr, String regionName, Properties dsProperties, Integer listenerCode, Boolean close) throws Exception {
    new DeltaPropagationDUnitTest().createCache(dsProperties);
    PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory();
    pf.init(poolAttr);
    PoolImpl p = (PoolImpl) pf.create("DeltaPropagationDUnitTest");
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setConcurrencyChecksEnabled(false);
    factory.setPoolName(p.getName());
    if (listenerCode.intValue() != 0) {
        factory.addCacheListener(getCacheListener(listenerCode));
    }
    RegionAttributes attrs = factory.create();
    Region r = cache.createRegion(regionName, attrs);
    r.registerInterest("ALL_KEYS");
    pool = p;
    cache.readyForEvents();
    logger = cache.getLogger();
    closeCache = close.booleanValue();
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Region(org.apache.geode.cache.Region) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl)

Example 93 with AttributesFactory

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

the class DeltaPropagationDUnitTest method createServerCache.

public static Integer createServerCache(String ePolicy, Integer cap, Integer listenerCode, Boolean conflate, Compressor compressor) throws Exception {
    ConnectionTable.threadWantsSharedResources();
    new DeltaPropagationDUnitTest().createCache(new Properties());
    AttributesFactory factory = new AttributesFactory();
    factory.setEnableSubscriptionConflation(conflate);
    if (listenerCode.intValue() != 0) {
        factory.addCacheListener(getCacheListener(listenerCode));
    }
    if (compressor != null) {
        factory.setCompressor(compressor);
    }
    if (listenerCode.intValue() == C2S2S_SERVER_LISTENER) {
        factory.setScope(Scope.DISTRIBUTED_NO_ACK);
        factory.setDataPolicy(DataPolicy.NORMAL);
        factory.setConcurrencyChecksEnabled(false);
        RegionAttributes attrs = factory.create();
        Region r = cache.createRegion(regionName, attrs);
        logger = cache.getLogger();
        r.create(DELTA_KEY, deltaPut[0]);
    } else {
        factory.setScope(Scope.DISTRIBUTED_ACK);
        factory.setDataPolicy(DataPolicy.REPLICATE);
        factory.setConcurrencyChecksEnabled(false);
        RegionAttributes attrs = factory.create();
        cache.createRegion(regionName, attrs);
        logger = cache.getLogger();
    }
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    CacheServer server1 = cache.addCacheServer();
    server1.setPort(port);
    server1.setNotifyBySubscription(true);
    if (ePolicy != null) {
        File overflowDirectory = new File("bsi_overflow_" + port);
        overflowDirectory.mkdir();
        DiskStoreFactory dsf = cache.createDiskStoreFactory();
        File[] dirs1 = new File[] { overflowDirectory };
        server1.getClientSubscriptionConfig().setEvictionPolicy(ePolicy);
        server1.getClientSubscriptionConfig().setCapacity(cap.intValue());
        // specify diskstore for this server
        server1.getClientSubscriptionConfig().setDiskStoreName(dsf.setDiskDirs(dirs1).create("bsi").getName());
    }
    server1.start();
    return new Integer(server1.getPort());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Region(org.apache.geode.cache.Region) CacheServer(org.apache.geode.cache.server.CacheServer) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory)

Example 94 with AttributesFactory

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

the class DeltaFaultInDUnitTest method test.

@Test
public void test() throws Exception {
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final boolean copyOnRead = false;
    final boolean clone = true;
    SerializableCallable createDataRegion = new SerializableCallable("createDataRegion") {

        public Object call() throws Exception {
            Cache cache = getCache();
            cache.setCopyOnRead(copyOnRead);
            cache.createDiskStoreFactory().create("DeltaFaultInDUnitTestData");
            AttributesFactory attr = new AttributesFactory();
            attr.setDiskStoreName("DeltaFaultInDUnitTestData");
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(1);
            PartitionAttributes prAttr = paf.create();
            attr.setPartitionAttributes(prAttr);
            attr.setCloningEnabled(clone);
            attr.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK));
            Region region = cache.createRegion("region1", attr.create());
            return null;
        }
    };
    vm0.invoke(createDataRegion);
    SerializableRunnable createEmptyRegion = new SerializableRunnable("createEmptyRegion") {

        public void run() {
            Cache cache = getCache();
            cache.setCopyOnRead(copyOnRead);
            AttributesFactory<Integer, TestDelta> attr = new AttributesFactory<Integer, TestDelta>();
            attr.setCloningEnabled(clone);
            PartitionAttributesFactory<Integer, TestDelta> paf = new PartitionAttributesFactory<Integer, TestDelta>();
            paf.setRedundantCopies(1);
            paf.setLocalMaxMemory(0);
            PartitionAttributes<Integer, TestDelta> prAttr = paf.create();
            attr.setPartitionAttributes(prAttr);
            attr.setDataPolicy(DataPolicy.PARTITION);
            attr.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.OVERFLOW_TO_DISK));
            Region<Integer, TestDelta> region = cache.createRegion("region1", attr.create());
            // Put an entry
            region.put(new Integer(0), new TestDelta(false, "initial"));
            // Put a delta object that is larger
            region.put(new Integer(0), new TestDelta(true, "initial_plus_some_more_data"));
        }
    };
    vm1.invoke(createEmptyRegion);
    vm0.invoke(new SerializableRunnable("doPut") {

        public void run() {
            Cache cache = getCache();
            Region<Integer, TestDelta> region = cache.getRegion("region1");
            // Evict the other object
            region.put(new Integer(113), new TestDelta(false, "bogus"));
            // Something was going weird with the LRU list. It was evicting this object.
            // I want to make sure the other object is the one evicted.
            region.get(new Integer(113));
            long entriesEvicted = ((AbstractLRURegionMap) ((PartitionedRegion) region).entries)._getLruList().stats().getEvictions();
            // assertIndexDetailsEquals(1, entriesEvicted);
            TestDelta result = region.get(new Integer(0));
            assertEquals("initial_plus_some_more_data", result.info);
        }
    });
}
Also used : PartitionAttributes(org.apache.geode.cache.PartitionAttributes) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) 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) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 95 with AttributesFactory

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

the class EvictionTestBase method createDistRegion.

public void createDistRegion() {
    final AttributesFactory factory = new AttributesFactory();
    factory.setOffHeap(getOffHeapEnabled());
    factory.setDataPolicy(DataPolicy.NORMAL);
    factory.setEvictionAttributes(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.LOCAL_DESTROY));
    DistributedRegion distRegion = (DistributedRegion) cache.createRegion("DR1", factory.create());
    assertNotNull(distRegion);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory)

Aggregations

AttributesFactory (org.apache.geode.cache.AttributesFactory)1156 Region (org.apache.geode.cache.Region)565 Test (org.junit.Test)550 RegionAttributes (org.apache.geode.cache.RegionAttributes)471 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)468 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)356 VM (org.apache.geode.test.dunit.VM)304 Host (org.apache.geode.test.dunit.Host)288 Properties (java.util.Properties)244 CacheException (org.apache.geode.cache.CacheException)243 Cache (org.apache.geode.cache.Cache)229 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)206 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)201 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)199 LocalRegion (org.apache.geode.internal.cache.LocalRegion)173 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)156 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)139 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)129 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)126 IgnoredException (org.apache.geode.test.dunit.IgnoredException)125