Search in sources :

Example 26 with RegionAttributes

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

the class ClearMultiVmDUnitTest method testClearSimpleScenarios.

// test methods
@Test
public void testClearSimpleScenarios() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // verifying Single VM clear functionalities
    vm0.invoke(new CacheSerializableRunnable("temp1") {

        public void run2() throws CacheException {
            region.put(new Integer(1), new String("first"));
            region.put(new Integer(2), new String("second"));
            region.put(new Integer(3), new String("third"));
            region.clear();
            assertEquals(0, region.size());
        }
    });
    vm1.invoke(new CacheSerializableRunnable("temp1vm1") {

        public void run2() throws CacheException {
            assertEquals(0, region.size());
        }
    });
    // verifying Single VM and single transaction clear functionalities
    vm1.invoke(new CacheSerializableRunnable("temp2") {

        public void run2() throws CacheException {
            try {
                region.put(new Integer(1), new String("first"));
                region.put(new Integer(2), new String("second"));
                region.put(new Integer(3), new String("third"));
                cacheTxnMgr = cache.getCacheTransactionManager();
                cacheTxnMgr.begin();
                region.put(new Integer(4), new String("forth"));
                try {
                    region.clear();
                    fail("expected exception not thrown");
                } catch (UnsupportedOperationInTransactionException e) {
                // expected
                }
                region.put(new Integer(5), new String("fifth"));
                cacheTxnMgr.commit();
                assertEquals(5, region.size());
                assertEquals("fifth", region.get(new Integer(5)).toString());
            } catch (CacheException ce) {
                ce.printStackTrace();
            } finally {
                if (cacheTxnMgr.exists()) {
                    try {
                        cacheTxnMgr.commit();
                    } catch (Exception cce) {
                        cce.printStackTrace();
                    }
                }
            }
        }
    });
    // verifying that region.clear does not clear the entries from sub region
    vm0.invoke(new CacheSerializableRunnable("temp3") {

        public void run2() throws CacheException {
            region.put(new Integer(1), new String("first"));
            region.put(new Integer(2), new String("second"));
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.DISTRIBUTED_ACK);
            RegionAttributes attr = factory.create();
            Region subRegion = region.createSubregion("subr", attr);
            subRegion.put(new Integer(3), new String("third"));
            subRegion.put(new Integer(4), new String("forth"));
            region.clear();
            assertEquals(0, region.size());
            assertEquals(2, subRegion.size());
        }
    });
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheException(org.apache.geode.cache.CacheException) RegionAttributes(org.apache.geode.cache.RegionAttributes) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) CacheException(org.apache.geode.cache.CacheException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 27 with RegionAttributes

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

the class ClearMultiVmDUnitTest method testGiiandClear.

// end of testClearExceptions
@Test
public void testGiiandClear() throws Throwable {
    if (false) {
        getSystem().getLogWriter().severe("testGiiandClear skipped because of bug 34963");
    } else {
        Host host = Host.getHost(0);
        VM vm0 = host.getVM(0);
        VM vm1 = host.getVM(1);
        SerializableRunnable create = new CacheSerializableRunnable("create mirrored region") {

            public void run2() throws CacheException {
                AttributesFactory factory1 = new AttributesFactory();
                factory1.setScope(Scope.DISTRIBUTED_ACK);
                factory1.setDataPolicy(DataPolicy.REPLICATE);
                RegionAttributes attr1 = factory1.create();
                mirroredRegion = cache.createRegion("mirrored", attr1);
                // reset slow
                org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
            }
        };
        vm0.invoke(create);
        vm0.invoke(new CacheSerializableRunnable("put initial data") {

            public void run2() throws CacheException {
                for (int i = 0; i < 1000; i++) {
                    mirroredRegion.put(new Integer(i), (new Integer(i)).toString());
                }
            }
        });
        // slow down image processing to make it more likely to get async updates
        vm1.invoke(new SerializableRunnable("set slow image processing") {

            public void run() {
                // if this is a no_ack test, then we need to slow down more because of the
                // pauses in the nonblocking operations
                int pause = 50;
                org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = pause;
            }
        });
        // now do the get initial image in vm1
        AsyncInvocation async1 = vm1.invokeAsync(create);
        // try to time a distributed clear to happen in the middle of gii
        vm0.invoke(new SerializableRunnable("call clear when gii") {

            public void run() {
                try {
                    Thread.sleep(3 * 1000);
                } catch (InterruptedException ex) {
                    fail("interrupted");
                }
                mirroredRegion.clear();
                assertEquals(0, mirroredRegion.size());
            }
        });
        ThreadUtils.join(async1, 30 * 1000);
        if (async1.exceptionOccurred()) {
            Assert.fail("async1 failed", async1.getException());
        }
        SerializableRunnable validate = new CacheSerializableRunnable("validate for region size") {

            public void run2() throws CacheException {
                assertEquals(0, mirroredRegion.size());
            }
        };
        vm0.invoke(validate);
        vm1.invoke(validate);
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 28 with RegionAttributes

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

the class CacheXml66DUnitTest method testDiskStoreInTemplates.

/**
   * Tests that a region created with a named attributes with diskstore
   */
@Test
public void testDiskStoreInTemplates() throws Exception {
    File dir = new File("west");
    dir.mkdir();
    dir.deleteOnExit();
    dir = new File("east");
    dir.mkdir();
    dir.deleteOnExit();
    setXmlFile(findFile("ewtest.xml"));
    String regionName_west = "orders/west";
    String regionName_east = "orders/east";
    Cache cache = getCache();
    // verify diskstores
    DiskStore ds = cache.findDiskStore("persistentDiskStore1");
    assertNotNull(ds);
    assertEquals(500, ds.getQueueSize());
    File[] dirs = ds.getDiskDirs();
    assertEquals("west", dirs[0].getPath());
    ds = cache.findDiskStore("persistentDiskStore2");
    assertNotNull(ds);
    assertEquals(500, ds.getQueueSize());
    dirs = ds.getDiskDirs();
    assertEquals("east", dirs[0].getPath());
    // verify templates
    assertNotNull(cache.getRegionAttributes("nack"));
    RegionAttributes attrs = cache.getRegionAttributes("persistent");
    assertEquals(DataPolicy.PERSISTENT_REPLICATE, attrs.getDataPolicy());
    assertEquals(false, attrs.isDiskSynchronous());
    assertEquals("persistentDiskStore1", attrs.getDiskStoreName());
    Region region = cache.getRegion(regionName_west);
    assertNotNull(region);
    attrs = region.getAttributes();
    assertEquals(DataPolicy.PERSISTENT_REPLICATE, attrs.getDataPolicy());
    assertEquals(false, attrs.isDiskSynchronous());
    assertEquals("persistentDiskStore1", attrs.getDiskStoreName());
    region = cache.getRegion(regionName_east);
    assertNotNull(region);
    // Make sure that attributes can be "overridden"
    attrs = region.getAttributes();
    assertEquals(DataPolicy.PERSISTENT_REPLICATE, attrs.getDataPolicy());
    assertEquals(false, attrs.isDiskSynchronous());
    assertEquals("persistentDiskStore2", attrs.getDiskStoreName());
    // bug 41934
    String regionName_datap = "data-p";
    region = cache.getRegion(regionName_datap);
    assertNotNull(region);
    attrs = region.getAttributes();
    PartitionAttributes pa = attrs.getPartitionAttributes();
    assertEquals(1, pa.getRedundantCopies());
    assertEquals(3, pa.getTotalNumBuckets());
    assertEquals(DataPolicy.PERSISTENT_PARTITION, attrs.getDataPolicy());
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) RegionAttributes(org.apache.geode.cache.RegionAttributes) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) FixedPartitionAttributes(org.apache.geode.cache.FixedPartitionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) File(java.io.File) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) Test(org.junit.Test)

Example 29 with RegionAttributes

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

the class RegionTestCase method testEntryIdleReset.

/**
   * Verify that accessing an entry resets its idle time
   * 
   * @throws Exception
   */
@Test
public void testEntryIdleReset() throws Exception {
    final String name = this.getUniqueName();
    // Test no longer waits for this timeout to expire
    // seconds
    final int timeout = 90;
    final String key = "KEY";
    final String value = "VALUE";
    AttributesFactory factory = new AttributesFactory(getRegionAttributes());
    ExpirationAttributes expire = new ExpirationAttributes(timeout, ExpirationAction.DESTROY);
    factory.setEntryIdleTimeout(expire);
    factory.setStatisticsEnabled(true);
    RegionAttributes attrs = factory.create();
    LocalRegion region = (LocalRegion) createRegion(name, attrs);
    region.create(key, null);
    EntryExpiryTask eet = region.getEntryExpiryTask(key);
    long createExpiryTime = eet.getExpirationTime();
    Wait.waitForExpiryClockToChange(region);
    // touch
    region.get(key);
    assertSame(eet, region.getEntryExpiryTask(key));
    long getExpiryTime = eet.getExpirationTime();
    if (getExpiryTime - createExpiryTime <= 0L) {
        fail("get did not reset the expiration time. createExpiryTime=" + createExpiryTime + " getExpiryTime=" + getExpiryTime);
    }
    Wait.waitForExpiryClockToChange(region);
    // touch
    region.put(key, value);
    assertSame(eet, region.getEntryExpiryTask(key));
    long putExpiryTime = eet.getExpirationTime();
    if (putExpiryTime - getExpiryTime <= 0L) {
        fail("put did not reset the expiration time. getExpiryTime=" + getExpiryTime + " putExpiryTime=" + putExpiryTime);
    }
    // TODO other ops that should be validated?
    // Now verify operations that do not modify the expiry time
    Wait.waitForExpiryClockToChange(region);
    // touch
    region.invalidate(key);
    assertSame(eet, region.getEntryExpiryTask(key));
    long invalidateExpiryTime = eet.getExpirationTime();
    if (region.getConcurrencyChecksEnabled()) {
        if (putExpiryTime - getExpiryTime <= 0L) {
            fail("invalidate did not reset the expiration time. putExpiryTime=" + putExpiryTime + " invalidateExpiryTime=" + invalidateExpiryTime);
        }
    } else {
        if (invalidateExpiryTime != putExpiryTime) {
            fail("invalidate did reset the expiration time. putExpiryTime=" + putExpiryTime + " invalidateExpiryTime=" + invalidateExpiryTime);
        }
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) EntryExpiryTask(org.apache.geode.internal.cache.EntryExpiryTask) RegionAttributes(org.apache.geode.cache.RegionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 30 with RegionAttributes

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

the class RegionTestCase method testEntryTtlDestroy.

/**
   * Tests that an entry in a region expires with a destroy after a given time to live.
   */
@Test
public void testEntryTtlDestroy() throws CacheException, InterruptedException {
    final String name = this.getUniqueName();
    // ms
    final int timeout = 20;
    final String key = "KEY";
    final String value = "VALUE";
    AttributesFactory factory = new AttributesFactory(getRegionAttributes());
    ExpirationAttributes expire = new ExpirationAttributes(timeout, ExpirationAction.DESTROY);
    factory.setEntryTimeToLive(expire);
    factory.setStatisticsEnabled(true);
    RegionAttributes attrs = factory.create();
    Region region = null;
    System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
    try {
        region = createRegion(name, attrs);
        ExpiryTask.suspendExpiration();
        Region.Entry entry = null;
        long tilt;
        try {
            region.put(key, value);
            tilt = System.currentTimeMillis();
            entry = region.getEntry(key);
            assertNotNull(entry.getValue());
        } finally {
            ExpiryTask.permitExpiration();
        }
        waitForDestroy(entry, tilt);
    } finally {
        System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Entry(org.apache.geode.cache.Region.Entry) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

RegionAttributes (org.apache.geode.cache.RegionAttributes)590 AttributesFactory (org.apache.geode.cache.AttributesFactory)471 Region (org.apache.geode.cache.Region)256 Test (org.junit.Test)251 Properties (java.util.Properties)158 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)128 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)126 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)118 LocalRegion (org.apache.geode.internal.cache.LocalRegion)112 Cache (org.apache.geode.cache.Cache)99 VM (org.apache.geode.test.dunit.VM)93 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)93 Host (org.apache.geode.test.dunit.Host)89 HashSet (java.util.HashSet)80 CacheException (org.apache.geode.cache.CacheException)65 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)62 CacheServer (org.apache.geode.cache.server.CacheServer)60 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)59 ArrayList (java.util.ArrayList)57 PartitionAttributesImpl (org.apache.geode.internal.cache.PartitionAttributesImpl)56