http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java index ed89a13..ce705ea 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/cache30/RegionTestCase.java @@ -111,7 +111,7 @@ public abstract class RegionTestCase extends CacheTestCase { } @Override - protected final void postTearDownCacheTestCase() throws Exception { + public final void postTearDownCacheTestCase() throws Exception { cleanup(); Invoke.invokeInEveryVM(getClass(), "cleanup"); postTearDownRegionTestCase();
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/cache30/RemoveAllMultiVmDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache30/RemoveAllMultiVmDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/cache30/RemoveAllMultiVmDUnitTest.java index cfd1ce8..f219539 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/cache30/RemoveAllMultiVmDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/cache30/RemoveAllMultiVmDUnitTest.java @@ -62,8 +62,7 @@ public class RemoveAllMultiVmDUnitTest extends DistributedTestCase { static CacheTransactionManager cacheTxnMgr; @Override - public void setUp() throws Exception { - super.setUp(); + public final void postSetUp() throws Exception { Host host = Host.getHost(0); VM vm0 = host.getVM(0); VM vm1 = host.getVM(1); @@ -72,7 +71,7 @@ public class RemoveAllMultiVmDUnitTest extends DistributedTestCase { } @Override - protected final void preTearDown() throws Exception { + public final void preTearDown() throws Exception { Host host = Host.getHost(0); VM vm0 = host.getVM(0); VM vm1 = host.getVM(1); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/cache30/SearchAndLoadDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache30/SearchAndLoadDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/cache30/SearchAndLoadDUnitTest.java index f26f94a..d564fca 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/cache30/SearchAndLoadDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/cache30/SearchAndLoadDUnitTest.java @@ -77,7 +77,7 @@ public class SearchAndLoadDUnitTest extends CacheTestCase { } @Override - protected final void preTearDownCacheTestCase() throws Exception { + public final void preTearDownCacheTestCase() throws Exception { for (int h = 0; h < Host.getHostCount(); h++) { Host host = Host.getHost(h); for (int v = 0; v < host.getVMCount(); v++) { http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/cache30/SlowRecDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache30/SlowRecDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/cache30/SlowRecDUnitTest.java index 899fbb1..b08fb73 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/cache30/SlowRecDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/cache30/SlowRecDUnitTest.java @@ -66,17 +66,14 @@ public class SlowRecDUnitTest extends CacheTestCase { // the setUp and tearDown methods need to make sure we don't // use the ds from previous test and that we don't leave ours around // for the next test to use. - - public void setUp() throws Exception { - try { - disconnectAllFromDS(); - } finally { - super.setUp(); - } + + @Override + public final void preSetUp() throws Exception { + disconnectAllFromDS(); } @Override - protected final void postTearDownCacheTestCase() throws Exception { + public final void postTearDownCacheTestCase() throws Exception { disconnectAllFromDS(); } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/cache30/TXDistributedDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache30/TXDistributedDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/cache30/TXDistributedDUnitTest.java index 720da56..604ca8a 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/cache30/TXDistributedDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/cache30/TXDistributedDUnitTest.java @@ -1077,8 +1077,8 @@ public class TXDistributedDUnitTest extends CacheTestCase { */ public static Serializable getSystemId() { Serializable ret = null; - if (DistributedTestCase.system != null) { - ret = DistributedTestCase.system.getDistributionManager().getId(); + if (getSystemStatic() != null) { + ret = getSystemStatic().getDistributionManager().getId(); } return ret; } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedMemberDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedMemberDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedMemberDUnitTest.java index 3dc6d75..d66fded 100755 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedMemberDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedMemberDUnitTest.java @@ -16,6 +16,8 @@ */ package com.gemstone.gemfire.distributed; +import static com.gemstone.gemfire.test.dunit.Assert.*; + import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Arrays; @@ -31,14 +33,14 @@ import com.gemstone.gemfire.distributed.internal.DM; import com.gemstone.gemfire.distributed.internal.DistributionConfig; import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem; import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember; -import com.gemstone.gemfire.test.dunit.Assert; -import com.gemstone.gemfire.test.dunit.DistributedTestCase; import com.gemstone.gemfire.test.dunit.Host; import com.gemstone.gemfire.test.dunit.SerializableCallable; import com.gemstone.gemfire.test.dunit.SerializableRunnable; import com.gemstone.gemfire.test.dunit.VM; - -import junit.framework.AssertionFailedError; +import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase; +import com.gemstone.gemfire.test.junit.categories.DistributedTest; +import org.junit.Test; +import org.junit.experimental.categories.Category; /** * Tests the functionality of the {@link DistributedMember} class. @@ -46,13 +48,10 @@ import junit.framework.AssertionFailedError; * @author Kirk Lund * @since 5.0 */ -public class DistributedMemberDUnitTest extends DistributedTestCase { +@Category(DistributedTest.class) +public class DistributedMemberDUnitTest extends JUnit4DistributedTestCase { - public DistributedMemberDUnitTest(String name) { - super(name); - } - - protected void sleep(long millis) { + protected void sleep(long millis) { // TODO: replace with Awaitility try { Thread.sleep(millis); } @@ -64,6 +63,7 @@ public class DistributedMemberDUnitTest extends DistributedTestCase { /** * Tests default settings. */ + @Test public void testDefaults() { Properties config = new Properties(); config.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); @@ -94,6 +94,7 @@ public class DistributedMemberDUnitTest extends DistributedTestCase { } } + @Test public void testNonDefaultName() { Properties config = new Properties(); config.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); @@ -118,6 +119,7 @@ public class DistributedMemberDUnitTest extends DistributedTestCase { * Tests the configuration of many Roles and groups in one vm. * Confirms no runtime distinction between roles and groups. */ + @Test public void testRolesInOneVM() { final String rolesProp = "A,B,C"; final String groupsProp = "D,E,F,G"; @@ -152,6 +154,7 @@ public class DistributedMemberDUnitTest extends DistributedTestCase { } } + @Test public void testTwoMembersSameName() { disconnectFromDS(); // or assertion on # members fails when run-dunit-tests Host.getHost(0).getVM(0).invoke(new SerializableRunnable() { @@ -185,7 +188,8 @@ public class DistributedMemberDUnitTest extends DistributedTestCase { * Tests the configuration of one unique Role in each of four vms. Verifies * that each vm is aware of the other vms' Roles. */ - public void testRolesInAllVMs() { + @Test + public void testRolesInAllVMs() { disconnectAllFromDS(); // or assertion on # members fails when run-dunit-tests // connect all four vms... @@ -227,7 +231,7 @@ public class DistributedMemberDUnitTest extends DistributedTestCase { assertEquals(3, members.size()); break; } - catch (AssertionFailedError e) { + catch (AssertionError e) { // TODO: delete this if (i < 3) { sleep(200); } else { @@ -268,7 +272,8 @@ public class DistributedMemberDUnitTest extends DistributedTestCase { * Tests the configuration of one unique group in each of four vms. Verifies * that each vm is aware of the other vms' groups. */ - public void testGroupsInAllVMs() { + @Test + public void testGroupsInAllVMs() { disconnectFromDS(); // or assertion on # members fails when run-dunit-tests // connect all four vms... @@ -307,7 +312,7 @@ public class DistributedMemberDUnitTest extends DistributedTestCase { assertEquals(3, members.size()); break; } - catch (AssertionFailedError e) { + catch (AssertionError e) { // TODO: delete this if (i < 3) { sleep(200); } else { @@ -359,6 +364,7 @@ public class DistributedMemberDUnitTest extends DistributedTestCase { * Changing the id can result in bad keys in JMX and can result in numerous * errors in Admin/JMX tests. */ + @Test public void testGetId() { Properties config = new Properties(); config.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); @@ -378,7 +384,8 @@ public class DistributedMemberDUnitTest extends DistributedTestCase { system.disconnect(); } } - + + @Test public void testFindMemberByName() { disconnectAllFromDS(); // or assertion on # members fails when run-dunit-tests VM vm0 = Host.getHost(0).getVM(0); @@ -408,7 +415,7 @@ public class DistributedMemberDUnitTest extends DistributedTestCase { assertTrue("Expected" + expected + " got " + members, members.containsAll(expected)); assertEquals(4, members.size()); } catch (UnknownHostException e) { - Assert.fail("Unable to get IpAddress", e); + fail("Unable to get IpAddress", e); } } }); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemDUnitTest.java index 610be11..f34fd7e 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/DistributedSystemDUnitTest.java @@ -16,6 +16,8 @@ */ package com.gemstone.gemfire.distributed; +import static com.gemstone.gemfire.test.dunit.Assert.*; + import java.net.Inet4Address; import java.net.Inet6Address; import java.net.InetAddress; @@ -26,7 +28,6 @@ import java.util.concurrent.TimeoutException; import com.gemstone.gemfire.CancelException; import com.gemstone.gemfire.GemFireConfigException; -import com.gemstone.gemfire.SystemConnectException; import com.gemstone.gemfire.cache.AttributesFactory; import com.gemstone.gemfire.cache.Cache; import com.gemstone.gemfire.cache.CacheFactory; @@ -44,11 +45,14 @@ import com.gemstone.gemfire.distributed.internal.membership.gms.mgr.GMSMembershi import com.gemstone.gemfire.internal.AvailablePort; import com.gemstone.gemfire.internal.AvailablePortHelper; import com.gemstone.gemfire.internal.SocketCreator; -import com.gemstone.gemfire.test.dunit.DistributedTestCase; import com.gemstone.gemfire.test.dunit.DistributedTestUtils; import com.gemstone.gemfire.test.dunit.Host; import com.gemstone.gemfire.test.dunit.LogWriterUtils; import com.gemstone.gemfire.test.dunit.VM; +import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase; +import com.gemstone.gemfire.test.junit.categories.DistributedTest; +import org.junit.Test; +import org.junit.experimental.categories.Category; /** * Tests the functionality of the {@link DistributedSystem} class. @@ -57,23 +61,18 @@ import com.gemstone.gemfire.test.dunit.VM; * * @author David Whitlock */ -public class DistributedSystemDUnitTest extends DistributedTestCase { +@Category(DistributedTest.class) +public class DistributedSystemDUnitTest extends JUnit4DistributedTestCase { - public DistributedSystemDUnitTest(String name) { - super(name); - } - - public void setUp() throws Exception { - super.setUp(); + public void postSetUp() throws Exception { disconnectAllFromDS(); } - //////// Test methods - /** * ensure that waitForMemberDeparture correctly flushes the serial message queue for * the given member */ + @Test public void testWaitForDeparture() throws Exception { disconnectAllFromDS(); int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); @@ -109,7 +108,7 @@ public class DistributedSystemDUnitTest extends DistributedTestCase { } } - static class FakeMessage extends SerialDistributionMessage { + private static class FakeMessage extends SerialDistributionMessage { volatile boolean[] blocked; volatile boolean processed; @@ -143,12 +142,9 @@ public class DistributedSystemDUnitTest extends DistributedTestCase { * Tests that we can get a DistributedSystem with the same * configuration twice. */ + @Test public void testGetSameSystemTwice() { Properties config = new Properties(); - -// int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS); -// config.setProperty("mcast-port", String.valueOf(unusedPort)); - // a loner is all this test needs config.setProperty("mcast-port", "0"); config.setProperty("locators", ""); // set a flow-control property for the test (bug 37562) @@ -165,12 +161,9 @@ public class DistributedSystemDUnitTest extends DistributedTestCase { * different configuration after one has already been obtained * throws an exception. */ + @Test public void testGetDifferentSystem() { Properties config = new Properties(); - -// int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS); -// config.setProperty("mcast-port", String.valueOf(unusedPort)); - // a loner is all this test needs config.setProperty("mcast-port", "0"); config.setProperty("locators", ""); config.setProperty("mcast-flow-control", "3000000,0.20,3000"); @@ -196,12 +189,9 @@ public class DistributedSystemDUnitTest extends DistributedTestCase { * Tests getting a system with a different configuration after * another system has been closed. */ + @Test public void testGetDifferentSystemAfterClose() { Properties config = new Properties(); - -// int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS); -// config.setProperty("mcast-port", String.valueOf(unusedPort)); - // a loner is all this test needs config.setProperty("mcast-port", "0"); config.setProperty("locators", ""); @@ -213,13 +203,11 @@ public class DistributedSystemDUnitTest extends DistributedTestCase { DistributedSystem system2 = DistributedSystem.connect(config); system2.disconnect(); } - - + + + @Test public void testGetProperties() { Properties config = new Properties(); - -// int unusedPort = AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS); -// config.setProperty("mcast-port", String.valueOf(unusedPort)); // a loner is all this test needs int unusedPort = 0; config.setProperty("mcast-port", "0"); @@ -235,13 +223,14 @@ public class DistributedSystemDUnitTest extends DistributedTestCase { assertTrue(config != system1.getProperties()); assertEquals(unusedPort, Integer.parseInt(system1.getProperties().getProperty("mcast-port"))); } - - + + + @Test public void testIsolatedDistributedSystem() throws Exception { Properties config = new Properties(); config.setProperty("mcast-port", "0"); config.setProperty("locators", ""); - system = (InternalDistributedSystem)DistributedSystem.connect(config); + getSystem(config); try { // make sure isolated distributed system can still create a cache and region Cache cache = CacheFactory.create(getSystem()); @@ -255,12 +244,13 @@ public class DistributedSystemDUnitTest extends DistributedTestCase { /** test the ability to set the port used to listen for tcp/ip connections */ + @Test public void testSpecificTcpPort() throws Exception { Properties config = new Properties(); int tcpPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); config.put("locators", "localhost["+DistributedTestUtils.getDUnitLocatorPort()+"]"); config.setProperty("tcp-port", String.valueOf(tcpPort)); - system = (InternalDistributedSystem)DistributedSystem.connect(config); + InternalDistributedSystem system = getSystem(config); DistributionManager dm = (DistributionManager)system.getDistributionManager(); GMSMembershipManager mgr = (GMSMembershipManager)dm.getMembershipManager(); int actualPort = mgr.getDirectChannelPort(); @@ -269,6 +259,7 @@ public class DistributedSystemDUnitTest extends DistributedTestCase { } /** test that loopback cannot be used as a bind address when a locator w/o a bind address is being used */ + @Test public void testLoopbackNotAllowed() throws Exception { // DISABLED for bug #49926 InetAddress loopback = null; @@ -291,7 +282,7 @@ public class DistributedSystemDUnitTest extends DistributedTestCase { config.setProperty(DistributionConfig.BIND_ADDRESS_NAME, loopback.getHostAddress()); LogWriterUtils.getLogWriter().info("attempting to connect with " + loopback +" and locators=" + locators); try { - system = (InternalDistributedSystem)DistributedSystem.connect(config); + InternalDistributedSystem system = getSystem(config); system.disconnect(); fail("expected a configuration exception disallowing use of loopback address"); } catch (GemFireConfigException e) { @@ -302,14 +293,15 @@ public class DistributedSystemDUnitTest extends DistributedTestCase { } } + @Test public void testUDPPortRange() throws Exception { Properties config = new Properties(); int unicastPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); config.put("locators", "localhost["+DistributedTestUtils.getDUnitLocatorPort()+"]"); // Minimum 3 ports required in range for UDP, FD_SOCK and TcpConduit. config.setProperty(DistributionConfig.MEMBERSHIP_PORT_RANGE_NAME, - ""+unicastPort+"-"+(unicastPort+2)); - system = (InternalDistributedSystem)DistributedSystem.connect(config); + ""+unicastPort+"-"+(unicastPort+2)); + InternalDistributedSystem system = getSystem(config); DistributionManager dm = (DistributionManager)system.getDistributionManager(); InternalDistributedMember idm = dm.getDistributionManagerId(); system.disconnect(); @@ -345,6 +337,7 @@ public class DistributedSystemDUnitTest extends DistributedTestCase { return startPort; } + @Test public void testMembershipPortRangeWithExactThreeValues() throws Exception { Properties config = new Properties(); config.setProperty("locators", "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]"); @@ -352,7 +345,7 @@ public class DistributedSystemDUnitTest extends DistributedTestCase { int portStartRange = getPortRange(portRange); int portEndRange = portStartRange + portRange - 1; config.setProperty(DistributionConfig.MEMBERSHIP_PORT_RANGE_NAME, "" + (portStartRange) + "-" + (portEndRange)); - system = (InternalDistributedSystem) DistributedSystem.connect(config); + InternalDistributedSystem system = getSystem(config); Cache cache = CacheFactory.create(system); cache.addCacheServer(); DistributionManager dm = (DistributionManager) system.getDistributionManager(); @@ -364,6 +357,7 @@ public class DistributedSystemDUnitTest extends DistributedTestCase { assertTrue(idm.getDirectChannelPort() >= portStartRange); } + @Test public void testConflictingUDPPort() throws Exception { final Properties config = new Properties(); final int mcastPort = AvailablePort.getRandomAvailablePort(AvailablePort.MULTICAST); @@ -373,7 +367,7 @@ public class DistributedSystemDUnitTest extends DistributedTestCase { config.setProperty("start-locator", "localhost["+socketPorts[1]+"]"); config.setProperty(DistributionConfig.MEMBERSHIP_PORT_RANGE_NAME, ""+unicastPort+"-"+(unicastPort+2)); - system = (InternalDistributedSystem)DistributedSystem.connect(config); + InternalDistributedSystem system = (InternalDistributedSystem)DistributedSystem.connect(config); try { DistributionManager dm = (DistributionManager)system.getDistributionManager(); InternalDistributedMember idm = dm.getDistributionManagerId(); @@ -402,13 +396,9 @@ public class DistributedSystemDUnitTest extends DistributedTestCase { * * @since 4.0 */ + @Test public void testEmptyCacheXmlFile() throws Exception { Properties config = new Properties(); - -// int unusedPort = -// AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS); -// config.setProperty("mcast-port", String.valueOf(unusedPort)); - // a loner is all this test needs config.setProperty("mcast-port", "0"); config.setProperty("locators", ""); config.setProperty(DistributionConfig.CACHE_XML_FILE_NAME, ""); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/distributed/HostedLocatorsDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/HostedLocatorsDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/HostedLocatorsDUnitTest.java index fe2202f..f874417 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/HostedLocatorsDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/HostedLocatorsDUnitTest.java @@ -50,13 +50,14 @@ public class HostedLocatorsDUnitTest extends DistributedTestCase { protected transient volatile int locatorPort; protected transient volatile LocatorLauncher launcher; - - public void setUp() throws Exception { + + @Override + public final void postSetUp() throws Exception { disconnectAllFromDS(); } @Override - protected final void preTearDown() throws Exception { + public final void preTearDown() throws Exception { disconnectAllFromDS(); } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorDUnitTest.java index 5969c51..f6dfde4 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/LocatorDUnitTest.java @@ -75,6 +75,8 @@ import com.gemstone.gemfire.test.dunit.WaitCriterion; */ public class LocatorDUnitTest extends DistributedTestCase { + private static volatile InternalDistributedSystem system = null; + static TestHook hook; /** @@ -93,15 +95,14 @@ public class LocatorDUnitTest extends DistributedTestCase { private int port2; @Override - public void setUp() throws Exception { - super.setUp(); + public final void postSetUp() throws Exception { port1 = -1; port2 = -1; IgnoredException.addIgnoredException("Removing shunned member"); } @Override - protected final void preTearDown() throws Exception { + public final void preTearDown() throws Exception { if (Locator.hasLocator()) { Locator.getLocator().stop(); } @@ -115,6 +116,14 @@ public class LocatorDUnitTest extends DistributedTestCase { } } + @Override + public final void postTearDown() throws Exception { + if (system != null) { + system.disconnect(); + system = null; + } + } + //////// Test Methods /** http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/distributed/SystemAdminDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/SystemAdminDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/SystemAdminDUnitTest.java index 64014de..73c9c8c 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/SystemAdminDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/SystemAdminDUnitTest.java @@ -1,19 +1,19 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.gemstone.gemfire.distributed; import java.io.BufferedReader; @@ -28,9 +28,9 @@ import java.util.Properties; import com.gemstone.gemfire.distributed.internal.DistributionManager; import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem; -import com.gemstone.gemfire.internal.SystemAdmin; -import com.gemstone.gemfire.test.dunit.DistributedTestCase; -import com.gemstone.gemfire.test.dunit.DistributedTestUtils; +import com.gemstone.gemfire.internal.SystemAdmin; +import com.gemstone.gemfire.test.dunit.DistributedTestCase; +import com.gemstone.gemfire.test.dunit.DistributedTestUtils; import com.gemstone.gemfire.test.dunit.LogWriterUtils; public class SystemAdminDUnitTest extends DistributedTestCase { @@ -40,19 +40,18 @@ public class SystemAdminDUnitTest extends DistributedTestCase { } @Override - public void setUp() throws Exception { - super.setUp(); + public final void postSetUp() throws Exception { disconnect(); } - @Override - protected final void preTearDown() throws Exception { + @Override + public final void preTearDown() throws Exception { disconnect(); } public void disconnect() { // get rid of the command-line distributed system created by SystemAdmin - system = null; + nullSystem(); InternalDistributedSystem sys = InternalDistributedSystem.getAnyInstance(); if (sys != null && sys.isConnected()) { LogWriterUtils.getLogWriter().info("disconnecting(3)"); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/Bug40751DUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/Bug40751DUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/Bug40751DUnitTest.java index e98c608..d906c09 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/Bug40751DUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/Bug40751DUnitTest.java @@ -48,7 +48,7 @@ public class Bug40751DUnitTest extends CacheTestCase { } @Override - protected final void postTearDownCacheTestCase() throws Exception { + public final void postTearDownCacheTestCase() throws Exception { disconnectAllFromDS(); } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ConsoleDistributionManagerDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ConsoleDistributionManagerDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ConsoleDistributionManagerDUnitTest.java index 847edb5..2aa9d27 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ConsoleDistributionManagerDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ConsoleDistributionManagerDUnitTest.java @@ -71,7 +71,8 @@ public class ConsoleDistributionManagerDUnitTest // this.lastAlert = alert; } - public void setUp() throws Exception { + @Override + public final void postSetUp() throws Exception { boolean finishedSetup = false; IgnoredException.addIgnoredException("Error occurred while reading system log"); try { @@ -83,7 +84,6 @@ public class ConsoleDistributionManagerDUnitTest DistributionManager.isDedicatedAdminVM = true; - super.setUp(); populateCache(); RemoteTransportConfig transport = null; @@ -145,12 +145,12 @@ public class ConsoleDistributionManagerDUnitTest } @Override - protected final void preTearDownCacheTestCase() throws Exception { + public final void preTearDownCacheTestCase() throws Exception { this.agent.disconnect(); } @Override - protected final void postTearDownCacheTestCase() throws Exception { + public final void postTearDownCacheTestCase() throws Exception { try { disconnectFromDS(); //make sure there's no ldm lying around } finally { http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionAdvisorDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionAdvisorDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionAdvisorDUnitTest.java index d11d22b..391cec9 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionAdvisorDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionAdvisorDUnitTest.java @@ -41,9 +41,9 @@ public class DistributionAdvisorDUnitTest extends DistributedTestCase { public DistributionAdvisorDUnitTest(String name) { super(name); } - - public void setUp() throws Exception { - super.setUp(); + + @Override + public final void postSetUp() throws Exception { // connect to distributed system in every VM Invoke.invokeInEveryVM(new SerializableRunnable("DistributionAdvisorDUnitTest: SetUp") { public void run() { @@ -84,7 +84,7 @@ public class DistributionAdvisorDUnitTest extends DistributedTestCase { } @Override - protected final void preTearDown() throws Exception { + public final void preTearDown() throws Exception { this.advisor.close(); } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionManagerDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionManagerDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionManagerDUnitTest.java index 25eec69..81d35d4 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionManagerDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionManagerDUnitTest.java @@ -46,6 +46,7 @@ import com.gemstone.gemfire.distributed.internal.membership.gms.MembershipManage import com.gemstone.gemfire.distributed.internal.membership.gms.interfaces.Manager; import com.gemstone.gemfire.distributed.internal.membership.gms.mgr.GMSMembershipManager; import com.gemstone.gemfire.internal.logging.LogService; +import com.gemstone.gemfire.test.dunit.internal.JUnit3DistributedTestCase; import com.gemstone.gemfire.test.dunit.DistributedTestCase; import com.gemstone.gemfire.test.dunit.Host; import com.gemstone.gemfire.test.dunit.IgnoredException; @@ -75,9 +76,8 @@ public class DistributionManagerDUnitTest extends DistributedTestCase { } @Override - public void setUp() throws Exception { + public void preSetUp() throws Exception { disconnectAllFromDS(); - super.setUp(); } //////// Test Methods @@ -310,18 +310,18 @@ public class DistributionManagerDUnitTest extends DistributedTestCase { rgn.put("bomb", "pow!"); // this will hang until vm1 responds rgn.getCache().close(); - system.disconnect(); + basicGetSystem().disconnect(); vm1.invoke(new SerializableRunnable("disconnect from ds") { public void run() { if (!myCache.isClosed()) { - if (system.isConnected()) { - system.disconnect(); + if (basicGetSystem().isConnected()) { + basicGetSystem().disconnect(); } myCache = null; } - if (system.isConnected()) { - system.disconnect(); + if (basicGetSystem().isConnected()) { + basicGetSystem().disconnect(); } synchronized(alertGuard) { assertTrue(alertReceived); @@ -347,8 +347,8 @@ public class DistributionManagerDUnitTest extends DistributedTestCase { public void afterCreate(EntryEvent event) { try { if (playDead) { - MembershipManagerHelper.beSickMember(system); - MembershipManagerHelper.playDead(system); + MembershipManagerHelper.beSickMember(getSystemStatic()); + MembershipManagerHelper.playDead(getSystemStatic()); } Thread.sleep(15000); } @@ -373,7 +373,7 @@ public class DistributionManagerDUnitTest extends DistributedTestCase { static void createAlertListener() throws Exception { DistributedSystemConfig config = - AdminDistributedSystemFactory.defineDistributedSystem(system, null); + AdminDistributedSystemFactory.defineDistributedSystem(getSystemStatic(), null); adminSystem = AdminDistributedSystemFactory.getDistributedSystem(config); adminSystem.setAlertLevel(AlertLevel.SEVERE); @@ -423,13 +423,13 @@ public class DistributionManagerDUnitTest extends DistributedTestCase { .setScope(Scope.DISTRIBUTED_ACK) .setDataPolicy(DataPolicy.REPLICATE) .create("testRegion"); - system.getLogWriter().info("<ExpectedException action=add>sec have elapsed while waiting for replies</ExpectedException>"); + basicGetSystem().getLogWriter().info("<ExpectedException action=add>sec have elapsed while waiting for replies</ExpectedException>"); vm1.invoke(new SerializableRunnable("Connect to distributed system") { public void run() { props.setProperty(DistributionConfig.NAME_NAME, "sleeper"); getSystem(props); - LogWriter log = system.getLogWriter(); + LogWriter log = basicGetSystem().getLogWriter(); log.info("<ExpectedException action=add>service failure</ExpectedException>"); log.info("<ExpectedException action=add>com.gemstone.gemfire.ForcedDisconnectException</ExpectedException>"); RegionFactory rf = new RegionFactory(); @@ -449,15 +449,15 @@ public class DistributionManagerDUnitTest extends DistributedTestCase { rgn.getCache().close(); - system.getLogWriter().info("<ExpectedException action=remove>sec have elapsed while waiting for replies</ExpectedException>"); - system.disconnect(); + basicGetSystem().getLogWriter().info("<ExpectedException action=remove>sec have elapsed while waiting for replies</ExpectedException>"); + basicGetSystem().disconnect(); vm1.invoke(new SerializableRunnable("wait for forced disconnect") { public void run() { // wait a while for the DS to finish disconnecting WaitCriterion ev = new WaitCriterion() { public boolean done() { - return !system.isConnected(); + return !basicGetSystem().isConnected(); } public String description() { return null; @@ -477,14 +477,14 @@ public class DistributionManagerDUnitTest extends DistributedTestCase { Wait.waitForCriterion(ev, 20 * 1000, 200, false); if (!myCache.isClosed()) { - if (system.isConnected()) { - system.disconnect(); + if (basicGetSystem().isConnected()) { + basicGetSystem().disconnect(); } myCache = null; throw new RuntimeException("Test Failed - vm1's cache is not closed"); } - if (system.isConnected()) { - system.disconnect(); + if (basicGetSystem().isConnected()) { + basicGetSystem().disconnect(); throw new RuntimeException("Test Failed - vm1's system should have been disconnected"); } @@ -545,7 +545,7 @@ public class DistributionManagerDUnitTest extends DistributedTestCase { public void testWaitForViewInstallation() { getSystem(new Properties()); - MembershipManager mgr = system.getDM().getMembershipManager(); + MembershipManager mgr = basicGetSystem().getDM().getMembershipManager(); final NetView v = mgr.getView(); @@ -553,7 +553,7 @@ public class DistributionManagerDUnitTest extends DistributedTestCase { Thread t = new Thread("wait for view installation") { public void run() { try { - ((DistributionManager)system.getDM()).waitForViewInstallation(v.getViewId()+1); + ((DistributionManager)basicGetSystem().getDM()).waitForViewInstallation(v.getViewId()+1); synchronized(passed) { passed[0] = true; } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ProductUseLogDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ProductUseLogDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ProductUseLogDUnitTest.java index 149d6d8..e2217b5 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ProductUseLogDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/ProductUseLogDUnitTest.java @@ -1,19 +1,19 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.gemstone.gemfire.distributed.internal; import java.io.BufferedReader; @@ -27,24 +27,24 @@ import com.gemstone.gemfire.cache.CacheFactory; import com.gemstone.gemfire.cache.server.CacheServer; import com.gemstone.gemfire.distributed.Locator; import com.gemstone.gemfire.internal.AvailablePort; -import com.gemstone.gemfire.internal.cache.CacheServerImpl; -import com.gemstone.gemfire.test.dunit.Assert; -import com.gemstone.gemfire.test.dunit.DistributedTestCase; -import com.gemstone.gemfire.test.dunit.Host; -import com.gemstone.gemfire.test.dunit.SerializableRunnable; +import com.gemstone.gemfire.internal.cache.CacheServerImpl; +import com.gemstone.gemfire.test.dunit.Assert; +import com.gemstone.gemfire.test.dunit.DistributedTestCase; +import com.gemstone.gemfire.test.dunit.Host; +import com.gemstone.gemfire.test.dunit.SerializableRunnable; import com.gemstone.gemfire.test.dunit.VM; public class ProductUseLogDUnitTest extends DistributedTestCase { public ProductUseLogDUnitTest(String name) { super(name); - } - - @Override - public Properties getDistributedSystemProperties() { - Properties p = super.getDistributedSystemProperties(); - p.put(DistributionConfig.USE_CLUSTER_CONFIGURATION_NAME, "false"); - return p; + } + + @Override + public Properties getDistributedSystemProperties() { + Properties p = super.getDistributedSystemProperties(); + p.put(DistributionConfig.USE_CLUSTER_CONFIGURATION_NAME, "false"); + return p; } public void testMembershipMonitoring() throws Exception { @@ -54,8 +54,8 @@ public class ProductUseLogDUnitTest extends DistributedTestCase { // use a locator so we will monitor server load and record member->server mappings int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET); Properties p = new Properties(); - p.put(DistributionConfig.START_LOCATOR_NAME, "localhost["+locatorPort+"],peer=false"); - p.put(DistributionConfig.USE_CLUSTER_CONFIGURATION_NAME, "false"); + p.put(DistributionConfig.START_LOCATOR_NAME, "localhost["+locatorPort+"],peer=false"); + p.put(DistributionConfig.USE_CLUSTER_CONFIGURATION_NAME, "false"); InternalDistributedSystem system = getSystem(p); InternalLocator locator = (InternalLocator)Locator.getLocator(); @@ -71,7 +71,7 @@ public class ProductUseLogDUnitTest extends DistributedTestCase { public void run() { InternalDistributedSystem system = getSystem(); Cache cache = CacheFactory.create(system); - CacheServer server = cache.addCacheServer(); + CacheServer server = cache.addCacheServer(); server.setPort(0); try { server.start(); @@ -101,8 +101,8 @@ public class ProductUseLogDUnitTest extends DistributedTestCase { return sb.toString(); } - @Override - protected final void preTearDown() throws Exception { + @Override + public final void preTearDown() throws Exception { disconnectAllFromDS(); } } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/GemFireDeadlockDetectorDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/GemFireDeadlockDetectorDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/GemFireDeadlockDetectorDUnitTest.java index bc3bee6..9120366 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/GemFireDeadlockDetectorDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/deadlock/GemFireDeadlockDetectorDUnitTest.java @@ -53,7 +53,7 @@ public class GemFireDeadlockDetectorDUnitTest extends CacheTestCase { @Override - protected final void preTearDownCacheTestCase() throws Exception { + public final void preTearDownCacheTestCase() throws Exception { disconnectAllFromDS(); } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServerBackwardCompatDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServerBackwardCompatDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServerBackwardCompatDUnitTest.java index 3685ac4..3ca83fb 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServerBackwardCompatDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/tcpserver/TcpServerBackwardCompatDUnitTest.java @@ -67,8 +67,7 @@ public class TcpServerBackwardCompatDUnitTest extends DistributedTestCase { } @Override - public void setUp() throws Exception { - super.setUp(); + public final void postSetUp() throws Exception { disconnectAllFromDS(); Invoke.invokeInEveryVM(new CacheSerializableRunnable("Set TcpServer.isTesting true") { @@ -80,7 +79,7 @@ public class TcpServerBackwardCompatDUnitTest extends DistributedTestCase { } @Override - protected final void preTearDown() throws Exception { + public final void preTearDown() throws Exception { Invoke.invokeInEveryVM(new CacheSerializableRunnable("Set TcpServer.isTesting true") { @Override http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/disttx/CacheMapDistTXDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/disttx/CacheMapDistTXDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/disttx/CacheMapDistTXDUnitTest.java index c0e8268..f0ea16d 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/disttx/CacheMapDistTXDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/disttx/CacheMapDistTXDUnitTest.java @@ -32,21 +32,32 @@ public class CacheMapDistTXDUnitTest extends CacheMapTxnDUnitTest { super(name); } - public void setUp() throws Exception { + @Override + public final void preSetUp() throws Exception { Host host = Host.getHost(0); VM vm0 = host.getVM(0); VM vm1 = host.getVM(1); vm0.invoke(() -> CacheMapDistTXDUnitTest.setDistributedTX()); vm1.invoke(() -> CacheMapDistTXDUnitTest.setDistributedTX()); + } - super.setUp(); // creates cache + @Override + public final void postSetUpCacheMapTxnDUnitTest() throws Exception { + Host host = Host.getHost(0); + VM vm0 = host.getVM(0); + VM vm1 = host.getVM(1); - // make sure that "distributed-transactions" is true + // make sure that "distributed-transactions" is true vm0.invoke(() -> CacheMapDistTXDUnitTest.checkIsDistributedTX()); vm1.invoke(() -> CacheMapDistTXDUnitTest.checkIsDistributedTX()); } + @Override + public final void postTearDown() throws Exception { + props.clear(); + } + public static void setDistributedTX() { props.setProperty(DistributionConfig.DISTRIBUTED_TRANSACTIONS_NAME, "true"); // props.setProperty(DistributionConfig.LOG_LEVEL_NAME, "fine"); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/57c8600b/geode-core/src/test/java/com/gemstone/gemfire/disttx/DistTXDebugDUnitDisabledTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/disttx/DistTXDebugDUnitDisabledTest.java b/geode-core/src/test/java/com/gemstone/gemfire/disttx/DistTXDebugDUnitDisabledTest.java new file mode 100644 index 0000000..dbd5d3c --- /dev/null +++ b/geode-core/src/test/java/com/gemstone/gemfire/disttx/DistTXDebugDUnitDisabledTest.java @@ -0,0 +1,1016 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gemstone.gemfire.disttx; + +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import java.io.Serializable; +import java.util.HashMap; + +import com.gemstone.gemfire.DataSerializable; +import com.gemstone.gemfire.DataSerializer; +import com.gemstone.gemfire.cache.AttributesFactory; +import com.gemstone.gemfire.cache.CacheException; +import com.gemstone.gemfire.cache.CacheTransactionManager; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.EntryOperation; +import com.gemstone.gemfire.cache.PartitionAttributes; +import com.gemstone.gemfire.cache.PartitionAttributesFactory; +import com.gemstone.gemfire.cache.PartitionResolver; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.Scope; +import com.gemstone.gemfire.cache30.CacheTestCase; +import com.gemstone.gemfire.internal.cache.PartitionedRegion; +import com.gemstone.gemfire.internal.cache.control.InternalResourceManager; +import com.gemstone.gemfire.internal.cache.execute.CustomerIDPartitionResolver; +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.SerializableCallable; +import com.gemstone.gemfire.test.dunit.SerializableRunnable; +import com.gemstone.gemfire.test.dunit.VM; + +/** + * TODO: reenable this test and fix it when work on Dist TX resumes -- it fails with no members to host buckets + */ +public class DistTXDebugDUnitDisabledTest extends CacheTestCase { + VM accessor = null; + VM dataStore1 = null; + VM dataStore2 = null; + VM dataStore3 = null; + + public DistTXDebugDUnitDisabledTest(String name) { + super(name); + } + + @Override + public final void postSetUp() throws Exception { + Host host = Host.getHost(0); + dataStore1 = host.getVM(0); + dataStore2 = host.getVM(1); + dataStore3 = host.getVM(2); + accessor = host.getVM(3); + postSetUpDistTXDebugDUnitTest(); + } + + protected void postSetUpDistTXDebugDUnitTest() throws Exception { + } + + @Override + public final void postTearDownCacheTestCase() throws Exception { + Invoke.invokeInEveryVM(new SerializableRunnable() { + public void run() { + InternalResourceManager.setResourceObserver(null); + } + }); + InternalResourceManager.setResourceObserver(null); + } + + public static void createCacheInVm() { + new DistTXDebugDUnitDisabledTest("temp").getCache(); + } + + protected void createCacheInAllVms() { + dataStore1.invoke(() -> DistTXDebugDUnitDisabledTest.createCacheInVm()); + dataStore2.invoke(() -> DistTXDebugDUnitDisabledTest.createCacheInVm()); + dataStore3.invoke(() -> DistTXDebugDUnitDisabledTest.createCacheInVm()); + accessor.invoke(() -> DistTXDebugDUnitDisabledTest.createCacheInVm()); + } + + public static void createPR(String partitionedRegionName, Integer redundancy, + Integer localMaxMemory, Integer totalNumBuckets, Object colocatedWith, + Boolean isPartitionResolver) { + createPR(partitionedRegionName, redundancy, localMaxMemory, + totalNumBuckets, colocatedWith, isPartitionResolver, + Boolean.TRUE/*Concurrency checks; By default is false*/); + } + + public static void createPR(String partitionedRegionName, Integer redundancy, + Integer localMaxMemory, Integer totalNumBuckets, Object colocatedWith, + Boolean isPartitionResolver, Boolean concurrencyChecks) { + PartitionAttributesFactory paf = new PartitionAttributesFactory(); + + paf.setRedundantCopies(redundancy.intValue()); + if (localMaxMemory != null) { + paf.setLocalMaxMemory(localMaxMemory.intValue()); + } + if (totalNumBuckets != null) { + paf.setTotalNumBuckets(totalNumBuckets.intValue()); + } + if (colocatedWith != null) { + paf.setColocatedWith((String) colocatedWith); + } + if (isPartitionResolver.booleanValue()) { + paf.setPartitionResolver(new CustomerIDPartitionResolver( + "CustomerIDPartitionResolver")); + } + PartitionAttributes prAttr = paf.create(); + AttributesFactory attr = new AttributesFactory(); + attr.setPartitionAttributes(prAttr); + attr.setConcurrencyChecksEnabled(concurrencyChecks); + // assertNotNull(basicGetCache()); + // Region pr = basicGetCache().createRegion(partitionedRegionName, + // attr.create()); + assertNotNull(basicGetCache()); + Region pr = basicGetCache().createRegion(partitionedRegionName, attr.create()); + assertNotNull(pr); + LogWriterUtils.getLogWriter().info( + "Partitioned Region " + partitionedRegionName + + " created Successfully :" + pr.toString()); + } + + protected void createPartitionedRegion(Object[] attributes) { + dataStore1.invoke(DistTXDebugDUnitDisabledTest.class, "createPR", attributes); + dataStore2.invoke(DistTXDebugDUnitDisabledTest.class, "createPR", attributes); + dataStore3.invoke(DistTXDebugDUnitDisabledTest.class, "createPR", attributes); + // make Local max memory = o for accessor + attributes[2] = new Integer(0); + accessor.invoke(DistTXDebugDUnitDisabledTest.class, "createPR", attributes); + } + + public static void destroyPR(String partitionedRegionName) { + // assertNotNull(basicGetCache()); + // Region pr = basicGetCache().getRegion(partitionedRegionName); + + assertNotNull(basicGetCache()); + Region pr = basicGetCache().getRegion(partitionedRegionName); + assertNotNull(pr); + LogWriterUtils.getLogWriter().info( + "Destroying Partitioned Region " + partitionedRegionName); + pr.destroyRegion(); + } + + public static void createRR(String replicatedRegionName, boolean empty) { + AttributesFactory af = new AttributesFactory(); + af.setScope(Scope.DISTRIBUTED_ACK); + if (empty) { + af.setDataPolicy(DataPolicy.EMPTY); + } else { + af.setDataPolicy(DataPolicy.REPLICATE); + } + // Region rr = basicGetCache().createRegion(replicatedRegionName, + // af.create()); + Region rr = basicGetCache().createRegion(replicatedRegionName, af.create()); + assertNotNull(rr); + LogWriterUtils.getLogWriter().info( + "Replicated Region " + replicatedRegionName + " created Successfully :" + + rr.toString()); + } + + protected void createReplicatedRegion(Object[] attributes) { + dataStore1.invoke(DistTXDebugDUnitDisabledTest.class, "createRR", attributes); + dataStore2.invoke(DistTXDebugDUnitDisabledTest.class, "createRR", attributes); + dataStore3.invoke(DistTXDebugDUnitDisabledTest.class, "createRR", attributes); + // DataPolicy.EMPTY for accessor + attributes[1] = Boolean.TRUE; + accessor.invoke(DistTXDebugDUnitDisabledTest.class, "createRR", attributes); + } + + public void testTXPR() throws Exception { + createCacheInAllVms(); + Object[] prAttrs = new Object[] { "pregion1", 1, null, 3, null, + Boolean.FALSE, Boolean.FALSE }; + createPartitionedRegion(prAttrs); + + SerializableCallable TxOps = new SerializableCallable("TxOps") { + @Override + public Object call() throws CacheException { + // PartitionedRegion pr1 = (PartitionedRegion) + // basicGetCache().getRegion( + // "pregion1"); + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1"); + // put some data (non tx ops) + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.put"); + pr1.put(dummy, "1_entry__" + i); + } + + // put in tx and commit + // CacheTransactionManager ctx = basicGetCache() + // .getCacheTransactionManager(); + CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager(); + ctx.setDistributed(true); + ctx.begin(); + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.put in tx 1"); + pr1.put(dummy, "2_entry__" + i); + } + ctx.commit(); + + // verify the data + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.get"); + assertEquals("2_entry__" + i, pr1.get(dummy)); + } + + // put data in tx and rollback + ctx.begin(); + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.put in tx 2"); + pr1.put(dummy, "3_entry__" + i); + } + ctx.rollback(); + + // verify the data + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.get"); + assertEquals("2_entry__" + i, pr1.get(dummy)); + } + + // destroy data in tx and commit + ctx.begin(); + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.destroy in tx 3"); + pr1.destroy(dummy); + } + ctx.commit(); + + // verify the data + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.get"); + assertEquals(null, pr1.get(dummy)); + } + + // verify data size on all replicas + SerializableCallable verifySize = new SerializableCallable("getOps") { + @Override + public Object call() throws CacheException { + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache() + .getRegion("pregion1"); + LogWriterUtils.getLogWriter().info( + " calling pr.getLocalSize " + pr1.getLocalSize()); + assertEquals(0, pr1.getLocalSize()); + return null; + } + }; + dataStore1.invoke(verifySize); + dataStore2.invoke(verifySize); + dataStore3.invoke(verifySize); + + return null; + } + }; + + accessor.invoke(TxOps); + + accessor.invoke(() -> DistTXDebugDUnitDisabledTest.destroyPR( "pregion1" )); + } + + public void testTXDestroy_invalidate() throws Exception { + createCacheInAllVms(); + Object[] prAttrs = new Object[] { "pregion1", 1, null, 3, null, + Boolean.FALSE, Boolean.FALSE }; + createPartitionedRegion(prAttrs); + + Object[] rrAttrs = new Object[] { "rregion1", Boolean.FALSE }; + createReplicatedRegion(rrAttrs); + + SerializableCallable TxOps = new SerializableCallable("TxOps") { + @Override + public Object call() throws CacheException { + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1"); + Region rr1 = basicGetCache().getRegion("rregion1"); + + // put some data (non tx ops) + for (int i = 1; i <= 6; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling non-tx put"); + pr1.put(dummy, "1_entry__" + i); + rr1.put(dummy, "1_entry__" + i); + } + + CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager(); + ctx.setDistributed(true); + // destroy data in tx and commit + ctx.begin(); + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info( + " calling pr1.destroy in tx key=" + dummy); + pr1.destroy(dummy); + LogWriterUtils.getLogWriter().info(" calling rr1.destroy in tx key=" + i); + rr1.destroy(dummy); + } + for (int i = 4; i <= 6; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info( + " calling pr1.invalidate in tx key=" + dummy); + pr1.invalidate(dummy); + LogWriterUtils.getLogWriter().info(" calling rr1.invalidate in tx key=" + i); + rr1.invalidate(dummy); + } + ctx.commit(); + + // verify the data + for (int i = 1; i <= 6; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr1.get"); + assertEquals(null, pr1.get(dummy)); + LogWriterUtils.getLogWriter().info(" calling rr1.get"); + assertEquals(null, rr1.get(i)); + } + return null; + } + }; + + accessor.invoke(TxOps); + + // verify data size on all replicas + SerializableCallable verifySize = new SerializableCallable("getOps") { + @Override + public Object call() throws CacheException { + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1"); + Region rr1 = basicGetCache().getRegion("rregion1"); + LogWriterUtils.getLogWriter().info( + " calling pr1.getLocalSize " + pr1.getLocalSize()); + assertEquals(2, pr1.getLocalSize()); + LogWriterUtils.getLogWriter().info(" calling rr1.size " + rr1.size()); + assertEquals(3, rr1.size()); + return null; + } + }; + dataStore1.invoke(verifySize); + dataStore2.invoke(verifySize); + dataStore3.invoke(verifySize); + + accessor.invoke(() -> DistTXDebugDUnitDisabledTest.destroyPR( "pregion1" )); + } + + public void testTXPR_RR() throws Exception { + createCacheInAllVms(); + Object[] prAttrs = new Object[] { "pregion1", 1, null, 3, null, + Boolean.FALSE, Boolean.FALSE }; + createPartitionedRegion(prAttrs); + + Object[] rrAttrs = new Object[] { "rregion1", Boolean.FALSE }; + createReplicatedRegion(rrAttrs); + + SerializableCallable TxOps = new SerializableCallable("TxOps") { + @Override + public Object call() throws CacheException { + // PartitionedRegion pr1 = (PartitionedRegion) + // basicGetCache().getRegion( + // "pregion1"); + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1"); + // Region rr1 = basicGetCache().getRegion("rregion1"); + Region rr1 = basicGetCache().getRegion("rregion1"); + // put some data (non tx ops) + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.put non-tx PR1_entry__" + i); + pr1.put(dummy, "PR1_entry__" + i); + LogWriterUtils.getLogWriter().info(" calling rr.put non-tx RR1_entry__" + i); + rr1.put(new Integer(i), "RR1_entry__" + i); + } + + // put in tx and commit + // CacheTransactionManager ctx = basicGetCache() + // .getCacheTransactionManager(); + CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager(); + ctx.setDistributed(true); + ctx.begin(); + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.put in tx PR2_entry__" + i); + pr1.put(dummy, "PR2_entry__" + i); + LogWriterUtils.getLogWriter().info(" calling rr.put in tx RR2_entry__" + i); + rr1.put(new Integer(i), "RR2_entry__" + i); + } + ctx.commit(); + + // verify the data + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.get PR2_entry__" + i); + assertEquals("PR2_entry__" + i, pr1.get(dummy)); + LogWriterUtils.getLogWriter().info(" calling rr.get RR2_entry__" + i); + assertEquals("RR2_entry__" + i, rr1.get(new Integer(i))); + } + return null; + } + }; + + accessor.invoke(TxOps); + + // verify data size on all replicas + SerializableCallable verifySize = new SerializableCallable("getOps") { + @Override + public Object call() throws CacheException { + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1"); + LogWriterUtils.getLogWriter().info( + " calling pr.getLocalSize " + pr1.getLocalSize()); + assertEquals(2, pr1.getLocalSize()); + + Region rr1 = basicGetCache().getRegion("rregion1"); + LogWriterUtils.getLogWriter() + .info(" calling rr.getLocalSize " + rr1.size()); + assertEquals(3, rr1.size()); + return null; + } + }; + dataStore1.invoke(verifySize); + dataStore2.invoke(verifySize); + dataStore3.invoke(verifySize); + + accessor.invoke(() -> DistTXDebugDUnitDisabledTest.destroyPR( "pregion1" )); + } + + public void testTXPR2() throws Exception { + createCacheInAllVms(); + Object[] prAttrs = new Object[] { "pregion1", 1, null, 3, null, + Boolean.FALSE, Boolean.FALSE }; + createPartitionedRegion(prAttrs); + + SerializableCallable TxOps = new SerializableCallable("TxOps") { + @Override + public Object call() throws CacheException { + // PartitionedRegion pr1 = (PartitionedRegion) + // basicGetCache().getRegion( + // "pregion1"); + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1"); + + // put in tx and commit + // CacheTransactionManager ctx = basicGetCache() + // .getCacheTransactionManager(); + CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager(); + ctx.setDistributed(true); + ctx.begin(); + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.put in tx 1"); + pr1.put(dummy, "2_entry__" + i); + } + ctx.commit(); + + // verify the data + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.get " + pr1.get(dummy)); + assertEquals("2_entry__" + i, pr1.get(dummy)); + } + return null; + } + }; + + accessor.invoke(TxOps); + + SerializableCallable TxGetOps = new SerializableCallable("TxGetOps") { + @Override + public Object call() throws CacheException { + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1"); + CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager(); + LogWriterUtils.getLogWriter().info( + " calling pr.getLocalSize " + pr1.getLocalSize()); + assertEquals(2, pr1.getLocalSize()); + return null; + } + }; + + dataStore1.invoke(TxGetOps); + dataStore2.invoke(TxGetOps); + dataStore3.invoke(TxGetOps); + + SerializableCallable TxRollbackOps = new SerializableCallable("TxOps") { + @Override + public Object call() throws CacheException { + // PartitionedRegion pr1 = (PartitionedRegion) + // basicGetCache().getRegion( + // "pregion1"); + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1"); + + // put in tx and commit + // CacheTransactionManager ctx = basicGetCache() + // .getCacheTransactionManager(); + CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager(); + ctx.setDistributed(true); + ctx.begin(); + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info( + " calling pr.put in tx for rollback no_entry__" + i); + pr1.put(dummy, "no_entry__" + i); + } + ctx.rollback(); + + // verify the data + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info( + " calling pr.get after rollback " + pr1.get(dummy)); + assertEquals("2_entry__" + i, pr1.get(dummy)); + } + return null; + } + }; + + accessor.invoke(TxRollbackOps); + + accessor.invoke(() -> DistTXDebugDUnitDisabledTest.destroyPR( "pregion1" )); + } + + public void testTXPRRR2_create() throws Exception { + createCacheInAllVms(); + Object[] prAttrs = new Object[] { "pregion1", 1, null, 3, null, + Boolean.FALSE, Boolean.FALSE }; + createPartitionedRegion(prAttrs); + + Object[] rrAttrs = new Object[] { "rregion1", Boolean.FALSE }; + createReplicatedRegion(rrAttrs); + + SerializableCallable TxOps = new SerializableCallable("TxOps") { + @Override + public Object call() throws CacheException { + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1"); + Region rr1 = basicGetCache().getRegion("rregion1"); + CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager(); + ctx.setDistributed(true); + ctx.begin(); + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.create in tx 1"); + pr1.create(dummy, "2_entry__" + i); + + LogWriterUtils.getLogWriter().info(" calling rr.create " + "2_entry__" + i); + rr1.create(new Integer(i), "2_entry__" + i); + } + ctx.commit(); + + // verify the data + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.get " + pr1.get(dummy)); + assertEquals("2_entry__" + i, pr1.get(dummy)); + + LogWriterUtils.getLogWriter().info( + " calling rr.get " + rr1.get(new Integer(i))); + assertEquals("2_entry__" + i, rr1.get(new Integer(i))); + } + return null; + } + }; + + accessor.invoke(TxOps); + + // verify data size on all replicas + SerializableCallable verifySize = new SerializableCallable("getOps") { + @Override + public Object call() throws CacheException { + Region rr1 = basicGetCache().getRegion("rregion1"); + LogWriterUtils.getLogWriter() + .info(" calling rr.getLocalSize " + rr1.size()); + assertEquals(3, rr1.size()); + + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1"); + LogWriterUtils.getLogWriter().info( + " calling pr.getLocalSize " + pr1.getLocalSize()); + assertEquals(2, pr1.getLocalSize()); + return null; + } + }; + dataStore1.invoke(verifySize); + dataStore2.invoke(verifySize); + dataStore3.invoke(verifySize); + } + + public void testTXPRRR2_putall() throws Exception { + createCacheInAllVms(); + Object[] prAttrs = new Object[] { "pregion1", 1, null, 3, null, + Boolean.FALSE, Boolean.FALSE }; + createPartitionedRegion(prAttrs); + + Object[] rrAttrs = new Object[] { "rregion1", Boolean.FALSE }; + createReplicatedRegion(rrAttrs); + + SerializableCallable TxOps = new SerializableCallable("TxOps") { + @Override + public Object call() throws CacheException { + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1"); + Region rr1 = basicGetCache().getRegion("rregion1"); + + CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager(); + ctx.setDistributed(true); + ctx.begin(); + HashMap<DummyKeyBasedRoutingResolver, String> phm = new HashMap<DummyKeyBasedRoutingResolver, String>(); + HashMap<Integer, String> rhm = new HashMap<Integer, String>(); + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + phm.put(dummy, "2_entry__" + i); + rhm.put(i, "2_entry__" + i); + } + pr1.putAll(phm); + rr1.putAll(rhm); + ctx.commit(); + + // verify the data + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.get " + pr1.get(dummy)); + assertEquals("2_entry__" + i, pr1.get(dummy)); + + LogWriterUtils.getLogWriter().info( + " calling rr.get " + rr1.get(new Integer(i))); + assertEquals("2_entry__" + i, rr1.get(new Integer(i))); + } + return null; + } + }; + + accessor.invoke(TxOps); + + // verify data size on all replicas + SerializableCallable verifySize = new SerializableCallable("getOps") { + @Override + public Object call() throws CacheException { + Region rr1 = basicGetCache().getRegion("rregion1"); + LogWriterUtils.getLogWriter() + .info(" calling rr.getLocalSize " + rr1.size()); + assertEquals(3, rr1.size()); + + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1"); + LogWriterUtils.getLogWriter().info( + " calling pr.getLocalSize " + pr1.getLocalSize()); + assertEquals(2, pr1.getLocalSize()); + return null; + } + }; + dataStore1.invoke(verifySize); + dataStore2.invoke(verifySize); + dataStore3.invoke(verifySize); + +// accessor.invoke(TxOps); + } + + public void testTXPR_putall() throws Exception { + createCacheInAllVms(); + Object[] prAttrs = new Object[] { "pregion1", 1, null, 3, null, + Boolean.FALSE, Boolean.FALSE }; + createPartitionedRegion(prAttrs); + + SerializableCallable TxOps = new SerializableCallable("TxOps") { + @Override + public Object call() throws CacheException { + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1"); + + CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager(); + ctx.setDistributed(true); + ctx.begin(); + HashMap<DummyKeyBasedRoutingResolver, String> phm = new HashMap<DummyKeyBasedRoutingResolver, String>(); + HashMap<Integer, String> rhm = new HashMap<Integer, String>(); + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + phm.put(dummy, "2_entry__" + i); + } + pr1.putAll(phm); + ctx.commit(); + + // verify the data + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.get " + pr1.get(dummy)); + assertEquals("2_entry__" + i, pr1.get(dummy)); + + } + return null; + } + }; + +// dataStore1.invoke(TxOps); + accessor.invoke(TxOps); + + // verify data size on all replicas + SerializableCallable verifySize = new SerializableCallable("getOps") { + @Override + public Object call() throws CacheException { + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1"); + LogWriterUtils.getLogWriter().info( + " calling pr.getLocalSize " + pr1.getLocalSize()); + assertEquals(2, pr1.getLocalSize()); + return null; + } + }; + dataStore1.invoke(verifySize); + dataStore2.invoke(verifySize); + dataStore3.invoke(verifySize); + +// accessor.invoke(TxOps); + } + + + public void testTXRR_removeAll() throws Exception { + performRR_removeAllTest(false); + } + + public void testTXRR_removeAll_dataNodeAsCoordinator() throws Exception { + performRR_removeAllTest(true); + } + + /** + * @param dataNodeAsCoordinator TODO + * + */ + private void performRR_removeAllTest(boolean dataNodeAsCoordinator) { + createCacheInAllVms(); + Object[] rrAttrs = new Object[] { "rregion1", Boolean.FALSE }; + createReplicatedRegion(rrAttrs); + + SerializableCallable TxOps = new SerializableCallable("TxOps") { + @Override + public Object call() throws CacheException { + Region rr1 = basicGetCache().getRegion("rregion1"); + //put some data + HashMap<Integer, String> rhm = new HashMap<Integer, String>(); + for (int i = 1; i <= 3; i++) { + rhm.put(i, "2_entry__" + i); + } + rr1.putAll(rhm); + + CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager(); + ctx.setDistributed(true); + ctx.begin(); + rr1.removeAll(rhm.keySet()); + + ctx.commit(); + + // verify the data + for (int i = 1; i <= 3; i++) { + LogWriterUtils.getLogWriter().info( + " calling rr.get " + rr1.get(new Integer(i))); + assertEquals(null, rr1.get(new Integer(i))); + } + return null; + } + }; + + if (dataNodeAsCoordinator) { + dataStore1.invoke(TxOps); + } else { + accessor.invoke(TxOps); + } + + // verify data size on all replicas + SerializableCallable verifySize = new SerializableCallable("getOps") { + @Override + public Object call() throws CacheException { + Region rr1 = basicGetCache().getRegion("rregion1"); + LogWriterUtils.getLogWriter() + .info(" calling rr.getLocalSize " + rr1.size()); + assertEquals(0, rr1.size()); + return null; + } + }; + dataStore1.invoke(verifySize); + dataStore2.invoke(verifySize); + dataStore3.invoke(verifySize); + +// accessor.invoke(TxOps); + } + + public void testTXPR_removeAll() throws Exception { + createCacheInAllVms(); + Object[] prAttrs = new Object[] { "pregion1", 1, null, 3, null, + Boolean.FALSE, Boolean.FALSE }; + createPartitionedRegion(prAttrs); + + SerializableCallable TxOps = new SerializableCallable("TxOps") { + @Override + public Object call() throws CacheException { + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1"); + HashMap<DummyKeyBasedRoutingResolver, String> phm = new HashMap<DummyKeyBasedRoutingResolver, String>(); + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + phm.put(dummy, "2_entry__" + i); + } + pr1.putAll(phm); + + CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager(); + ctx.setDistributed(true); + ctx.begin(); + pr1.removeAll(phm.keySet()); + ctx.commit(); + + // verify the data + for (int i = 1; i <= 3; i++) { + DummyKeyBasedRoutingResolver dummy = new DummyKeyBasedRoutingResolver( + i); + LogWriterUtils.getLogWriter().info(" calling pr.get " + pr1.get(dummy)); + assertEquals(null, pr1.get(dummy)); + } + return null; + } + }; + + accessor.invoke(TxOps); + + // verify data size on all replicas + SerializableCallable verifySize = new SerializableCallable("getOps") { + @Override + public Object call() throws CacheException { + PartitionedRegion pr1 = (PartitionedRegion) basicGetCache().getRegion("pregion1"); + LogWriterUtils.getLogWriter().info( + " calling pr.getLocalSize " + pr1.getLocalSize()); + assertEquals(0, pr1.getLocalSize()); + return null; + } + }; + dataStore1.invoke(verifySize); + dataStore2.invoke(verifySize); + dataStore3.invoke(verifySize); + +// accessor.invoke(TxOps); + } + + + public void performTXRRtestOps(boolean makeDatNodeAsCoordinator) { + createCacheInAllVms(); + Object[] prAttrs = new Object[] { "pregion1", 1, null, 3, null, + Boolean.FALSE, Boolean.FALSE }; + createPartitionedRegion(prAttrs); + + Object[] rrAttrs = new Object[] { "rregion1", Boolean.FALSE }; + createReplicatedRegion(rrAttrs); + + SerializableCallable TxOps = new SerializableCallable("TxOps") { + @Override + public Object call() throws CacheException { + Region rr1 = basicGetCache().getRegion("rregion1"); + CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager(); + ctx.setDistributed(true); + ctx.begin(); + for (int i = 1; i <= 3; i++) { + LogWriterUtils.getLogWriter().info(" calling rr.put " + "2_entry__" + i); + rr1.put(new Integer(i), "2_entry__" + i); + } + ctx.commit(); + + // verify the data + for (int i = 1; i <= 3; i++) { + LogWriterUtils.getLogWriter().info( + " calling rr.get " + rr1.get(new Integer(i))); + assertEquals("2_entry__" + i, rr1.get(new Integer(i))); + } + return null; + } + }; + + if (makeDatNodeAsCoordinator) { + dataStore1.invoke(TxOps); + } else { + accessor.invoke(TxOps); + } + + // verify data size on all replicas + SerializableCallable verifySize = new SerializableCallable("getOps") { + @Override + public Object call() throws CacheException { + Region rr1 = basicGetCache().getRegion("rregion1"); + LogWriterUtils.getLogWriter() + .info(" calling rr.getLocalSize " + rr1.size()); + assertEquals(3, rr1.size()); + return null; + } + }; + dataStore1.invoke(verifySize); + dataStore2.invoke(verifySize); + dataStore3.invoke(verifySize); + + SerializableCallable TxRollbackOps = new SerializableCallable("TxOps") { + @Override + public Object call() throws CacheException { + Region rr1 = basicGetCache().getRegion("rregion1"); + CacheTransactionManager ctx = basicGetCache().getCacheTransactionManager(); + ctx.setDistributed(true); + ctx.begin(); + for (int i = 1; i <= 3; i++) { + LogWriterUtils.getLogWriter().info( + " calling rr.put for rollback no_entry__" + i); + rr1.put(new Integer(i), "no_entry__" + i); + } + ctx.rollback(); + ; + + // verify the data + for (int i = 1; i <= 3; i++) { + LogWriterUtils.getLogWriter().info( + " calling rr.get after rollback " + + rr1.get(new Integer(i))); + assertEquals("2_entry__" + i, rr1.get(new Integer(i))); + } + return null; + } + }; + + if (makeDatNodeAsCoordinator) { + dataStore1.invoke(TxRollbackOps); + } else { + accessor.invoke(TxRollbackOps); + } + } + + + public void testTXRR2() throws Exception { + performTXRRtestOps(false); // actual test + } + + public void testTXRR2_dataNodeAsCoordinator() throws Exception { + performTXRRtestOps(true); + } +} + +class DummyKeyBasedRoutingResolver implements PartitionResolver, + DataSerializable { + Integer dummyID; + + public DummyKeyBasedRoutingResolver() { + } + + public DummyKeyBasedRoutingResolver(int id) { + this.dummyID = new Integer(id); + } + + public String getName() { + // TODO Auto-generated method stub + return null; + } + + public Serializable getRoutingObject(EntryOperation opDetails) { + return (Serializable) opDetails.getKey(); + } + + public void close() { + // TODO Auto-generated method stub + } + + public void fromData(DataInput in) throws IOException, ClassNotFoundException { + this.dummyID = DataSerializer.readInteger(in); + } + + public void toData(DataOutput out) throws IOException { + DataSerializer.writeInteger(this.dummyID, out); + } + + @Override + public int hashCode() { + int i = this.dummyID.intValue(); + return i; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + + if (!(o instanceof DummyKeyBasedRoutingResolver)) + return false; + + DummyKeyBasedRoutingResolver otherDummyID = (DummyKeyBasedRoutingResolver) o; + return (otherDummyID.dummyID.equals(dummyID)); + + } +}
