Search in sources :

Example 71 with RegionFactory

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

the class DistrbutedRegionProfileOffHeapDUnitTest method testPartitionedRegionProfileWithConflict.

/**
   * Asserts that creating a region on two members, with one member having the region as on-heap and
   * the other as having the region as off-heap, will cause an exception and the region will not be
   * created.
   */
@Test
public void testPartitionedRegionProfileWithConflict() throws Exception {
    final String regionName = getTestMethodName() + "Region";
    Host.getHost(0).getVM(0).invoke(new CacheSerializableRunnable("createRegionNoException") {

        private static final long serialVersionUID = 1L;

        @Override
        public void run2() throws CacheException {
            disconnectFromDS();
            Properties properties = new Properties();
            properties.put(OFF_HEAP_MEMORY_SIZE, "2m");
            getSystem(properties);
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
            regionFactory.setOffHeap(true);
            Region region = regionFactory.create(regionName);
            assertNotNull("Region is null", region);
            assertNotNull("Cache does not contain region", cache.getRegion(regionName));
        }
    });
    Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("createRegionException") {

        private static final long serialVersionUID = 1L;

        @SuppressWarnings("synthetic-access")
        @Override
        public void run2() throws CacheException {
            disconnectFromDS();
            final GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            final RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
            Region region = null;
            try {
                IgnoredException.addIgnoredException("IllegalStateException");
                region = regionFactory.create(regionName);
                fail("Expected exception upon creation with invalid off-heap state");
            } catch (IllegalStateException expected) {
            // An exception is expected.
            } finally {
                removeExceptionTag1("IllegalStateException");
            }
            assertNull("Region is not null", region);
            assertNull("Cache contains region", cache.getRegion(regionName));
        }
    });
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) RegionFactory(org.apache.geode.cache.RegionFactory) CacheException(org.apache.geode.cache.CacheException) Region(org.apache.geode.cache.Region) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 72 with RegionFactory

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

the class RemoteTransactionDUnitTest method testExpirySuspend_bug45984.

@Test
public void testExpirySuspend_bug45984() {
    Host host = Host.getHost(0);
    VM vm1 = host.getVM(0);
    VM vm2 = host.getVM(1);
    final String regionName = getName();
    // create region with expiration
    vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
            try {
                RegionFactory<String, String> rf = getCache().createRegionFactory();
                rf.setEntryTimeToLive(new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
                rf.setScope(Scope.DISTRIBUTED_ACK);
                rf.create(regionName);
            } finally {
                System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
            }
            return null;
        }
    });
    // create replicate region
    vm2.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
            return null;
        }
    });
    vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            final Region<String, String> r = getCache().getRegion(regionName);
            WaitCriterion wc2 = new WaitCriterion() {

                @Override
                public boolean done() {
                    return !r.containsKey("key") && !r.containsKey("nonTXKey");
                }

                @Override
                public String description() {
                    return "did not expire containsKey(key)=" + r.containsKey("key") + " r.containsKey(nonTXKey)=" + r.containsKey("nonTXKey");
                }
            };
            ExpiryTask.suspendExpiration();
            Region.Entry entry = null;
            long tilt;
            try {
                r.put("key", "value");
                LocalRegion lr = (LocalRegion) r;
                r.put("nonTXkey", "nonTXvalue");
                getCache().getCacheTransactionManager().begin();
                r.put("key", "newvalue");
                TXExpiryJUnitTest.waitForEntryExpiration(lr, "key");
            } finally {
                ExpiryTask.permitExpiration();
            }
            TransactionId tx = getCache().getCacheTransactionManager().suspend();
            // A remote tx will allow expiration to happen on the side that
            // is not hosting the tx. But it will not allow an expiration
            // initiated on the hosting jvm.
            // tx is hosted in vm2 so expiration can happen in vm1.
            Wait.waitForCriterion(wc2, 30000, 5, true);
            getCache().getCacheTransactionManager().resume(tx);
            assertTrue(r.containsKey("key"));
            getCache().getCacheTransactionManager().commit();
            Wait.waitForCriterion(wc2, 30000, 5, true);
            return null;
        }
    });
}
Also used : Host(org.apache.geode.test.dunit.Host) NamingException(javax.naming.NamingException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) RollbackException(javax.transaction.RollbackException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) CommitConflictException(org.apache.geode.cache.CommitConflictException) TransactionId(org.apache.geode.cache.TransactionId) Entry(org.apache.geode.cache.Region.Entry) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ClientRegionFactory(org.apache.geode.cache.client.ClientRegionFactory) RegionFactory(org.apache.geode.cache.RegionFactory) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 73 with RegionFactory

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

the class PersistentPartitionedRegionDUnitTest method testOverflowCacheClose.

/**
   * This test is in here just to test to make sure that we don't get a suspect string with an
   * exception during cache closure.
   */
@Test
public void testOverflowCacheClose() {
    Cache cache = getCache();
    RegionFactory rf = new RegionFactory();
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    rf.setPartitionAttributes(paf.create());
    rf.setDataPolicy(DataPolicy.PARTITION);
    rf.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(50, EvictionAction.OVERFLOW_TO_DISK));
    rf.setDiskDirs(getDiskDirs());
    Region region = rf.create(PR_REGION_NAME);
    region.get(0);
    cache.getDistributedSystem().disconnect();
// cache.close();
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionFactory(org.apache.geode.cache.RegionFactory) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 74 with RegionFactory

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

the class CliUtilDUnitTest method createRegion.

@SuppressWarnings("rawtypes")
private Region createRegion(String regionName) {
    RegionFactory regionFactory = getCache().createRegionFactory(RegionShortcut.REPLICATE);
    Region region = regionFactory.create(regionName);
    final ManagementService service = ManagementService.getManagementService(getCache());
    assertNotNull(service.getMemberMXBean());
    RegionMXBean bean = service.getLocalRegionMBean(Region.SEPARATOR + regionName);
    assertNotNull(bean);
    LogWriterUtils.getLogWriter().info("Created region=" + regionName + " Bean=" + bean);
    return region;
}
Also used : ManagementService(org.apache.geode.management.ManagementService) DistributedRegionMXBean(org.apache.geode.management.DistributedRegionMXBean) RegionMXBean(org.apache.geode.management.RegionMXBean) RegionFactory(org.apache.geode.cache.RegionFactory) Region(org.apache.geode.cache.Region)

Example 75 with RegionFactory

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

the class MyGatewayEventSubstitutionFilter method createReplicatedRegionWithCacheLoaderAndAsyncEventQueue.

public static void createReplicatedRegionWithCacheLoaderAndAsyncEventQueue(String regionName, String asyncQueueIds) {
    AttributesFactory fact = new AttributesFactory();
    addAsyncEventQueueIds(fact, asyncQueueIds);
    fact.setDataPolicy(DataPolicy.REPLICATE);
    // set the CacheLoader
    fact.setCacheLoader(new MyCacheLoader());
    RegionFactory regionFactory = cache.createRegionFactory(fact.create());
    Region r = regionFactory.create(regionName);
    assertNotNull(r);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) RegionFactory(org.apache.geode.cache.RegionFactory) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region)

Aggregations

RegionFactory (org.apache.geode.cache.RegionFactory)124 Region (org.apache.geode.cache.Region)63 Cache (org.apache.geode.cache.Cache)57 Test (org.junit.Test)54 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)51 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)44 VM (org.apache.geode.test.dunit.VM)44 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)31 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)31 CacheException (org.apache.geode.cache.CacheException)30 Host (org.apache.geode.test.dunit.Host)28 Properties (java.util.Properties)25 DiskStoreFactory (org.apache.geode.cache.DiskStoreFactory)22 File (java.io.File)21 DiskStore (org.apache.geode.cache.DiskStore)20 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)20 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)20 AttributesFactory (org.apache.geode.cache.AttributesFactory)18 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)17 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)17