[jboss-cvs] JBossAS SVN: r108985 - in branches/JBPAPP_5_1_datagrid: testsuite and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Oct 29 06:50:34 EDT 2010


Author: mlinhard
Date: 2010-10-29 06:50:33 -0400 (Fri, 29 Oct 2010)
New Revision: 108985

Added:
   branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/MemcachedClientTestCase.java
   branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/MemcachedSession.java
   branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/SpyMemcachedClientTestCase.java
Modified:
   branches/JBPAPP_5_1_datagrid/component-matrix/pom.xml
   branches/JBPAPP_5_1_datagrid/testsuite/.classpath
   branches/JBPAPP_5_1_datagrid/testsuite/build.xml
   branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientTestCase.java
   branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/RESTClientTestCase.java
   branches/JBPAPP_5_1_datagrid/thirdparty/
   branches/JBPAPP_5_1_datagrid/thirdparty/pom.xml
Log:
Added spy memcached dependency, added memcached server module tests, fixed import in hotrodclienttestcase, added new dependencies into eclipse .classpath

Modified: branches/JBPAPP_5_1_datagrid/component-matrix/pom.xml
===================================================================
--- branches/JBPAPP_5_1_datagrid/component-matrix/pom.xml	2010-10-29 10:39:36 UTC (rev 108984)
+++ branches/JBPAPP_5_1_datagrid/component-matrix/pom.xml	2010-10-29 10:50:33 UTC (rev 108985)
@@ -2296,6 +2296,12 @@
         <artifactId>cobertura</artifactId>
         <version>1.9.3</version>
       </dependency>
+      
+      <dependency>
+         <groupId>spy</groupId>
+         <artifactId>memcached</artifactId>
+         <version>2.5</version>
+      </dependency>
 
     </dependencies>
 

Modified: branches/JBPAPP_5_1_datagrid/testsuite/.classpath
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/.classpath	2010-10-29 10:39:36 UTC (rev 108984)
+++ branches/JBPAPP_5_1_datagrid/testsuite/.classpath	2010-10-29 10:50:33 UTC (rev 108985)
@@ -61,5 +61,8 @@
 	<classpathentry kind="lib" path="/thirdparty/jboss/jboss-ejb3-proxy-spi/lib/jboss-ejb3-proxy-spi.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/jboss/jbossts/lib/jbossjts-integration.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/hibernate/lib/hibernate-jbosscache2.jar" sourcepath="/thirdparty/hibernate/lib/hibernate-jbosscache2-sources.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/spy/lib/memcached.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/org/infinispan/client/hotrod/lib/infinispan-client-hotrod.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/org/infinispan/lib/infinispan-core.jar"/>
 	<classpathentry kind="output" path="output/eclipse-classes"/>
 </classpath>

Modified: branches/JBPAPP_5_1_datagrid/testsuite/build.xml
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/build.xml	2010-10-29 10:39:36 UTC (rev 108984)
+++ branches/JBPAPP_5_1_datagrid/testsuite/build.xml	2010-10-29 10:50:33 UTC (rev 108985)
@@ -218,6 +218,8 @@
       <path refid="org.infinispan.classpath"/>
       <path refid="org.infinispan.client.hotrod.classpath"/>
       <path refid="commons.pool.classpath"/>
+      <!-- spymemcached for Memcached server tests -->
+      <path refid="spy.spy.classpath"/>
 
    </path>
 
@@ -455,6 +457,8 @@
       <pathelement path="${jboss.dist.common.lib}/jbossts-common.jar" />
       <pathelement path="${jboss.dist}/docs/examples/transactions/jbossts-tools.sar" />
       <pathelement path="${jboss.dist}/docs/examples/transactions/jbossxts.sar" />
+      <!-- spymemcached for Memcached server tests -->
+      <pathelement path="${spy.spy.lib}/memcached.jar"/>
 	
       <!-- datagrid tests -->
       <path refid="org.infinispan.classpath"/>

Modified: branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientTestCase.java
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientTestCase.java	2010-10-29 10:39:36 UTC (rev 108984)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/HotRodClientTestCase.java	2010-10-29 10:50:33 UTC (rev 108985)
@@ -38,6 +38,7 @@
 
 import org.jboss.test.JBossClusteredTestCase;
 import org.jboss.test.JBossTestSetup;
+import org.jboss.test.JBossTestClusteredSetup;
 
 import junit.framework.Test;
 import junit.framework.TestCase;

Added: branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/MemcachedClientTestCase.java
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/MemcachedClientTestCase.java	                        (rev 0)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/MemcachedClientTestCase.java	2010-10-29 10:50:33 UTC (rev 108985)
@@ -0,0 +1,375 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.cluster.datagrid.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.test.cluster.datagrid.test.RESTClientTestCase.TestSerializable;
+
+/**
+ * Tests for the Memcached client.
+ * 
+ * @author <a href="mailto:mlinhard at redhat.com">Michal Linhard</a>
+ * @version $Revision: $
+ */
+public class MemcachedClientTestCase extends JBossClusteredTestCase {
+	private static final String ENCODING = "UTF-8";
+	// keys used during tests
+	// they are deleted in the setUp and tearDown methods
+	private static final String KEY_A = "a";
+	private static final String KEY_B = "b";
+	private static final String KEY_C = "c";
+	
+	private MemcachedSession mc;
+	
+	public MemcachedClientTestCase(String name) {
+		super(name);
+	}
+	
+	@Override
+	protected void setUp() throws Exception {
+		super.setUp();
+		// to run original memcached server: memcached -p 11212
+//		mc = new MemcachedSession(ENCODING, "localhost", 11212); // to run against original memcached server
+		mc = new MemcachedSession(ENCODING, getServers()[0], 11211); // to run against infinispan memcached server
+		mc.delete(KEY_A);
+		mc.delete(KEY_B);
+		mc.delete(KEY_C);
+		assertNull(mc.get(KEY_A));
+		assertNull(mc.get(KEY_B));
+		assertNull(mc.get(KEY_C));
+	}
+
+	@Override
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		mc.delete(KEY_A);
+		mc.delete(KEY_B);
+		mc.delete(KEY_C);
+		mc.close();
+	}
+
+	public void testSetGet() throws Exception {
+		mc.set(KEY_A, "A");
+		assertEquals("A", mc.get(KEY_A));
+	}
+
+	public void testSetGetNewLineChars() throws Exception {
+		mc.set(KEY_A, "A\r\nA");
+		assertEquals("A\r\nA", mc.get(KEY_A));
+	}
+	
+	public void testSetGetObject() throws Exception {
+		ByteArrayOutputStream bout = new ByteArrayOutputStream();
+		ObjectOutputStream oo = new ObjectOutputStream(bout);
+		oo.writeObject(new TestSerializable("CONTENT"));
+		oo.flush();
+
+		byte[] byteData = bout.toByteArray();
+		mc.writeln("set "+KEY_A+" 0 0 "+byteData.length);
+		mc.flush();
+		mc.write(byteData);
+		mc.write("\r\n".getBytes(ENCODING));
+		mc.flush();
+		assertEquals("STORED", mc.readln());
+		byte[] bytesBack = mc.getBytes(KEY_A);
+		assertEquals(byteData.length, bytesBack.length);
+		ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(
+				bytesBack));
+		TestSerializable ts = (TestSerializable) oin.readObject();
+		assertEquals("CONTENT", ts.getContent());
+	}
+	
+	public void testSetGetFlags() throws Exception {
+		mc.writeln("set "+KEY_A+" 1234 0 1");
+		mc.writeln("A");
+		mc.flush();
+		assertEquals("STORED", mc.readln());
+		mc.writeln("get "+KEY_A);
+		mc.flush();
+		assertEquals("VALUE "+KEY_A+" 1234 1", mc.readln());
+		assertEquals("A", mc.readln());
+		assertEquals("END", mc.readln());
+	}
+	
+	public void testSecondSet() throws Exception {
+		mc.set(KEY_A, "A");
+		assertEquals("A", mc.get(KEY_A));
+		mc.set(KEY_A, "B");
+		assertEquals("B", mc.get(KEY_A));
+	}
+	
+	public void testGetMultipleKeys() throws Exception {
+		mc.set(KEY_A, "A");
+		mc.set(KEY_B, "B");
+		mc.writeln("get "+KEY_A+" "+KEY_B);
+		mc.flush();
+		assertEquals("VALUE "+KEY_A+" 0 1", mc.readln());
+		assertEquals("A", mc.readln());
+		assertEquals("VALUE "+KEY_B+" 0 1", mc.readln());
+		assertEquals("B", mc.readln());
+		assertEquals("END", mc.readln());
+	}
+	
+	public void testAdd() throws Exception {
+		String data = "testAdd";
+		mc.writeln("add "+KEY_A+" 0 0 " + data.getBytes(ENCODING).length);
+		mc.writeln(data);
+		mc.flush();
+		assertEquals("STORED", mc.readln());
+		assertEquals(data, mc.get(KEY_A));
+		// second add
+		mc.writeln("add "+KEY_A+" 0 0 " + data.getBytes(ENCODING).length);
+		mc.writeln(data);
+		mc.flush();
+		assertEquals("NOT_STORED", mc.readln());
+	}
+	
+	public void testReplace() throws Exception {
+		mc.set(KEY_A, "testAdd");
+		assertEquals("testAdd", mc.get(KEY_A));
+		// replace
+		mc.writeln("replace "+KEY_A+" 0 0 " + "replacement".getBytes(ENCODING).length);
+		mc.writeln("replacement");
+		mc.flush();
+		assertEquals("STORED", mc.readln());
+		assertEquals("replacement", mc.get(KEY_A));
+	}
+	
+	public void testReplaceNonExistent() throws Exception {
+		mc.writeln("replace "+KEY_A+" 0 0 " + "replacement".getBytes(ENCODING).length);
+		mc.writeln("replacement");
+		mc.flush();
+		assertEquals("NOT_STORED", mc.readln());
+	}
+	
+	public void testAppend() throws Exception {
+		mc.set(KEY_A, "Hello");
+		assertEquals("Hello", mc.get(KEY_A));
+		mc.writeln("append "+KEY_A+" 0 0 " + ", World!".getBytes(ENCODING).length);
+		mc.writeln(", World!");
+		mc.flush();
+		assertEquals("STORED", mc.readln());
+		assertEquals("Hello, World!", mc.get(KEY_A));
+	}
+	
+	public void testAppendNonExistent() throws Exception {
+		mc.writeln("append "+KEY_A+" 0 0 " + ", World!".getBytes(ENCODING).length);
+		mc.writeln(", World!");
+		mc.flush();
+		assertEquals("NOT_STORED", mc.readln());
+	}
+	
+	public void testPrepend() throws Exception {
+		mc.set(KEY_A, "World!");
+		assertEquals("World!", mc.get(KEY_A));
+		mc.writeln("prepend "+KEY_A+" 0 0 " + "Hello, ".getBytes(ENCODING).length);
+		mc.writeln("Hello, ");
+		mc.flush();
+		assertEquals("STORED", mc.readln());
+		assertEquals("Hello, World!", mc.get(KEY_A));
+	}
+	
+	public void testPrependNonExistent() throws Exception {
+		mc.writeln("prepend "+KEY_A+" 0 0 " + "Hello, ".getBytes(ENCODING).length);
+		mc.writeln("Hello, ");
+		mc.flush();
+		assertEquals("NOT_STORED", mc.readln());
+	}
+	
+	public void testCas() throws Exception {
+		mc.set(KEY_A, "A");
+		mc.writeln("gets "+KEY_A);
+		mc.flush();
+		String[] valueline = mc.readln().split(" ");
+		assertEquals("VALUE", valueline[0]);
+		assertEquals(KEY_A, valueline[1]);
+		assertEquals("0", valueline[2]); // flags
+		assertEquals("1", valueline[3]); // number of bytes in str "A"
+		assertEquals("A", mc.readln());
+		String casId = valueline[4];
+		assertEquals("END", mc.readln());
+		mc.writeln("cas "+KEY_A+" 0 0 1 " + casId);
+		mc.writeln("B");
+		mc.flush();
+		assertEquals("STORED", mc.readln());
+		assertEquals("B", mc.get(KEY_A));
+	}
+	
+	public void testCasExists() throws Exception {
+		mc.set(KEY_A, "A");
+		mc.writeln("gets "+KEY_A);
+		mc.flush();
+		String[] valueline = mc.readln().split(" ");
+		assertEquals("VALUE", valueline[0]);
+		assertEquals(KEY_A, valueline[1]);
+		assertEquals("0", valueline[2]); // flags
+		assertEquals("1", valueline[3]); // number of bytes in str "A"
+		assertEquals("A", mc.readln());
+		String casId = valueline[4];
+		assertEquals("END", mc.readln());
+		mc.writeln("cas "+KEY_A+" 0 0 1 1" + casId); // note appended 1 before casId
+		mc.writeln("B");
+		mc.flush();
+		assertEquals("EXISTS", mc.readln());
+		assertEquals("A", mc.get(KEY_A));
+	}
+	
+	public void testNoReply() throws Exception {
+		mc.writeln("set "+KEY_A+" 0 0 1 noreply");
+		mc.writeln("A");
+		mc.flush();
+		mc.writeln("get "+KEY_A);
+		mc.flush();
+		assertEquals("VALUE "+KEY_A+" 0 1", mc.readln());
+		assertEquals("A", mc.readln());
+		assertEquals("END", mc.readln());
+	}
+	
+	public void testExpTime() throws Exception {
+		mc.writeln("set "+KEY_A+" 0 2 1");
+		mc.writeln("A");
+		mc.flush();
+		assertEquals("STORED", mc.readln());
+		assertEquals("A", mc.get(KEY_A));
+		Thread.sleep(2000);
+		assertNull(mc.get(KEY_A));
+	}
+	
+	public void testExpTimeMaxSeconds() throws Exception {
+		// set exp.time to max number treated as seconds
+		// 2592000 = 60*60*24*30
+		mc.writeln("set "+KEY_A+" 0 2592000 1");
+		mc.writeln("A");
+		mc.flush();
+		assertEquals("STORED", mc.readln());
+		assertEquals("A", mc.get(KEY_A));
+		Thread.sleep(2000);
+		assertEquals("A", mc.get(KEY_A));
+	}
+	
+	// FAILS: https://jira.jboss.org/browse/JBPAPP-5331
+	public void testExpTimeAbsolutePast() throws Exception {
+		// set exp.time to min number treated as unix time
+		// 2592001 = 60*60*24*30 + 1
+		// corresponding to Sat, 31 Jan 1970 00:00:01 GMT
+		mc.writeln("set "+KEY_A+" 0 2592001 1");
+		mc.writeln("A");
+		mc.flush();
+		assertEquals("STORED", mc.readln());
+		// should expire immediately
+		assertNull(mc.get(KEY_A));
+	}
+	
+	public void testExpTimeAbsoluteFuture() throws Exception {
+		long now = mc.getServerTime();
+		System.out.println("server time: " + now);
+		mc.writeln("set "+KEY_A+" 0 " + (now + 2) + " 1");
+		mc.writeln("A");
+		mc.flush();
+		assertEquals("STORED", mc.readln());
+		assertEquals("A", mc.get(KEY_A));
+		Thread.sleep(2000);
+		assertNull(mc.get(KEY_A));
+	}
+	
+	// FAILS: https://jira.jboss.org/browse/JBPAPP-5332
+	public void testKeyLonger250() throws Exception {
+		String key250 = "";
+		for (int i = 0; i <  250; i++) {
+			key250 += "a";
+		}
+		String key251 = key250 + "a";
+		// byte length is the same, because we're using "UTF-8 safe" char 'a'
+		assertEquals(key250.length(), key250.getBytes(ENCODING).length);
+		assertEquals(key251.length(), key251.getBytes(ENCODING).length);
+		mc.set(key250, "A");
+		assertEquals("A", mc.get(key250));
+		mc.writeln("set "+key251+" 0 0 1");
+		mc.writeln("A");
+		mc.flush();
+		assertTrue(mc.readln().startsWith("CLIENT_ERROR"));
+	}
+	
+	public void testDelete() throws Exception {
+		mc.set(KEY_A, "A");
+		assertEquals("A", mc.get(KEY_A));
+		assertEquals("DELETED", mc.delete(KEY_A));
+		assertNull(mc.get(KEY_A));
+	}
+
+	public void testDeleteNonExistent() throws Exception {
+		assertEquals("NOT_FOUND", mc.delete(KEY_A));
+	}
+	
+	public void testIncr() throws Exception {
+		mc.set(KEY_A, "0");
+		mc.writeln("incr "+KEY_A+" 1");
+		mc.flush();
+		assertEquals("1", mc.readln());
+	}
+	
+	public void testDecr() throws Exception {
+		mc.set(KEY_A, "1");
+		mc.writeln("decr "+KEY_A+" 1");
+		mc.flush();
+		assertEquals("0", mc.readln());
+	}
+	
+	// FAILS: https://jira.jboss.org/browse/JBPAPP-5307
+	public void testIncr64BitMax() throws Exception {
+		mc.set(KEY_A, "18446744073709551614");
+		mc.writeln("incr "+KEY_A+" 1");
+		mc.flush();
+		assertEquals("18446744073709551615", mc.readln());
+		mc.writeln("incr "+KEY_A+" 1");
+		mc.flush();
+		assertEquals("0", mc.readln());
+	}
+
+	public void testDecrZero() throws Exception {
+		mc.set(KEY_A, "0");
+		mc.writeln("decr "+KEY_A+" 1");
+		mc.flush();
+		assertEquals("0", mc.readln());
+	}
+	
+	// FAILS: https://jira.jboss.org/browse/JBPAPP-5307
+	public void testIncrBigIncrement() throws Exception {
+		mc.set(KEY_A, "0");
+		mc.writeln("incr "+KEY_A+" 18446744073709551615");
+		mc.flush();
+		assertEquals("18446744073709551615", mc.readln());
+	}
+	
+	// FAILS: https://jira.jboss.org/browse/JBPAPP-5307
+	public void testIncrBigDecrement() throws Exception {
+		mc.set(KEY_A, "18446744073709551615");
+		mc.writeln("decr "+KEY_A+" 18446744073709551615");
+		mc.flush();
+		assertEquals("0", mc.readln());
+	}
+}
\ No newline at end of file

Added: branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/MemcachedSession.java
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/MemcachedSession.java	                        (rev 0)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/MemcachedSession.java	2010-10-29 10:50:33 UTC (rev 108985)
@@ -0,0 +1,193 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.cluster.datagrid.test;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.net.Socket;
+import java.util.Arrays;
+
+/**
+ * A Really simple Memcached client/helper.
+ * 
+ * @author <a href="mailto:mlinhard at redhat.com">Michal Linhard</a>
+ * @version $Revision: $
+ */
+public class MemcachedSession {
+	public static final int DEFAULT_MEMCACHED_PORT = 11211;
+	/**
+	 * is there any standard replacement for this ?
+	 * somthing that can read both binary data and also strings when needed.
+	 */
+	public class StringAndBytesReader {
+		private InputStream input;
+		private String encoding;
+		private byte[] TEMP = new byte[1];
+		
+		public StringAndBytesReader(InputStream input, String encoding) {
+			super();
+			this.input = input;
+			this.encoding = encoding;
+		}
+		
+		public byte[] read(int len) throws IOException {
+			byte[] ret = new byte[len];
+			input.read(ret, 0, len);
+			return ret;
+		}
+		
+		public byte read() throws IOException {
+			input.read(TEMP, 0, 1);
+			return TEMP[0];
+		}
+		
+		public String readln() throws IOException {
+			byte[] buf = new byte[512];
+			int maxlen = 512;
+			int read = 0;
+			buf[read] = read();
+			while (buf[read] != '\n') {
+				read++;
+				if (read == maxlen) {
+					maxlen += 512;
+					buf = Arrays.copyOf(buf, maxlen);
+				}
+				buf[read] = read();
+			}
+			if (read == 0) {
+				return "";
+			}
+			if (buf[read-1] == '\r') {
+				read--;
+			}
+			buf = Arrays.copyOf(buf, read);
+			return new String(buf, encoding);
+		}
+	}
+	private String encoding;
+	private Socket socket;
+	private PrintWriter out;
+	private StringAndBytesReader in;
+	
+	public MemcachedSession() throws IOException {
+		this("UTF-8", "localhost", DEFAULT_MEMCACHED_PORT);
+	}
+	
+	public MemcachedSession(String enc, String host, int port) throws IOException {
+		encoding = enc;
+		socket = new Socket(host, port);
+		out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream(), encoding));
+		in = new StringAndBytesReader(socket.getInputStream(), encoding);
+	}
+	
+	public void writeln(String str) {
+		out.print(str + "\r\n");
+	}
+	public void write(byte[] data) throws IOException {
+		socket.getOutputStream().write(data);
+	}
+	
+	public String readln() throws IOException {
+		return in.readln();
+	}
+	
+	public void flush() {
+		out.flush();
+	}
+	
+	public void close() throws IOException {
+		socket.close();
+	}
+	/**
+	 * Returns the value for the key. 
+	 */
+	public String get(String key) throws IOException {
+		byte[] data = getBytes(key);
+		if (data == null) {
+			return null;
+		}
+		return new String(data, encoding);
+	}
+	
+	/**
+	 * Returns the value for the key. 
+	 */
+	public byte[] getBytes(String key) throws IOException {
+		writeln("get " + key);
+		flush();
+		String valueStr = readln();
+		if ("END".equals(valueStr)) {
+			return null;
+		}
+		if (valueStr.startsWith("VALUE")) {
+			String[] value = valueStr.split(" ");
+			MemcachedClientTestCase.assertEquals(key, value[1]);
+			int size = new Integer(value[3]);
+			byte[] ret = in.read(size);
+			MemcachedClientTestCase.assertEquals('\r', in.read());
+			MemcachedClientTestCase.assertEquals('\n', in.read());
+			MemcachedClientTestCase.assertEquals("END", readln());
+			return ret;
+		} else {
+			return null;
+		}
+	}
+	
+	public void set(String key, String value) throws IOException {
+		writeln("set " + key + " 0 0 " + value.getBytes(encoding).length);
+		writeln(value);
+		flush();
+		MemcachedClientTestCase.assertEquals("STORED", readln());
+	}
+	
+	/**
+	 * returns "DELETED" or "NOT_FOUND" depending whether the key
+	 * existed.
+	 */
+	public String delete(String key) throws IOException {
+		writeln("delete " + key);
+		flush();
+		return readln();
+	}
+	
+	/**
+	 * returns server time retrieved via stats command
+	 * -1 if time stat is not returned. 
+	 */
+	public long getServerTime() throws IOException {
+		writeln("stats");
+		flush();
+		String statline = readln();
+		long time = -1;
+		while (statline.startsWith("STAT")) {
+			String[] stat = statline.split(" ");
+			if (stat[1].equals("time")) {
+				time = new Long(stat[2]);
+			}
+			statline = readln();
+		}
+		MemcachedClientTestCase.assertEquals("END", statline);
+		return time;
+	}
+}
\ No newline at end of file

Modified: branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/RESTClientTestCase.java
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/RESTClientTestCase.java	2010-10-29 10:39:36 UTC (rev 108984)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/RESTClientTestCase.java	2010-10-29 10:50:33 UTC (rev 108985)
@@ -60,7 +60,7 @@
 	private String fullPath;
 	private static final String DATE_PATTERN_RFC1123 = "EEE, dd MMM yyyy HH:mm:ss zzz";
 
-	private static class TestSerializable implements Serializable {
+	public static class TestSerializable implements Serializable {
 		private String content;
 
 		public TestSerializable(String content) {

Added: branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/SpyMemcachedClientTestCase.java
===================================================================
--- branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/SpyMemcachedClientTestCase.java	                        (rev 0)
+++ branches/JBPAPP_5_1_datagrid/testsuite/src/main/org/jboss/test/cluster/datagrid/test/SpyMemcachedClientTestCase.java	2010-10-29 10:50:33 UTC (rev 108985)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.cluster.datagrid.test;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.concurrent.Future;
+
+import net.spy.memcached.AddrUtil;
+import net.spy.memcached.MemcachedClient;
+
+import org.jboss.test.JBossClusteredTestCase;
+
+/**
+ * Tests for the Spy Memcached client.
+ * 
+ * @author <a href="mailto:mlinhard at redhat.com">Michal Linhard</a>
+ * @version $Revision: $
+ */
+public class SpyMemcachedClientTestCase extends JBossClusteredTestCase {
+	private static final String KEY_A = "a";
+	private static final String KEY_B = "b";
+	private static final String KEY_C = "c";
+	private MemcachedClient mc;
+	
+	public SpyMemcachedClientTestCase(String name) {
+		super(name);
+	}
+
+	@Override
+	protected void setUp() throws Exception {
+		super.setUp();
+		mc = new MemcachedClient(AddrUtil.getAddresses(getServers()[0]+":11211"));
+		mc.delete(KEY_A).get();
+		mc.delete(KEY_B).get();
+		mc.delete(KEY_C).get();
+		assertNull(mc.get(KEY_A));
+		assertNull(mc.get(KEY_B));
+		assertNull(mc.get(KEY_C));
+	}
+
+	@Override
+	protected void tearDown() throws Exception {
+		super.tearDown();
+		mc.delete(KEY_A).get();
+		mc.delete(KEY_B).get();
+		mc.delete(KEY_C).get();
+		mc.shutdown();
+	}
+	
+	public void testSetBasic() throws Exception {
+		Future<Boolean> f = mc.set(KEY_A, 0, "DATA");
+		assertTrue(f.get());
+		assertEquals("DATA", mc.get(KEY_A));
+	}
+
+	public void testSetWithExpirySeconds() throws Exception {
+		Future<Boolean> f = mc.set(KEY_A, 1, "DATA");
+		assertTrue(f.get());
+		assertEquals("DATA", mc.get(KEY_A));
+		Thread.sleep(1000);
+		assertNull(mc.get(KEY_A));
+	}
+	
+	public void testGetMultipleKeys() throws Exception {
+		Future<Boolean> f1 = mc.set(KEY_A, 0, "DATA1");
+		Future<Boolean> f2 = mc.set(KEY_B, 0, "DATA2");
+		Future<Boolean> f3 = mc.set(KEY_C, 0, "DATA3");
+		assertTrue(f1.get());
+		assertTrue(f2.get());
+		assertTrue(f3.get());
+		Map<String, Object> ret = mc.getBulk(Arrays.asList(KEY_A, KEY_B, KEY_C));
+		assertEquals("DATA1", ret.get(KEY_A));
+		assertEquals("DATA2", ret.get(KEY_B));
+		assertEquals("DATA3", ret.get(KEY_C));
+	}
+	
+	public void testAddBasic() throws Exception {
+		Future<Boolean> f = mc.add(KEY_A, 0, "DATA");
+		assertTrue(f.get());
+		assertEquals("DATA", mc.get(KEY_A));
+	}
+	
+	public void testAddWithExpirySeconds() throws Exception {
+		Future<Boolean> f = mc.add(KEY_A, 1, "DATA");
+		assertTrue(f.get());
+		assertEquals("DATA", mc.get(KEY_A));
+		Thread.sleep(1000);
+		assertNull(mc.get(KEY_A));
+	}
+
+	// TODO: some more spy memcached usecases
+
+}


Property changes on: branches/JBPAPP_5_1_datagrid/thirdparty
___________________________________________________________________
Name: svn:ignore
   - antlr
apache-avalon
apache-avalon-logkit
apache-bcel
apache-beanutils
apache-bsf
apache-codec
apache-collections
apache-digester
apache-discovery
apache-fileupload
apache-httpclient
apache-jaxme
apache-lang
apache-log4j
apache-logging
apache-modeler
apache-myfaces
apache-pool
apache-scout
apache-slide
apache-struts
apache-taglibs
apache-tomcat
apache-validator
apache-velocity
apache-vfs
apache-xalan
apache-xerces
apache-xmlsec
asm
beanshell
cglib
codehaus-stax
commons-el
dom4j
easymock
ehcache
gjt-jpl-util
gnu-getopt
hibernate
hibernate-annotations
hibernate-entitymanager
hibernate-validator
hsqldb
ibm-wsdl4j
jacorb
javassist
jaxen
jboss
jbpm
jbpm-bpel
jfreechart
jgroups
joesnmp
juddi
junit
junitejb
licenses
objectweb-joramtests
odmg
opensaml
oswego-concurrent
qdox
quartz
sleepycat
spring
struts-test-case
sun-jaf
sun-javacc
sun-javamail
sun-jaxb
sun-jaxp
sun-jmf
sun-jmx
sun-jsf
sun-jstl
sun-servlet
sun-xacml
target
trove
validation-api
wutka-dtdparser
xdoclet
xmlunit-xmlunit
libraries.ent
sun-opends
testsuite-libraries.ent
woodstox
stax-api
httpunit
nekohtml
sun-jaxws
snmptrapappender
wscommons-policy
hibernate-commons-annotations
hibernate-validator
apache-maven-ant-tasks
osgi
sun-fi
xalan
struts
javax
bsh
rhino
xerces
aopalliance
log4j
ant
org
commons-validator
oro
commons-io
jtidy
net
xml-apis
commons-logging
classworlds
urbanophile
tjws
com
xml-security
stax
webbeans-deployer
dependency-maven-plugin-markers
hibernate-validator-legacy
weld-deployer

   + antlr
apache-avalon
apache-avalon-logkit
apache-bcel
apache-beanutils
apache-bsf
apache-codec
apache-collections
apache-digester
apache-discovery
apache-fileupload
apache-httpclient
apache-jaxme
apache-lang
apache-log4j
apache-logging
apache-modeler
apache-myfaces
apache-pool
apache-scout
apache-slide
apache-struts
apache-taglibs
apache-tomcat
apache-validator
apache-velocity
apache-vfs
apache-xalan
apache-xerces
apache-xmlsec
asm
beanshell
cglib
codehaus-stax
commons-el
dom4j
easymock
ehcache
gjt-jpl-util
gnu-getopt
hibernate
hibernate-annotations
hibernate-entitymanager
hibernate-validator
hsqldb
ibm-wsdl4j
jacorb
javassist
jaxen
jboss
jbpm
jbpm-bpel
jfreechart
jgroups
joesnmp
juddi
junit
junitejb
licenses
objectweb-joramtests
odmg
opensaml
oswego-concurrent
qdox
quartz
sleepycat
spring
struts-test-case
sun-jaf
sun-javacc
sun-javamail
sun-jaxb
sun-jaxp
sun-jmf
sun-jmx
sun-jsf
sun-jstl
sun-servlet
sun-xacml
target
trove
validation-api
wutka-dtdparser
xdoclet
xmlunit-xmlunit
libraries.ent
sun-opends
testsuite-libraries.ent
woodstox
stax-api
httpunit
nekohtml
sun-jaxws
snmptrapappender
wscommons-policy
hibernate-commons-annotations
hibernate-validator
apache-maven-ant-tasks
osgi
sun-fi
xalan
struts
javax
bsh
rhino
xerces
aopalliance
log4j
ant
org
commons-validator
oro
commons-io
jtidy
net
xml-apis
commons-logging
classworlds
urbanophile
tjws
com
xml-security
stax
webbeans-deployer
dependency-maven-plugin-markers
hibernate-validator-legacy
weld-deployer
commons-pool
spy


Modified: branches/JBPAPP_5_1_datagrid/thirdparty/pom.xml
===================================================================
--- branches/JBPAPP_5_1_datagrid/thirdparty/pom.xml	2010-10-29 10:39:36 UTC (rev 108984)
+++ branches/JBPAPP_5_1_datagrid/thirdparty/pom.xml	2010-10-29 10:50:33 UTC (rev 108985)
@@ -2181,6 +2181,11 @@
       <artifactId>cobertura</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>spy</groupId>
+      <artifactId>memcached</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   
   <profiles>



More information about the jboss-cvs-commits mailing list