Skip to content

Commit

Permalink
ISPN-8077 Split test classes in order to get clean test runs for nati…
Browse files Browse the repository at this point in the history
…ve clients
  • Loading branch information
mgencur authored and tristantarrant committed Jul 19, 2017
1 parent 1cb3342 commit 93baa02
Show file tree
Hide file tree
Showing 4 changed files with 144 additions and 61 deletions.
@@ -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<String, String> rcDontForceReturn = remoteCacheManager.getCache(false);
RemoteCache<String, String> rcDontForceReturn2 = remoteCacheManager.getCache(false);
assertSame("RemoteCache instances should be the same", rcDontForceReturn, rcDontForceReturn2);

RemoteCache<String, String> rcForceReturn = remoteCacheManager.getCache(true);
RemoteCache<String, String> rcForceReturn2 = remoteCacheManager.getCache(true);
assertSame("RemoteCache instances should be the same", rcForceReturn, rcForceReturn2);
}

public void testDifferentInstancesForDifferentForceReturnValues() {
RemoteCache<String, String> rcDontForceReturn = remoteCacheManager.getCache(false);
RemoteCache<String, String> 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);
}
}
@@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -58,31 +52,4 @@ public void testForceReturnValues() {
assert rv != null;
assert "Value".equals(rv);
}

public void testSameInstanceForSameForceReturnValues() {
RemoteCache<String, String> rcDontForceReturn = remoteCacheManager.getCache(false);
RemoteCache<String, String> rcDontForceReturn2 = remoteCacheManager.getCache(false);
assertSame("RemoteCache instances should be the same", rcDontForceReturn, rcDontForceReturn2);

RemoteCache<String, String> rcForceReturn = remoteCacheManager.getCache(true);
RemoteCache<String, String> rcForceReturn2 = remoteCacheManager.getCache(true);
assertSame("RemoteCache instances should be the same", rcForceReturn, rcForceReturn2);
}

public void testDifferentInstancesForDifferentForceReturnValues() {
RemoteCache<String, String> rcDontForceReturn = remoteCacheManager.getCache(false);
RemoteCache<String, String> 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);
}
}
@@ -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());
}
}
Expand Up @@ -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;
Expand Down Expand Up @@ -67,29 +66,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");
}

private void assertWorks(RemoteCacheManager remoteCacheManager) {
RemoteCache<Object, Object> cache = remoteCacheManager.getCache();
cache.put("aKey", "aValue");
assert cache.get("aKey").equals("aValue");
}

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());
}
}

0 comments on commit 93baa02

Please sign in to comment.