[infinispan-commits] Infinispan SVN: r1653 - in trunk/client/hotrod-client/src: main/java/org/infinispan/client/hotrod/impl/transport and 2 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Thu Apr 1 14:38:19 EDT 2010
Author: mircea.markus
Date: 2010-04-01 14:38:18 -0400 (Thu, 01 Apr 2010)
New Revision: 1653
Added:
trunk/client/hotrod-client/src/main/resources/empty-config.properties
trunk/client/hotrod-client/src/main/resources/hotrod-client.properties
trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteCacheManagerTest.java
Removed:
trunk/client/hotrod-client/src/main/resources/hotrod-client.properties
Modified:
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java
trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/AbstractTransportFactory.java
trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValueTest.java
Log:
ongoing work n hotrod client
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java 2010-04-01 17:36:09 UTC (rev 1652)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/RemoteCacheManager.java 2010-04-01 18:38:18 UTC (rev 1653)
@@ -7,10 +7,13 @@
import org.infinispan.client.hotrod.impl.RemoteCacheImpl;
import org.infinispan.client.hotrod.impl.SerializationMarshaller;
import org.infinispan.client.hotrod.impl.TransportFactory;
+import org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory;
import org.infinispan.lifecycle.Lifecycle;
import org.infinispan.manager.CacheContainer;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.util.Util;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
import java.io.IOException;
import java.io.InputStream;
@@ -25,14 +28,18 @@
*/
public class RemoteCacheManager implements CacheContainer, Lifecycle {
+ private static Log log = LogFactory.getLog(RemoteCacheManager.class);
+
private Properties props;
private TransportFactory transportFactory;
private String hotrodMarshaller;
+ private static final String HOTROD_CLIENT_PROPERTIES = "hotrod-client.properties";
+ private boolean started = false;
/**
- * Build a cache manager based on supplied given properties.
- * TODO - add a list of all possible configuration parameters here
+ * Build a cache manager based on supplied given properties. TODO - add a list of all possible configuration
+ * parameters here
*/
public RemoteCacheManager(Properties props, boolean start) {
this.props = props;
@@ -43,19 +50,25 @@
* Same as {@link #RemoteCacheManager(java.util.Properties, boolean)}, and it also starts the cache (start==true).
*/
public RemoteCacheManager(Properties props) {
- this.props = props;
+ this(props, true);
}
/**
* Same as {@link #RemoteCacheManager(java.util.Properties)}, but it will try to lookup the config properties in the
* classpath, in a file named <tt>hotrod-client.properties</tt>.
+ *
* @param start weather or not to start the RemoteCacheManager
* @throws HotRodClientException if such a file cannot be found in the classpath
*/
public RemoteCacheManager(boolean start) {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- InputStream stream = loader.getResourceAsStream("hotrod-client.properties");
- loadFromStream(stream);
+ InputStream stream = loader.getResourceAsStream(HOTROD_CLIENT_PROPERTIES);
+ if (stream == null) {
+ log.warn("Could not find '" + HOTROD_CLIENT_PROPERTIES + "' file in classpath, using defaults.");
+ props = new Properties();
+ } else {
+ loadFromStream(stream);
+ }
if (start) start();
}
@@ -69,7 +82,8 @@
/**
* Same as {@link #RemoteCacheManager(java.util.Properties)}, but it will try to lookup the config properties in
* supplied URL.
- * @param start weather or not to start the RemoteCacheManager
+ *
+ * @param start weather or not to start the RemoteCacheManager
* @throws HotRodClientException if properties could not be loaded
*/
public RemoteCacheManager(URL config, boolean start) {
@@ -84,45 +98,58 @@
/**
* Same as {@link #RemoteCacheManager(java.net.URL)} and it also starts the cache (start==true).
+ *
* @param config
*/
public RemoteCacheManager(URL config) {
this(config, true);
}
-
- private void loadFromStream(InputStream stream) {
- props = new Properties();
- try {
- props.load(stream);
- } catch (IOException e) {
- throw new HotRodClientException("Issues configuring from client hotrod-client.properties",e);
- }
- }
- public <K,V> RemoteCache<K,V> getCache(String cacheName) {
+ public <K, V> RemoteCache<K, V> getCache(String cacheName) {
return createRemoteCache(cacheName);
}
- public <K,V> RemoteCache<K,V> getCache() {
+ public <K, V> RemoteCache<K, V> getCache() {
return createRemoteCache(DefaultCacheManager.DEFAULT_CACHE_NAME);
}
@Override
public void start() {
- String factory = props.getProperty("transport-factory"); //todo switch to Netty transport by default (second param)
- if (factory == null)
- throw new IllegalStateException("Missing required property: transport-factory!");
+ String factory = props.getProperty("transport-factory");
+ if (factory == null) {
+ factory = TcpTransportFactory.class.getName();
+ log.info("'transport-factory' factory not specified, using " + factory);
+ }
transportFactory = (TransportFactory) newInstance(factory);
transportFactory.init(props);
- hotrodMarshaller = props.getProperty("marshaller", SerializationMarshaller.class.getName());
+ hotrodMarshaller = props.getProperty("marshaller");
+ if (hotrodMarshaller == null) {
+ hotrodMarshaller = SerializationMarshaller.class.getName();
+ log.info("'marshaller' not specified, using " + hotrodMarshaller);
+ }
+ started = true;
}
@Override
public void stop() {
transportFactory.destroy();
+ started = false;
}
+ public boolean isStarted() {
+ return started;
+ }
+
+ private void loadFromStream(InputStream stream) {
+ props = new Properties();
+ try {
+ props.load(stream);
+ } catch (IOException e) {
+ throw new HotRodClientException("Issues configuring from client hotrod-client.properties",e);
+ }
+ }
+
private Object newInstance(String clazz) {
try {
return Util.getInstance(clazz);
Modified: trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/AbstractTransportFactory.java
===================================================================
--- trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/AbstractTransportFactory.java 2010-04-01 17:36:09 UTC (rev 1652)
+++ trunk/client/hotrod-client/src/main/java/org/infinispan/client/hotrod/impl/transport/AbstractTransportFactory.java 2010-04-01 18:38:18 UTC (rev 1653)
@@ -1,6 +1,8 @@
package org.infinispan.client.hotrod.impl.transport;
import org.infinispan.client.hotrod.impl.TransportFactory;
+import org.infinispan.util.logging.Log;
+import org.infinispan.util.logging.LogFactory;
import java.util.Properties;
import java.util.StringTokenizer;
@@ -12,11 +14,18 @@
* @since 4.1
*/
public abstract class AbstractTransportFactory implements TransportFactory {
+
+ private static Log log = LogFactory.getLog(AbstractTransportFactory.class);
+
protected String serverHost;
protected int serverPort;
public void init(Properties props) {
String servers = props.getProperty("hotrod-servers");
+ if (servers == null) {
+ servers = "127.0.0.1:11311";
+ log.info("'hotrod-servers' property not found, defaulting to " + servers);
+ }
StringTokenizer tokenizer = new StringTokenizer(servers,";");
String server = tokenizer.nextToken();
String[] serverDef = tokenizeServer(server);
Added: trunk/client/hotrod-client/src/main/resources/empty-config.properties
===================================================================
Deleted: trunk/client/hotrod-client/src/main/resources/hotrod-client.properties
===================================================================
--- trunk/client/hotrod-client/src/main/resources/hotrod-client.properties 2010-04-01 17:36:09 UTC (rev 1652)
+++ trunk/client/hotrod-client/src/main/resources/hotrod-client.properties 2010-04-01 18:38:18 UTC (rev 1653)
@@ -1,2 +0,0 @@
-hotrod-servers=127.0.0.1:11311;127.0.0.2:11411
-transport-factory=org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory
\ No newline at end of file
Added: trunk/client/hotrod-client/src/main/resources/hotrod-client.properties
===================================================================
--- trunk/client/hotrod-client/src/main/resources/hotrod-client.properties (rev 0)
+++ trunk/client/hotrod-client/src/main/resources/hotrod-client.properties 2010-04-01 18:38:18 UTC (rev 1653)
@@ -0,0 +1,2 @@
+hotrod-servers=127.0.0.1:11311
+transport-factory=org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory
\ No newline at end of file
Modified: trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValueTest.java
===================================================================
--- trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValueTest.java 2010-04-01 17:36:09 UTC (rev 1652)
+++ trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/ForceReturnValueTest.java 2010-04-01 18:38:18 UTC (rev 1653)
@@ -37,7 +37,6 @@
@Override
protected CacheManager createCacheManager() throws Exception {
- Configuration standaloneConfig = getDefaultStandaloneConfig(false);
cacheManager = TestCacheManagerFactory.createLocalCacheManager();
cache = cacheManager.getCache();
hotrodServer = HotRodTestingUtil.startHotRodServer(cacheManager);
Added: trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteCacheManagerTest.java
===================================================================
--- trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteCacheManagerTest.java (rev 0)
+++ trunk/client/hotrod-client/src/test/java/org/infinispan/client/hotrod/RemoteCacheManagerTest.java 2010-04-01 18:38:18 UTC (rev 1653)
@@ -0,0 +1,94 @@
+package org.infinispan.client.hotrod;
+
+import org.infinispan.manager.CacheManager;
+import org.infinispan.server.hotrod.HotRodServer;
+import org.infinispan.test.SingleCacheManagerTest;
+import org.infinispan.test.fwk.TestCacheManagerFactory;
+import org.testng.annotations.AfterTest;
+import org.testng.annotations.Test;
+
+import java.net.URL;
+import java.util.Properties;
+
+/**
+ * // TODO: Document this
+ *
+ * @author Mircea.Markus at jboss.com
+ * @since 4.1
+ */
+ at Test(testName = "client.hotrod.RemoteCacheManagerTest", groups = "functional")
+public class RemoteCacheManagerTest extends SingleCacheManagerTest {
+
+ CacheManager cacheManager = null;
+ HotRodServer hotrodServer = null;
+
+
+ @Override
+ protected CacheManager createCacheManager() throws Exception {
+ cacheManager = TestCacheManagerFactory.createLocalCacheManager();
+ hotrodServer = new HotRodServer();
+ hotrodServer.start("127.0.0.1", 11311, cacheManager, 0, 0);
+ return cacheManager;
+ }
+
+ @AfterTest(alwaysRun = true)
+ public void release() {
+ if (hotrodServer != null) hotrodServer.stop();
+ if (cacheManager != null) cacheManager.stop();
+ }
+
+ public void testNoArgConstructor() {
+ RemoteCacheManager remoteCacheManager = new RemoteCacheManager();
+ assert remoteCacheManager.isStarted();
+ assertWorks(remoteCacheManager);
+ remoteCacheManager.stop();
+ }
+
+ public void testBooleanConstructor() {
+ RemoteCacheManager remoteCacheManager = new RemoteCacheManager(false);
+ assert !remoteCacheManager.isStarted();
+ remoteCacheManager.start();
+ assertWorks(remoteCacheManager);
+ remoteCacheManager.stop();
+ }
+
+ public void testUrlConstructor() throws Exception {
+ URL resource = Thread.currentThread().getContextClassLoader().getResource("empty-config.properties");
+ assert resource != null;
+ RemoteCacheManager remoteCacheManager = new RemoteCacheManager(resource);
+ assertWorks(remoteCacheManager);
+ remoteCacheManager.stop();
+ }
+
+ public void testUrlAndBooleanConstructor() throws Exception {
+ URL resource = Thread.currentThread().getContextClassLoader().getResource("empty-config.properties");
+ assert resource != null;
+ RemoteCacheManager remoteCacheManager = new RemoteCacheManager(resource, false);
+ assert !remoteCacheManager.isStarted();
+ remoteCacheManager.start();
+ assertWorks(remoteCacheManager);
+ remoteCacheManager.stop();
+ }
+
+ public void testPropertiesConstructor() {
+ RemoteCacheManager remoteCacheManager = new RemoteCacheManager(new Properties());
+ assert remoteCacheManager.isStarted();
+ assertWorks(remoteCacheManager);
+ remoteCacheManager.stop();
+ }
+
+ public void testPropertiesAndBooleanConstructor() {
+ RemoteCacheManager remoteCacheManager = new RemoteCacheManager(new Properties(), false);
+ assert !remoteCacheManager.isStarted();
+ remoteCacheManager.start();
+ assertWorks(remoteCacheManager);
+ remoteCacheManager.stop();
+ }
+
+ private void assertWorks(RemoteCacheManager remoteCacheManager) {
+ RemoteCache<Object, Object> cache = remoteCacheManager.getCache();
+ assert cache.ping();
+ cache.put("aKey", "aValue");
+ assert cache.get("aKey").equals("aValue");
+ }
+}
More information about the infinispan-commits
mailing list