diff --git a/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValuesIdentityTest.java b/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValuesIdentityTest.java new file mode 100644 index 00000000000..49f874a807e --- /dev/null +++ b/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValuesIdentityTest.java @@ -0,0 +1,72 @@ +package org.infinispan.client.hotrod; + +import org.infinispan.client.hotrod.test.HotRodClientTestingUtil; +import org.infinispan.manager.EmbeddedCacheManager; +import org.infinispan.server.hotrod.HotRodServer; +import org.infinispan.test.SingleCacheManagerTest; +import org.infinispan.test.fwk.CleanupAfterMethod; +import org.infinispan.test.fwk.TestCacheManagerFactory; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.Test; + +import static org.infinispan.server.hotrod.test.HotRodTestingUtil.hotRodCacheConfiguration; +import static org.testng.AssertJUnit.assertEquals; +import static org.testng.AssertJUnit.assertNotNull; +import static org.testng.AssertJUnit.assertNotSame; +import static org.testng.AssertJUnit.assertNull; +import static org.testng.AssertJUnit.assertSame; + +@Test(testName = "client.hotrod.ForceReturnValuesIdentityTest", groups = "functional") +@CleanupAfterMethod +public class ForceReturnValuesIdentityTest extends SingleCacheManagerTest { + + private HotRodServer hotRodServer; + private RemoteCacheManager remoteCacheManager; + + @Override + protected EmbeddedCacheManager createCacheManager() throws Exception { + cacheManager = TestCacheManagerFactory.createCacheManager(hotRodCacheConfiguration()); + cache = cacheManager.getCache(); + + hotRodServer = HotRodClientTestingUtil.startHotRodServer(cacheManager); + + org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilder = + new org.infinispan.client.hotrod.configuration.ConfigurationBuilder(); + clientBuilder.addServer().host("localhost").port(hotRodServer.getPort()); + remoteCacheManager = new RemoteCacheManager(clientBuilder.build()); + return cacheManager; + } + + @AfterMethod + void shutdown() { + HotRodClientTestingUtil.killRemoteCacheManager(remoteCacheManager); + HotRodClientTestingUtil.killServers(hotRodServer); + } + + public void testSameInstanceForSameForceReturnValues() { + RemoteCache rcDontForceReturn = remoteCacheManager.getCache(false); + RemoteCache rcDontForceReturn2 = remoteCacheManager.getCache(false); + assertSame("RemoteCache instances should be the same", rcDontForceReturn, rcDontForceReturn2); + + RemoteCache rcForceReturn = remoteCacheManager.getCache(true); + RemoteCache rcForceReturn2 = remoteCacheManager.getCache(true); + assertSame("RemoteCache instances should be the same", rcForceReturn, rcForceReturn2); + } + + public void testDifferentInstancesForDifferentForceReturnValues() { + RemoteCache rcDontForceReturn = remoteCacheManager.getCache(false); + RemoteCache rcForceReturn = remoteCacheManager.getCache(true); + assertNotSame("RemoteCache instances should not be the same", rcDontForceReturn, rcForceReturn); + + String rv = rcDontForceReturn.put("Key", "Value"); + assertNull(rv); + rv = rcDontForceReturn.put("Key", "Value2"); + assertNull(rv); + + rv = rcForceReturn.put("Key2", "Value"); + assertNull(rv); + rv = rcForceReturn.put("Key2", "Value2"); + assertNotNull(rv); + assertEquals("Previous value should be 'Value'", "Value", rv); + } +} diff --git a/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValuesTest.java b/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValuesTest.java index c7f98346415..a8f44d5bdf1 100644 --- a/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValuesTest.java +++ b/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValuesTest.java @@ -1,12 +1,5 @@ package org.infinispan.client.hotrod; -import static org.infinispan.server.hotrod.test.HotRodTestingUtil.hotRodCacheConfiguration; -import static org.testng.AssertJUnit.assertEquals; -import static org.testng.AssertJUnit.assertNotNull; -import static org.testng.AssertJUnit.assertNotSame; -import static org.testng.AssertJUnit.assertNull; -import static org.testng.AssertJUnit.assertSame; - import org.infinispan.client.hotrod.test.HotRodClientTestingUtil; import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.server.hotrod.HotRodServer; @@ -15,6 +8,7 @@ import org.infinispan.test.fwk.TestCacheManagerFactory; import org.testng.annotations.AfterMethod; import org.testng.annotations.Test; +import static org.infinispan.server.hotrod.test.HotRodTestingUtil.hotRodCacheConfiguration; @Test(testName = "client.hotrod.ForceReturnValuesTest", groups = "functional") @CleanupAfterMethod @@ -30,7 +24,7 @@ protected EmbeddedCacheManager createCacheManager() throws Exception { hotRodServer = HotRodClientTestingUtil.startHotRodServer(cacheManager); org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilder = - new org.infinispan.client.hotrod.configuration.ConfigurationBuilder(); + new org.infinispan.client.hotrod.configuration.ConfigurationBuilder(); clientBuilder.addServer().host("localhost").port(hotRodServer.getPort()); remoteCacheManager = new RemoteCacheManager(clientBuilder.build()); return cacheManager; @@ -58,31 +52,4 @@ public void testForceReturnValues() { assert rv != null; assert "Value".equals(rv); } - - public void testSameInstanceForSameForceReturnValues() { - RemoteCache rcDontForceReturn = remoteCacheManager.getCache(false); - RemoteCache rcDontForceReturn2 = remoteCacheManager.getCache(false); - assertSame("RemoteCache instances should be the same", rcDontForceReturn, rcDontForceReturn2); - - RemoteCache rcForceReturn = remoteCacheManager.getCache(true); - RemoteCache rcForceReturn2 = remoteCacheManager.getCache(true); - assertSame("RemoteCache instances should be the same", rcForceReturn, rcForceReturn2); - } - - public void testDifferentInstancesForDifferentForceReturnValues() { - RemoteCache rcDontForceReturn = remoteCacheManager.getCache(false); - RemoteCache rcForceReturn = remoteCacheManager.getCache(true); - assertNotSame("RemoteCache instances should not be the same", rcDontForceReturn, rcForceReturn); - - String rv = rcDontForceReturn.put("Key", "Value"); - assertNull(rv); - rv = rcDontForceReturn.put("Key", "Value2"); - assertNull(rv); - - rv = rcForceReturn.put("Key2", "Value"); - assertNull(rv); - rv = rcForceReturn.put("Key2", "Value2"); - assertNotNull(rv); - assertEquals("Previous value should be 'Value'", "Value", rv); - } } diff --git a/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteCacheManagerExtendedTest.java b/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteCacheManagerExtendedTest.java new file mode 100644 index 00000000000..e01133a4237 --- /dev/null +++ b/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteCacheManagerExtendedTest.java @@ -0,0 +1,70 @@ +package org.infinispan.client.hotrod; + +import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; +import org.infinispan.client.hotrod.test.HotRodClientTestingUtil; +import org.infinispan.commons.marshall.jboss.GenericJBossMarshaller; +import org.infinispan.manager.EmbeddedCacheManager; +import org.infinispan.server.hotrod.HotRodServer; +import org.infinispan.test.SingleCacheManagerTest; +import org.infinispan.test.TestingUtil; +import org.infinispan.test.fwk.TestCacheManagerFactory; +import org.testng.annotations.AfterTest; +import org.testng.annotations.Test; + +import static org.infinispan.server.hotrod.test.HotRodTestingUtil.hotRodCacheConfiguration; +import static org.testng.AssertJUnit.assertTrue; + +/** + * @author Mircea.Markus@jboss.com + * @since 4.1 + * + * Adds tests for remote cache mangaer which are not supported + * by native clients (C++ and C#). See HRCPP-189 HRCPP-190. + */ +@Test(testName = "client.hotrod.RemoteCacheManagerExtendedTest", groups = "functional" ) +public class RemoteCacheManagerExtendedTest extends SingleCacheManagerTest { + + HotRodServer hotrodServer; + int port; + RemoteCacheManager remoteCacheManager; + + @Override + protected EmbeddedCacheManager createCacheManager() throws Exception { + return TestCacheManagerFactory.createCacheManager( + hotRodCacheConfiguration()); + } + + @Override + protected void setup() throws Exception { + super.setup(); + hotrodServer = HotRodClientTestingUtil.startHotRodServer(cacheManager); + port = hotrodServer.getPort(); + remoteCacheManager = null; + } + + @AfterTest + public void release() { + TestingUtil.killCacheManagers(cacheManager); + HotRodClientTestingUtil.killServers(hotrodServer); + HotRodClientTestingUtil.killRemoteCacheManager(remoteCacheManager); + } + + public void testGetUndefinedCache() { + ConfigurationBuilder clientBuilder = + new ConfigurationBuilder(); + clientBuilder.addServer().host("localhost").port(port); + remoteCacheManager = new RemoteCacheManager(clientBuilder.build(), false); + assert !remoteCacheManager.isStarted(); + remoteCacheManager.start(); + assert null == remoteCacheManager.getCache("Undefined1234"); + } + + public void testMarshallerInstance() { + ConfigurationBuilder builder = new ConfigurationBuilder(); + builder.addServer().host("127.0.0.1").port(port); + GenericJBossMarshaller marshaller = new GenericJBossMarshaller(); + builder.marshaller(marshaller); + remoteCacheManager = new RemoteCacheManager(builder.build()); + assertTrue(marshaller == remoteCacheManager.getMarshaller()); + } +} diff --git a/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteCacheManagerTest.java b/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteCacheManagerTest.java index cd2bbcbd363..c6d34262b9a 100644 --- a/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteCacheManagerTest.java +++ b/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteCacheManagerTest.java @@ -6,7 +6,6 @@ import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; import org.infinispan.client.hotrod.test.HotRodClientTestingUtil; -import org.infinispan.commons.marshall.jboss.GenericJBossMarshaller; import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.server.hotrod.HotRodServer; import org.infinispan.test.SingleCacheManagerTest; @@ -76,23 +75,4 @@ public void testConfigurationConstructor() { remoteCacheManager = new RemoteCacheManager(builder.build()); assertTrue(remoteCacheManager.isStarted()); } - - public void testGetUndefinedCache() { - org.infinispan.client.hotrod.configuration.ConfigurationBuilder clientBuilder = - new org.infinispan.client.hotrod.configuration.ConfigurationBuilder(); - clientBuilder.addServer().host("localhost").port(port); - remoteCacheManager = new RemoteCacheManager(clientBuilder.build(), false); - assert !remoteCacheManager.isStarted(); - remoteCacheManager.start(); - assert null == remoteCacheManager.getCache("Undefined1234"); - } - - public void testMarshallerInstance() { - ConfigurationBuilder builder = new ConfigurationBuilder(); - builder.addServer().host("127.0.0.1").port(port); - GenericJBossMarshaller marshaller = new GenericJBossMarshaller(); - builder.marshaller(marshaller); - remoteCacheManager = new RemoteCacheManager(builder.build()); - assertTrue(marshaller == remoteCacheManager.getMarshaller()); - } }