Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 651E4200B33 for ; Wed, 15 Jun 2016 02:07:58 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 63893160A56; Wed, 15 Jun 2016 00:07:58 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 6AC6E160A5F for ; Wed, 15 Jun 2016 02:07:56 +0200 (CEST) Received: (qmail 88039 invoked by uid 500); 15 Jun 2016 00:07:55 -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 88030 invoked by uid 99); 15 Jun 2016 00:07:55 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Jun 2016 00:07:55 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 091B5C2153 for ; Wed, 15 Jun 2016 00:07:55 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.646 X-Spam-Level: X-Spam-Status: No, score=-4.646 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-1.426] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id gO5Ayvwv4W8m for ; Wed, 15 Jun 2016 00:07:50 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 0EF7460E1B for ; Wed, 15 Jun 2016 00:07:19 +0000 (UTC) Received: (qmail 83122 invoked by uid 99); 15 Jun 2016 00:07:18 -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, 15 Jun 2016 00:07:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0EF2DE07FE; Wed, 15 Jun 2016 00:07:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hiteshkhamesra@apache.org To: commits@geode.incubator.apache.org Date: Wed, 15 Jun 2016 00:07:38 -0000 Message-Id: In-Reply-To: <60f2027f4d98435cba2ee6ef29b9a036@git.apache.org> References: <60f2027f4d98435cba2ee6ef29b9a036@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [22/94] [abbrv] [partial] incubator-geode git commit: GEODE-837: update tests from JUnit3 to JUnit4 archived-at: Wed, 15 Jun 2016 00:07:58 -0000 http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b914df23/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HAExpiryDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HAExpiryDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HAExpiryDUnitTest.java index 0e8514f..939e81e 100755 --- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HAExpiryDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HAExpiryDUnitTest.java @@ -16,8 +16,13 @@ */ package com.gemstone.gemfire.internal.cache.ha; +import static org.junit.Assert.*; + import java.util.Properties; +import org.junit.Test; +import org.junit.experimental.categories.Category; + import com.gemstone.gemfire.cache.AttributesFactory; import com.gemstone.gemfire.cache.Cache; import com.gemstone.gemfire.cache.CacheException; @@ -34,13 +39,14 @@ import com.gemstone.gemfire.distributed.DistributedSystem; import com.gemstone.gemfire.internal.cache.EventID; import com.gemstone.gemfire.internal.cache.HARegion; import com.gemstone.gemfire.internal.cache.RegionQueue; -import com.gemstone.gemfire.test.dunit.DistributedTestCase; import com.gemstone.gemfire.test.dunit.Host; import com.gemstone.gemfire.test.dunit.Invoke; import com.gemstone.gemfire.test.dunit.SerializableRunnable; import com.gemstone.gemfire.test.dunit.VM; import com.gemstone.gemfire.test.dunit.Wait; import com.gemstone.gemfire.test.dunit.WaitCriterion; +import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase; +import com.gemstone.gemfire.test.junit.categories.DistributedTest; /** * This test checks Expiration of events in the regionqueue. @@ -49,11 +55,9 @@ import com.gemstone.gemfire.test.dunit.WaitCriterion; * 3. Checks size of the regionqueue. Size of the regionqueue should be greater than 0. * 4. Waits for the period which is slightly greater than expiration period. * 5. Checks size of the regionqueue. Size of the regionqueue should be equal to 0. - * */ - -public class HAExpiryDUnitTest extends DistributedTestCase -{ +@Category(DistributedTest.class) +public class HAExpiryDUnitTest extends JUnit4DistributedTestCase { VM vm0 = null; @@ -73,8 +77,8 @@ public class HAExpiryDUnitTest extends DistributedTestCase protected static int regionQueueSize = -1; - public HAExpiryDUnitTest(String name) { - super(name); + public HAExpiryDUnitTest() { + super(); } /** @@ -103,6 +107,7 @@ public class HAExpiryDUnitTest extends DistributedTestCase Invoke.invokeInEveryVM(new SerializableRunnable() { public void run() { cache = null; } }); } + @Test public void testExpiryPeriod() throws Exception { vm0.invoke(() -> HAExpiryDUnitTest.createRegionQueue(new Boolean(false))); @@ -132,6 +137,7 @@ public class HAExpiryDUnitTest extends DistributedTestCase vm3.invoke(() -> HAExpiryDUnitTest.checkSizeAfterExpiration()); } + @Test public void testDurableExpiryPeriod() throws Exception { vm0.invoke(() -> HAExpiryDUnitTest.createRegionQueue(new Boolean(true))); @@ -234,7 +240,7 @@ public class HAExpiryDUnitTest extends DistributedTestCase public static void createRegionQueue(Boolean isDurable) throws Exception { - new HAExpiryDUnitTest("temp").createCache(new Properties()); + new HAExpiryDUnitTest().createCache(new Properties()); HARegionQueueAttributes hattr = new HARegionQueueAttributes(); // setting expiry time for the regionqueue. hattr.setExpiryTime(4); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b914df23/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HAGIIBugDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HAGIIBugDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HAGIIBugDUnitTest.java index b6b4071..5e659f5 100755 --- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HAGIIBugDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HAGIIBugDUnitTest.java @@ -16,10 +16,16 @@ */ package com.gemstone.gemfire.internal.cache.ha; +import static org.junit.Assert.*; + import java.util.ArrayList; import java.util.Iterator; import java.util.Properties; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; + import com.gemstone.gemfire.cache.AttributesFactory; import com.gemstone.gemfire.cache.Cache; import com.gemstone.gemfire.cache.CacheException; @@ -28,9 +34,9 @@ import com.gemstone.gemfire.cache.CacheListener; import com.gemstone.gemfire.cache.DataPolicy; import com.gemstone.gemfire.cache.EntryEvent; import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.Region.Entry; import com.gemstone.gemfire.cache.RegionAttributes; import com.gemstone.gemfire.cache.Scope; -import com.gemstone.gemfire.cache.Region.Entry; import com.gemstone.gemfire.cache.util.CacheListenerAdapter; import com.gemstone.gemfire.cache30.CacheSerializableRunnable; import com.gemstone.gemfire.distributed.DistributedSystem; @@ -39,13 +45,14 @@ import com.gemstone.gemfire.internal.cache.HARegion; import com.gemstone.gemfire.internal.cache.RegionQueue; import com.gemstone.gemfire.test.dunit.Assert; import com.gemstone.gemfire.test.dunit.AsyncInvocation; -import com.gemstone.gemfire.test.dunit.DistributedTestCase; import com.gemstone.gemfire.test.dunit.Host; import com.gemstone.gemfire.test.dunit.Invoke; import com.gemstone.gemfire.test.dunit.LogWriterUtils; import com.gemstone.gemfire.test.dunit.SerializableRunnable; import com.gemstone.gemfire.test.dunit.ThreadUtils; import com.gemstone.gemfire.test.dunit.VM; +import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase; +import com.gemstone.gemfire.test.junit.categories.DistributedTest; /** * This test points out the bug when GII of HARegion Queue is happening and at the same time it is receiving puts from peer to peer. @@ -55,11 +62,9 @@ import com.gemstone.gemfire.test.dunit.VM; * 4. Start vm1 and create HARegion Queue asynchronously and notify vm0 after its creation * 5. Put the data from vm0 asynchronously till HARegion Queue gets created in vm1. * 6. Validate the data. Puts happened during GII should be missed. - * */ - -public class HAGIIBugDUnitTest extends DistributedTestCase -{ +@Category(DistributedTest.class) +public class HAGIIBugDUnitTest extends JUnit4DistributedTestCase { VM vm0 = null; @@ -133,15 +138,9 @@ public class HAGIIBugDUnitTest extends DistributedTestCase assertNotNull(cache); } - - public void testDummy() throws Exception - { - LogWriterUtils.getLogWriter().info("This is Dummy test for the GII"); - } - - - public void _testGIIBug() throws Exception - { + @Ignore("TODO") + @Test + public void testGIIBug() throws Exception { vm0.invoke(putFromVmBeforeGII("vm0_1")); populateKeySet("vm0_1"); @@ -336,7 +335,7 @@ public class HAGIIBugDUnitTest extends DistributedTestCase public static void createRegionQueue() throws Exception { - new HAGIIBugDUnitTest("temp").createCache(new Properties()); + new HAGIIBugDUnitTest().createCache(new Properties()); HARegionQueueAttributes hattr = new HARegionQueueAttributes(); // setting expiry time for the regionqueue. hattr.setExpiryTime(12000000); @@ -361,11 +360,6 @@ public class HAGIIBugDUnitTest extends DistributedTestCase } } - public HAGIIBugDUnitTest(String arg0) { - super(arg0); - - } - } /** http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b914df23/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HAGIIDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HAGIIDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HAGIIDUnitTest.java index fabe3e6..62375f9 100755 --- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HAGIIDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HAGIIDUnitTest.java @@ -14,10 +14,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.gemstone.gemfire.internal.cache.ha; -import com.gemstone.gemfire.cache.*; +import static com.gemstone.gemfire.distributed.DistributedSystemConfigProperties.*; +import static com.gemstone.gemfire.test.dunit.Assert.*; + +import java.util.Collections; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; + +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import com.gemstone.gemfire.cache.AttributesFactory; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.EntryEvent; +import com.gemstone.gemfire.cache.InterestResultPolicy; +import com.gemstone.gemfire.cache.Operation; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.RegionAttributes; +import com.gemstone.gemfire.cache.Scope; import com.gemstone.gemfire.cache.server.CacheServer; import com.gemstone.gemfire.cache.util.CacheListenerAdapter; import com.gemstone.gemfire.cache30.ClientServerTestCase; @@ -32,86 +51,35 @@ import com.gemstone.gemfire.internal.cache.tier.sockets.CacheClientNotifier; import com.gemstone.gemfire.internal.cache.tier.sockets.ClientTombstoneMessage; import com.gemstone.gemfire.internal.cache.tier.sockets.ConflationDUnitTest; import com.gemstone.gemfire.internal.cache.versions.VersionSource; -import com.gemstone.gemfire.test.dunit.*; - -import java.util.Collections; -import java.util.Iterator; -import java.util.Map; -import java.util.Properties; - -import static com.gemstone.gemfire.distributed.DistributedSystemConfigProperties.LOCATORS; -import static com.gemstone.gemfire.distributed.DistributedSystemConfigProperties.MCAST_PORT; +import com.gemstone.gemfire.test.dunit.Assert; +import com.gemstone.gemfire.test.dunit.Host; +import com.gemstone.gemfire.test.dunit.Invoke; +import com.gemstone.gemfire.test.dunit.NetworkUtils; +import com.gemstone.gemfire.test.dunit.VM; +import com.gemstone.gemfire.test.dunit.Wait; +import com.gemstone.gemfire.test.dunit.WaitCriterion; +import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase; +import com.gemstone.gemfire.test.junit.categories.DistributedTest; /** * Client is connected to S1 which has a slow dispatcher. Puts are made on S1. Then S2 is started * and made available for the client. After that , S1 's server is stopped. The client fails over to * S2. The client should receive all the puts . These puts have arrived on S2 via GII of HARegion. - * - * */ +@Category(DistributedTest.class) +public class HAGIIDUnitTest extends JUnit4DistributedTestCase { -class GIIChecker extends CacheListenerAdapter -{ - private boolean gotFirst = false; - private boolean gotSecond = false; - private boolean gotThird = false; - private int updates = 0; - - public void afterUpdate(EntryEvent event) { - - this.updates++; - - String key = (String) event.getKey(); - String value = (String) event.getNewValue(); - - if (key.equals("key-1") && value.equals("value-1")) { - this.gotFirst = true; - } - - if (key.equals("key-2") && value.equals("value-2")) { - this.gotSecond = true; - } - - if (key.equals("key-3") && value.equals("value-3")) { - this.gotThird = true; - } - } - - public int getUpdates() { - return this.updates; - } - - public boolean gotFirst() { - return this.gotFirst; - } - - public boolean gotSecond() { - return this.gotSecond; - } - - public boolean gotThird() { - return this.gotThird; - } -} - -public class HAGIIDUnitTest extends DistributedTestCase -{ private static Cache cache = null; //server private static VM server0 = null; private static VM server1 = null; private static VM client0 = null; - private static final String REGION_NAME = "HAGIIDUnitTest_region"; + private static final String REGION_NAME = HAGIIDUnitTest.class.getSimpleName() + "_region"; protected static GIIChecker checker = new GIIChecker(); private int PORT2; - /** constructor */ - public HAGIIDUnitTest(String name) { - super(name); - } - @Override public final void postSetUp() throws Exception { final Host host = Host.getHost(0); @@ -134,6 +102,7 @@ public class HAGIIDUnitTest extends DistributedTestCase client0.invoke(() -> HAGIIDUnitTest.createClientCache( NetworkUtils.getServerHostName(host), new Integer(PORT1),new Integer(PORT2))); } + @Test public void testGIIRegionQueue() { client0.invoke(() -> HAGIIDUnitTest.createEntries()); @@ -167,7 +136,7 @@ public class HAGIIDUnitTest extends DistributedTestCase Properties props = new Properties(); props.setProperty(MCAST_PORT, "0"); props.setProperty(LOCATORS, ""); - new HAGIIDUnitTest("temp").createCache(props); + new HAGIIDUnitTest().createCache(props); AttributesFactory factory = new AttributesFactory(); ClientServerTestCase.configureConnectionPool(factory, host, new int[] {PORT1,PORT2}, true, -1, 2, null, 1000, -1, false, -1); factory.setScope(Scope.DISTRIBUTED_ACK); @@ -178,7 +147,7 @@ public class HAGIIDUnitTest extends DistributedTestCase public static Integer createServer1Cache() throws Exception { - new HAGIIDUnitTest("temp").createCache(new Properties()); + new HAGIIDUnitTest().createCache(new Properties()); AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); factory.setDataPolicy(DataPolicy.REPLICATE); @@ -194,7 +163,7 @@ public class HAGIIDUnitTest extends DistributedTestCase public static void createServer2Cache(Integer port) throws Exception { - new HAGIIDUnitTest("temp").createCache(new Properties()); + new HAGIIDUnitTest().createCache(new Properties()); AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); factory.setDataPolicy(DataPolicy.REPLICATE); @@ -219,6 +188,7 @@ public class HAGIIDUnitTest extends DistributedTestCase Assert.fail("failed while registering keys ", ex); } } + public static void createEntries() { try { @@ -244,7 +214,7 @@ public class HAGIIDUnitTest extends DistributedTestCase } } catch (Exception e) { - fail("failed while stopServer()" + e); + fail("failed while stopServer()", e); } } @@ -401,7 +371,6 @@ public class HAGIIDUnitTest extends DistributedTestCase Wait.waitForCriterion(ev, 60 * 1000, 200, true); // assertIndexDetailsEquals( "key-2",r.getEntry("key-2").getValue()); - // wait until // we have a // dead server @@ -450,4 +419,49 @@ public class HAGIIDUnitTest extends DistributedTestCase cache.getDistributedSystem().disconnect(); } } + + private static class GIIChecker extends CacheListenerAdapter { + + private boolean gotFirst = false; + private boolean gotSecond = false; + private boolean gotThird = false; + private int updates = 0; + + @Override + public void afterUpdate(EntryEvent event) { + + this.updates++; + + String key = (String) event.getKey(); + String value = (String) event.getNewValue(); + + if (key.equals("key-1") && value.equals("value-1")) { + this.gotFirst = true; + } + + if (key.equals("key-2") && value.equals("value-2")) { + this.gotSecond = true; + } + + if (key.equals("key-3") && value.equals("value-3")) { + this.gotThird = true; + } + } + + public int getUpdates() { + return this.updates; + } + + public boolean gotFirst() { + return this.gotFirst; + } + + public boolean gotSecond() { + return this.gotSecond; + } + + public boolean gotThird() { + return this.gotThird; + } + } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b914df23/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARQAddOperationJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARQAddOperationJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARQAddOperationJUnitTest.java index 6cb5b47..4bbc49f 100755 --- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARQAddOperationJUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARQAddOperationJUnitTest.java @@ -16,37 +16,41 @@ */ package com.gemstone.gemfire.internal.cache.ha; +import static com.gemstone.gemfire.distributed.DistributedSystemConfigProperties.*; +import static org.junit.Assert.*; + +import java.io.IOException; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.apache.logging.log4j.Logger; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; + import com.gemstone.gemfire.LogWriter; -import com.gemstone.gemfire.cache.*; +import com.gemstone.gemfire.cache.AttributesFactory; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheException; +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.cache.CacheListener; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.EntryEvent; +import com.gemstone.gemfire.cache.Scope; import com.gemstone.gemfire.cache.util.CacheListenerAdapter; import com.gemstone.gemfire.internal.cache.Conflatable; import com.gemstone.gemfire.internal.cache.EventID; import com.gemstone.gemfire.internal.logging.LogService; import com.gemstone.gemfire.test.dunit.ThreadUtils; import com.gemstone.gemfire.test.junit.categories.IntegrationTest; -import junit.framework.Assert; -import org.apache.logging.log4j.Logger; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.io.IOException; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import static com.gemstone.gemfire.distributed.DistributedSystemConfigProperties.MCAST_PORT; -import static org.junit.Assert.*; /** * Test to verify Add operation to HARegion Queue with and without conflation. - * */ - @Category(IntegrationTest.class) -public class HARQAddOperationJUnitTest -{ +public class HARQAddOperationJUnitTest { private static final Logger logger = LogService.getLogger(); /** The cache instance */ @@ -74,78 +78,40 @@ public class HARQAddOperationJUnitTest volatile static int expiryCount = 0; - /** - * Create the cache in setup - * - * @throws Exception - - * thrown if any exception occurs in setUp - */ @Before - public void setUp() throws Exception - { + public void setUp() throws Exception { this.cache = createCache(); this.logWriter = cache.getLogger(); } - /** - * Close the cache in tear down * - * - * @throws Exception - - * thrown if any exception occurs in tearDown - */ @After - public void tearDown() throws Exception - { + public void tearDown() throws Exception { this.cache.close(); } /** * Creates the cache instance for the test - * - * @return the cache instance - * @throws CacheException - - * thrown if any exception occurs in cache creation */ - private Cache createCache() throws CacheException - { + private Cache createCache() throws CacheException { return new CacheFactory().set(MCAST_PORT, "0").create(); } /** * Creates HA region-queue object - * - * @return HA region-queue object - * @throws IOException - * @throws ClassNotFoundException - * @throws CacheException - * @throws InterruptedException */ - protected HARegionQueue createHARegionQueue(String name) - throws IOException, ClassNotFoundException, CacheException, InterruptedException - { + protected HARegionQueue createHARegionQueue(String name) throws IOException, ClassNotFoundException, CacheException, InterruptedException { AttributesFactory factory = new AttributesFactory(); factory.setDataPolicy(DataPolicy.REPLICATE); factory.setScope(Scope.DISTRIBUTED_ACK); - HARegionQueue regionqueue = HARegionQueue.getHARegionQueueInstance(name, - cache, HARegionQueue.NON_BLOCKING_HA_QUEUE, false); + HARegionQueue regionqueue = HARegionQueue.getHARegionQueueInstance(name, cache, HARegionQueue.NON_BLOCKING_HA_QUEUE, false); return regionqueue; } /** * Creates HA region-queue object - * - * @return HA region-queue object - * @throws IOException - * @throws ClassNotFoundException - * @throws CacheException - * @throws InterruptedException */ - protected HARegionQueue createHARegionQueue(String name, - HARegionQueueAttributes attrs) throws IOException, ClassNotFoundException, CacheException, InterruptedException - { - - HARegionQueue regionqueue = HARegionQueue.getHARegionQueueInstance(name, - cache, attrs, HARegionQueue.NON_BLOCKING_HA_QUEUE, false); + protected HARegionQueue createHARegionQueue(String name, HARegionQueueAttributes attrs) throws IOException, ClassNotFoundException, CacheException, InterruptedException { + HARegionQueue regionqueue = HARegionQueue.getHARegionQueueInstance(name, cache, attrs, HARegionQueue.NON_BLOCKING_HA_QUEUE, false); return regionqueue; } @@ -155,11 +121,9 @@ public class HARQAddOperationJUnitTest * to value 2 3) Available IDs , Last DispatchedWrapper Set & Conflation Map * should have size 1. 4) Conflation Map , LastDispatchedWrapper Set & * Available IDs should have counter corresponding to second operation - * */ @Test - public void testQueueAddOperationWithConflation() throws Exception - { + public void testQueueAddOperationWithConflation() throws Exception { this.logWriter .info("HARegionQueueJUnitTest : testQueueAddOperationWithConflation BEGIN"); this.rq = createHARegionQueue("testQueueAddOperationWithConflation"); @@ -191,11 +155,9 @@ public class HARQAddOperationJUnitTest * 3) This wrapper should have a set with size 1. 4) The available IDs set * shoudl have size 1. 5) Put another object by same thread. 6) The wrapper * set & availableIs List should have size 2 . - * */ @Test - public void testQueueAddOperationWithoutConflation() throws Exception - { + public void testQueueAddOperationWithoutConflation() throws Exception { this.logWriter .info("HARegionQueueJUnitTest : testQueueAddOperationWithoutConflation BEGIN"); this.rq = createHARegionQueue("testQueueAddOperationWithConflation"); @@ -239,12 +201,9 @@ public class HARQAddOperationJUnitTest * available IDs , LastDispatchedWrapper's Set should have size 0. Events map * containg should have size 1 ( corresponding to the * lastDispatchedAndCurrentEvent Wrapper objcet) - * - * @throws Exception */ @Test - public void testQueueAddTakeOperationWithoutConflation() throws Exception - { + public void testQueueAddTakeOperationWithoutConflation() throws Exception { this.logWriter .info("HARegionQueueJUnitTest : testQueueAddTakeOperationWithoutConflation BEGIN"); @@ -269,12 +228,9 @@ public class HARQAddOperationJUnitTest * with Threaddentifer as key & sequence as the value for Expiry. Perform a * take operation. Validate that expiry on ThreadIdentifier removes itself * from Events Map - * - * */ @Test - public void testExpiryOnThreadIdentifier() - { + public void testExpiryOnThreadIdentifier() { try { HARegionQueueAttributes attrs = new HARegionQueueAttributes(); attrs.setExpiryTime(2); @@ -312,12 +268,9 @@ public class HARQAddOperationJUnitTest * expiry. Validate the data present in Queue experiences expiry. After the * expiry of the data , AvaialbleIds size should be 0, entry removed from * Region, LastDispatchedWrapperSet should have size 0. - * - * */ @Test - public void testNoExpiryOnThreadIdentifier() - { + public void testNoExpiryOnThreadIdentifier() { try { HARegionQueueAttributes hqa = new HARegionQueueAttributes(); hqa.setExpiryTime(8); @@ -370,11 +323,9 @@ public class HARQAddOperationJUnitTest * queue contains objects from 1- 10. QRM with sequenceID 5 arrives It should * remove only remove objects for 1- 5. Then sequenceID 10 come which should * remove 5-10. - * */ @Test - public void testMultipleQRMArrival() throws Exception - { + public void testMultipleQRMArrival() throws Exception { HARegionQueue regionqueue = createHARegionQueue("testNoExpiryOnThreadIdentifier"); EventID[] ids = new EventID[10]; @@ -404,7 +355,6 @@ public class HARQAddOperationJUnitTest regionqueue.removeDispatchedEvents(ids[9]); assertEquals(0, regionqueue.getAvalaibleIds().size()); - } /** @@ -414,11 +364,9 @@ public class HARQAddOperationJUnitTest * before QRM thread acts , the object should be present in the * lastDispatchedSet & AvailableID. Then the QRM thread gets unblocked , it * should remove from the available ID. - * */ @Test - public void testConcurrentPutAndQRM() throws Exception - { + public void testConcurrentPutAndQRM() throws Exception { testFailed = false; message = new StringBuffer(); final HARegionQueue regionqueue = createHARegionQueue("testConcurrentPutAndQRM"); @@ -475,8 +423,7 @@ public class HARQAddOperationJUnitTest * put operation shud remove from region without adding the ID anywhere. */ @Test - public void testConcurrentQRMAndPut() throws Exception - { + public void testConcurrentQRMAndPut() throws Exception { testFailed = false; final HARegionQueue regionqueue = createHARegionQueue("testConcurrentQRMAndPut"); final EventID id1 = new EventID(new byte[] { 1 }, 1, 1); @@ -523,20 +470,15 @@ public class HARQAddOperationJUnitTest assertEquals(0, regionqueue.getAvalaibleIds().size()); assertEquals(2, regionqueue.getLastDispatchedSequenceId(id2)); - } /** * Two QRMs arriving such that higer sequence number arriving before lower * sequence number. The lower squnce number should not set itself & also not * do any checking on the IDs of the LinkedHashSet - * - * @throws Exception */ - @Test - public void testEventMapPopulationForQRM() throws Exception - { + public void testEventMapPopulationForQRM() throws Exception { HARegionQueue regionqueue = createHARegionQueue("testEventMapPopulationForQRM"); EventID id1 = new EventID(new byte[] { 1 }, 1, 1); EventID id2 = new EventID(new byte[] { 1 }, 1, 2); @@ -566,13 +508,9 @@ public class HARQAddOperationJUnitTest * for that ThreadIdentifier. The ID which gets conflated should not be * present in the availableID, Region & that ThreadIdentifier's HashSet . The * conflation map should contain the Old IDs position. - * - * @throws Exception */ - @Test - public void testCleanUpForConflation() throws Exception - { + public void testCleanUpForConflation() throws Exception { this.logWriter .info("HARQAddOperationJUnitTest : testCleanUpForConflation BEGIN"); testFailed = false; @@ -661,10 +599,8 @@ public class HARQAddOperationJUnitTest * are deleted from the available IDs & the Counters set contained in DACE. * Conflation is disabled. */ - @Test - public void testPeekAndRemoveWithoutConflation() throws Exception - { + public void testPeekAndRemoveWithoutConflation() throws Exception { testFailed = false; message = null; final int numOfThreads = 5; @@ -719,7 +655,6 @@ public class HARQAddOperationJUnitTest this.logWriter .info("testPeekAndRemoveWithoutConflation() completed successfully"); - } /** @@ -728,10 +663,8 @@ public class HARQAddOperationJUnitTest * are deleted from the available IDs & the Counters set contained in DACE. * Conflation is enabled */ - @Test - public void testPeekAndRemoveWithConflation() throws Exception - { + public void testPeekAndRemoveWithConflation() throws Exception { testFailed = false; message = null; final int numOfThreads = 5; @@ -791,7 +724,6 @@ public class HARQAddOperationJUnitTest this.logWriter .info("testPeekAndRemoveWithConflation() completed successfully"); - } /** @@ -799,13 +731,9 @@ public class HARQAddOperationJUnitTest * do a peek of batch size 5, 10 , 15 & 20 respectively. And all of them * concurrently cal remove. The remove should ensure that the entries are * deleted from the available IDs & the Counters set contained in DACE. - * - * @throws Exception */ - @Test - public void testPeekForDiffBatchSizeAndRemoveAll() throws Exception - { + public void testPeekForDiffBatchSizeAndRemoveAll() throws Exception { testFailed = false; message = null; barrierCount = 0; @@ -913,12 +841,9 @@ public class HARQAddOperationJUnitTest * do a peek of batch size 5, 10 and 15 respectively. And all of them * concurrently call remove. The remove should ensure that the entries are * deleted from the available IDs & the Counters set contained in DACE. - * - * @throws Exception */ @Test - public void testPeekForDiffBatchSizeAndRemoveSome() throws Exception - { + public void testPeekForDiffBatchSizeAndRemoveSome() throws Exception { testFailed = false; barrierCount = 0; message = null; @@ -1010,7 +935,6 @@ public class HARQAddOperationJUnitTest this.logWriter .info("testPeekForDiffBatchSizeAndRemoveSome() completed successfully"); - } /** @@ -1023,9 +947,8 @@ public class HARQAddOperationJUnitTest * next expiry should remove the LastDisptachedWrapper */ @Test - public void testAddWithQRMAndExpiry() throws Exception - { - try{ + public void testAddWithQRMAndExpiry() throws Exception { + try { HARegionQueueAttributes attrs = new HARegionQueueAttributes(); attrs.setExpiryTime(10); final HARegionQueue regionqueue = new HARegionQueue.TestOnlyHARegionQueue("testing", cache, attrs) { @@ -1067,11 +990,11 @@ public class HARQAddOperationJUnitTest assertEquals(4, regionqueue.getLastDispatchedSequenceId(new EventID(new byte[] { 1 }, 1, 1))); // verify 1-5 not in region for (long i = 1; i < 6; i++) { - Assert.assertTrue(!regionqueue.getRegion().containsKey(new Long(i))); + assertTrue(!regionqueue.getRegion().containsKey(new Long(i))); } // verify 6-10 still in region queue for (long i = 6; i < 11; i++) { - Assert.assertTrue(regionqueue.getRegion().containsKey(new Long(i))); + assertTrue(regionqueue.getRegion().containsKey(new Long(i))); } // Perform 5 take operations to remove next 5-9 sequence ids @@ -1083,7 +1006,7 @@ public class HARQAddOperationJUnitTest assertEquals(9, regionqueue.getLastDispatchedSequenceId(new EventID(new byte[] { 1 }, 1, 1))); // verify that sequence ids 1-10 all are removed from the RQ for (long i = 1; i < 11; i++) { - Assert.assertTrue(!regionqueue.getRegion().containsKey(new Long(i))); + assertTrue(!regionqueue.getRegion().containsKey(new Long(i))); } // wait until expiry thread has run once @@ -1109,11 +1032,11 @@ public class HARQAddOperationJUnitTest assertNull(regionqueue.getRegion().get(tID)); } catch (Exception e) { - fail("Exception occured in test due to " + e); + throw new AssertionError("Exception occurred in test due to", e); } } - /** + /* * This test does the following:
* 1)Create a blocking HARegionQueue
* 2)Add some events to the queue with same ThreadIdentifier
@@ -1125,18 +1048,13 @@ public class HARQAddOperationJUnitTest * 7)Verify that the size of wrapper-map is 1 as all events had same ThreadId
* 8)Verify that the sequenceId against the ThreadId in the wrapper-map is * same as that of the last event taken
- * - * @throws Exception - - * thrown if any exception occurs in test execution */ /** * Behaviour of take() has been changed for relaible messaging feature. Region queue take() * operation will no longer add to the Dispatch Message Map. Hence disabling the test - SUYOG - */ - - public void _testDispatchedMsgsMapUpdateOnTakes() throws Exception - { + */ + public void _testDispatchedMsgsMapUpdateOnTakes() throws Exception { this.logWriter .info("HARQAddOperationJUnitTest : testDispatchedEventsMapUpdateOnTakes BEGIN"); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b914df23/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARQueueNewImplDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARQueueNewImplDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARQueueNewImplDUnitTest.java index 2843fc0..340f10b 100755 --- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARQueueNewImplDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARQueueNewImplDUnitTest.java @@ -14,17 +14,38 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/** - * - */ package com.gemstone.gemfire.internal.cache.ha; +import static com.gemstone.gemfire.distributed.DistributedSystemConfigProperties.*; +import static com.gemstone.gemfire.test.dunit.Assert.*; +import static com.gemstone.gemfire.test.dunit.NetworkUtils.*; +import static com.gemstone.gemfire.test.dunit.Wait.*; + +import java.io.File; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Properties; +import java.util.Set; + +import org.junit.Ignore; +import org.junit.Test; + import com.gemstone.gemfire.LogWriter; -import com.gemstone.gemfire.cache.*; +import com.gemstone.gemfire.cache.AttributesFactory; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.DiskStoreFactory; +import com.gemstone.gemfire.cache.EntryEvent; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.RegionAttributes; +import com.gemstone.gemfire.cache.Scope; import com.gemstone.gemfire.cache.server.CacheServer; import com.gemstone.gemfire.cache.util.CacheListenerAdapter; import com.gemstone.gemfire.cache30.ClientServerTestCase; import com.gemstone.gemfire.distributed.DistributedSystem; +import com.gemstone.gemfire.distributed.internal.DistributionConfig; import com.gemstone.gemfire.internal.AvailablePort; import com.gemstone.gemfire.internal.cache.CacheServerImpl; import com.gemstone.gemfire.internal.cache.LocalRegion; @@ -32,71 +53,53 @@ import com.gemstone.gemfire.internal.cache.tier.sockets.CacheServerTestUtil; import com.gemstone.gemfire.internal.cache.tier.sockets.ClientUpdateMessage; import com.gemstone.gemfire.internal.cache.tier.sockets.ConflationDUnitTest; import com.gemstone.gemfire.internal.cache.tier.sockets.HAEventWrapper; -import com.gemstone.gemfire.test.dunit.*; -import util.TestException; - -import java.io.File; -import java.util.*; - -import static com.gemstone.gemfire.distributed.DistributedSystemConfigProperties.*; +import com.gemstone.gemfire.test.dunit.Host; +import com.gemstone.gemfire.test.dunit.VM; +import com.gemstone.gemfire.test.dunit.WaitCriterion; +import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase; /** * This DUnit contains various tests to ensure new implementation of ha region * queues works as expected. * * @since GemFire 5.7 - * */ -public class HARQueueNewImplDUnitTest extends DistributedTestCase { - protected static Cache cache = null; +public class HARQueueNewImplDUnitTest extends JUnit4DistributedTestCase { - protected static VM serverVM0 = null; + private static final String regionName = HARQueueNewImplDUnitTest.class.getSimpleName(); + private static final Map map = new HashMap(); + private static Cache cache = null; + private static VM serverVM0 = null; private static VM serverVM1 = null; + private static VM clientVM1 = null; + private static VM clientVM2 = null; - protected static VM clientVM1 = null; - - protected static VM clientVM2 = null; + private static LogWriter logger = null; + private static int numOfCreates = 0; + private static int numOfUpdates = 0; + private static int numOfInvalidates = 0; + private static Object[] deletedValues = null; private int PORT1; - private int PORT2; - private static final String regionName = "HARQueueNewImplDUnitTest"; - - private static final Map map = new HashMap(); - - protected static LogWriter logger = null; - - protected static int numOfCreates = 0; - - protected static int numOfUpdates = 0; - - protected static int numOfInvalidates = 0; - - private static Object[] deletedValues = null; - - /** - * @param name - * name of the test - */ - public HARQueueNewImplDUnitTest(String name) { - super(name); - } - /** * Sets up the test. */ @Override public final void postSetUp() throws Exception { + map.clear(); + final Host host = Host.getHost(0); serverVM0 = host.getVM(0); serverVM1 = host.getVM(1); clientVM1 = host.getVM(2); clientVM2 = host.getVM(3); - PORT1 = ((Integer)serverVM0.invoke(() -> HARQueueNewImplDUnitTest.createServerCache( HARegionQueue.HA_EVICTION_POLICY_MEMORY ))).intValue(); - PORT2 = ((Integer)serverVM1.invoke(() -> HARQueueNewImplDUnitTest.createServerCache( HARegionQueue.HA_EVICTION_POLICY_ENTRY ))).intValue(); + PORT1 = serverVM0.invoke(() -> HARQueueNewImplDUnitTest.createServerCache( HARegionQueue.HA_EVICTION_POLICY_MEMORY )); + PORT2 = serverVM1.invoke(() -> HARQueueNewImplDUnitTest.createServerCache( HARegionQueue.HA_EVICTION_POLICY_ENTRY )); + numOfCreates = 0; numOfUpdates = 0; numOfInvalidates = 0; @@ -107,6 +110,8 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { */ @Override public final void preTearDown() throws Exception { + map.clear(); + closeCache(); clientVM1.invoke(() -> HARQueueNewImplDUnitTest.closeCache()); clientVM2.invoke(() -> HARQueueNewImplDUnitTest.closeCache()); @@ -114,6 +119,7 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { // Unset the isSlowStartForTesting flag serverVM0.invoke(() -> ConflationDUnitTest.unsetIsSlowStart()); serverVM1.invoke(() -> ConflationDUnitTest.unsetIsSlowStart()); + // then close the servers serverVM0.invoke(() -> HARQueueNewImplDUnitTest.closeCache()); serverVM1.invoke(() -> HARQueueNewImplDUnitTest.closeCache()); @@ -138,9 +144,8 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { return createServerCache(ePolicy, new Integer(1)); } - public static Integer createServerCache(String ePolicy, Integer cap) - throws Exception { - new HARQueueNewImplDUnitTest("temp").createCache(new Properties()); + public static Integer createServerCache(String ePolicy, Integer cap) throws Exception { + new HARQueueNewImplDUnitTest().createCache(new Properties()); AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); factory.setDataPolicy(DataPolicy.REPLICATE); @@ -167,8 +172,7 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { return new Integer(server1.getPort()); } - public static Integer createOneMoreBridgeServer(Boolean notifyBySubscription) - throws Exception { + public static Integer createOneMoreBridgeServer(Boolean notifyBySubscription) throws Exception { int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); CacheServer server1 = cache.addCacheServer(); server1.setPort(port); @@ -180,14 +184,13 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { return new Integer(server1.getPort()); } - public static void createClientCache(String host, Integer port1, Integer port2, - String rLevel, Boolean addListener) throws Exception { + public static void createClientCache(String host, Integer port1, Integer port2, String rLevel, Boolean addListener) throws Exception { CacheServerTestUtil.disableShufflingOfEndpoints(); Properties props = new Properties(); props.setProperty(MCAST_PORT, "0"); props.setProperty(LOCATORS, ""); - new HARQueueNewImplDUnitTest("temp").createCache(props); + new HARQueueNewImplDUnitTest().createCache(props); AttributesFactory factory = new AttributesFactory(); ClientServerTestCase.configureConnectionPool(factory, host, port1 .intValue(), port2.intValue(), true, Integer.parseInt(rLevel), 2, null, @@ -222,8 +225,7 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { logger = cache.getLogger(); } - public static void createClientCache(String host, Integer port1, Integer port2, - String rLevel) throws Exception { + public static void createClientCache(String host, Integer port1, Integer port2, String rLevel) throws Exception { createClientCache(host, port1, port2, rLevel, Boolean.FALSE); } @@ -234,7 +236,7 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { r.registerInterest("ALL_KEYS"); } catch (Exception ex) { - Assert.fail("failed in registerInterestListAll", ex); + fail("failed in registerInterestListAll", ex); } } @@ -247,7 +249,7 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { r.registerInterest("k5"); } catch (Exception ex) { - Assert.fail("failed while registering keys", ex); + fail("failed while registering keys", ex); } } @@ -264,7 +266,7 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { r.put("k5", "pv5"); } catch (Exception ex) { - Assert.fail("failed in putEntries()", ex); + fail("failed in putEntries()", ex); } } @@ -280,7 +282,7 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { r.create("k5", "v5"); } catch (Exception ex) { - Assert.fail("failed in createEntries()", ex); + fail("failed in createEntries()", ex); } } @@ -293,7 +295,7 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { } } catch (Exception ex) { - Assert.fail("failed in createEntries(Long)", ex); + fail("failed in createEntries(Long)", ex); } } @@ -308,7 +310,7 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { } } catch (Exception ex) { - Assert.fail("failed in putHeavyEntries(Long)", ex); + fail("failed in putHeavyEntries(Long)", ex); } } @@ -316,18 +318,17 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { * This test verifies that the client-messages-region does not store duplicate * ClientUpdateMessageImpl instances, during a normal put path as well as the * GII path. - * - * @throws Exception */ + @Test public void testClientMsgsRegionSize() throws Exception { // slow start for dispatcher serverVM0.invoke(() -> ConflationDUnitTest.setIsSlowStart( "30000" )); serverVM1.invoke(() -> ConflationDUnitTest.setIsSlowStart( "30000" )); - createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); - final String client1Host = NetworkUtils.getServerHostName(clientVM1.getHost()); + createClientCache(getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); + final String client1Host = getServerHostName(clientVM1.getHost()); clientVM1.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client1Host, new Integer(PORT1), new Integer(PORT2), "1" )); - final String client2Host = NetworkUtils.getServerHostName(clientVM2.getHost()); + final String client2Host = getServerHostName(clientVM2.getHost()); clientVM2.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client2Host, new Integer(PORT1), new Integer(PORT2), "1" )); registerInterestListAll(); @@ -348,18 +349,17 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { * This test verifies that the ha-region-queues increment the reference count * of their respective HAEventWrapper instances in the client-messages-region * correctly, during put as well as GII path. - * - * @throws Exception */ + @Test public void testRefCountForNormalAndGIIPut() throws Exception { // slow start for dispatcher serverVM0.invoke(() -> ConflationDUnitTest.setIsSlowStart( "30000" )); serverVM1.invoke(() -> ConflationDUnitTest.setIsSlowStart( "30000" )); - createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); - final String client1Host = NetworkUtils.getServerHostName(clientVM1.getHost()); + createClientCache(getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); + final String client1Host = getServerHostName(clientVM1.getHost()); clientVM1.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client1Host, new Integer(PORT1), new Integer(PORT2), "1" )); - final String client2Host = NetworkUtils.getServerHostName(clientVM2.getHost()); + final String client2Host = getServerHostName(clientVM2.getHost()); clientVM2.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client2Host, new Integer(PORT1), new Integer(PORT2), "1" )); registerInterestListAll(); @@ -384,16 +384,15 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { * This test verifies that the ha-region-queues decrement the reference count * of their respective HAEventWrapper instances in the client-messages-region * correctly, after the events have been peeked and removed from the queue. - * - * @throws Exception */ + @Test public void testRefCountForPeekAndRemove() throws Exception { serverVM0.invoke(() -> ConflationDUnitTest.setIsSlowStart( "30000" )); - createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); - final String client1Host = NetworkUtils.getServerHostName(clientVM1.getHost()); + createClientCache(getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); + final String client1Host = getServerHostName(clientVM1.getHost()); clientVM1.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client1Host, new Integer(PORT1), new Integer(PORT2), "1" )); - final String client2Host = NetworkUtils.getServerHostName(clientVM2.getHost()); + final String client2Host = getServerHostName(clientVM2.getHost()); clientVM2.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client2Host, new Integer(PORT1), new Integer(PORT2), "1" )); registerInterestListAll(); @@ -415,16 +414,15 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { * This test verifies that the processing of the QRM messages results in * decrementing the reference count of corresponding HAEventWrapper instances, * correctly. - * - * @throws Exception */ + @Test public void testRefCountForQRM() throws Exception { serverVM0.invoke(() -> ConflationDUnitTest.setIsSlowStart( "30000" )); - createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); - final String client1Host = NetworkUtils.getServerHostName(clientVM1.getHost()); + createClientCache(getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); + final String client1Host = getServerHostName(clientVM1.getHost()); clientVM1.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client1Host, new Integer(PORT1), new Integer(PORT2), "1" )); - final String client2Host = NetworkUtils.getServerHostName(clientVM2.getHost()); + final String client2Host = getServerHostName(clientVM2.getHost()); clientVM2.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client2Host, new Integer(PORT1), new Integer(PORT2), "1" )); registerInterestListAll(); @@ -449,18 +447,17 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { * proxy/client disconnect), causes the reference count of all HAEventWrapper * instances belonging to the ha-region-queue to be decremented by one, and * makes it visible to the client-messages-region. - * - * @throws Exception */ + @Test public void testRefCountForDestroy() throws Exception { // slow start for dispatcher serverVM0.invoke(() -> ConflationDUnitTest.setIsSlowStart( "30000" )); serverVM1.invoke(() -> ConflationDUnitTest.setIsSlowStart( "30000" )); - createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); - final String client1Host = NetworkUtils.getServerHostName(clientVM1.getHost()); + createClientCache(getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); + final String client1Host = getServerHostName(clientVM1.getHost()); clientVM1.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client1Host, new Integer(PORT1), new Integer(PORT2), "1" )); - final String client2Host = NetworkUtils.getServerHostName(clientVM2.getHost()); + final String client2Host = getServerHostName(clientVM2.getHost()); clientVM2.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client2Host, new Integer(PORT1), new Integer(PORT2), "1" )); registerInterestListAll(); @@ -497,17 +494,16 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { * Addresses the bug 39179. If a clientUpdateMessage is dispatched to the * client while its GII was under way, then it should not be put into the * HARegionQueue of a client at receiving server side. - * - * @throws Exception */ + @Test public void testConcurrentGIIAndDispatch() throws Exception { serverVM0.invoke(() -> ConflationDUnitTest.setIsSlowStart( "40000" )); serverVM1.invoke(() -> ConflationDUnitTest.setIsSlowStart( "40000" )); - createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); - final String client1Host = NetworkUtils.getServerHostName(clientVM1.getHost()); + createClientCache(getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); + final String client1Host = getServerHostName(clientVM1.getHost()); clientVM1.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client1Host, new Integer(PORT1), new Integer(PORT2), "1" )); - final String client2Host = NetworkUtils.getServerHostName(clientVM2.getHost()); + final String client2Host = getServerHostName(clientVM2.getHost()); clientVM2.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client2Host, new Integer(PORT1), new Integer(PORT2), "1" )); registerInterestListAll(); @@ -537,27 +533,21 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { serverVM1.invoke(() -> ConflationDUnitTest.unsetIsSlowStart()); } - /* - * public void PtestRefCountForConcurrentPutAndRemove() throws Exception { } - * public void PtestRefCountForConcurrentGIIPut() throws Exception { } - */ - /** * This test verifies that when two BridgeServerImpl instances are created in * a single VM, they do share the client-messages-region. - * - * @throws Exception */ + @Test public void testTwoBridgeServersInOneVMDoShareCMR() throws Exception { // slow start for dispatcher serverVM0.invoke(() -> ConflationDUnitTest.setIsSlowStart( "30000" )); Integer port3 = (Integer)serverVM0.invoke(() -> HARQueueNewImplDUnitTest.createOneMoreBridgeServer( Boolean.TRUE )); - createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), new Integer(PORT1), port3, "0"); - final String client1Host = NetworkUtils.getServerHostName(clientVM1.getHost()); + createClientCache(getServerHostName(Host.getHost(0)), new Integer(PORT1), port3, "0"); + final String client1Host = getServerHostName(clientVM1.getHost()); clientVM1.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client1Host, new Integer(PORT1), new Integer(PORT2), "1" )); - final String client2Host = NetworkUtils.getServerHostName(clientVM2.getHost()); + final String client2Host = getServerHostName(clientVM2.getHost()); clientVM2.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client2Host, new Integer(PORT1), new Integer(PORT2), "1" )); registerInterestListAll(); @@ -574,14 +564,13 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { * This test verifies that two clients, connected to two bridge servers with * different notifyBySubscription values, on a single VM, receive * updates/invalidates depending upon their notifyBySubscription value. - * - * @throws Exception */ + @Test public void testUpdatesWithTwoBridgeServersInOneVM() throws Exception { Integer port3 = (Integer)serverVM0.invoke(() -> HARQueueNewImplDUnitTest.createOneMoreBridgeServer( Boolean.FALSE )); - createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1", Boolean.TRUE); - final String client1Host = NetworkUtils.getServerHostName(clientVM1.getHost()); + createClientCache(getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1", Boolean.TRUE); + final String client1Host = getServerHostName(clientVM1.getHost()); clientVM1.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client1Host, port3, new Integer(PORT2), "1", Boolean.TRUE )); registerInterestListAll(); @@ -606,17 +595,16 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { * This test verifies that the HAEventWrapper instances present in the * client-messages-region give up the references to their respective * ClientUpdateMessageImpl instances. - * - * @throws Exception */ + @Test public void testHAEventWrapperDoesNotHoldCUMOnceInsideCMR() throws Exception { // slow start for dispatcher serverVM0.invoke(() -> ConflationDUnitTest.setIsSlowStart( "30000" )); - createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); - final String client1Host = NetworkUtils.getServerHostName(clientVM1.getHost()); + createClientCache(getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); + final String client1Host = getServerHostName(clientVM1.getHost()); clientVM1.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client1Host, new Integer(PORT1), new Integer(PORT2), "1" )); - final String client2Host = NetworkUtils.getServerHostName(clientVM2.getHost()); + final String client2Host = getServerHostName(clientVM2.getHost()); clientVM2.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client2Host, new Integer(PORT1), new Integer(PORT2), "1" )); registerInterestListAll(); @@ -640,9 +628,8 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { * servers will have simple HashMap structures. Also, it verifies that such a * structure (referred to as haContainer, in general) is destroyed when its * bridge server is stopped. - * - * @throws Exception */ + @Test public void testCMRNotCreatedForNoneEvictionPolicy() throws Exception { serverVM0.invoke(() -> HARQueueNewImplDUnitTest.closeCache()); serverVM1.invoke(() -> HARQueueNewImplDUnitTest.closeCache()); @@ -653,10 +640,10 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { // slow start for dispatcher serverVM0.invoke(() -> ConflationDUnitTest.setIsSlowStart( "30000" )); - createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); - final String client1Host = NetworkUtils.getServerHostName(clientVM1.getHost()); + createClientCache(getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); + final String client1Host = getServerHostName(clientVM1.getHost()); clientVM1.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client1Host, new Integer(PORT1), new Integer(PORT2), "1" )); - final String client2Host = NetworkUtils.getServerHostName(clientVM2.getHost()); + final String client2Host = getServerHostName(clientVM2.getHost()); clientVM2.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client2Host, new Integer(PORT1), new Integer(PORT2), "1" )); registerInterestListAll(); @@ -680,18 +667,17 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { * servers who have eviction policy either as 'mem' or as 'entry'. Also, it * verifies that such a client-messages-region is destroyed when its bridge * server is stopped. - * - * @throws Exception */ + @Test public void testCMRCreatedForMemOrEntryEvictionPolicy() throws Exception { Boolean isRegion = Boolean.TRUE; // slow start for dispatcher serverVM0.invoke(() -> ConflationDUnitTest.setIsSlowStart( "30000" )); - createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); - final String client1Host = NetworkUtils.getServerHostName(clientVM1.getHost()); + createClientCache(getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); + final String client1Host = getServerHostName(clientVM1.getHost()); clientVM1.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client1Host, new Integer(PORT1), new Integer(PORT2), "1" )); - final String client2Host = NetworkUtils.getServerHostName(clientVM1.getHost()); + final String client2Host = getServerHostName(clientVM1.getHost()); clientVM2.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client2Host, new Integer(PORT1), new Integer(PORT2), "1" )); registerInterestListAll(); @@ -713,15 +699,14 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { /** * This test verifies that the Cache.rootRegions() method does not return the * client-messages-region of any of the cache's attached bridge servers. - * - * @throws Exception */ + @Test public void testCMRNotReturnedByRootRegionsMethod() throws Exception { - createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); - final String client1Host = NetworkUtils.getServerHostName(clientVM1.getHost()); + createClientCache(getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); + final String client1Host = getServerHostName(clientVM1.getHost()); clientVM1.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client1Host, new Integer(PORT1), new Integer(PORT2), "1" )); - final String client2Host = NetworkUtils.getServerHostName(clientVM2.getHost()); + final String client2Host = getServerHostName(clientVM2.getHost()); clientVM2.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client2Host, new Integer(PORT1), new Integer(PORT2), "1" )); registerInterestListAll(); @@ -735,14 +720,13 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { } /** - * This test verifies that the memory foorprint of the ha region queues is + * This test verifies that the memory footprint of the ha region queues is * less when ha-overflow is enabled (with an appropriate value of haCapacity) * compared to when it is disabled, for the same amount of data feed. - * - * @throws Exception */ - public void _testMemoryFootprintOfHARegionQueuesWithAndWithoutOverflow() - throws Exception { + @Ignore("TODO") + @Test + public void testMemoryFootprintOfHARegionQueuesWithAndWithoutOverflow() throws Exception { serverVM0.invoke(() -> HARQueueNewImplDUnitTest.closeCache()); serverVM1.invoke(() -> HARQueueNewImplDUnitTest.closeCache()); Thread.sleep(2000); @@ -756,10 +740,10 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { serverVM0.invoke(() -> ConflationDUnitTest.setIsSlowStart( "60000" )); serverVM1.invoke(() -> ConflationDUnitTest.setIsSlowStart( "60000" )); - createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); - final String client1Host = NetworkUtils.getServerHostName(clientVM1.getHost()); + createClientCache(getServerHostName(Host.getHost(0)), new Integer(PORT1), new Integer(PORT2), "1"); + final String client1Host = getServerHostName(clientVM1.getHost()); clientVM1.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client1Host, new Integer(PORT1), new Integer(PORT2), "1" )); - final String client2Host = NetworkUtils.getServerHostName(clientVM2.getHost()); + final String client2Host = getServerHostName(clientVM2.getHost()); clientVM2.invoke(() -> HARQueueNewImplDUnitTest.createClientCache( client2Host, new Integer(PORT1), new Integer(PORT2), "1" )); registerInterestListAll(); @@ -813,8 +797,7 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { } } - static Long getUsedMemoryAndVerifyRegionSize(Integer rSize, - Integer haContainerSize, Integer port) { + static Long getUsedMemoryAndVerifyRegionSize(Integer rSize, Integer haContainerSize, Integer port) { Long retVal = null; try { retVal = new Long(Runtime.getRuntime().totalMemory() @@ -942,22 +925,22 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { } } - public static void verifyNullValuesInCMR(final Integer numOfEntries, - final Integer port, - String[] keys) { + public static void verifyNullValuesInCMR(final Integer numOfEntries, final Integer port, String[] keys) { final Region msgsRegion = cache.getRegion(CacheServerImpl .generateNameForClientMsgsRegion(port.intValue())); WaitCriterion wc = new WaitCriterion() { String excuse; + @Override public boolean done() { int sz = msgsRegion.size(); return sz == numOfEntries.intValue(); } + @Override public String description() { return excuse; } }; - Wait.waitForCriterion(wc, 60 * 1000, 1000, true); + waitForCriterion(wc, 60 * 1000, 1000, true); Set entries = msgsRegion.entrySet(); Iterator iter = entries.iterator(); @@ -972,8 +955,7 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { } } - public static void makeValuesOfSomeKeysNullInClientMsgsRegion(Integer port, - String[] keys) { + public static void makeValuesOfSomeKeysNullInClientMsgsRegion(Integer port, String[] keys) { Region msgsRegion = cache.getRegion(CacheServerImpl .generateNameForClientMsgsRegion(port.intValue())); assertNotNull(msgsRegion); @@ -994,8 +976,7 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { } } - public static void populateValuesOfSomeKeysInClientMsgsRegion(Integer port, - String[] keys) { + public static void populateValuesOfSomeKeysInClientMsgsRegion(Integer port, String[] keys) { Region msgsRegion = cache.getRegion(CacheServerImpl .generateNameForClientMsgsRegion(port.intValue())); assertNotNull(msgsRegion); @@ -1020,8 +1001,7 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { } } - public static void verifyQueueData(Integer regionsize, - Integer msgsRegionsize, Integer port) { + public static void verifyQueueData(Integer regionsize, Integer msgsRegionsize, Integer port) { try { // Get the clientMessagesRegion and check the size. Region msgsRegion = cache.getRegion(CacheServerImpl @@ -1049,10 +1029,10 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { } } - public static void verifyRegionSize(final Integer regionSize, - final Integer msgsRegionsize, final Integer port) { + public static void verifyRegionSize(final Integer regionSize, final Integer msgsRegionsize, final Integer port) { WaitCriterion wc = new WaitCriterion() { String excuse; + @Override public boolean done() { try { // Get the clientMessagesRegion and check the size. @@ -1086,17 +1066,18 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { return false; } } + @Override public String description() { return excuse; } }; - Wait.waitForCriterion(wc, 120 * 1000, 1000, true); + waitForCriterion(wc, 120 * 1000, 1000, true); } - public static void verifyRegionSize(final Integer regionSize, - final Integer msgsRegionsize) { + public static void verifyRegionSize(final Integer regionSize, final Integer msgsRegionsize) { WaitCriterion wc = new WaitCriterion() { String excuse; + @Override public boolean done() { try { // Get the clientMessagesRegion and check the size. @@ -1124,11 +1105,12 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { return false; } } + @Override public String description() { return excuse; } }; - Wait.waitForCriterion(wc, 120 * 1000, 1000, true); + waitForCriterion(wc, 120 * 1000, 1000, true); } public static void verifyHaContainerType(Boolean isRegion, Integer port) { @@ -1169,7 +1151,7 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { while (iter.hasNext()) { rName = ((Region)iter.next()).getName(); if (cmrName.equals(rName)) { - throw new TestException( + throw new AssertionError( "Cache.rootRegions() method should not return the client_messages_region."); } logger.fine("Region name returned from cache.rootRegions(): " + rName); @@ -1180,30 +1162,33 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { } } - public static void verifyUpdatesReceived(final Integer num, Boolean isUpdate, - Long waitLimit) { + public static void verifyUpdatesReceived(final Integer num, Boolean isUpdate, Long waitLimit) { try { if (isUpdate.booleanValue()) { WaitCriterion ev = new WaitCriterion() { + @Override public boolean done() { return num.intValue() == numOfUpdates; } + @Override public String description() { return null; } }; - Wait.waitForCriterion(ev, waitLimit.longValue(), 200, true); + waitForCriterion(ev, waitLimit.longValue(), 200, true); } else { WaitCriterion ev = new WaitCriterion() { + @Override public boolean done() { return num.intValue() == numOfInvalidates; } + @Override public String description() { return null; } }; - Wait.waitForCriterion(ev, waitLimit.longValue(), 200, true); + waitForCriterion(ev, waitLimit.longValue(), 200, true); } } catch (Exception e) { @@ -1228,14 +1213,16 @@ public class HARQueueNewImplDUnitTest extends DistributedTestCase { } final Map m = haContainer; WaitCriterion ev = new WaitCriterion() { + @Override public boolean done() { return m.size() == 0; } + @Override public String description() { return null; } }; - Wait.waitForCriterion(ev, waitLimit.longValue(), 200, true); + waitForCriterion(ev, waitLimit.longValue(), 200, true); } catch (Exception e) { fail("failed in waitTillMessagesAreDispatched()" + e); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b914df23/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARegionDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARegionDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARegionDUnitTest.java index 194ce89..3f90b36 100755 --- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARegionDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARegionDUnitTest.java @@ -16,9 +16,12 @@ */ package com.gemstone.gemfire.internal.cache.ha; +import static org.junit.Assert.*; + import java.util.Properties; -import junit.framework.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; import com.gemstone.gemfire.cache.AttributesFactory; import com.gemstone.gemfire.cache.Cache; @@ -30,20 +33,20 @@ import com.gemstone.gemfire.distributed.DistributedSystem; import com.gemstone.gemfire.internal.cache.EventID; import com.gemstone.gemfire.internal.cache.GemFireCacheImpl; import com.gemstone.gemfire.internal.cache.HARegion; -import com.gemstone.gemfire.test.dunit.DistributedTestCase; import com.gemstone.gemfire.test.dunit.Host; import com.gemstone.gemfire.test.dunit.VM; +import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase; +import com.gemstone.gemfire.test.junit.categories.DistributedTest; /** * Test to verify : * * 1)put() on a mirrored HARegion does not propagate 2)localDestroy() allowed on * a mirrored region 3) GII happens normally - * - * */ -public class HARegionDUnitTest extends DistributedTestCase -{ +@Category(DistributedTest.class) +public class HARegionDUnitTest extends JUnit4DistributedTestCase { + VM vm0 = null; VM vm1 = null; @@ -52,8 +55,8 @@ public class HARegionDUnitTest extends DistributedTestCase private static final String REGION_NAME = "HARegionDUnitTest_region" ; /** constructor */ - public HARegionDUnitTest(String name) { - super(name); + public HARegionDUnitTest() { + super(); } /** @@ -102,6 +105,7 @@ public class HARegionDUnitTest extends DistributedTestCase * assert put in VM2 was successful by doing a get * */ + @Test public void testLocalPut() { vm0.invoke(() -> HARegionDUnitTest.createRegion()); @@ -123,6 +127,7 @@ public class HARegionDUnitTest extends DistributedTestCase * key has not been destroyed in VM2 * */ + @Test public void testLocalDestroy() { vm0.invoke(() -> HARegionDUnitTest.createRegion()); @@ -144,6 +149,7 @@ public class HARegionDUnitTest extends DistributedTestCase * through GII 6) do a put in VM2 7) assert put in VM2 was successful * */ + @Test public void testGII() { vm0.invoke(() -> HARegionDUnitTest.createRegion()); @@ -163,6 +169,7 @@ public class HARegionDUnitTest extends DistributedTestCase * through GII 6) do a put in VM2 7) assert put in VM2 was successful * */ + @Test public void testLocalDestroyRegion() { vm0.invoke(() -> HARegionDUnitTest.createRegion()); @@ -187,7 +194,7 @@ public class HARegionDUnitTest extends DistributedTestCase */ public static void verifyRegionNotDestroyed() { - Assert.assertTrue(cache.getRegion(REGION_NAME) != null); + assertTrue(cache.getRegion(REGION_NAME) != null); } /** @@ -197,6 +204,7 @@ public class HARegionDUnitTest extends DistributedTestCase * through GII 6) do a put in VM2 7) assert put in VM2 was successful * */ + @Test public void testQRM() { vm0.invoke(() -> HARegionDUnitTest.createRegionQueue()); @@ -219,7 +227,7 @@ public class HARegionDUnitTest extends DistributedTestCase public static void createRegion() throws Exception { - HARegionDUnitTest test = new HARegionDUnitTest(REGION_NAME); + HARegionDUnitTest test = new HARegionDUnitTest(); cache = test.createCache(); AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); @@ -239,7 +247,7 @@ public class HARegionDUnitTest extends DistributedTestCase public static void createRegionQueue() throws Exception { - HARegionDUnitTest test = new HARegionDUnitTest(REGION_NAME); + HARegionDUnitTest test = new HARegionDUnitTest(); cache = test.createCache(); /*AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_ACK); @@ -258,10 +266,10 @@ public class HARegionDUnitTest extends DistributedTestCase public static void verifyAddingDispatchMesgs() { - Assert.assertTrue(HARegionQueue.getDispatchedMessagesMapForTesting() + assertTrue(HARegionQueue.getDispatchedMessagesMapForTesting() .isEmpty()); hrq.addDispatchedMessage(new ThreadIdentifier(new byte[1],1),1); - Assert.assertTrue(!HARegionQueue.getDispatchedMessagesMapForTesting() + assertTrue(!HARegionQueue.getDispatchedMessagesMapForTesting() .isEmpty()); } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/b914df23/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARegionJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARegionJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARegionJUnitTest.java index d98b3c7..6c027ea 100755 --- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARegionJUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/ha/HARegionJUnitTest.java @@ -16,40 +16,56 @@ */ package com.gemstone.gemfire.internal.cache.ha; -import com.gemstone.gemfire.cache.*; -import com.gemstone.gemfire.cache.util.CacheListenerAdapter; -import com.gemstone.gemfire.internal.cache.EntryEventImpl; -import com.gemstone.gemfire.internal.cache.GemFireCacheImpl; -import com.gemstone.gemfire.internal.cache.HARegion; -import com.gemstone.gemfire.test.junit.categories.IntegrationTest; -import junit.framework.Assert; +import static com.gemstone.gemfire.distributed.DistributedSystemConfigProperties.*; +import static org.junit.Assert.*; + +import java.io.IOException; + import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.experimental.categories.Category; -import java.io.IOException; - -import static com.gemstone.gemfire.distributed.DistributedSystemConfigProperties.MCAST_PORT; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import com.gemstone.gemfire.cache.AttributesFactory; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheExistsException; +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.cache.CacheWriterException; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.EntryEvent; +import com.gemstone.gemfire.cache.EvictionAction; +import com.gemstone.gemfire.cache.EvictionAttributes; +import com.gemstone.gemfire.cache.ExpirationAction; +import com.gemstone.gemfire.cache.ExpirationAttributes; +import com.gemstone.gemfire.cache.GatewayException; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.RegionAttributes; +import com.gemstone.gemfire.cache.RegionExistsException; +import com.gemstone.gemfire.cache.Scope; +import com.gemstone.gemfire.cache.TimeoutException; +import com.gemstone.gemfire.cache.util.CacheListenerAdapter; +import com.gemstone.gemfire.internal.cache.EntryEventImpl; +import com.gemstone.gemfire.internal.cache.GemFireCacheImpl; +import com.gemstone.gemfire.internal.cache.HARegion; +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; /** * Test verifies the properties of a HARegion which allows localPuts and * localDestroys on a MirroredRegion - * - * */ @Category(IntegrationTest.class) -public class HARegionJUnitTest -{ +public class HARegionJUnitTest { + + /** + * cache + */ + private Cache cache = null; /** * create the cache */ @Before - public void setUp() throws Exception - { + public void setUp() throws Exception { cache = createCache(); } @@ -57,49 +73,21 @@ public class HARegionJUnitTest * close the cache in tear down */ @After - public void tearDown() throws Exception - { + public void tearDown() throws Exception { cache.close(); } /** - * cache - */ - private Cache cache = null; - - /** - * * create the cache - * - * @throws TimeoutException - * @throws CacheWriterException - * @throws GatewayException - * @throws CacheExistsException - * @throws RegionExistsException */ - private Cache createCache() throws TimeoutException, CacheWriterException, - GatewayException, CacheExistsException, - RegionExistsException - { + private Cache createCache() throws TimeoutException, CacheWriterException, GatewayException, CacheExistsException, RegionExistsException { return new CacheFactory().set(MCAST_PORT, "0").create(); } /** * create the HARegion - * - * @throws TimeoutException - * @throws CacheWriterException - * @throws GatewayException - * @throws CacheExistsException - * @throws RegionExistsException - * @throws IOException - * @throws ClassNotFoundException */ - private Region createHARegion() throws TimeoutException, - CacheWriterException, GatewayException, - CacheExistsException, RegionExistsException, IOException, - ClassNotFoundException - { + private Region createHARegion() throws TimeoutException, CacheWriterException, GatewayException, CacheExistsException, RegionExistsException, IOException, ClassNotFoundException { AttributesFactory factory = new AttributesFactory(); factory.setDataPolicy(DataPolicy.REPLICATE); factory.setScope(Scope.DISTRIBUTED_ACK); @@ -108,8 +96,8 @@ public class HARegionJUnitTest factory.setStatisticsEnabled(true); ; factory.setCacheListener(new CacheListenerAdapter() { - public void afterInvalidate(EntryEvent event) - { + @Override + public void afterInvalidate(EntryEvent event) { } }); RegionAttributes ra = factory.create(); @@ -117,88 +105,56 @@ public class HARegionJUnitTest null, ra); region.getAttributesMutator().setEntryTimeToLive(ea); return region; - } /** * test no exception being thrown while creating an HARegion - * */ @Test - public void testRegionCreation() - { - try { - createHARegion(); - } - catch (Exception e) { - e.printStackTrace(); - fail("Test failed due to " + e); - } + public void testRegionCreation() throws Exception { + createHARegion(); } /** * test no exception being thrown while put is being done on an HARegion - * */ @Test - public void testPut() - { - try { - Region region = createHARegion(); - region.put("key1", "value1"); - Assert.assertEquals(region.get("key1"), "value1"); - } - catch (Exception e) { - fail("put failed due to " + e); - } + public void testPut() throws Exception { + Region region = createHARegion(); + region.put("key1", "value1"); + assertEquals(region.get("key1"), "value1"); } /** * test no exception being thrown while doing a localDestroy on a HARegion - * */ @Test - public void testLocalDestroy() - { - try { - Region region = createHARegion(); - region.put("key1", "value1"); - region.localDestroy("key1"); - Assert.assertEquals(region.get("key1"), null); - } - catch (Exception e) { - e.printStackTrace(); - fail("put failed due to " + e); - } + public void testLocalDestroy() throws Exception { + Region region = createHARegion(); + region.put("key1", "value1"); + region.localDestroy("key1"); + assertEquals(region.get("key1"), null); } + /** * Test to verify event id exists when evict destroy happens. - * */ @Test - public void testEventIdSetForEvictDestroy() - { - try{ - AttributesFactory factory = new AttributesFactory(); - - factory.setCacheListener(new CacheListenerAdapter(){ - public void afterDestroy(EntryEvent event){ - assertTrue("eventId has not been set for "+ event, ((EntryEventImpl)event).getEventId() != null); - } - }); - - EvictionAttributes evAttr = EvictionAttributes.createLRUEntryAttributes(1,EvictionAction.LOCAL_DESTROY); - factory.setEvictionAttributes(evAttr); - - RegionAttributes attrs = factory.createRegionAttributes(); - Region region = cache.createVMRegion("TEST_REGION", attrs); - region.put("key1", "value1"); - region.put("key2", "value2"); - } - catch (Exception e) { - } - - - } + public void testEventIdSetForEvictDestroy() throws Exception { + AttributesFactory factory = new AttributesFactory(); + factory.setCacheListener(new CacheListenerAdapter(){ + public void afterDestroy(EntryEvent event){ + assertTrue("eventId has not been set for "+ event, ((EntryEventImpl)event).getEventId() != null); + } + }); + + EvictionAttributes evAttr = EvictionAttributes.createLRUEntryAttributes(1,EvictionAction.LOCAL_DESTROY); + factory.setEvictionAttributes(evAttr); + + RegionAttributes attrs = factory.createRegionAttributes(); + Region region = cache.createVMRegion("TEST_REGION", attrs); + region.put("key1", "value1"); + region.put("key2", "value2"); + } }