Search in sources :

Example 46 with PartitionAttributesFactory

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

the class Bug43684DUnitTest method createServerCache.

@SuppressWarnings("rawtypes")
public static Integer createServerCache(Boolean isReplicated, Boolean isPrimaryEmpty) throws Exception {
    disconnectFromDS();
    Properties props = new Properties();
    props.setProperty(LOCATORS, "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]");
    props.setProperty(STATISTIC_ARCHIVE_FILE, "server_" + OSProcess.getId() + ".gfs");
    props.setProperty(STATISTIC_SAMPLING_ENABLED, "true");
    CacheFactory cf = new CacheFactory(props);
    cache = (GemFireCacheImpl) cf.create();
    RegionFactory rf;
    if (isReplicated) {
        RegionShortcut rs = isPrimaryEmpty ? RegionShortcut.REPLICATE_PROXY : RegionShortcut.REPLICATE;
        rf = cache.createRegionFactory(rs);
    } else {
        RegionShortcut rs = isPrimaryEmpty ? RegionShortcut.PARTITION_PROXY : RegionShortcut.PARTITION;
        rf = cache.createRegionFactory(rs);
        rf.setPartitionAttributes(new PartitionAttributesFactory().setTotalNumBuckets(numBuckets).create());
    }
    rf.create(REGION_NAME);
    CacheServerImpl server = (CacheServerImpl) cache.addCacheServer();
    server.setPort(AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET));
    server.start();
    return server.getPort();
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionFactory(org.apache.geode.cache.RegionFactory) ClientRegionFactory(org.apache.geode.cache.client.ClientRegionFactory) RegionShortcut(org.apache.geode.cache.RegionShortcut) ClientRegionShortcut(org.apache.geode.cache.client.ClientRegionShortcut) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 47 with PartitionAttributesFactory

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

the class ShutdownAllDUnitTest method getCreatePRRunnable.

private SerializableRunnable getCreatePRRunnable(final String regionName, final String diskStoreName, final int redundancy) {
    return new SerializableRunnable("create pr") {

        @Override
        public void run() {
            final CountDownLatch recoveryDone;
            if (redundancy > 0) {
                recoveryDone = new CountDownLatch(1);
                ResourceObserver observer = new InternalResourceManager.ResourceObserverAdapter() {

                    @Override
                    public void recoveryFinished(Region region) {
                        recoveryDone.countDown();
                    }
                };
                InternalResourceManager.setResourceObserver(observer);
            } else {
                recoveryDone = null;
            }
            Cache cache = ShutdownAllDUnitTest.this.getCache();
            if (diskStoreName != null) {
                DiskStore ds = cache.findDiskStore(diskStoreName);
                if (ds == null) {
                    ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create(diskStoreName);
                }
            }
            AttributesFactory af = new AttributesFactory();
            // use async to trigger flush
            af.setDiskSynchronous(false);
            af.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK));
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(redundancy);
            af.setPartitionAttributes(paf.create());
            if (diskStoreName != null) {
                af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
                af.setDiskStoreName(diskStoreName);
            } else {
                af.setDataPolicy(DataPolicy.PARTITION);
            }
            cache.createRegion(regionName, af.create());
            if (recoveryDone != null) {
                try {
                    recoveryDone.await();
                } catch (InterruptedException e) {
                    Assert.fail("Interrupted", e);
                }
            }
        }
    };
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) DiskRegion(org.apache.geode.internal.cache.DiskRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) CountDownLatch(java.util.concurrent.CountDownLatch) ResourceObserver(org.apache.geode.internal.cache.control.InternalResourceManager.ResourceObserver) InternalCache(org.apache.geode.internal.cache.InternalCache) Cache(org.apache.geode.cache.Cache)

Example 48 with PartitionAttributesFactory

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

the class PersistentPartitionedRegionOldConfigDUnitTest method getPersistentPRAttributes.

@Override
protected RegionAttributes getPersistentPRAttributes(final int redundancy, final int recoveryDelay, Cache cache, int numBuckets, boolean synchronous) {
    AttributesFactory af = new AttributesFactory();
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(redundancy);
    paf.setRecoveryDelay(recoveryDelay);
    paf.setTotalNumBuckets(numBuckets);
    af.setPartitionAttributes(paf.create());
    af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
    af.setDiskDirs(getDiskDirs());
    RegionAttributes attr = af.create();
    return attr;
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes)

Example 49 with PartitionAttributesFactory

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

the class PersistentPartitionedRegionTestBase method getPersistentPRAttributes.

protected RegionAttributes getPersistentPRAttributes(final int redundancy, final int recoveryDelay, Cache cache, int numBuckets, boolean synchronous) {
    DiskStore ds = cache.findDiskStore("disk");
    if (ds == null) {
        ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
    }
    AttributesFactory af = new AttributesFactory();
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(redundancy);
    paf.setRecoveryDelay(recoveryDelay);
    paf.setTotalNumBuckets(numBuckets);
    // Make sure all vms end up with the same local max memory
    paf.setLocalMaxMemory(500);
    af.setPartitionAttributes(paf.create());
    af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
    af.setDiskStoreName("disk");
    af.setDiskSynchronous(synchronous);
    RegionAttributes attr = af.create();
    return attr;
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes)

Example 50 with PartitionAttributesFactory

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

the class ClientServerForceInvalidateDUnitTest method createServerCache.

private static Integer createServerCache(Boolean concurrencyChecksEnabled, Boolean partitioned, Integer maxThreads) throws Exception {
    AbstractRegionMap.FORCE_INVALIDATE_EVENT = true;
    Properties props = new Properties();
    Cache cache = new ClientServerForceInvalidateDUnitTest().createCacheV(props);
    RegionFactory<String, String> factory = cache.createRegionFactory();
    if (partitioned) {
        factory.setDataPolicy(DataPolicy.PARTITION);
        factory.setPartitionAttributes(new PartitionAttributesFactory<String, String>().setRedundantCopies(0).setTotalNumBuckets(251).create());
    } else {
        factory.setDataPolicy(DataPolicy.REPLICATE);
    }
    factory.setConcurrencyChecksEnabled(concurrencyChecksEnabled);
    factory.addCacheListener(new ServerListener());
    Region<String, String> r1 = factory.create(REGION_NAME1);
    assertNotNull(r1);
    CacheServer server = cache.addCacheServer();
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    logger.info("Starting server on port " + port);
    server.setPort(port);
    server.setMaxThreads(maxThreads.intValue());
    server.start();
    logger.info("Started server on port " + server.getPort());
    return new Integer(server.getPort());
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheServer(org.apache.geode.cache.server.CacheServer) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Cache(org.apache.geode.cache.Cache)

Aggregations

PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)340 AttributesFactory (org.apache.geode.cache.AttributesFactory)289 Region (org.apache.geode.cache.Region)173 Test (org.junit.Test)154 Cache (org.apache.geode.cache.Cache)136 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)116 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)112 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)110 VM (org.apache.geode.test.dunit.VM)101 Host (org.apache.geode.test.dunit.Host)99 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)95 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)75 CacheException (org.apache.geode.cache.CacheException)58 LocalRegion (org.apache.geode.internal.cache.LocalRegion)48 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)47 IOException (java.io.IOException)42 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)42 DiskStore (org.apache.geode.cache.DiskStore)41 RegionAttributes (org.apache.geode.cache.RegionAttributes)41 BucketRegion (org.apache.geode.internal.cache.BucketRegion)35