Repository: incubator-geode Updated Branches: refs/heads/develop af3199e45 -> b2b2de8b2
GEODE-526: Fix oplog unit test race condition KRF files are created asynchronously. The test needs to wait for the files to be created before checking header content. Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/066c11eb Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/066c11eb Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/066c11eb Branch: refs/heads/develop Commit: 066c11ebdb26fffbdad89d1bf2a045b6cca1fc56 Parents: ee4cc01 Author: Ashvin Agrawal <[email protected]> Authored: Wed Nov 4 13:54:45 2015 -0800 Committer: Ashvin Agrawal <[email protected]> Committed: Wed Nov 4 13:54:45 2015 -0800 ---------------------------------------------------------------------- .../gemstone/gemfire/internal/cache/Oplog.java | 1 - .../gemfire/internal/cache/OplogJUnitTest.java | 46 +++++++++++--------- 2 files changed, 26 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/066c11eb/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/Oplog.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/Oplog.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/Oplog.java index f0b33f1..cd197f2 100755 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/Oplog.java +++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/Oplog.java @@ -107,7 +107,6 @@ import com.gemstone.gemfire.internal.i18n.LocalizedStrings; import com.gemstone.gemfire.internal.logging.LogService; import com.gemstone.gemfire.internal.logging.log4j.LocalizedMessage; import com.gemstone.gemfire.internal.logging.log4j.LogMarker; -import com.gemstone.gemfire.internal.offheap.MemoryChunkWithRefCount; import com.gemstone.gemfire.internal.offheap.OffHeapHelper; import com.gemstone.gemfire.internal.offheap.SimpleMemoryAllocatorImpl; import com.gemstone.gemfire.internal.offheap.StoredObject; http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/066c11eb/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OplogJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OplogJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OplogJUnitTest.java index 1fc39bf..433af3d 100755 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OplogJUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/OplogJUnitTest.java @@ -27,15 +27,18 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; +import java.util.List; import java.util.Random; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; - -import junit.framework.Assert; +import java.util.stream.IntStream; import org.apache.commons.io.FileUtils; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; @@ -55,6 +58,7 @@ import com.gemstone.gemfire.cache.util.CacheWriterAdapter; import com.gemstone.gemfire.internal.InternalDataSerializer; import com.gemstone.gemfire.internal.cache.Oplog.OPLOG_TYPE; import com.gemstone.gemfire.test.junit.categories.IntegrationTest; +import com.jayway.awaitility.Awaitility; import dunit.DistributedTestCase; import dunit.DistributedTestCase.WaitCriterion; @@ -3806,8 +3810,8 @@ public class OplogJUnitTest extends DiskRegionTestingBase return sum; } - // disabled - this test frequently fails. See bug #52213 - public void disabledtestMagicSeqPresence() throws Exception { + @Test + public void testMagicSeqPresence() throws Exception { final int MAX_OPLOG_SIZE = 200; diskProps.setMaxOplogSize(MAX_OPLOG_SIZE); diskProps.setPersistBackup(true); @@ -3815,34 +3819,35 @@ public class OplogJUnitTest extends DiskRegionTestingBase diskProps.setSynchronous(true); diskProps.setOverflow(false); diskProps.setDiskDirsAndSizes(new File[] { dirs[0] }, new int[] { 4000 }); - region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, - Scope.LOCAL); + region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL); - // at least 3 kinds of files will be verified - assertEquals(3, verifyOplogHeader(dirs[0])); + // 3 types of oplog files will be verified + verifyOplogHeader(dirs[0], ".if", ".crf", ".drf"); try { LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = true; - for (int i = 0; i < 10; ++i) { - region.put("key-" + i, "value-"); - } - assertEquals(4, verifyOplogHeader(dirs[0])); + IntStream.range(0, 20).forEach(i -> region.put("key-" + i, "value-" + i)); + // krf is created, so 4 types of oplog files will be verified + verifyOplogHeader(dirs[0], ".if", ".crf", ".drf", ".krf"); region.close(); - region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, - diskProps, Scope.LOCAL); + region = DiskRegionHelperFactory.getSyncPersistOnlyRegion(cache, diskProps, Scope.LOCAL); - assertEquals(4, verifyOplogHeader(dirs[0])); + verifyOplogHeader(dirs[0], ".if", ".crf", ".drf", ".krf"); region.close(); } finally { LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = false; } } - /* - * returns number of types of files verified - */ - private int verifyOplogHeader(File dir) throws IOException { + private void verifyOplogHeader(File dir, String ... oplogTypes) throws IOException { + + Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> { + List<String> types = new ArrayList<>(Arrays.asList(oplogTypes)); + Arrays.stream(dir.listFiles()).map(File::getName).map(f -> f.substring(f.indexOf("."))).forEach(types::remove); + return types.isEmpty(); + }); + File[] files = dir.listFiles(); HashSet<String> verified = new HashSet<String>(); for (File file : files) { @@ -3880,7 +3885,8 @@ public class OplogJUnitTest extends DiskRegionTestingBase assertEquals("expected a read to return 8 but it returned " + count + " for file " + file, 8, count); assertTrue(Arrays.equals(expect, buf)); } - return verified.size(); + + assertEquals(oplogTypes.length, verified.size()); } /**
