http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb91dedc/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/tier/sockets/InterestListDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/tier/sockets/InterestListDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/tier/sockets/InterestListDUnitTest.java index f13e46e..ff199d0 100755 --- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/tier/sockets/InterestListDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/tier/sockets/InterestListDUnitTest.java @@ -16,22 +16,16 @@ */ package com.gemstone.gemfire.internal.cache.tier.sockets; -import org.junit.experimental.categories.Category; -import org.junit.Test; - import static org.junit.Assert.*; -import com.gemstone.gemfire.test.dunit.cache.internal.JUnit4CacheTestCase; -import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase; -import com.gemstone.gemfire.test.junit.categories.DistributedTest; - import java.util.ArrayList; import java.util.List; import java.util.Properties; import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; -import junit.framework.AssertionFailedError; +import org.junit.Test; +import org.junit.experimental.categories.Category; import com.gemstone.gemfire.cache.AttributesFactory; import com.gemstone.gemfire.cache.Cache; @@ -45,10 +39,14 @@ import com.gemstone.gemfire.cache.InterestRegistrationEvent; import com.gemstone.gemfire.cache.InterestRegistrationListener; import com.gemstone.gemfire.cache.InterestResultPolicy; import com.gemstone.gemfire.cache.LoaderHelper; +import com.gemstone.gemfire.cache.NoSubscriptionServersAvailableException; import com.gemstone.gemfire.cache.Region; import com.gemstone.gemfire.cache.RegionAttributes; import com.gemstone.gemfire.cache.RegionShortcut; import com.gemstone.gemfire.cache.Scope; +import com.gemstone.gemfire.cache.client.Pool; +import com.gemstone.gemfire.cache.client.PoolFactory; +import com.gemstone.gemfire.cache.client.PoolManager; import com.gemstone.gemfire.cache.server.CacheServer; import com.gemstone.gemfire.cache.util.CacheListenerAdapter; import com.gemstone.gemfire.distributed.DistributedMember; @@ -57,7 +55,6 @@ import com.gemstone.gemfire.distributed.internal.DistributionConfig; 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.Invoke; import com.gemstone.gemfire.test.dunit.LogWriterUtils; @@ -66,8 +63,8 @@ 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.cache.client.*; -import com.gemstone.gemfire.cache.NoSubscriptionServersAvailableException; +import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase; +import com.gemstone.gemfire.test.junit.categories.DistributedTest; /** * Test Scenario : @@ -104,57 +101,68 @@ import com.gemstone.gemfire.cache.NoSubscriptionServersAvailableException; * then both client connects to the server * c1 register(k1,k2,k3) and c2 register (k4,k5) * then verify that updates has occurred as a result of interest registration. - * - * - * */ @Category(DistributedTest.class) -public class InterestListDUnitTest extends JUnit4DistributedTestCase -{ - static Cache cache = null; - - VM vm0 = null; +public class InterestListDUnitTest extends JUnit4DistributedTestCase { - VM vm1 = null; + private static final String REGION_NAME = "InterestListDUnitTest_region"; - VM vm2 = null; - - /** the server cache's port number */ - int PORT1; + // using a Integer instead of String to make sure ALL_KEYS works on non-String keys + private final static Integer key1 = new Integer(1); + private final static Integer key2 = new Integer(2); + private final static String key1_originalValue = "key-1-orig-value"; + private final static String key2_originalValue = "key-2-orig-value"; - // using a Integer instead of String to make sure ALL_KEYS works - // on non-String keys - final static Integer key1 = new Integer(1); - final static Integer key2 = new Integer(2); - final static String key1_originalValue = "key-1-orig-value"; - final static String key2_originalValue = "key-2-orig-value"; - - static final String REGION_NAME = "InterestListDUnitTest_region"; + private static Cache cache = null; /** some tests use this to hold the server for invoke() access */ - static CacheServer server; + private static CacheServer server; /** interestListener listens in cache server vms */ - static InterestListener interestListener; + private static InterestListener interestListener; - /** constructor */ - public InterestListDUnitTest() { - super(); - } + private VM vm0 = null; + private VM vm1 = null; + private VM vm2 = null; + + /** the server cache's port number */ + private int PORT1; @Override public final void postSetUp() throws Exception { disconnectAllFromDS(); - Wait.pause(10000); + final Host host = Host.getHost(0); vm0 = host.getVM(0); vm1 = host.getVM(1); vm2 = host.getVM(2); + // start servers first - PORT1 = ((Integer) vm0.invoke(() -> InterestListDUnitTest.createServerCache())).intValue(); + PORT1 = vm0.invoke(() -> InterestListDUnitTest.createServerCache()); } -/** + @Override + public final void preTearDown() throws Exception { + // close the clients first + vm1.invoke(() -> InterestListDUnitTest.closeCache()); + vm2.invoke(() -> InterestListDUnitTest.closeCache()); + // then close the servers + vm0.invoke(() -> InterestListDUnitTest.closeCache()); + + cache = null; + server = null; + interestListener = null; + + Invoke.invokeInEveryVM(new SerializableRunnable() { + public void run() { + cache = null; + server = null; + interestListener = null; + } + }); + } + + /** * one server two clients * create Entries in all the vms * c1 : register (k1) @@ -169,69 +177,64 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase * c2 : validate (k1 == vm2-k1) AND (k2 == vm2-k2) // as both are not registered * c2 : put (k1 -> vm2-k1-again) AND (k2 -> vm2-k2-again) * c1 : validate (k1 == vm1-k1-again) AND (k2 == vm1-k2-again)// as both are not registered - * */ @Test - public void testInterestListRegistration() - { - - vm1.invoke(() -> InterestListDUnitTest.createClientCache( - NetworkUtils.getServerHostName(vm0.getHost()), new Integer(PORT1))); - vm2.invoke(() -> InterestListDUnitTest.createClientCache( - NetworkUtils.getServerHostName(vm0.getHost()), new Integer(PORT1))); - - vm1.invoke(() -> InterestListDUnitTest.createEntriesK1andK2()); - vm2.invoke(() -> InterestListDUnitTest.createEntriesK1andK2()); - - vm1.invoke(() -> InterestListDUnitTest.registerKey( key1 )); - vm2.invoke(() -> InterestListDUnitTest.registerKey( key2 )); - - vm1.invoke(() -> InterestListDUnitTest.put( "vm1" )); - Wait.pause(10000); - vm2.invoke(() -> InterestListDUnitTest.validateEntriesK1andK2( "vm2" )); - vm2.invoke(() -> InterestListDUnitTest.put( "vm2" )); - Wait.pause(10000); - vm1.invoke(() -> InterestListDUnitTest.validateEntriesK1andK2( "vm1" )); - - vm1.invoke(() -> InterestListDUnitTest.unregisterKey( key1 )); - vm2.invoke(() -> InterestListDUnitTest.unregisterKey( key2 )); - - vm1.invoke(() -> InterestListDUnitTest.putAgain( "vm1" )); - Wait.pause(10000); - vm2.invoke(() -> InterestListDUnitTest.validateEntriesAgain( "vm2" )); - vm2.invoke(() -> InterestListDUnitTest.putAgain( "vm2" )); - Wait.pause(10000); - vm1.invoke(() -> InterestListDUnitTest.validateEntriesAgain( "vm1" )); - } + public void testInterestListRegistration() throws Exception { + vm1.invoke(() -> InterestListDUnitTest.createClientCache( + NetworkUtils.getServerHostName(vm0.getHost()), new Integer(PORT1))); + vm2.invoke(() -> InterestListDUnitTest.createClientCache( + NetworkUtils.getServerHostName(vm0.getHost()), new Integer(PORT1))); -/** - * one server two clients - * create Entries in all the vms - * - * STEP 1: - * c2: put (k2 -> vm-k2) - * c1: validate k2 == k2 (not updated because no interest) - * - * STEP 2 - * c1: register k2 - * c1 : validate k2 == vm-k2 (updated because of registerInterest) - * c1: validate k1 == k1 (other key not updated because still no interest) - * - * STEP 3: - * c1: put (k1 -> vm-k1) - * c2: validate k1 == k1 (not updated because no interest) - * c2: register k1 - * c2: validate k1 == vm-k1 (updated because of registerInterest) - * - * STEP 4: - * c2: unregister k1 - * c1: put k1->k1 (old value) - * c2: validate k1 == vm-k1 (no interest, so missing update) - */ - @Test - public void testValueRefresh() - { + vm1.invoke(() -> InterestListDUnitTest.createEntriesK1andK2()); + vm2.invoke(() -> InterestListDUnitTest.createEntriesK1andK2()); + + vm1.invoke(() -> InterestListDUnitTest.registerKey( key1 )); + vm2.invoke(() -> InterestListDUnitTest.registerKey( key2 )); + + vm1.invoke(() -> InterestListDUnitTest.put( "vm1" )); + Wait.pause(10000); + vm2.invoke(() -> InterestListDUnitTest.validateEntriesK1andK2( "vm2" )); + vm2.invoke(() -> InterestListDUnitTest.put( "vm2" )); + Wait.pause(10000); + vm1.invoke(() -> InterestListDUnitTest.validateEntriesK1andK2( "vm1" )); + + vm1.invoke(() -> InterestListDUnitTest.unregisterKey( key1 )); + vm2.invoke(() -> InterestListDUnitTest.unregisterKey( key2 )); + vm1.invoke(() -> InterestListDUnitTest.putAgain( "vm1" )); + Wait.pause(10000); + vm2.invoke(() -> InterestListDUnitTest.validateEntriesAgain( "vm2" )); + vm2.invoke(() -> InterestListDUnitTest.putAgain( "vm2" )); + Wait.pause(10000); + vm1.invoke(() -> InterestListDUnitTest.validateEntriesAgain( "vm1" )); + } + + /** + * one server two clients + * create Entries in all the vms + * + * STEP 1: + * c2: put (k2 -> vm-k2) + * c1: validate k2 == k2 (not updated because no interest) + * + * STEP 2 + * c1: register k2 + * c1 : validate k2 == vm-k2 (updated because of registerInterest) + * c1: validate k1 == k1 (other key not updated because still no interest) + * + * STEP 3: + * c1: put (k1 -> vm-k1) + * c2: validate k1 == k1 (not updated because no interest) + * c2: register k1 + * c2: validate k1 == vm-k1 (updated because of registerInterest) + * + * STEP 4: + * c2: unregister k1 + * c1: put k1->k1 (old value) + * c2: validate k1 == vm-k1 (no interest, so missing update) + */ + @Test + public void testValueRefresh() throws Exception { // Initialization Host host = Host.getHost(0); vm1.invoke(() -> InterestListDUnitTest.createClientCache( NetworkUtils.getServerHostName(host), new Integer(PORT1))); @@ -269,16 +272,13 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase vm2.invoke(() -> InterestListDUnitTest.validateSingleEntry(key1, "vm1")); // update lost } -/** - * one server two clients - * create Entries in all the vms - * register ALL_KEYS and verifies that updates are receiving to all the keys - * - */ + /** + * one server two clients + * create Entries in all the vms + * register ALL_KEYS and verifies that updates are receiving to all the keys + */ @Test - public void testInterestListRegistration_ALL_KEYS() - { - + public void testInterestListRegistration_ALL_KEYS() throws Exception { vm1.invoke(() -> InterestListDUnitTest.createClientCache( NetworkUtils.getServerHostName(vm0.getHost()), new Integer(PORT1))); vm2.invoke(() -> InterestListDUnitTest.createClientCache( @@ -292,20 +292,18 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase vm1.invoke(() -> InterestListDUnitTest.put_ALL_KEYS()); Wait.pause(10000); vm2.invoke(() -> InterestListDUnitTest.validate_ALL_KEYS()); - } - /** - * one server two clients - * create Entries in all the vms - * server directly puts some values - * then both clients connect to the server - * c1 register(k1,k2,k3) and c2 register (k4,k5) - * then verify that updates has occured as a result of interest registration. - * - */ + + /** + * one server two clients + * create Entries in all the vms + * server directly puts some values + * then both clients connect to the server + * c1 register(k1,k2,k3) and c2 register (k4,k5) + * then verify that updates has occured as a result of interest registration. + */ @Test - public void testInitializationOfRegionFromInterestList() - { + public void testInitializationOfRegionFromInterestList() throws Exception { // directly put on server vm0.invoke(() -> InterestListDUnitTest.multiple_put()); Wait.pause(1000); @@ -322,7 +320,6 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase // verify the values for registered keys vm1.invoke(() -> InterestListDUnitTest.validateRegionEntriesFromInterestListInVm1()); vm2.invoke(() -> InterestListDUnitTest.validateRegionEntriesFromInterestListInVm2()); - } /** @@ -340,129 +337,124 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase * c2 : validate (k1 == vm2-k1) AND (k2 == vm2-k2) // as both are not registered * c2 : put (k1 -> vm2-k1-again) AND (k2 -> vm2-k2-again) * c1 : validate (k1 == vm1-k1-again) AND (k2 == vm1-k2-again)// as both are not registered - * */ @Test - public void testInterestListRegistrationOnServer() - { - - DistributedMember c1 = (DistributedMember)vm1 - .invoke(() -> InterestListDUnitTest.createClientCache( - NetworkUtils.getServerHostName(vm0.getHost()), PORT1)); - DistributedMember c2 = (DistributedMember)vm2 - .invoke(() -> InterestListDUnitTest.createClientCache( - NetworkUtils.getServerHostName(vm0.getHost()), PORT1)); + public void testInterestListRegistrationOnServer() throws Exception { + DistributedMember c1 = (DistributedMember)vm1 + .invoke(() -> InterestListDUnitTest.createClientCache( + NetworkUtils.getServerHostName(vm0.getHost()), PORT1)); + DistributedMember c2 = (DistributedMember)vm2 + .invoke(() -> InterestListDUnitTest.createClientCache( + NetworkUtils.getServerHostName(vm0.getHost()), PORT1)); - vm1.invoke(() -> InterestListDUnitTest.createEntriesK1andK2()); - vm2.invoke(() -> InterestListDUnitTest.createEntriesK1andK2()); + vm1.invoke(() -> InterestListDUnitTest.createEntriesK1andK2()); + vm2.invoke(() -> InterestListDUnitTest.createEntriesK1andK2()); - vm0.invoke(() -> InterestListDUnitTest.registerKeyForClient( c1, key1 )); - vm0.invoke(() -> InterestListDUnitTest.registerKeyForClient( c2, key2 )); + vm0.invoke(() -> InterestListDUnitTest.registerKeyForClient( c1, key1 )); + vm0.invoke(() -> InterestListDUnitTest.registerKeyForClient( c2, key2 )); - vm0.invoke(() -> InterestListDUnitTest.flushQueues()); + vm0.invoke(() -> InterestListDUnitTest.flushQueues()); - vm1.invoke(() -> InterestListDUnitTest.put( "vm1" )); + vm1.invoke(() -> InterestListDUnitTest.put( "vm1" )); - vm0.invoke(() -> InterestListDUnitTest.flushQueues()); + vm0.invoke(() -> InterestListDUnitTest.flushQueues()); - vm2.invoke(() -> InterestListDUnitTest.validateEntriesK1andK2( "vm2" )); - vm2.invoke(() -> InterestListDUnitTest.put( "vm2" )); + vm2.invoke(() -> InterestListDUnitTest.validateEntriesK1andK2( "vm2" )); + vm2.invoke(() -> InterestListDUnitTest.put( "vm2" )); - vm0.invoke(() -> InterestListDUnitTest.flushQueues()); + vm0.invoke(() -> InterestListDUnitTest.flushQueues()); - vm1.invoke(() -> InterestListDUnitTest.validateEntriesK1andK2( "vm1" )); + vm1.invoke(() -> InterestListDUnitTest.validateEntriesK1andK2( "vm1" )); - vm0.invoke(() -> InterestListDUnitTest.unregisterKeyForClient( c1, key1 )); - vm0.invoke(() -> InterestListDUnitTest.unregisterKeyForClient( c2, key2 )); + vm0.invoke(() -> InterestListDUnitTest.unregisterKeyForClient( c1, key1 )); + vm0.invoke(() -> InterestListDUnitTest.unregisterKeyForClient( c2, key2 )); - vm1.invoke(() -> InterestListDUnitTest.putAgain( "vm1" )); + vm1.invoke(() -> InterestListDUnitTest.putAgain( "vm1" )); - vm0.invoke(() -> InterestListDUnitTest.flushQueues()); + vm0.invoke(() -> InterestListDUnitTest.flushQueues()); - vm2.invoke(() -> InterestListDUnitTest.validateEntriesAgain( "vm2" )); - vm2.invoke(() -> InterestListDUnitTest.putAgain( "vm2" )); + vm2.invoke(() -> InterestListDUnitTest.validateEntriesAgain( "vm2" )); + vm2.invoke(() -> InterestListDUnitTest.putAgain( "vm2" )); - vm0.invoke(() -> InterestListDUnitTest.flushQueues()); + vm0.invoke(() -> InterestListDUnitTest.flushQueues()); - vm1.invoke(() -> InterestListDUnitTest.validateEntriesAgain( "vm1" )); - } + vm1.invoke(() -> InterestListDUnitTest.validateEntriesAgain( "vm1" )); + } - /** - * two servers one client - * create Entries in all the vms - * register interest in various ways and ensure that registration listeners - * are properly invoked - * @throws Exception - */ + /** + * two servers one client + * create Entries in all the vms + * register interest in various ways and ensure that registration listeners + * are properly invoked + */ @Test public void testInterestRegistrationListeners() throws Exception { - int port2; + int port2; - createCache(); - server = addCacheServer(); - port2 = server.getPort(); + createCache(); + server = addCacheServer(); + port2 = server.getPort(); - addRegisterInterestListener(); - vm0.invoke(() -> InterestListDUnitTest.addRegisterInterestListener()); + addRegisterInterestListener(); + vm0.invoke(() -> InterestListDUnitTest.addRegisterInterestListener()); - // servers are set up, now do the clients - DistributedMember c1 = (DistributedMember)vm1 - .invoke(() -> InterestListDUnitTest.createClientCache( - NetworkUtils.getServerHostName(vm0.getHost()), PORT1, port2)); - DistributedMember c2 = (DistributedMember)vm2 - .invoke(() -> InterestListDUnitTest.createClientCache( - NetworkUtils.getServerHostName(vm0.getHost()), PORT1, port2)); + // servers are set up, now do the clients + DistributedMember c1 = (DistributedMember)vm1 + .invoke(() -> InterestListDUnitTest.createClientCache( + NetworkUtils.getServerHostName(vm0.getHost()), PORT1, port2)); + DistributedMember c2 = (DistributedMember)vm2 + .invoke(() -> InterestListDUnitTest.createClientCache( + NetworkUtils.getServerHostName(vm0.getHost()), PORT1, port2)); - vm1.invoke(() -> InterestListDUnitTest.createEntriesK1andK2()); - vm2.invoke(() -> InterestListDUnitTest.createEntriesK1andK2()); + vm1.invoke(() -> InterestListDUnitTest.createEntriesK1andK2()); + vm2.invoke(() -> InterestListDUnitTest.createEntriesK1andK2()); - // interest registration from clients should cause listeners to be invoked - // in both servers - LogWriterUtils.getLogWriter().info("test phase 1"); - vm1.invoke(() -> InterestListDUnitTest.registerKey( key1 )); - vm2.invoke(() -> InterestListDUnitTest.registerKey( key2 )); + // interest registration from clients should cause listeners to be invoked + // in both servers + LogWriterUtils.getLogWriter().info("test phase 1"); + vm1.invoke(() -> InterestListDUnitTest.registerKey( key1 )); + vm2.invoke(() -> InterestListDUnitTest.registerKey( key2 )); - Integer zero = new Integer(0); - Integer two = new Integer(2); + Integer zero = new Integer(0); + Integer two = new Integer(2); - interestListener.verifyCountsAndClear(2, 0); - vm0.invoke(() -> InterestListDUnitTest.verifyCountsAndClear( two, zero )); + interestListener.verifyCountsAndClear(2, 0); + vm0.invoke(() -> InterestListDUnitTest.verifyCountsAndClear( two, zero )); - // unregistration from clients should invoke listeners on both servers - LogWriterUtils.getLogWriter().info("test phase 2"); - vm1.invoke(() -> InterestListDUnitTest.unregisterKey( key1 )); - vm2.invoke(() -> InterestListDUnitTest.unregisterKey( key2 )); + // unregistration from clients should invoke listeners on both servers + LogWriterUtils.getLogWriter().info("test phase 2"); + vm1.invoke(() -> InterestListDUnitTest.unregisterKey( key1 )); + vm2.invoke(() -> InterestListDUnitTest.unregisterKey( key2 )); - interestListener.verifyCountsAndClear(0, 2); - vm0.invoke(() -> InterestListDUnitTest.verifyCountsAndClear( zero, two )); + interestListener.verifyCountsAndClear(0, 2); + vm0.invoke(() -> InterestListDUnitTest.verifyCountsAndClear( zero, two )); - // now the primary server for eache client will register and unregister - LogWriterUtils.getLogWriter().info("test phase 3"); - registerKeyForClient(c1, key1); - vm0.invoke(() -> InterestListDUnitTest.registerKeyForClient( c1, key1 )); - registerKeyForClient(c2, key2); - vm0.invoke(() -> InterestListDUnitTest.registerKeyForClient( c2, key2 )); + // now the primary server for eache client will register and unregister + LogWriterUtils.getLogWriter().info("test phase 3"); + registerKeyForClient(c1, key1); + vm0.invoke(() -> InterestListDUnitTest.registerKeyForClient( c1, key1 )); + registerKeyForClient(c2, key2); + vm0.invoke(() -> InterestListDUnitTest.registerKeyForClient( c2, key2 )); - interestListener.verifyCountsAndClear(2, 0); - vm0.invoke(() -> InterestListDUnitTest.verifyCountsAndClear( two, zero )); + interestListener.verifyCountsAndClear(2, 0); + vm0.invoke(() -> InterestListDUnitTest.verifyCountsAndClear( two, zero )); - LogWriterUtils.getLogWriter().info("test phase 4"); - unregisterKeyForClient(c1, key1); - vm0.invoke(() -> InterestListDUnitTest.unregisterKeyForClient( c1, key1 )); - unregisterKeyForClient(c2, key2); - vm0.invoke(() -> InterestListDUnitTest.unregisterKeyForClient( c2, key2 )); + LogWriterUtils.getLogWriter().info("test phase 4"); + unregisterKeyForClient(c1, key1); + vm0.invoke(() -> InterestListDUnitTest.unregisterKeyForClient( c1, key1 )); + unregisterKeyForClient(c2, key2); + vm0.invoke(() -> InterestListDUnitTest.unregisterKeyForClient( c2, key2 )); - interestListener.verifyCountsAndClear(0, 2); - vm0.invoke(() -> InterestListDUnitTest.verifyCountsAndClear( zero, two )); - } + interestListener.verifyCountsAndClear(0, 2); + vm0.invoke(() -> InterestListDUnitTest.verifyCountsAndClear( zero, two )); + } /** * This tests whether an exception is thrown in register/unregister when no * server is available. */ @Test - public void testNoAvailableServer() { - + public void testNoAvailableServer() throws Exception { // Register interest in key1. vm1.invoke(() -> InterestListDUnitTest.createClientCache( NetworkUtils.getServerHostName(vm0.getHost()), new Integer(PORT1) )); vm1.invoke(() -> InterestListDUnitTest.registerKey( key1 )); @@ -483,7 +475,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } @Test - public void testRegisterInterestOnPartitionedRegionWithCacheLoader() { + public void testRegisterInterestOnPartitionedRegionWithCacheLoader() throws Exception { runRegisterInterestWithCacheLoaderTest(false); } @@ -524,20 +516,17 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase vm1.invoke(() -> InterestListDUnitTest.confirmNoCacheListenerInvalidates()); } - private void createCache(Properties props) throws Exception - { + private void createCache(Properties props) throws Exception { DistributedSystem ds = getSystem(props); cache = CacheFactory.create(ds); assertNotNull(cache); } - public static DistributedMember createClientCache(String host, int port) throws Exception { + private static DistributedMember createClientCache(String host, int port) throws Exception { return createClientCache(host, port, 0); } - public static DistributedMember createClientCache(String host, - int port, int port2) throws Exception - { + private static DistributedMember createClientCache(String host, int port, int port2) throws Exception { Properties props = new Properties(); props.setProperty(DistributionConfig.MCAST_PORT_NAME, "0"); props.setProperty(DistributionConfig.LOCATORS_NAME, ""); @@ -607,25 +596,27 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase // this method is for use in vm0 where the CacheServer used by // most of these tests resides. This server is held in the // static variable 'server1' - public static Integer createServerCache() throws Exception { + private static Integer createServerCache() throws Exception { return createServerCache(true); } - public static Integer createServerCache(boolean addReplicatedRegion) throws Exception { + private static Integer createServerCache(boolean addReplicatedRegion) throws Exception { createCache(addReplicatedRegion); server = addCacheServer(); return new Integer(server.getPort()); } /** wait for queues to drain in the server */ - public static void flushQueues() throws Exception { + private static void flushQueues() throws Exception { CacheServerImpl impl = (CacheServerImpl)server; for (CacheClientProxy proxy: (Set<CacheClientProxy>)impl.getAllClientSessions()) { final CacheClientProxy fproxy = proxy; WaitCriterion ev = new WaitCriterion() { + @Override public boolean done() { return fproxy.getHARegionQueue().size() == 0; } + @Override public String description() { return "waiting for queues to drain for " + fproxy.getProxyID(); } @@ -634,7 +625,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } } - public static void addRegisterInterestListener() { + private static void addRegisterInterestListener() { interestListener = new InterestListener(); List<CacheServer> servers = cache.getCacheServers(); for (CacheServer s: servers) { @@ -669,9 +660,11 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase final EventCountingCacheListener fCacheListener = (EventCountingCacheListener) region.getAttributes().getCacheListener(); WaitCriterion ev = new WaitCriterion() { + @Override public boolean done() { return fCacheListener.hasReceivedAllCreateEvents(); } + @Override public String description() { return "waiting for " + fCacheListener.getExpectedCreates() + " create events"; } @@ -695,12 +688,11 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase assertEquals(0/*expected*/, cacheListener.getInvalidates()/*actual*/); } - public static void verifyCountsAndClear(int count1, int count2) { + private static void verifyCountsAndClear(int count1, int count2) { interestListener.verifyCountsAndClear(count1, count2); } - public static void createEntriesK1andK2() - { + private static void createEntriesK1andK2() { try { Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(r); @@ -720,14 +712,12 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } private static void registerKeyOnly(Object key) { - Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(r); r.registerInterest(key); } - public static void registerKey(Object key) - { + private static void registerKey(Object key) { try { registerKeyOnly(key); } @@ -742,7 +732,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase * @param clientId the DM of the client * @param key the key that the client is interested in */ - public static void registerKeyForClient(DistributedMember clientId, Object key) { + private static void registerKeyForClient(DistributedMember clientId, Object key) { try { ClientSession cs = server.getClientSession(clientId); if (cs.isPrimary()) { @@ -754,8 +744,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } } - public static void registerKeyEx(Object key) { - + private static void registerKeyEx(Object key) { try { registerKeyOnly(key); fail("Expected an exception during register interest with no available servers."); @@ -766,8 +755,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } } - public static void registerALL_KEYS() - { + private static void registerALL_KEYS() { try { Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(r); @@ -778,8 +766,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } } - public static void put_ALL_KEYS() - { + private static void put_ALL_KEYS() { try { Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(r); @@ -794,8 +781,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } } - public static void validate_ALL_KEYS() - { + private static void validate_ALL_KEYS() { try { Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(r); @@ -807,8 +793,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } } - public static void registerKeys() - { + private static void registerKeys() { List list = new ArrayList(); try { Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); @@ -822,8 +807,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } } - public static void registerKeysAgain() - { + private static void registerKeysAgain() { List list = new ArrayList(); try { Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); @@ -838,14 +822,12 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } private static void unregisterKeyOnly(Object key) { - Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(r); r.unregisterInterest(key); } - public static void unregisterKey(Object key) - { + private static void unregisterKey(Object key) { try { unregisterKeyOnly(key); } @@ -859,8 +841,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase * @param clientId the client's ID * @param key the key it's no longer interest in */ - public static void unregisterKeyForClient(DistributedMember clientId, Object key) - { + private static void unregisterKeyForClient(DistributedMember clientId, Object key) { try { ClientSession cs = server.getClientSession(clientId); if (cs.isPrimary()) { @@ -872,12 +853,11 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } } - public static void unregisterKeyEx(Object key) { + private static void unregisterKeyEx(Object key) { unregisterKeyOnly(key); } - public static void validateRegionEntriesFromInterestListInVm1() - { + private static void validateRegionEntriesFromInterestListInVm1() { Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(r); Region.Entry k1, k2; @@ -889,8 +869,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase assertEquals(k2.getValue(), "server2"); } - public static void validateRegionEntriesFromInterestListInVm2() - { + private static void validateRegionEntriesFromInterestListInVm2() { Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(r); assertEquals(r.getEntry("k3").getValue(), "server3"); @@ -898,7 +877,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase assertEquals(r.getEntry("k5").getValue(), "server5"); } - public static void putSingleEntry(Object key, String value) { + private static void putSingleEntry(Object key, String value) { try { Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(r); @@ -911,8 +890,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } } - public static void put(String vm) - { + private static void put(String vm) { try { Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(r); @@ -937,8 +915,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } } - public static void multiple_put() - { + private static void multiple_put() { try { Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(r); @@ -954,8 +931,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } } - public static void putAgain(String vm) - { + private static void putAgain(String vm) { try { Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(r); @@ -980,9 +956,9 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } } - public static void validateEntriesK1andK2(final String vm) - { + private static void validateEntriesK1andK2(final String vm) { WaitCriterion ev = new WaitCriterion() { + @Override public boolean done() { try { Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); @@ -1001,10 +977,11 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } return true; } - catch (AssertionFailedError ex) { + catch (AssertionError ex) { return false; } } + @Override public String description() { return "waiting for client to apply events from server"; } @@ -1012,7 +989,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase Wait.waitForCriterion(ev, 5 * 10 * 1000, 200, true); } - public static void validateSingleEntry(Object key, String value) { + private static void validateSingleEntry(Object key, String value) { try { Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertEquals(value, r.getEntry(key).getValue()); @@ -1022,8 +999,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } } - public static void validateEntriesAgain(String vm) - { + private static void validateEntriesAgain(String vm) { try { Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(r); @@ -1044,40 +1020,25 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase } } - @Override - public final void preTearDown() throws Exception { - // close the clients first - vm1.invoke(() -> InterestListDUnitTest.closeCache()); - vm2.invoke(() -> InterestListDUnitTest.closeCache()); - // then close the servers - vm0.invoke(() -> InterestListDUnitTest.closeCache()); - cache = null; - Invoke.invokeInEveryVM(new SerializableRunnable() { public void run() { cache = null; } }); - } - - public static void closeCache() - { + private static void closeCache() { if (cache != null && !cache.isClosed()) { cache.close(); cache.getDistributedSystem().disconnect(); } } - static class InterestListener implements InterestRegistrationListener { + private static class InterestListener implements InterestRegistrationListener { + private int registrationCount; private int unregistrationCount; - /* (non-Javadoc) - * @see com.gemstone.gemfire.cache.InterestRegistrationListener#afterRegisterInterest(com.gemstone.gemfire.cache.InterestRegistrationEvent) - */ + @Override public void afterRegisterInterest(InterestRegistrationEvent event) { LogWriterUtils.getLogWriter().info("InterestListener.afterRegisterInterest invoked with this event: " + event); registrationCount++; } - /* (non-Javadoc) - * @see com.gemstone.gemfire.cache.InterestRegistrationListener#afterUnregisterInterest(com.gemstone.gemfire.cache.InterestRegistrationEvent) - */ + @Override public void afterUnregisterInterest(InterestRegistrationEvent event) { LogWriterUtils.getLogWriter().info("InterestListener.afterUnregisterInterest invoked with this event: " + event); unregistrationCount++; @@ -1096,9 +1057,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase unregistrationCount = 0; } - /* (non-Javadoc) - * @see com.gemstone.gemfire.cache.CacheCallback#close() - */ + @Override public void close() { } @@ -1109,9 +1068,7 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase private static class EventCountingCacheListener extends CacheListenerAdapter { private AtomicInteger creates = new AtomicInteger(); - private AtomicInteger updates = new AtomicInteger(); - private AtomicInteger invalidates = new AtomicInteger(); private int expectedCreates; @@ -1124,15 +1081,18 @@ public class InterestListDUnitTest extends JUnit4DistributedTestCase return this.expectedCreates; } + @Override public void afterCreate(EntryEvent event) { incrementCreates(); } + @Override public void afterUpdate(EntryEvent event) { incrementUpdates(); event.getRegion().getCache().getLogger().warning("Received update event " + getUpdates() + " for " + event.getKey()); } + @Override public void afterInvalidate(EntryEvent event) { incrementInvalidates(); event.getRegion().getCache().getLogger().warning("Received invalidate event " + getInvalidates() + " for " + event.getKey());
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb91dedc/geode-core/src/test/java/com/gemstone/gemfire/management/ClientHealthStatsDUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/ClientHealthStatsDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/management/ClientHealthStatsDUnitTest.java index c940869..6661a0a 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/management/ClientHealthStatsDUnitTest.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/management/ClientHealthStatsDUnitTest.java @@ -16,19 +16,15 @@ */ package com.gemstone.gemfire.management; -import org.junit.experimental.categories.Category; -import org.junit.Test; - -import static org.junit.Assert.*; - -import com.gemstone.gemfire.test.dunit.cache.internal.JUnit4CacheTestCase; -import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase; -import com.gemstone.gemfire.test.junit.categories.DistributedTest; +import static com.gemstone.gemfire.test.dunit.Assert.*; import java.util.Collection; import java.util.Iterator; import java.util.Properties; +import org.junit.Test; +import org.junit.experimental.categories.Category; + import com.gemstone.gemfire.cache.Cache; import com.gemstone.gemfire.cache.EntryEvent; import com.gemstone.gemfire.cache.Region; @@ -45,41 +41,31 @@ import com.gemstone.gemfire.internal.cache.GemFireCacheImpl; import com.gemstone.gemfire.internal.cache.tier.sockets.CacheClientNotifier; import com.gemstone.gemfire.internal.cache.tier.sockets.CacheClientProxy; import com.gemstone.gemfire.internal.i18n.LocalizedStrings; -import com.gemstone.gemfire.test.dunit.DistributedTestCase; import com.gemstone.gemfire.test.dunit.Host; import com.gemstone.gemfire.test.dunit.IgnoredException; -import com.gemstone.gemfire.test.dunit.RMIException; import com.gemstone.gemfire.test.dunit.VM; import com.gemstone.gemfire.test.dunit.Wait; import com.gemstone.gemfire.test.dunit.WaitCriterion; - -import junit.framework.AssertionFailedError; +import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase; +import com.gemstone.gemfire.test.junit.categories.DistributedTest; /** * Client health stats check - * - * */ @Category(DistributedTest.class) +@SuppressWarnings("serial") public class ClientHealthStatsDUnitTest extends JUnit4DistributedTestCase { private static final String k1 = "k1"; - private static final String k2 = "k2"; - private static final String client_k1 = "client-k1"; - private static final String client_k2 = "client-k2"; /** name of the test region */ private static final String REGION_NAME = "ClientHealthStatsDUnitTest_Region"; - private VM server = null; - private static VM client = null; - private static VM client2 = null; - private static VM managingNode = null; private static ManagementTestBase helper = new ManagementTestBase(){}; @@ -91,9 +77,7 @@ public class ClientHealthStatsDUnitTest extends JUnit4DistributedTestCase { private static GemFireCacheImpl cache = null; - public ClientHealthStatsDUnitTest() { - super(); - } + private VM server = null; @Override public final void postSetUp() throws Exception { @@ -104,6 +88,7 @@ public class ClientHealthStatsDUnitTest extends JUnit4DistributedTestCase { server = host.getVM(1); client = host.getVM(2); client2 = host.getVM(3); + IgnoredException.addIgnoredException("Connection reset"); } @@ -117,19 +102,16 @@ public class ClientHealthStatsDUnitTest extends JUnit4DistributedTestCase { disconnectAllFromDS(); } - - public static void reset() throws Exception { + + private static void reset() throws Exception { lastKeyReceived = false; numOfCreates = 0; numOfUpdates = 0; numOfInvalidates = 0; } - private static final long serialVersionUID = 1L; - @Test public void testClientHealthStats_SubscriptionEnabled() throws Exception { - helper.createManagementCache(managingNode); helper.startManagingNode(managingNode); @@ -150,7 +132,6 @@ public class ClientHealthStatsDUnitTest extends JUnit4DistributedTestCase { @Test public void testClientHealthStats_SubscriptionDisabled() throws Exception { - helper.createManagementCache(managingNode); helper.startManagingNode(managingNode); @@ -171,7 +152,6 @@ public class ClientHealthStatsDUnitTest extends JUnit4DistributedTestCase { @Test public void testClientHealthStats_DurableClient() throws Exception { - helper.createManagementCache(managingNode); helper.startManagingNode(managingNode); @@ -238,15 +218,14 @@ public class ClientHealthStatsDUnitTest extends JUnit4DistributedTestCase { @Override public String description() { - // TODO Auto-generated method stub return "Proxy has not paused yet"; } }; Wait.waitForCriterion(criterion, 15 * 1000, 200, true); } - - public static int createServerCache() throws Exception { + + private static int createServerCache() throws Exception { Cache cache = helper.createCache(false); RegionFactory<String, String> rf = cache.createRegionFactory(RegionShortcut.REPLICATE); @@ -259,22 +238,16 @@ public class ClientHealthStatsDUnitTest extends JUnit4DistributedTestCase { return server1.getPort(); } - - - public static void closeClientCache() throws Exception { + private static void closeClientCache() throws Exception { cache.close(true); } - public static void createClientCache(Host host, Integer port, int clientNum, boolean subscriptionEnabled, boolean durable) throws Exception { - + private static void createClientCache(Host host, Integer port, int clientNum, boolean subscriptionEnabled, boolean durable) throws Exception { Properties props = new Properties(); props.setProperty(DistributionConfig.DURABLE_CLIENT_ID_NAME, "durable-"+clientNum); props.setProperty(DistributionConfig.DURABLE_CLIENT_TIMEOUT_NAME, "300000"); - -// props.setProperty("log-file", getTestMethodName()+"_client_" + clientNum + ".log"); props.setProperty("log-level", "info"); - props.setProperty("statistic-archive-file", getTestMethodName()+"_client_" + clientNum - + ".gfs"); + props.setProperty("statistic-archive-file", getTestMethodName()+"_client_" + clientNum + ".gfs"); props.setProperty("statistic-sampling-enabled", "true"); ClientCacheFactory ccf = new ClientCacheFactory(props); @@ -321,10 +294,9 @@ public class ClientHealthStatsDUnitTest extends JUnit4DistributedTestCase { r.registerInterest("ALL_KEYS", true); cache.readyForEvents(); } - } - public static void doPuts() throws Exception { + private static void doPuts() throws Exception { Cache cache = GemFireCacheImpl.getInstance(); final Region<String, String> r = cache.getRegion(Region.SEPARATOR + REGION_NAME); Thread t1 = new Thread(new Runnable() { @@ -357,8 +329,8 @@ public class ClientHealthStatsDUnitTest extends JUnit4DistributedTestCase { t2.join(); t3.join(); } - - public static void resumePuts() { + + private static void resumePuts() { Cache cache = GemFireCacheImpl.getInstance(); Region<String, String> r = cache.getRegion(Region.SEPARATOR + REGION_NAME); for (int i = 0; i < 100; i++) { @@ -367,7 +339,7 @@ public class ClientHealthStatsDUnitTest extends JUnit4DistributedTestCase { r.put("last_key", "last_value"); } - public static void waitForLastKey() { + private static void waitForLastKey() { WaitCriterion wc = new WaitCriterion() { @Override public boolean done() { @@ -381,14 +353,12 @@ public class ClientHealthStatsDUnitTest extends JUnit4DistributedTestCase { Wait.waitForCriterion(wc, 60*1000, 500, true); } - - @SuppressWarnings("serial") - protected static DistributedMember getMember() throws Exception { + private static DistributedMember getMember() throws Exception { GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); return cache.getDistributedSystem().getDistributedMember(); } - protected static void verifyClientStats(DistributedMember serverMember, int serverPort, int numSubscriptions) { + private static void verifyClientStats(DistributedMember serverMember, int serverPort, int numSubscriptions) { GemFireCacheImpl cache = GemFireCacheImpl.getInstance(); try { ManagementService service = ManagementService.getExistingManagementService(cache); @@ -401,8 +371,6 @@ public class ClientHealthStatsDUnitTest extends JUnit4DistributedTestCase { ClientHealthStatus[] clientStatuses = bean.showAllClientStats(); - - ClientHealthStatus clientStatus1 = bean.showClientStats(clientIds[0]); ClientHealthStatus clientStatus2 = bean.showClientStats(clientIds[1]); assertNotNull(clientStatus1); @@ -416,22 +384,18 @@ public class ClientHealthStatsDUnitTest extends JUnit4DistributedTestCase { assertTrue(clientStatuses.length == 2); for (ClientHealthStatus status : clientStatuses) { System.out.println("<ExpectedString> ClientStats of the Server is " + status + "</ExpectedString> "); - } - DistributedSystemMXBean dsBean = service.getDistributedSystemMXBean(); assertEquals(2, dsBean.getNumClients()); assertEquals(numSubscriptions, dsBean.getNumSubscriptions()); } catch (Exception e) { - e.printStackTrace(); - fail("Error while verifying cache server from remote member " + e); + fail("Error while verifying cache server from remote member", e); } - } - protected static void put() { + private static void put() { Cache cache = GemFireCacheImpl.getInstance(); Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME); assertNotNull(r1); @@ -457,11 +421,9 @@ public class ClientHealthStatsDUnitTest extends JUnit4DistributedTestCase { } catch (Exception e) { // sleep } - } - - public static void verifyStats(int serverPort) throws Exception { + private static void verifyStats(int serverPort) throws Exception { Cache cache = GemFireCacheImpl.getInstance(); ManagementService service = ManagementService.getExistingManagementService(cache); CacheServerMXBean serverBean = service.getLocalCacheServerMXBean(serverPort); @@ -477,5 +439,4 @@ public class ClientHealthStatsDUnitTest extends JUnit4DistributedTestCase { ClientQueueDetail queueDetails = serverBean.showClientQueueDetails()[0]; assertEquals(queueDetails.getQueueSize(), ccp.getQueueSizeStat()); } - } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb91dedc/geode-core/src/test/java/com/gemstone/gemfire/management/ManagementTestBase.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/ManagementTestBase.java b/geode-core/src/test/java/com/gemstone/gemfire/management/ManagementTestBase.java index 0c5c75d..59847b9 100644 --- a/geode-core/src/test/java/com/gemstone/gemfire/management/ManagementTestBase.java +++ b/geode-core/src/test/java/com/gemstone/gemfire/management/ManagementTestBase.java @@ -16,35 +16,49 @@ */ package com.gemstone.gemfire.management; -import org.junit.experimental.categories.Category; -import org.junit.Test; - import static org.junit.Assert.*; -import com.gemstone.gemfire.test.dunit.cache.internal.JUnit4CacheTestCase; -import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase; -import com.gemstone.gemfire.test.junit.categories.DistributedTest; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Properties; +import java.util.Set; +import javax.management.MBeanServer; +import javax.management.ObjectName; import com.gemstone.gemfire.LogWriter; -import com.gemstone.gemfire.cache.*; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.RegionFactory; +import com.gemstone.gemfire.cache.RegionShortcut; import com.gemstone.gemfire.distributed.DistributedMember; import com.gemstone.gemfire.distributed.DistributedSystem; import com.gemstone.gemfire.distributed.internal.DistributionConfig; import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem; import com.gemstone.gemfire.internal.cache.GemFireCacheImpl; import com.gemstone.gemfire.internal.statistics.SampleCollector; -import com.gemstone.gemfire.management.internal.*; -import com.gemstone.gemfire.test.dunit.*; - -import javax.management.MBeanServer; -import javax.management.ObjectName; -import java.util.*; +import com.gemstone.gemfire.management.internal.FederatingManager; +import com.gemstone.gemfire.management.internal.LocalManager; +import com.gemstone.gemfire.management.internal.MBeanJMXAdapter; +import com.gemstone.gemfire.management.internal.ManagementStrings; +import com.gemstone.gemfire.management.internal.SystemManagementService; +import com.gemstone.gemfire.test.dunit.Assert; +import com.gemstone.gemfire.test.dunit.AsyncInvocation; +import com.gemstone.gemfire.test.dunit.Host; +import com.gemstone.gemfire.test.dunit.Invoke; +import com.gemstone.gemfire.test.dunit.SerializableCallable; +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; +@SuppressWarnings("serial") public abstract class ManagementTestBase extends JUnit4DistributedTestCase { private static final int MAX_WAIT = 70 * 1000; - private static final long serialVersionUID = 1L; /** * log writer instance */ @@ -184,7 +198,6 @@ public abstract class ManagementTestBase extends JUnit4DistributedTestCase { } } - @SuppressWarnings("serial") public void createCache(VM vm1) throws Exception { vm1.invoke(new SerializableRunnable("Create Cache") { public void run() { @@ -194,7 +207,6 @@ public abstract class ManagementTestBase extends JUnit4DistributedTestCase { } - @SuppressWarnings("serial") public void createCache(VM vm1, final Properties props) throws Exception { vm1.invoke(new SerializableRunnable("Create Cache") { public void run() { @@ -240,7 +252,6 @@ public abstract class ManagementTestBase extends JUnit4DistributedTestCase { return cache; } - @SuppressWarnings("serial") public void createManagementCache(VM vm1) throws Exception { vm1.invoke(new SerializableRunnable("Create Management Cache") { public void run() { @@ -249,7 +260,6 @@ public abstract class ManagementTestBase extends JUnit4DistributedTestCase { }); } - @SuppressWarnings("serial") public void closeCache(VM vm1) throws Exception { vm1.invoke(new SerializableRunnable("Close Cache") { public void run() { @@ -320,7 +330,6 @@ public abstract class ManagementTestBase extends JUnit4DistributedTestCase { * * @throws Exception */ - @SuppressWarnings("serial") public void startManagingNode(VM vm1) throws Exception { vm1.invoke(new SerializableRunnable("Start Being Managing Node") { public void run() { @@ -345,7 +354,6 @@ public abstract class ManagementTestBase extends JUnit4DistributedTestCase { * * @throws Exception */ - @SuppressWarnings("serial") public void startManagingNodeAsync(VM vm1) throws Exception { vm1.invokeAsync(new SerializableRunnable("Start Being Managing Node") { @@ -367,7 +375,6 @@ public abstract class ManagementTestBase extends JUnit4DistributedTestCase { * * @throws Exception */ - @SuppressWarnings("serial") public void stopManagingNode(VM vm1) throws Exception { vm1.invoke(new SerializableRunnable("Stop Being Managing Node") { public void run() { @@ -389,7 +396,6 @@ public abstract class ManagementTestBase extends JUnit4DistributedTestCase { * remove all the artifacts of management namely a) Notification region b) * Monitoring Region c) Management task should stop */ - @SuppressWarnings("serial") public void checkManagedNodeCleanup(VM vm) throws Exception { vm.invoke(new SerializableRunnable("Managing Node Clean up") { http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb91dedc/geode-core/src/test/java/com/gemstone/gemfire/pdx/VersionClassLoader.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/com/gemstone/gemfire/pdx/VersionClassLoader.java b/geode-core/src/test/java/com/gemstone/gemfire/pdx/VersionClassLoader.java deleted file mode 100644 index f2e6b5a..0000000 --- a/geode-core/src/test/java/com/gemstone/gemfire/pdx/VersionClassLoader.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * 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. - */ - -/** Class containing pdx tests. - * - */ -package com.gemstone.gemfire.pdx; - -import java.io.File; -import java.lang.reflect.Constructor; -import java.net.URL; -import java.net.URLClassLoader; - -import com.gemstone.gemfire.test.dunit.LogWriterUtils; - -public class VersionClassLoader { - - /** If PdxPrms.initClassLoader is true, then randomly choose a versioned - * class path and create and install a class loader for it on this thread. - * - * @return The installed class loader (which includes a versioned class path) - * or null if this call did not install a new class loader. - */ - public static ClassLoader initClassLoader(long classVersion) throws Exception { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - cl = ClassLoader.getSystemClassLoader(); - - String alternateVersionClassPath = System.getProperty("JTESTS") + - File.separator + ".." + File.separator + ".." + File.separator + - "classes" + File.separator + "version" + classVersion; - LogWriterUtils.getLogWriter().info("Initializing the class loader :" + alternateVersionClassPath); - ClassLoader versionCL = null; - try { - versionCL = new URLClassLoader(new URL[]{new File(alternateVersionClassPath).toURI().toURL()}, cl); - Thread.currentThread().setContextClassLoader(versionCL); - } catch (Exception e) { - LogWriterUtils.getLogWriter().info("error", e); - throw new Exception("Failed to initialize the class loader. " + e.getMessage()); - } - LogWriterUtils.getLogWriter().info("Setting/adding class loader with " + alternateVersionClassPath); - return versionCL; - } - - - /** Use reflection to create a new instance of a versioned class whose - * name is specified by className. - * - * Since versioned classes are compled outside outside the <checkoutDir>/tests - * directory, code within <checkoutDir>/tests cannot directly reference - * versioned classes, however the versioned class should be available at - * runtime if the test has installed the correct class loader. - * - * @param className The name of the versioned class to create. - * @return A new instance of className. - */ - public static Object getVersionedInstance(String className, Object[] args) throws Exception { - Object newObj = null; - try { - Class aClass = Class.forName(className, true, Thread.currentThread().getContextClassLoader()); - if (args != null && args.length > 0) { - if (className.endsWith("PdxTestObject")){ - Constructor constructor = aClass.getConstructor(int.class, String.class); - newObj = constructor.newInstance(((Integer)args[0]).intValue(), args[1]); - } else if (className.endsWith("PortfolioPdxVersion1")) { - Constructor constructor = aClass.getConstructor(int.class, int.class); - newObj = constructor.newInstance(((Integer)args[0]).intValue(), ((Integer)args[1]).intValue()); - } else if (className.endsWith("PdxVersionedNewPortfolio")) { - Constructor constructor = aClass.getConstructor(String.class, int.class); - newObj = constructor.newInstance(((String)args[0]), ((Integer)args[1]).intValue()); - } else if (className.endsWith("PdxVersionedFieldType")) { - Constructor constructor = aClass.getConstructor( int.class); - newObj = constructor.newInstance(((Integer)args[0]).intValue()); - } - } else { - Constructor constructor = aClass.getConstructor(); - newObj = constructor.newInstance(); - } - } catch (Exception e) { - LogWriterUtils.getLogWriter().info("error", e); - throw new Exception("Failed to get the class instance. ClassName: " + className + " error: ", e); - } - return newObj; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bb91dedc/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneEventListenerJUnitTest.java ---------------------------------------------------------------------- diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneEventListenerJUnitTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneEventListenerJUnitTest.java index 9660393..53c9db1 100644 --- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneEventListenerJUnitTest.java +++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneEventListenerJUnitTest.java @@ -22,11 +22,9 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.*; -import java.io.IOException; import java.util.ArrayList; import java.util.List; -import junit.framework.AssertionFailedError; import org.junit.Test; import org.junit.experimental.categories.Category; import org.mockito.Mockito; @@ -36,7 +34,6 @@ import com.gemstone.gemfire.cache.Region; import com.gemstone.gemfire.cache.asyncqueue.AsyncEvent; import com.gemstone.gemfire.cache.lucene.internal.repository.IndexRepository; import com.gemstone.gemfire.cache.lucene.internal.repository.RepositoryManager; -import com.gemstone.gemfire.internal.cache.BucketNotFoundException; import com.gemstone.gemfire.test.junit.categories.UnitTest; /** @@ -47,7 +44,7 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest; public class LuceneEventListenerJUnitTest { @Test - public void testProcessBatch() throws IOException, BucketNotFoundException { + public void testProcessBatch() throws Exception { RepositoryManager manager = Mockito.mock(RepositoryManager.class); IndexRepository repo1 = Mockito.mock(IndexRepository.class); IndexRepository repo2 = Mockito.mock(IndexRepository.class); @@ -84,7 +81,7 @@ public class LuceneEventListenerJUnitTest { break; case 2: Mockito.when(event.getOperation()).thenReturn(Operation.DESTROY); - Mockito.when(event.getDeserializedValue()).thenThrow(new AssertionFailedError()); + Mockito.when(event.getDeserializedValue()).thenThrow(new AssertionError()); break; }
