Return-Path: X-Original-To: apmail-geode-commits-archive@minotaur.apache.org Delivered-To: apmail-geode-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 15D39186D1 for ; Wed, 25 Nov 2015 19:07:32 +0000 (UTC) Received: (qmail 85833 invoked by uid 500); 25 Nov 2015 19:07:32 -0000 Delivered-To: apmail-geode-commits-archive@geode.apache.org Received: (qmail 85799 invoked by uid 500); 25 Nov 2015 19:07:32 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 85789 invoked by uid 99); 25 Nov 2015 19:07:32 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Nov 2015 19:07:31 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 88076C143C for ; Wed, 25 Nov 2015 19:07:31 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.227 X-Spam-Level: * X-Spam-Status: No, score=1.227 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.554, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id JPsvO29YeZEe for ; Wed, 25 Nov 2015 19:07:19 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 15CA042ABE for ; Wed, 25 Nov 2015 19:07:14 +0000 (UTC) Received: (qmail 84106 invoked by uid 99); 25 Nov 2015 19:07:14 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Nov 2015 19:07:14 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 7AE92E0A3D; Wed, 25 Nov 2015 19:07:14 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vford13@apache.org To: commits@geode.incubator.apache.org Date: Wed, 25 Nov 2015 19:07:19 -0000 Message-Id: In-Reply-To: <7cde6054e33a43d9bcaf38e7180aa4d8@git.apache.org> References: <7cde6054e33a43d9bcaf38e7180aa4d8@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [06/50] [abbrv] incubator-geode git commit: GEODE-343 Fix race in ConcurrentMapOpsDUnitTest. GEODE-343 Fix race in ConcurrentMapOpsDUnitTest. Added a new listener to clients that will keep track of the initial creates, then wait for this listener to get all initial creates. Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/8a5920d5 Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/8a5920d5 Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/8a5920d5 Branch: refs/heads/feature/GEODE-78 Commit: 8a5920d51346b661e253bbb33d392f92b83184eb Parents: 71e8dc8 Author: Swapnil Bawaskar Authored: Wed Sep 23 07:30:45 2015 -0700 Committer: Swapnil Bawaskar Committed: Wed Sep 23 09:29:21 2015 -0700 ---------------------------------------------------------------------- .../cache/ConcurrentMapOpsDUnitTest.java | 69 ++++++++++++++++++-- 1 file changed, 65 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/8a5920d5/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/ConcurrentMapOpsDUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/ConcurrentMapOpsDUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/ConcurrentMapOpsDUnitTest.java index 72db3f1..a34f6d2 100644 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/ConcurrentMapOpsDUnitTest.java +++ b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/ConcurrentMapOpsDUnitTest.java @@ -16,6 +16,7 @@ import java.io.IOException; import java.io.Serializable; import java.util.HashSet; import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; import junit.framework.AssertionFailedError; @@ -186,6 +187,17 @@ public class ConcurrentMapOpsDUnitTest extends CacheTestCase { fail("should not be called. Event="+event); } } + + static class InitialCreatesListener extends AbstractConcMapOpsListener { + AtomicInteger numCreates = new AtomicInteger(); + @Override + void validate(EntryEvent event) { + if (!event.getOperation().isCreate()) { + fail("expected only create events"); + } + numCreates.incrementAndGet(); + } + } /** * @param name */ @@ -205,18 +217,67 @@ public class ConcurrentMapOpsDUnitTest extends CacheTestCase { createClientRegionWithRI(client1, port1, true); createClientRegionWithRI(client2, port2, true); - + SerializableCallable addListenerToClientForInitialCreates = new SerializableCallable() { + public Object call() throws Exception { + Region r = getCache().getRegion(REP_REG_NAME); + r.getAttributesMutator().addCacheListener(new InitialCreatesListener()); + Region pr = getCache().getRegion(PR_REG_NAME); + pr.getAttributesMutator().addCacheListener(new InitialCreatesListener()); + return null; + } + }; + client1.invoke(addListenerToClientForInitialCreates); + client2.invoke(addListenerToClientForInitialCreates); + vm1.invoke(new SerializableCallable() { public Object call() throws Exception { Region r = getGemfireCache().getRegion(REP_REG_NAME); Region pr = getGemfireCache().getRegion(PR_REG_NAME); - for (int i=0; i r = getGemfireCache().getRegion(REP_REG_NAME); + Region pr = getGemfireCache().getRegion(PR_REG_NAME); + waitForCreates(r); + waitForCreates(pr); + return null; + } + private void waitForCreates(Region region) { + CacheListener[] listeners = region.getAttributes().getCacheListeners(); + boolean listenerFound = false; + for (CacheListener listener : listeners) { + if (listener instanceof InitialCreatesListener) { + listenerFound = true; + final InitialCreatesListener initialCreatesListener = (InitialCreatesListener) listener; + WaitCriterion wc = new WaitCriterion() { + @Override + public boolean done() { + return initialCreatesListener.numCreates.get() == MAX_ENTRIES; + } + @Override + public String description() { + return "Client expected to get "+MAX_ENTRIES+" creates, but got "+initialCreatesListener.numCreates.get(); + } + }; + DistributedTestCase.waitForCriterion(wc, 30*1000, 500, true); + } + } + if (!listenerFound) { + fail("Client listener should have been found"); + } + } + }; + client1.invoke(waitForInitialCreates); + client2.invoke(waitForInitialCreates); + SerializableCallable addListener = new SerializableCallable() { public Object call() throws Exception { Region r = getCache().getRegion(REP_REG_NAME);