http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb91dedc/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegRecoveryJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegRecoveryJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegRecoveryJUnitTest.java index e4aa706..391aed0 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegRecoveryJUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegRecoveryJUnitTest.java @@ -16,6 +16,8 @@ */ package com.gemstone.gemfire.internal.cache; +import static org.junit.Assert.*; + import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.File; @@ -25,13 +27,9 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.Arrays; -import org.junit.After; -import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; -import static org.junit.Assert.*; - import com.gemstone.gemfire.cache.DiskStore; import com.gemstone.gemfire.cache.EntryNotFoundException; import com.gemstone.gemfire.cache.Region; @@ -45,33 +43,24 @@ import com.gemstone.gemfire.test.junit.categories.IntegrationTest; * @since 5.1 */ @Category(IntegrationTest.class) -public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase -{ - DiskRegionProperties diskProps = new DiskRegionProperties(); - - private static int EMPTY_RVV_SIZE = 6; - -// private static final boolean debug = false; - - @Before - public void setUp() throws Exception - { - super.setUp(); - diskProps.setDiskDirs(dirs); - } - - @After - public void tearDown() throws Exception - { - super.tearDown(); - } +public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase { + private static int EMPTY_RVV_SIZE = 6; private static int ENTRY_SIZE = 1024; private static boolean oplogsIDsNotifiedToRoll; + + private boolean proceedWithRolling; + private boolean rollingDone; + private boolean verifiedOplogs; + private final Object verifiedSync = new Object(); + + private DiskRegionProperties diskProps = new DiskRegionProperties(); - boolean proceedWithRolling, rollingDone, verifiedOplogs; - final Object verifiedSync = new Object(); + @Override + protected final void postSetUp() throws Exception { + diskProps.setDiskDirs(dirs); + } /** * Disk region recovery test for Persist only with sync writes. Test has four @@ -82,11 +71,9 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase * 1. Get and verify the entries put in STEP 1 and STEP 2. STEP 4: Create * cache. Create Region with the same name as that of in STEP 1. Get and * verify the entries put in STEP 1 and STEP 2. - * */ @Test - public void testDiskRegRecovery() - { + public void testDiskRegRecovery() { /** * STEP 1 */ @@ -310,21 +297,18 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase getByteArrValZeroLnth("119", region); closeDown(); // closes disk file which will flush all buffers - } -/** + /** * Disk region recovery test for Persist only with sync writes. Test has four * steps : STEP 1: Create cache. Create Region. Put entries. Close cache. STEP * 2: Create cache. Create Region with the same name as that of in STEP 1. Delete some entries. * Close the Cache * * 3: Again Create cache. Create Region with the same name as that of in STEP * 4) Verify that the entries got deleted - * */ @Test - public void testBug39989_1() - { + public void testBug39989_1() { /** * STEP 1 */ @@ -409,9 +393,7 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase } closeDown(); // closes disk file which will flush all buffers - } - /** * Disk region recovery test for Persist only with sync writes. Test has four @@ -421,11 +403,9 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase * Close the Cache * * 3: Again Create cache. * 4) check if the region creation is successful - * */ @Test - public void testBug39989_2() - { + public void testBug39989_2() { /** * STEP 1 */ @@ -516,16 +496,12 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase } closeDown(); // closes disk file which will flush all buffers - } /** * To validate the get operation performed on a byte array. - * */ - - private void getByteArrVal(String key, Region region) - { + private void getByteArrVal(String key, Region region) { byte[] val = (byte[])region.get(key); //verify that the retrieved byte[] equals to the value put initially. // val should be an unitialized array of bytes of length 1024 @@ -537,10 +513,8 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase /** * to validate the get operation performed on a byte array of length zero - * */ - private boolean getByteArrValZeroLnth(String key, Region region) - { + private boolean getByteArrValZeroLnth(String key, Region region) { Object val0 = null; byte[] val2 = new byte[0]; try { @@ -567,14 +541,12 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase return result; } - public void verifyOplogSizeZeroAfterRecovery(Region region) - { + private void verifyOplogSizeZeroAfterRecovery(Region region) { assertEquals(Oplog.OPLOG_MAGIC_SEQ_REC_SIZE*2 + Oplog.OPLOG_DISK_STORE_REC_SIZE*2 + EMPTY_RVV_SIZE + Oplog.OPLOG_GEMFIRE_VERSION_REC_SIZE*2, ((LocalRegion)region).getDiskRegion().testHook_getChild().getOplogSize()); } @Test - public void testNoEvictionDuringRecoveryIfNoGIIRecoverValuesTrue() - { + public void testNoEvictionDuringRecoveryIfNoGIIRecoverValuesTrue() { String oldValue = System.getProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME); System.setProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME, "true"); try { @@ -628,8 +600,7 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase } @Test - public void testNoEvictionDuringRecoveryIfNoGIIRecoverValuesFalse() - { + public void testNoEvictionDuringRecoveryIfNoGIIRecoverValuesFalse() { String oldValue = System.getProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME); System.setProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME, "false"); try { @@ -688,8 +659,7 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase } @Test - public void testEmptyRegionRecover() - { + public void testEmptyRegionRecover() { diskProps.setDiskDirs(dirs); region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL); Assert.assertTrue(region.size() == 0); @@ -714,8 +684,7 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase } @Test - public void testReadCorruptedFile() - { + public void testReadCorruptedFile() { diskProps.setDiskDirs(dirs); region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL); @@ -765,8 +734,7 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase } @Test - public void testForceCompactionForRegionWithRollingDisabled() - throws Exception { + public void testForceCompactionForRegionWithRollingDisabled() throws Exception { diskProps.setDiskDirs(dirs); diskProps.setMaxOplogSize(2048+(18*2)+15*7); diskProps.setRolling(false); @@ -837,12 +805,9 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase * leaves it in created set & so when the compactor processes the created Set it * thinks that the entry is now referenced in the any of the subsequent oplogs & thus * overwrites it with a byte[]. - * @throws Exception */ - @Test - public void testVestigialCreatesInOplog() throws Exception - { + public void testVestigialCreatesInOplog() throws Exception { diskProps.setDiskDirs(dirs); diskProps.setMaxOplogSize(40); diskProps.setPersistBackup(true); @@ -907,9 +872,7 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase } @Test - public void testDiskIDFieldsForPersistOnlyRecoverValuesTrue() - throws Exception - { + public void testDiskIDFieldsForPersistOnlyRecoverValuesTrue() throws Exception { String oldValue = System.getProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME); System.setProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME, "true"); try { @@ -985,13 +948,10 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase System.clearProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME); } } - } @Test - public void testDiskIDFieldsForPersistOverFlowRecoverValuesTrue() - throws Exception - { + public void testDiskIDFieldsForPersistOverFlowRecoverValuesTrue() throws Exception { String oldValue = System.getProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME); System.setProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME, "true"); try { @@ -1067,8 +1027,7 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase } @Test - public void testDiskIDFieldsForPersistOnlyRecoverValuesFalse() - throws Exception { + public void testDiskIDFieldsForPersistOnlyRecoverValuesFalse() throws Exception { String oldValue = System.getProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME); System.setProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME, "false"); try { @@ -1145,8 +1104,7 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase } @Test - public void testDiskIDFieldsForPersistOverFlowRecoverValuesFalse() - throws Exception { + public void testDiskIDFieldsForPersistOverFlowRecoverValuesFalse() throws Exception { String oldValue = System.getProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME); System.setProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME, "false"); try { @@ -1224,7 +1182,7 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase @Test public void testBug40375() throws Exception { - try { + try { diskProps.setDiskDirs(dirs); diskProps.setPersistBackup(true); diskProps.setSynchronous(true); @@ -1249,66 +1207,65 @@ public class DiskRegRecoveryJUnitTest extends DiskRegionTestingBase region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL); assertEquals(4, region.size()); region.close(); - }finally { - + } finally { System.setProperty(DiskStoreImpl.COMPLETE_COMPACTION_BEFORE_TERMINATION_PROPERTY_NAME,""); - } + } } @Test public void testBug41340() throws Exception { - diskProps.setDiskDirs(dirs); - diskProps.setPersistBackup(true); - diskProps.setSynchronous(true); - diskProps.setRolling(true); - diskProps.setRegionName("testBug41340"); - region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL); - assertEquals(0, region.size()); - //put some entries - region.put("0","0"); - region.put("1","1"); - region.put("2","2"); - region.put("3","3"); - - - //Create another oplog - DiskStore store = cache.findDiskStore(region.getAttributes().getDiskStoreName()); - store.forceRoll(); - - //Now create and destroy all of the entries in the new - //oplog. This should cause us to remove the CRF but leave - //the DRF, which has creates in reverse order. Now we have - //garbage destroys which have higher IDs than any crate - region.put("4","1"); - region.put("5","2"); - region.put("6","3"); - region.destroy("0"); - region.destroy("6"); - region.destroy("5"); - region.destroy("4"); - - store.forceRoll(); - - //Force a recovery - GemFireCacheImpl.getInstance().close(); - cache = createCache(); - region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL); - assertEquals(3, region.size()); - - //With bug 41340, this is reusing an oplog id. - region.put("7","7"); + diskProps.setDiskDirs(dirs); + diskProps.setPersistBackup(true); + diskProps.setSynchronous(true); + diskProps.setRolling(true); + diskProps.setRegionName("testBug41340"); + region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL); + assertEquals(0, region.size()); + //put some entries + region.put("0","0"); + region.put("1","1"); + region.put("2","2"); + region.put("3","3"); + + + //Create another oplog + DiskStore store = cache.findDiskStore(region.getAttributes().getDiskStoreName()); + store.forceRoll(); + + //Now create and destroy all of the entries in the new + //oplog. This should cause us to remove the CRF but leave + //the DRF, which has creates in reverse order. Now we have + //garbage destroys which have higher IDs than any crate + region.put("4","1"); + region.put("5","2"); + region.put("6","3"); + region.destroy("0"); + region.destroy("6"); + region.destroy("5"); + region.destroy("4"); + + store.forceRoll(); + + //Force a recovery + GemFireCacheImpl.getInstance().close(); + cache = createCache(); + region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL); + assertEquals(3, region.size()); + + //With bug 41340, this is reusing an oplog id. + region.put("7","7"); // region.close(); - - //Force another recovery - GemFireCacheImpl.getInstance().close(); - cache = createCache(); - region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL); - - //Make sure we didn't lose the entry - assertEquals(4, region.size()); - assertEquals("7", region.get("7")); - region.close(); - } + + //Force another recovery + GemFireCacheImpl.getInstance().close(); + cache = createCache(); + region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL); + + //Make sure we didn't lose the entry + assertEquals(4, region.size()); + assertEquals("7", region.get("7")); + region.close(); + } @Test public void testRecoverValuesFalse() {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb91dedc/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionAsyncRecoveryJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionAsyncRecoveryJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionAsyncRecoveryJUnitTest.java index 350a588..84c8500 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionAsyncRecoveryJUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionAsyncRecoveryJUnitTest.java @@ -16,10 +16,7 @@ */ package com.gemstone.gemfire.internal.cache; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import java.io.File; import java.io.IOException; @@ -28,7 +25,6 @@ import java.util.Set; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.junit.After; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -37,15 +33,11 @@ import com.gemstone.gemfire.cache.Region; import com.gemstone.gemfire.internal.FileUtil; import com.gemstone.gemfire.test.junit.categories.IntegrationTest; -/** - * - */ @Category(IntegrationTest.class) public class DiskRegionAsyncRecoveryJUnitTest extends DiskRegionTestingBase { - @After - public void tearDown() throws Exception { - super.tearDown(); + @Override + protected final void postTearDown() throws Exception { DiskStoreObserver.setInstance(null); System.setProperty(DiskStoreImpl.RECOVER_VALUE_PROPERTY_NAME, "true"); System.setProperty(DiskStoreImpl.RECOVER_VALUES_SYNC_PROPERTY_NAME, "false"); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb91dedc/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionChangingRegionAttributesJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionChangingRegionAttributesJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionChangingRegionAttributesJUnitTest.java index 07bd273..51352d1 100755 --- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionChangingRegionAttributesJUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionChangingRegionAttributesJUnitTest.java @@ -16,11 +16,8 @@ */ package com.gemstone.gemfire.internal.cache; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; -import org.junit.After; -import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -32,47 +29,33 @@ import com.gemstone.gemfire.test.junit.categories.IntegrationTest; * if the the region attributes are changed after starting it again. * * The behaviour should be predictable - * - * */ @Category(IntegrationTest.class) -public class DiskRegionChangingRegionAttributesJUnitTest extends - DiskRegionTestingBase -{ +public class DiskRegionChangingRegionAttributesJUnitTest extends DiskRegionTestingBase { + + private DiskRegionProperties props; - @Before - public void setUp() throws Exception - { - super.setUp(); + @Override + protected final void postSetUp() throws Exception { props = new DiskRegionProperties(); props.setDiskDirs(dirs); - - } - - @After - public void tearDown() throws Exception - { - super.tearDown(); } - - private DiskRegionProperties props; - - private void createOverflowOnly(){ + private void createOverflowOnly() { props.setOverFlowCapacity(1); region = DiskRegionHelperFactory.getSyncOverFlowOnlyRegion(cache,props); } - private void createPersistOnly(){ + private void createPersistOnly() { region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache,props, Scope.LOCAL); } - private void createPersistAndOverflow(){ + private void createPersistAndOverflow() { region = DiskRegionHelperFactory.getSyncOverFlowAndPersistRegion(cache,props); } @Test - public void testOverflowOnlyAndThenPersistOnly(){ + public void testOverflowOnlyAndThenPersistOnly() { createOverflowOnly(); put100Int(); region.close(); @@ -81,7 +64,7 @@ public class DiskRegionChangingRegionAttributesJUnitTest extends } @Test - public void testPersistOnlyAndThenOverflowOnly(){ + public void testPersistOnlyAndThenOverflowOnly() { createPersistOnly(); put100Int(); region.close(); @@ -97,7 +80,7 @@ public class DiskRegionChangingRegionAttributesJUnitTest extends } @Test - public void testOverflowOnlyAndThenPeristAndOverflow(){ + public void testOverflowOnlyAndThenPeristAndOverflow() { createOverflowOnly(); put100Int(); region.close(); @@ -106,7 +89,7 @@ public class DiskRegionChangingRegionAttributesJUnitTest extends } @Test - public void testPersistAndOverflowAndThenOverflowOnly(){ + public void testPersistAndOverflowAndThenOverflowOnly() { createPersistAndOverflow(); put100Int(); region.close(); @@ -119,7 +102,7 @@ public class DiskRegionChangingRegionAttributesJUnitTest extends } @Test - public void testPersistOnlyAndThenPeristAndOverflow(){ + public void testPersistOnlyAndThenPeristAndOverflow() { createPersistOnly(); put100Int(); region.close(); @@ -128,15 +111,11 @@ public class DiskRegionChangingRegionAttributesJUnitTest extends } @Test - public void testPersistAndOverflowAndThenPersistOnly(){ + public void testPersistAndOverflowAndThenPersistOnly() { createPersistAndOverflow(); put100Int(); region.close(); createPersistOnly(); assertTrue(region.size()==100); } - - - } - http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb91dedc/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionJUnitTest.java index 4d88f43..009e4df 100755 --- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionJUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionJUnitTest.java @@ -16,25 +16,23 @@ */ package com.gemstone.gemfire.internal.cache; +import static org.junit.Assert.*; + import java.io.File; import java.lang.reflect.Array; import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicReference; +import junit.framework.Assert; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; -import static org.junit.Assert.*; -import junit.framework.Assert; - import com.gemstone.gemfire.SystemFailure; import com.gemstone.gemfire.cache.DiskAccessException; import com.gemstone.gemfire.cache.DiskStore; @@ -55,44 +53,71 @@ import com.gemstone.gemfire.test.junit.categories.IntegrationTest; /** * TODO: fails when running integrationTest from gradle command-line on Windows 7 * -com.gemstone.gemfire.internal.cache.DiskRegionJUnitTest > testAssertionErrorIfMissingOplog FAILED - junit.framework.AssertionFailedError - at junit.framework.Assert.fail(Assert.java:55) - at junit.framework.Assert.assertTrue(Assert.java:22) - at junit.framework.Assert.assertTrue(Assert.java:31) - at com.gemstone.gemfire.internal.cache.DiskRegionJUnitTest.testAssertionErrorIfMissingOplog(DiskRegionJUnitTest.java:2630) - * * JUnit tests covering some miscellaneous functionalites of Disk Region. */ @Category(IntegrationTest.class) -public class DiskRegionJUnitTest extends DiskRegionTestingBase -{ - DiskRegionProperties diskProps = new DiskRegionProperties(); - - @Before - public void setUp() throws Exception - { - super.setUp(); +public class DiskRegionJUnitTest extends DiskRegionTestingBase { + + private static volatile boolean hasNotified = false; + private static volatile boolean putsHaveStarted = false; + + private volatile boolean exceptionOccured = false; + private volatile boolean finished = false; + + private DiskRegionProperties diskProps = new DiskRegionProperties(); + + private DiskRegionProperties diskProps1 = new DiskRegionProperties(); + private DiskRegionProperties diskProps2 = new DiskRegionProperties(); + private DiskRegionProperties diskProps3 = new DiskRegionProperties(); + private DiskRegionProperties diskProps4 = new DiskRegionProperties(); + private DiskRegionProperties diskProps5 = new DiskRegionProperties(); + private DiskRegionProperties diskProps6 = new DiskRegionProperties(); + private DiskRegionProperties diskProps7 = new DiskRegionProperties(); + private DiskRegionProperties diskProps8 = new DiskRegionProperties(); + private DiskRegionProperties diskProps9 = new DiskRegionProperties(); + private DiskRegionProperties diskProps10 = new DiskRegionProperties(); + private DiskRegionProperties diskProps11 = new DiskRegionProperties(); + private DiskRegionProperties diskProps12 = new DiskRegionProperties(); + + private Region region1; + private Region region2; + private Region region3; + private Region region4; + private Region region5; + private Region region6; + private Region region7; + private Region region8; + private Region region9; + private Region region10; + private Region region11; + private Region region12; + + private boolean failed = false; + + private int counter = 0; + private boolean hasBeenNotified = false; + + @Override + protected final void postSetUp() throws Exception { this.exceptionOccured = false; DiskStoreImpl.SET_IGNORE_PREALLOCATE = true; } - @After - public void tearDown() throws Exception - { - super.tearDown(); + @Override + protected final void postTearDown() throws Exception { DiskStoreImpl.SET_IGNORE_PREALLOCATE = false; } private static class MyCL extends CacheListenerAdapter { public EntryEvent lastEvent; + @Override public void afterDestroy(EntryEvent event) { this.lastEvent = event; } } @Test - public void testRemoveCorrectlyRecorded() { + public void testRemoveCorrectlyRecorded() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setOverflow(true); props.setOverFlowCapacity(1); @@ -105,12 +130,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase MyCL cacheListener = new MyCL(); region.getAttributesMutator().addCacheListener(cacheListener); - try { - region.destroy("1"); - } - catch (Exception e) { - fail("Exception not expected but did occur due to "+e); - } + region.destroy("1"); // Make sure we don't get an old value when doing a destroy // of an entry that overflowed to disk. @@ -131,7 +151,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase exceptionOccured = true; } - if(!exceptionOccured){ + if (!exceptionOccured){ fail("exception did not occur although was supposed to occur"); } @@ -140,20 +160,14 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase Assert.assertTrue(region.get("1")==null); region.destroyRegion(); - } - - - + /** * Tests if region overflows correctly and stats are create and updated * correctly. - * */ @Test - public void testDiskRegionOverflow() - { - + public void testDiskRegionOverflow() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setOverflow(true); props.setOverFlowCapacity(100); @@ -210,8 +224,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase } } - public void assertArrayEquals(Object expected, Object v) - { + private void assertArrayEquals(Object expected, Object v) { assertEquals(expected.getClass(), v.getClass()); int vLength = Array.getLength(v); assertEquals(Array.getLength(expected), vLength); @@ -223,12 +236,9 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase /** * test method for putting different objects and validating that they have * been correctly put - * */ @Test - public void testDifferentObjectTypePuts() - { - + public void testDifferentObjectTypePuts() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setOverflow(true); props.setOverFlowCapacity(100); @@ -244,33 +254,29 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase region.put(s, s); } region.put("foobar", "junk"); - try { - region.localDestroy("foobar"); - - region.put("foobar2", "junk"); - dr.flushForTesting(); - region.localDestroy("foobar2"); - // test invalidate - region.put("invalid", "invalid"); - dr.flushForTesting(); - region.invalidate("invalid"); - dr.flushForTesting(); - assertTrue(region.containsKey("invalid") - && !region.containsValueForKey("invalid")); - total++; - // test local-invalidate - region.put("localinvalid", "localinvalid"); - dr.flushForTesting(); - region.localInvalidate("localinvalid"); - dr.flushForTesting(); - assertTrue(region.containsKey("localinvalid") - && !region.containsValueForKey("localinvalid")); - total++; - } - catch (EntryNotFoundException e) { - logWriter.error("Exception occured", e); - fail(" Entry not found although was expected to be there"); - } + + region.localDestroy("foobar"); + + region.put("foobar2", "junk"); + dr.flushForTesting(); + region.localDestroy("foobar2"); + // test invalidate + region.put("invalid", "invalid"); + dr.flushForTesting(); + region.invalidate("invalid"); + dr.flushForTesting(); + assertTrue(region.containsKey("invalid") + && !region.containsValueForKey("invalid")); + total++; + // test local-invalidate + region.put("localinvalid", "localinvalid"); + dr.flushForTesting(); + region.localInvalidate("localinvalid"); + dr.flushForTesting(); + assertTrue(region.containsKey("localinvalid") + && !region.containsValueForKey("localinvalid")); + total++; + // test byte[] values region.put("byteArray", new byte[0]); dr.flushForTesting(); @@ -286,13 +292,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase assertEquals(total, region.size()); } cache.close(); - try { - cache = createCache(); - } - catch (Exception e) { - logWriter.error("Exception occured", e); - fail("Exception in trying to create a cache due to " + e); - } + cache = createCache(); { Region region = DiskRegionHelperFactory.getAsyncOverFlowAndPersistRegion( cache, props); @@ -300,30 +300,23 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase assertEquals(true, region.containsKey("invalid")); assertEquals(null, region.get("invalid")); assertEquals(false, region.containsValueForKey("invalid")); - try { - region.localDestroy("invalid"); - total--; - assertTrue(region.containsKey("localinvalid") - && !region.containsValueForKey("localinvalid")); - region.localDestroy("localinvalid"); - total--; - assertArrayEquals(new byte[0], region.get("byteArray")); - region.localDestroy("byteArray"); - total--; - assertEquals("modified", region.get("modified")); - region.localDestroy("modified"); - total--; - } - catch (EntryNotFoundException e) { - logWriter.error("Exception occured", e); - fail(" Entry not found although was expected to be there"); - } + + region.localDestroy("invalid"); + total--; + assertTrue(region.containsKey("localinvalid") + && !region.containsValueForKey("localinvalid")); + region.localDestroy("localinvalid"); + total--; + assertArrayEquals(new byte[0], region.get("byteArray")); + region.localDestroy("byteArray"); + total--; + assertEquals("modified", region.get("modified")); + region.localDestroy("modified"); + total--; } } - - class DoesPut implements Runnable - { + private static class DoesPut implements Runnable { private Region region; @@ -331,15 +324,14 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase this.region = region; } - public void run() - { + @Override + public void run() { region.put(new Integer(1), new Integer(2)); } } - class DoesGet implements Runnable - { + private class DoesGet implements Runnable { private final Region region; @@ -347,8 +339,8 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase this.region = region; } - public void run() - { + @Override + public void run() { synchronized (this.region) { if (!hasNotified) { try { @@ -373,12 +365,8 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase } // run() } - boolean failed = false; - static volatile boolean hasNotified = false; - @Test - public void testFaultingInRemovalFromAsyncBuffer() - { + public void testFaultingInRemovalFromAsyncBuffer() throws Exception { failed = false; DiskRegionProperties props = new DiskRegionProperties(); props.setOverflow(true); @@ -426,16 +414,8 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase } - protected int counter = 0; - - protected boolean hasBeenNotified = false; - - volatile boolean finished = false; - @Test - public void testGetWhileRolling() - { - + public void testGetWhileRolling() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setOverflow(true); props.setOverFlowCapacity(1); @@ -446,8 +426,8 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase cache, props); CacheObserverHolder.setInstance(new CacheObserverAdapter() { - public void beforeGoingToCompact() - { + @Override + public void beforeGoingToCompact() { synchronized (region) { region.notifyAll(); hasBeenNotified = true; @@ -456,30 +436,12 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase }); Runnable get = new Runnable() { - public void run() - { + @Override + public void run() { int localCounter = 0; synchronized (region) { localCounter = counter; counter++; -// try { -// if (!hasBeenNotified) { -// long startTime = System.currentTimeMillis(); -// region.wait(24000); -// long interval = System.currentTimeMillis() - startTime; -// if (interval > 24000) { -// failed = true; -// fail("Getter #" + localCounter + " took too long in going to join, it should have exited before 24000 ms"); -// } -// } -// -// } -// catch (InterruptedException e) { -// if (finished) { -// return; -// } -// fail("interrupted"); -// } } int limit = ((localCounter * 1000) + 1000); for (int i = localCounter * 1000; i < limit; i++) { @@ -495,8 +457,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase return; } failed = true; - fail(" failed due to " + e); - logWriter.error("Exception occured but not failing test ", e); // NOTREACHED + throw new AssertionError("failed due to ", e); } } @@ -545,12 +506,9 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase * to the Max Oplog Size. In such situations , if during switch over , if the * Oplog to be rolled is added after function call of obtaining nextDir , a * dead lock occurs - * */ - @Test - public void testSingleDirectoryNotHanging() - { + public void testSingleDirectoryNotHanging() throws Exception { DiskRegionProperties diskRegionProperties = new DiskRegionProperties(); //setting to null will make only one directory File dir = new File("testSingleDirectoryNotHanging"); @@ -586,11 +544,8 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase closeDown(); } - static volatile boolean putsHaveStarted = false; - @Test - public void testOperationGreaterThanMaxOplogSize() - { + public void testOperationGreaterThanMaxOplogSize() throws Exception { putsHaveStarted = false; DiskRegionProperties diskRegionProperties = new DiskRegionProperties(); diskRegionProperties.setDiskDirs(dirs); @@ -617,15 +572,13 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase if (puts.exceptionOccurred()) { fail(" Exception was not supposed to occur but did occur"); } - } /** * As we have relaxed the constraint of max dir size */ @Test - public void testOperationGreaterThanMaxDirSize() - { + public void testOperationGreaterThanMaxDirSize() throws Exception { putsHaveStarted = false; DiskRegionProperties diskRegionProperties = new DiskRegionProperties(); diskRegionProperties.setRegionName("IGNORE_EXCEPTION_testOperationGreaterThanMaxDirSize"); @@ -669,7 +622,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase * one op per oplog (which is caused by bug 42464). */ @Test - public void testBug42464() { + public void testBug42464() throws Exception { putsHaveStarted = false; DiskRegionProperties diskRegionProperties = new DiskRegionProperties(); File[] myDirs = new File[] { dirs[0] }; @@ -727,10 +680,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase assertEquals(1, oplogs.size()); } - protected volatile boolean exceptionOccured = false; - - class Puts implements Runnable - { + private static class Puts implements Runnable { private int dataSize = 1024; private Region region; @@ -753,6 +703,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase return putSuccessful[index]; } + @Override public void run() { performPuts(); } @@ -783,9 +734,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase } @Test - public void testSingleDirectorySizeViolation() - { - + public void testSingleDirectorySizeViolation() throws Exception { DiskRegionProperties diskRegionProperties = new DiskRegionProperties(); diskRegionProperties.setRegionName("IGNORE_EXCEPTION_testSingleDirectorySizeViolation"); //setting to null will make only one directory @@ -824,8 +773,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase * DiskRegDiskAccessExceptionTest : Disk region test for DiskAccessException. */ @Test - public void testDiskFullExcep() - { + public void testDiskFullExcep() throws Exception { int[] diskDirSize1 = new int[4]; diskDirSize1[0] = (2048 + 500); diskDirSize1[1] = (2048 + 500); @@ -849,14 +797,9 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase final byte[] value = new byte[1024]; Arrays.fill(value, (byte)77); - try { - for (int i = 0; i < 8; i++) { - region.put("" + i, value); - } - } - catch (DiskAccessException e) { - logWriter.error("Exception occured but not expected", e); - fail("FAILED::" + e.toString()); + + for (int i = 0; i < 8; i++) { + region.put("" + i, value); } // we should have put 2 values in each dir so the next one should not fit @@ -883,8 +826,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase * Make sure if compaction is enabled that we can exceed the disk dir limit */ @Test - public void testNoDiskFullExcep() - { + public void testNoDiskFullExcep() throws Exception { int[] diskDirSize1 = new int[4]; diskDirSize1[0] = (2048 + 500); diskDirSize1[1] = (2048 + 500); @@ -931,12 +873,12 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase assertEquals(false, cache.isClosed()); } + /** * DiskRegDiskAccessExceptionTest : Disk region test for DiskAccessException. */ @Test - public void testDiskFullExcepOverflowOnly() - { + public void testDiskFullExcepOverflowOnly() throws Exception { int[] diskDirSize1 = new int[4]; diskDirSize1[0] = (2048 + 500); diskDirSize1[1] = (2048 + 500); @@ -998,8 +940,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase * Make sure if compaction is enabled that we can exceed the disk dir limit */ @Test - public void testNoDiskFullExcepOverflowOnly() - { + public void testNoDiskFullExcepOverflowOnly() throws Exception { int[] diskDirSize1 = new int[4]; diskDirSize1[0] = (2048 + 500); diskDirSize1[1] = (2048 + 500); @@ -1055,8 +996,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase * time, the operation should not get stuck or see Exception */ @Test - public void testSynchModeAllowOperationToProceedEvenIfDiskSpaceIsNotSufficient() - { + public void testSynchModeAllowOperationToProceedEvenIfDiskSpaceIsNotSufficient() throws Exception { File[] dirs1 = null; File testingDirectory1 = new File("testingDirectory1"); testingDirectory1.mkdir(); @@ -1089,8 +1029,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase }// end of testSyncPersistRegionDAExp @Test - public void testAsynchModeAllowOperationToProceedEvenIfDiskSpaceIsNotSufficient() - { + public void testAsynchModeAllowOperationToProceedEvenIfDiskSpaceIsNotSufficient() throws Exception { File[] dirs1 = null; File testingDirectory1 = new File("testingDirectory1"); testingDirectory1.mkdir(); @@ -1154,11 +1093,10 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase try { ThreadUtils.join(t1, 60 * 1000); } - catch (Exception ignore) { - logWriter.error("Exception occured", ignore); + catch (Exception e) { testFailed = true; failureCause = "Test failed as the compactor thread not guaranteed to have not rolled the oplog"; - fail("Test failed as the compactor thread not guaranteed to have not rolled the oplog"); + throw new AssertionError("Test failed as the compactor thread not guaranteed to have not rolled the oplog", e); } } @@ -1201,60 +1139,9 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase /** * DiskRegDiskAttributesTest: This test is for testing Disk attributes set * programmatically - * */ - - DiskRegionProperties diskProps1 = new DiskRegionProperties(); - - DiskRegionProperties diskProps2 = new DiskRegionProperties(); - - DiskRegionProperties diskProps3 = new DiskRegionProperties(); - - DiskRegionProperties diskProps4 = new DiskRegionProperties(); - - DiskRegionProperties diskProps5 = new DiskRegionProperties(); - - DiskRegionProperties diskProps6 = new DiskRegionProperties(); - - DiskRegionProperties diskProps7 = new DiskRegionProperties(); - - DiskRegionProperties diskProps8 = new DiskRegionProperties(); - - DiskRegionProperties diskProps9 = new DiskRegionProperties(); - - DiskRegionProperties diskProps10 = new DiskRegionProperties(); - - DiskRegionProperties diskProps11 = new DiskRegionProperties(); - - DiskRegionProperties diskProps12 = new DiskRegionProperties(); - - Region region1; - - Region region2; - - Region region3; - - Region region4; - - Region region5; - - Region region6; - - Region region7; - - Region region8; - - Region region9; - - Region region10; - - Region region11; - - Region region12; - @Test - public void testDiskRegDWAttrbts() - { + public void testDiskRegDWAttrbts() throws Exception { diskProps1.setDiskDirs(dirs); diskProps2.setDiskDirs(dirs); diskProps3.setDiskDirs(dirs); @@ -1373,13 +1260,12 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase lr.getDiskStore().close(); lr.getGemFireCache().removeDiskStore(lr.getDiskStore()); } + /** * DiskRegGetInvalidEntryTest: get invalid entry should return null. - * */ @Test - public void testDiskGetInvalidEntry() - { + public void testDiskGetInvalidEntry() throws Exception { Object getInvalidEnt = "some val"; diskProps.setDiskDirsAndSizes(dirs, diskDirSize); @@ -1398,17 +1284,14 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase } } catch (Exception e) { - logWriter.error("Exception occured but not expected", e); - fail("Failed while put:" + e.toString()); + throw new AssertionError("Failed while put:", e); } // invalidate an entry try { region.invalidate("key1"); } catch (Exception e) { - - fail("Failed while invalidating:" + e.toString()); - + throw new AssertionError("Failed while invalidating:" + e.toString()); } // get the invalid entry and verify that the value returned is null try { @@ -1432,8 +1315,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase * presented as a byte array */ @Test - public void testDiskRegionByteArray() - { + public void testDiskRegionByteArray() throws Exception { Object val = null; diskProps.setPersistBackup(true); diskProps.setDiskDirs(dirs); @@ -1483,9 +1365,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase * SimpleDiskRegion. */ @Test - public void testInstanceOfDiskRegion() - { - + public void testInstanceOfDiskRegion() throws Exception { DiskRegionProperties diskProps = new DiskRegionProperties(); diskProps.setDiskDirs(dirs); // dirs is an array of four dirs @@ -1525,11 +1405,9 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase /** * DiskRegionStatsJUnitTest : - * */ @Test - public void testStats() - { + public void testStats() throws Exception { final int overflowCapacity = 100; int counter = 0; DiskRegionProperties diskRegionProperties = new DiskRegionProperties(); @@ -1568,11 +1446,9 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase /** * DiskRegOverflowOnlyNoFilesTest: Overflow only mode has no files of previous * run, during startup - * */ @Test - public void testOverflowOnlyNoFiles() - { + public void testOverflowOnlyNoFiles() throws Exception { diskProps.setTimeInterval(15000l); diskProps.setBytesThreshold(100000l); diskProps.setOverFlowCapacity(1000); @@ -1618,7 +1494,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase }//end of testOverflowOnlyNoFiles @Test - public void testPersistNoFiles() { + public void testPersistNoFiles() throws Exception { diskProps.setOverflow(false); diskProps.setRolling(false); diskProps.setDiskDirs(dirs); @@ -1666,12 +1542,9 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase * Test to verify that DiskAccessException is not thrown if rolling has been enabled. The * test configurations will cause the disk to go full and wait for the compactor to release space. * A DiskAccessException should not be thrown by this test - * - * @throws Exception */ @Test - public void testDiskAccessExceptionNotThrown() throws Exception - { + public void testDiskAccessExceptionNotThrown() throws Exception { File diskDir = new File("dir"); diskDir.mkdir(); DiskRegionProperties diskRegionProperties = new DiskRegionProperties(); @@ -1701,11 +1574,9 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase * If an entry which has just been written on the disk, sees clear just before * updating the LRULiist, then that deleted entry should not go into the * LRUList - * */ @Test - public void testClearInteractionWithLRUList_Bug37605() - { + public void testClearInteractionWithLRUList_Bug37605() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setOverflow(true); props.setOverFlowCapacity(1); @@ -1755,11 +1626,9 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase * happened, the entry on which create op is going on was no longer valid, but * we would not be able to detect the conflict. The fix was to first clear the * region map & then reset the Htree Ref. - * */ @Test - public void testClearInteractionWithCreateOperation_Bug37606() - { + public void testClearInteractionWithCreateOperation_Bug37606() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setOverflow(false); props.setRolling(false); @@ -1815,8 +1684,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase * Similar test in case of 'update' */ @Test - public void testClearInteractionWithUpdateOperation_Bug37606() - { + public void testClearInteractionWithUpdateOperation_Bug37606() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setOverflow(false); props.setRolling(false); @@ -1870,44 +1738,37 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase } } - /** * If IOException occurs while updating an entry in a persist only synch mode, * DiskAccessException should occur & region should be destroyed - * - * @throws Exception */ @Test - public void testEntryUpdateInSynchPersistOnlyForIOExceptionCase() - throws Exception { - DiskRegionProperties props = new DiskRegionProperties(); - props.setRegionName("IGNORE_EXCEPTION_testEntryUpdateInSynchPersistOnlyForIOExceptionCase"); - props.setOverflow(false); - props.setRolling(false); - props.setDiskDirs(dirs); - props.setPersistBackup(true); - - region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL); - entryUpdateInSynchPersistTypeForIOExceptionCase(region); + public void testEntryUpdateInSynchPersistOnlyForIOExceptionCase() throws Exception { + DiskRegionProperties props = new DiskRegionProperties(); + props.setRegionName("IGNORE_EXCEPTION_testEntryUpdateInSynchPersistOnlyForIOExceptionCase"); + props.setOverflow(false); + props.setRolling(false); + props.setDiskDirs(dirs); + props.setPersistBackup(true); + + region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL); + entryUpdateInSynchPersistTypeForIOExceptionCase(region); } /** * If IOException occurs while updating an entry in a persist overflow synch mode, * we should get DiskAccessException & region be destroyed - * - * @throws Exception */ @Test - public void testEntryUpdateInSyncOverFlowPersistOnlyForIOExceptionCase() - throws Exception { - DiskRegionProperties props = new DiskRegionProperties(); - props.setRegionName("IGNORE_EXCEPTION_testEntryUpdateInSyncOverFlowPersistOnlyForIOExceptionCase"); - props.setOverflow(true); - props.setRolling(false); - props.setDiskDirs(dirs); - props.setPersistBackup(true); - region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL); - entryUpdateInSynchPersistTypeForIOExceptionCase(region); + public void testEntryUpdateInSyncOverFlowPersistOnlyForIOExceptionCase() throws Exception { + DiskRegionProperties props = new DiskRegionProperties(); + props.setRegionName("IGNORE_EXCEPTION_testEntryUpdateInSyncOverFlowPersistOnlyForIOExceptionCase"); + props.setOverflow(true); + props.setRolling(false); + props.setDiskDirs(dirs); + props.setPersistBackup(true); + region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL); + entryUpdateInSynchPersistTypeForIOExceptionCase(region); } /** @@ -1939,42 +1800,37 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase /** * If IOException occurs while invalidating an entry in a persist only synch mode, - * DiskAccessException should occur & region should be destroyed - * - * @throws Exception + * DiskAccessException should occur & region should be destroyed */ @Test - public void testEntryInvalidateInSynchPersistOnlyForIOExceptionCase() - throws Exception { - DiskRegionProperties props = new DiskRegionProperties(); - props.setRegionName("IGNORE_EXCEPTION_testEntryInvalidateInSynchPersistOnlyForIOExceptionCase"); - props.setOverflow(false); - props.setRolling(false); - props.setDiskDirs(dirs); - props.setPersistBackup(true); - region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL); - entryInvalidateInSynchPersistTypeForIOExceptionCase(region); + public void testEntryInvalidateInSynchPersistOnlyForIOExceptionCase() throws Exception { + DiskRegionProperties props = new DiskRegionProperties(); + props.setRegionName("IGNORE_EXCEPTION_testEntryInvalidateInSynchPersistOnlyForIOExceptionCase"); + props.setOverflow(false); + props.setRolling(false); + props.setDiskDirs(dirs); + props.setPersistBackup(true); + region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL); + entryInvalidateInSynchPersistTypeForIOExceptionCase(region); } /** * If IOException occurs while invalidating an entry in a persist overflow synch mode, - * DiskAccessException should occur & region should be destroyed - * - * @throws Exception + * DiskAccessException should occur & region should be destroyed */ @Test - public void testEntryInvalidateInSynchPersistOverflowForIOExceptionCase() - throws Exception { - DiskRegionProperties props = new DiskRegionProperties(); - props.setRegionName("IGNORE_EXCEPTION_testEntryInvalidateInSynchPersistOverflowForIOExceptionCase"); - - props.setOverflow(true); - props.setRolling(false); - props.setDiskDirs(dirs); - props.setPersistBackup(true); - region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL); - entryInvalidateInSynchPersistTypeForIOExceptionCase(region); + public void testEntryInvalidateInSynchPersistOverflowForIOExceptionCase() throws Exception { + DiskRegionProperties props = new DiskRegionProperties(); + props.setRegionName("IGNORE_EXCEPTION_testEntryInvalidateInSynchPersistOverflowForIOExceptionCase"); + + props.setOverflow(true); + props.setRolling(false); + props.setDiskDirs(dirs); + props.setPersistBackup(true); + region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL); + entryInvalidateInSynchPersistTypeForIOExceptionCase(region); } + /** * If IOException occurs while invalidating an entry in a persist only synch mode, * DiskAccessException should occur & region should be destroyed @@ -2002,15 +1858,11 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase } /** - * * If IOException occurs while creating an entry in a persist only synch mode, - * DiskAccessException should occur & region should be destroyed - * - * @throws Exception + * DiskAccessException should occur & region should be destroyed */ @Test - public void testEntryCreateInSynchPersistOnlyForIOExceptionCase() - throws Exception { + public void testEntryCreateInSynchPersistOnlyForIOExceptionCase() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setRegionName("IGNORE_EXCEPTION_testEntryCreateInSynchPersistOnlyForIOExceptionCase"); props.setOverflow(false); @@ -2022,15 +1874,11 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase } /** - * * If IOException occurs while creating an entry in a persist overflow synch mode, * DiskAccessException should occur & region should be destroyed - * - * @throws Exception */ @Test - public void testEntryCreateInSynchPersistOverflowForIOExceptionCase() - throws Exception { + public void testEntryCreateInSynchPersistOverflowForIOExceptionCase() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setRegionName("IGNORE_EXCEPTION_testEntryCreateInSynchPersistOverflowForIOExceptionCase"); props.setOverflow(true); @@ -2069,13 +1917,10 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase /** * If IOException occurs while destroying an entry in a persist only synch mode, - DiskAccessException should occur & region should be destroyed - * - * @throws Exception + * DiskAccessException should occur & region should be destroyed */ @Test - public void testEntryDestructionInSynchPersistOnlyForIOExceptionCase() - throws Exception { + public void testEntryDestructionInSynchPersistOnlyForIOExceptionCase() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setRegionName("IGNORE_EXCEPTION_testEntryDestructionInSynchPersistOnlyForIOExceptionCase"); props.setOverflow(false); @@ -2084,18 +1929,14 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase props.setPersistBackup(true); region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL); entryDestructionInSynchPersistTypeForIOExceptionCase(region); - } /** * If IOException occurs while destroying an entry in a persist overflow synch mode, * DiskAccessException should occur & region should be destroyed - * - * @throws Exception */ @Test - public void testEntryDestructionInSynchPersistOverflowForIOExceptionCase() - throws Exception { + public void testEntryDestructionInSynchPersistOverflowForIOExceptionCase() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setRegionName("IGNORE_EXCEPTION_testEntryDestructionInSynchPersistOverflowForIOExceptionCase"); props.setOverflow(true); @@ -2104,7 +1945,6 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase props.setPersistBackup(true); region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL); entryDestructionInSynchPersistTypeForIOExceptionCase(region); - } /** @@ -2134,198 +1974,180 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase /** * If IOException occurs while updating an entry in a Overflow only synch mode, - * DiskAccessException should occur & region should be destroyed - * - * @throws Exception + * DiskAccessException should occur & region should be destroyed */ @Test - public void testEntryUpdateInSynchOverflowOnlyForIOExceptionCase() - throws Exception { - DiskRegionProperties props = new DiskRegionProperties(); - props.setRegionName("IGNORE_EXCEPTION_testEntryUpdateInSynchOverflowOnlyForIOExceptionCase"); - props.setOverflow(true); - props.setRolling(false); - props.setDiskDirs(dirs); - props.setPersistBackup(false); - props.setOverFlowCapacity(1); - region = DiskRegionHelperFactory.getSyncOverFlowOnlyRegion(cache, props); + public void testEntryUpdateInSynchOverflowOnlyForIOExceptionCase() throws Exception { + DiskRegionProperties props = new DiskRegionProperties(); + props.setRegionName("IGNORE_EXCEPTION_testEntryUpdateInSynchOverflowOnlyForIOExceptionCase"); + props.setOverflow(true); + props.setRolling(false); + props.setDiskDirs(dirs); + props.setPersistBackup(false); + props.setOverFlowCapacity(1); + region = DiskRegionHelperFactory.getSyncOverFlowOnlyRegion(cache, props); - region.create("key1", "value1"); - region.create("key2", "value2"); - ((LocalRegion)region).getDiskRegion().testHookCloseAllOverflowChannels(); - try { - //Update key1, so that key2 goes on disk & encounters an exception - region.put("key1", "value1'"); - fail("Should have encountered DiskAccessException"); - } - catch (DiskAccessException dae) { - //OK - } - ((LocalRegion) region).getDiskStore().waitForClose(); - assertTrue(cache.isClosed()); - region = null; + region.create("key1", "value1"); + region.create("key2", "value2"); + ((LocalRegion)region).getDiskRegion().testHookCloseAllOverflowChannels(); + try { + //Update key1, so that key2 goes on disk & encounters an exception + region.put("key1", "value1'"); + fail("Should have encountered DiskAccessException"); + } + catch (DiskAccessException dae) { + //OK + } + ((LocalRegion) region).getDiskStore().waitForClose(); + assertTrue(cache.isClosed()); + region = null; } /** * If IOException occurs while creating an entry in a Overflow only synch mode, * DiskAccessException should occur & region should be destroyed - * - * @throws Exception */ @Test - public void testEntryCreateInSynchOverflowOnlyForIOExceptionCase() - throws Exception { - DiskRegionProperties props = new DiskRegionProperties(); - props.setRegionName("IGNORE_EXCEPTION_testEntryCreateInSynchOverflowOnlyForIOExceptionCase"); - props.setOverflow(true); - props.setRolling(false); - props.setDiskDirs(dirs); - props.setPersistBackup(false); - props.setOverFlowCapacity(1); - region = DiskRegionHelperFactory.getSyncOverFlowOnlyRegion(cache, props); + public void testEntryCreateInSynchOverflowOnlyForIOExceptionCase() throws Exception { + DiskRegionProperties props = new DiskRegionProperties(); + props.setRegionName("IGNORE_EXCEPTION_testEntryCreateInSynchOverflowOnlyForIOExceptionCase"); + props.setOverflow(true); + props.setRolling(false); + props.setDiskDirs(dirs); + props.setPersistBackup(false); + props.setOverFlowCapacity(1); + region = DiskRegionHelperFactory.getSyncOverFlowOnlyRegion(cache, props); - region.create("key1", "value1"); - region.create("key2", "value2"); - ((LocalRegion)region).getDiskRegion().testHookCloseAllOverflowChannels(); - try { - region.create("key3", "value3"); - fail("Should have encountered DiskAccessException"); - } - catch (DiskAccessException dae) { - //OK - } - ((LocalRegion) region).getDiskStore().waitForClose(); - assertTrue(cache.isClosed()); - region = null; + region.create("key1", "value1"); + region.create("key2", "value2"); + ((LocalRegion)region).getDiskRegion().testHookCloseAllOverflowChannels(); + try { + region.create("key3", "value3"); + fail("Should have encountered DiskAccessException"); + } + catch (DiskAccessException dae) { + //OK + } + ((LocalRegion) region).getDiskStore().waitForClose(); + assertTrue(cache.isClosed()); + region = null; } /** * A deletion of an entry in overflow only mode should not cause * any eviction & hence no DiskAccessException - * - * @throws Exception */ @Test - public void testEntryDeletionInSynchOverflowOnlyForIOExceptionCase() - throws Exception { - DiskRegionProperties props = new DiskRegionProperties(); - props.setOverflow(true); - props.setRolling(false); - props.setDiskDirs(dirs); - props.setPersistBackup(false); - props.setOverFlowCapacity(1); - region = DiskRegionHelperFactory.getSyncOverFlowOnlyRegion(cache, props); + public void testEntryDeletionInSynchOverflowOnlyForIOExceptionCase() throws Exception { + DiskRegionProperties props = new DiskRegionProperties(); + props.setOverflow(true); + props.setRolling(false); + props.setDiskDirs(dirs); + props.setPersistBackup(false); + props.setOverFlowCapacity(1); + region = DiskRegionHelperFactory.getSyncOverFlowOnlyRegion(cache, props); - region.create("key1", "value1"); - region.create("key2", "value2"); - region.create("key3", "value3"); - ((LocalRegion)region).getDiskRegion().testHookCloseAllOverflowChannels(); - try { - //Update key1, so that key2 goes on disk & encounters an exception - region.destroy("key1"); - region.destroy("key3"); - } - catch (DiskAccessException dae) { - fail("Should not have encountered DiskAccessException"); - } + region.create("key1", "value1"); + region.create("key2", "value2"); + region.create("key3", "value3"); + ((LocalRegion)region).getDiskRegion().testHookCloseAllOverflowChannels(); + try { + //Update key1, so that key2 goes on disk & encounters an exception + region.destroy("key1"); + region.destroy("key3"); + } + catch (DiskAccessException dae) { + fail("Should not have encountered DiskAccessException"); + } } /** * If IOException occurs while updating an entry in an Asynch mode, - * DiskAccessException should occur & region should be destroyed - * - * - * @throws Exception + * DiskAccessException should occur & region should be destroyed */ @Test - public void testEntryUpdateInASynchPersistOnlyForIOExceptionCase() - throws Exception { - DiskRegionProperties props = new DiskRegionProperties(); - props.setRegionName("IGNORE_EXCEPTION_testEntryUpdateInASynchPersistOnlyForIOExceptionCase"); - props.setOverflow(true); - props.setRolling(false); - props.setBytesThreshold(48); - props.setDiskDirs(dirs); - props.setPersistBackup(true); - region = DiskRegionHelperFactory.getAsyncPersistOnlyRegion(cache, props); - // Get the oplog handle & hence the underlying file & close it - UninterruptibleFileChannel oplogFileChannel = ((LocalRegion)region).getDiskRegion() - .testHook_getChild().getFileChannel(); - oplogFileChannel.close(); - - region.create("key1", new byte[16]); - region.create("key2", new byte[16]); + public void testEntryUpdateInASynchPersistOnlyForIOExceptionCase() throws Exception { + DiskRegionProperties props = new DiskRegionProperties(); + props.setRegionName("IGNORE_EXCEPTION_testEntryUpdateInASynchPersistOnlyForIOExceptionCase"); + props.setOverflow(true); + props.setRolling(false); + props.setBytesThreshold(48); + props.setDiskDirs(dirs); + props.setPersistBackup(true); + region = DiskRegionHelperFactory.getAsyncPersistOnlyRegion(cache, props); + // Get the oplog handle & hence the underlying file & close it + UninterruptibleFileChannel oplogFileChannel = ((LocalRegion)region).getDiskRegion() + .testHook_getChild().getFileChannel(); + oplogFileChannel.close(); - DiskRegion dr = ((LocalRegion)region).getDiskRegion(); - dr.flushForTesting(); - //Join till the asynch writer terminates - if (!dr.testWaitForAsyncFlusherThread(2000)) { - fail("async flusher thread did not terminate"); + region.create("key1", new byte[16]); + region.create("key2", new byte[16]); + + DiskRegion dr = ((LocalRegion)region).getDiskRegion(); + dr.flushForTesting(); + //Join till the asynch writer terminates + if (!dr.testWaitForAsyncFlusherThread(2000)) { + fail("async flusher thread did not terminate"); + } + + Wait.waitForCriterion(new WaitCriterion() { + @Override + public boolean done() { + return cache.isClosed(); } - Wait.waitForCriterion(new WaitCriterion() { - @Override - public boolean done() { - return cache.isClosed(); - } + @Override + public String description() { + return "Waiting for region IGNORE_EXCEPTION_testEntryUpdateInASynchPersistOnlyForIOExceptionCase to be destroyed."; + } + }, 5000, 500, true); - @Override - public String description() { - return "Waiting for region IGNORE_EXCEPTION_testEntryUpdateInASynchPersistOnlyForIOExceptionCase to be destroyed."; - } - }, 5000, 500, true); - - ((LocalRegion) region).getDiskStore().waitForClose(); - assertTrue(cache.isClosed()); - region = null; + ((LocalRegion) region).getDiskStore().waitForClose(); + assertTrue(cache.isClosed()); + region = null; } /** * If IOException occurs while updating an entry in an already initialized * DiskRegion ,then the bridge servers should not be stopped , if any running as * they are no clients connected to it. - * - * @throws Exception */ @Test - public void testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase() - throws Exception { - DiskRegionProperties props = new DiskRegionProperties(); - props.setRegionName("IGNORE_EXCEPTION_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase"); - props.setOverflow(true); - props.setRolling(true); - props.setDiskDirs(dirs); - props.setPersistBackup(true); - - region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL); - CacheServer bs1 = cache.addCacheServer(); - bs1.setPort(5555); - bs1.start(); + public void testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase() throws Exception { + DiskRegionProperties props = new DiskRegionProperties(); + props.setRegionName("IGNORE_EXCEPTION_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase"); + props.setOverflow(true); + props.setRolling(true); + props.setDiskDirs(dirs); + props.setPersistBackup(true); - region.create("key1", new byte[16]); - region.create("key2", new byte[16]); + region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL); + CacheServer bs1 = cache.addCacheServer(); + bs1.setPort(5555); + bs1.start(); + + region.create("key1", new byte[16]); + region.create("key2", new byte[16]); // Get the oplog handle & hence the underlying file & close it - UninterruptibleFileChannel oplogFileChannel = ((LocalRegion)region).getDiskRegion() - .testHook_getChild().getFileChannel(); - oplogFileChannel.close(); - try { - region.put("key2", new byte[16]); - }catch(DiskAccessException dae) { - //OK expected - } - ((LocalRegion) region).getDiskStore().waitForClose(); - assertTrue(cache.isClosed()); - region = null; - List bsRunning = cache.getCacheServers(); - // [anil & bruce] the following assertion was changed to true because - // a disk access exception in a server should always stop the server - assertTrue(bsRunning.isEmpty()); + UninterruptibleFileChannel oplogFileChannel = ((LocalRegion)region).getDiskRegion() + .testHook_getChild().getFileChannel(); + oplogFileChannel.close(); + try { + region.put("key2", new byte[16]); + }catch(DiskAccessException dae) { + //OK expected + } + ((LocalRegion) region).getDiskStore().waitForClose(); + assertTrue(cache.isClosed()); + region = null; + List bsRunning = cache.getCacheServers(); + // [anil & bruce] the following assertion was changed to true because + // a disk access exception in a server should always stop the server + assertTrue(bsRunning.isEmpty()); } @Test - public void testDummyByteBugDuringRegionClose_Bug40250() - throws Exception - { + public void testDummyByteBugDuringRegionClose_Bug40250() throws Exception { try { // Create a region with rolling enabled. DiskRegionProperties props = new DiskRegionProperties(); @@ -2395,63 +2217,58 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = false; CacheObserverHolder.setInstance(new CacheObserverAdapter()); } - } /** * If IOException occurs while initializing a region * ,then the bridge servers should not be stopped - * - * @throws Exception */ @Test - public void testBridgeServerRunningInSynchPersistOnlyForIOExceptionCase() - throws Exception { - DiskRegionProperties props = new DiskRegionProperties(); - props.setRegionName("IGNORE_EXCEPTION_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase"); - props.setOverflow(true); - props.setRolling(true); - props.setDiskDirs(dirs); - props.setPersistBackup(true); - props.setMaxOplogSize(100000); // just needs to be bigger than 65550 + public void testBridgeServerRunningInSynchPersistOnlyForIOExceptionCase() throws Exception { + DiskRegionProperties props = new DiskRegionProperties(); + props.setRegionName("IGNORE_EXCEPTION_testBridgeServerStoppingInSynchPersistOnlyForIOExceptionCase"); + props.setOverflow(true); + props.setRolling(true); + props.setDiskDirs(dirs); + props.setPersistBackup(true); + props.setMaxOplogSize(100000); // just needs to be bigger than 65550 - region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL); - CacheServer bs1 = cache.addCacheServer(); - bs1.setPort(5555); - bs1.start(); - - region.create("key1", new byte[16]); - region.create("key2", new byte[16]); - //Get the oplog file path - UninterruptibleFileChannel oplogFileChnl = ((LocalRegion)region).getDiskRegion() - .testHook_getChild().getFileChannel(); - //corrupt the opfile - oplogFileChnl.position(2); - ByteBuffer bf = ByteBuffer.allocate(416); - for(int i = 0; i <5;++i) { - bf.putInt(i); - } - bf.flip(); + region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL); + CacheServer bs1 = cache.addCacheServer(); + bs1.setPort(5555); + bs1.start(); + + region.create("key1", new byte[16]); + region.create("key2", new byte[16]); + //Get the oplog file path + UninterruptibleFileChannel oplogFileChnl = ((LocalRegion)region).getDiskRegion() + .testHook_getChild().getFileChannel(); + //corrupt the opfile + oplogFileChnl.position(2); + ByteBuffer bf = ByteBuffer.allocate(416); + for(int i = 0; i <5;++i) { + bf.putInt(i); + } + bf.flip(); // Corrupt the oplogFile - oplogFileChnl.write(bf); - //Close the region - region.close(); - assertTrue(region.isDestroyed()); - try { - region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL); - fail("expected DiskAccessException"); - }catch(DiskAccessException dae) { - //OK expected - } - assertTrue(region.isDestroyed()); - region = null; - List bsRunning = cache.getCacheServers(); - assertTrue(!bsRunning.isEmpty()); + oplogFileChnl.write(bf); + //Close the region + region.close(); + assertTrue(region.isDestroyed()); + try { + region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, props, Scope.LOCAL); + fail("expected DiskAccessException"); + }catch(DiskAccessException dae) { + //OK expected + } + assertTrue(region.isDestroyed()); + region = null; + List bsRunning = cache.getCacheServers(); + assertTrue(!bsRunning.isEmpty()); } @Test - public void testEarlyTerminationOfCompactorByDefault() - throws Exception { + public void testEarlyTerminationOfCompactorByDefault() throws Exception { try { // Create a region with rolling enabled. DiskRegionProperties props = new DiskRegionProperties(); @@ -2601,11 +2418,9 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase CacheObserverHolder.setInstance(new CacheObserverAdapter()); } } - - + @Test - public void testAssertionErrorIfMissingOplog() - throws Exception { + public void testAssertionErrorIfMissingOplog() throws Exception { try { // Create a region with rolling enabled. DiskRegionProperties props = new DiskRegionProperties(); @@ -2669,8 +2484,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase } @Test - public void testNoTerminationOfCompactorTillRollingCompleted() - throws Exception { + public void testNoTerminationOfCompactorTillRollingCompleted() throws Exception { try { // Create a region with rolling enabled. System.getProperties().setProperty(DiskStoreImpl.COMPLETE_COMPACTION_BEFORE_TERMINATION_PROPERTY_NAME, "true"); @@ -2874,7 +2688,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase } @Test - public void testBug40648part1() { + public void testBug40648part1() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setRegionName("testBug40648part1"); props.setRolling(true); @@ -2898,7 +2712,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase } @Test - public void testBug40648part2() { + public void testBug40648part2() throws Exception { // Same as part1 but no persistence. I wasn't able to get part2 // to fail but thought this was worth testing anyway. DiskRegionProperties props = new DiskRegionProperties(); @@ -2924,7 +2738,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase } @Test - public void testForceCompactionDoesRoll() { + public void testForceCompactionDoesRoll() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setRegionName("testForceCompactionDoesRoll"); props.setRolling(false); @@ -2955,7 +2769,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase * Confirm that forceCompaction waits for the compaction to finish */ @Test - public void testNonDefaultCompaction() { + public void testNonDefaultCompaction() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setRegionName("testForceCompactionDoesRoll"); props.setRolling(false); @@ -2985,7 +2799,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase * Confirm that forceCompaction waits for the compaction to finish */ @Test - public void testForceCompactionIsSync() { + public void testForceCompactionIsSync() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setRegionName("testForceCompactionDoesRoll"); props.setRolling(false); @@ -3011,8 +2825,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase } @Test - public void testBug40876() throws Exception - { + public void testBug40876() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setRegionName("testBug40876"); @@ -3027,15 +2840,13 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase Object obj =((LocalRegion)this.region).getValueOnDiskOrBuffer("key1"); assertEquals(Token.INVALID,obj); assertFalse(this.region.containsValueForKey("key1")); - - } /** * Make sure oplog created by recovery goes in the proper directory */ @Test - public void testBug41822() { + public void testBug41822() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setRegionName("testBug41822"); props.setRolling(false); @@ -3104,7 +2915,7 @@ public class DiskRegionJUnitTest extends DiskRegionTestingBase } @Test - public void testBug41770() throws InterruptedException { + public void testBug41770() throws Exception { DiskRegionProperties props = new DiskRegionProperties(); props.setRegionName("testBug41770"); props.setOverflow(false); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb91dedc/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionTestingBase.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionTestingBase.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionTestingBase.java index 75eb9db..0019270 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionTestingBase.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/DiskRegionTestingBase.java @@ -20,9 +20,7 @@ */ package com.gemstone.gemfire.internal.cache; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; import java.io.File; import java.io.IOException; @@ -36,7 +34,6 @@ import org.junit.Rule; import org.junit.rules.TestName; import com.gemstone.gemfire.LogWriter; -import com.gemstone.gemfire.SystemFailure; import com.gemstone.gemfire.cache.Cache; import com.gemstone.gemfire.cache.CacheFactory; import com.gemstone.gemfire.cache.CacheTransactionManager; @@ -54,33 +51,30 @@ import com.gemstone.gemfire.internal.cache.versions.VersionTag; * all tests are present here. * * @since 5.1 - * */ -public class DiskRegionTestingBase -{ - @Rule public TestName name = new TestName(); - - boolean testFailed = false; - String failureCause = ""; - protected static Cache cache = null; +public abstract class DiskRegionTestingBase { + protected static final boolean debug = false; + + protected static Cache cache = null; protected static DistributedSystem ds = null; protected static Properties props = new Properties(); - protected static File[] dirs = null; - protected static int[] diskDirSize = null; - protected Region region = null; - - protected static final boolean debug = false; - + protected Region region; protected LogWriter logWriter; + boolean testFailed; + String failureCause = ""; + + @Rule + public TestName name = new TestName(); @Before - public void setUp() throws Exception - { + public final void setUp() throws Exception { + preSetUp(); + props.setProperty("mcast-port", "0"); props.setProperty("locators", ""); props.setProperty("log-level", "config"); // to keep diskPerf logs smaller @@ -121,14 +115,20 @@ public class DiskRegionTestingBase deleteFiles(); DiskStoreImpl.SET_IGNORE_PREALLOCATE = true; + + postSetUp(); + } + + protected void preSetUp() throws Exception { + } + + protected void postSetUp() throws Exception { } @After - public void tearDown() throws Exception - { - /*if (cache != null && !cache.isClosed()) { - cache.close(); - }*/ + public final void tearDown() throws Exception { + preTearDown(); + try { if (cache != null && !cache.isClosed()) { for (Iterator itr = cache.rootRegions().iterator(); itr.hasNext();) { @@ -144,13 +144,6 @@ public class DiskRegionTestingBase catch (RegionDestroyedException e) { // ignore } - catch (VirtualMachineError e) { - SystemFailure.initiateFailure(e); - throw e; - } - catch (Throwable t) { - logWriter.error(t); - } } } @@ -159,22 +152,20 @@ public class DiskRegionTestingBase } } finally { - try { - closeCache(); - } - catch (VirtualMachineError e) { - SystemFailure.initiateFailure(e); - throw e; - } - catch (Throwable t) { - logWriter.error("Error in closing the cache ", t); - - } + closeCache(); } ds.disconnect(); //Asif : below is not needed but leave it deleteFiles(); DiskStoreImpl.SET_IGNORE_PREALLOCATE = false; + + postTearDown(); + } + + protected void preTearDown() throws Exception { + } + + protected void postTearDown() throws Exception { } protected Cache createCache() { @@ -210,8 +201,7 @@ public class DiskRegionTestingBase /** * cleans all the directory of all the files present in them */ - protected static void deleteFiles() - { + protected static void deleteFiles() { closeDiskStores(); for (int i = 0; i < dirs.length; i++) { System.out.println("trying to delete files in " + dirs[i].getAbsolutePath()); @@ -238,7 +228,6 @@ public class DiskRegionTestingBase } } } - } protected static void closeDiskStores() { @@ -251,34 +240,30 @@ public class DiskRegionTestingBase * clears and closes the region * */ - - protected void closeDown() - { - try{ - if(!region.isDestroyed()) { + protected void closeDown() { + try { + if (!region.isDestroyed()) { region.destroyRegion(); } - }catch(Exception e) { + } catch(Exception e) { this.logWriter.error("DiskRegionTestingBase::closeDown:Exception in destroyiong the region",e); } } /** * puts a 100 integers into the region - * */ - protected void put100Int() - { + protected void put100Int() { for (int i = 0; i < 100; i++) { region.put(new Integer(i), new Integer(i)); } } + protected void verify100Int() { verify100Int(true); } - protected void verify100Int(boolean verifySize) - { + protected void verify100Int(boolean verifySize) { if (verifySize) { assertEquals(100,region.size()); } @@ -291,31 +276,26 @@ public class DiskRegionTestingBase /** * will keep on putting till region overflows - * */ - protected void putTillOverFlow(Region region) - { + protected void putTillOverFlow(Region region) { int i = 0; for (i = 0; i < 1010; i++) { region.put(new Integer(i + 200), new Integer(i + 200)); } } - /* + /** * put an entry - * */ - protected void putForValidation(Region region) - { + protected void putForValidation(Region region) { final byte[] value = new byte[1024]; region.put("testKey", value); } - /* + /** * get val from disk */ - protected void validatePut(Region region) - { + protected void validatePut(Region region) { // flush data to disk ((LocalRegion)region).getDiskRegion().flushForTesting(); try { @@ -324,9 +304,7 @@ public class DiskRegionTestingBase catch (Exception ex) { ex.printStackTrace(); fail("Failed to get the value on disk"); - } - } protected HashMap<String, VersionTag> saveVersionTags(LocalRegion region) { @@ -353,17 +331,15 @@ public class DiskRegionTestingBase } } - /** Since these are not visible to cache.diskPerf we add wrapper methods to + /** + * Since these are not visible to cache.diskPerf we add wrapper methods to * make the following parameters/visible - * */ - public static void setCacheObserverCallBack() - { + public static void setCacheObserverCallBack() { LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = true; } - public static void unSetCacheObserverCallBack() - { + public static void unSetCacheObserverCallBack() { LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = false; }
