improve memcached test

This commit is contained in:
kimchy 2010-07-20 20:53:00 +03:00
parent b3b5c9b0cc
commit 2eeb4ebd8c
1 changed files with 16 additions and 4 deletions

View File

@ -21,6 +21,7 @@ package org.elasticsearch.memcached.test;
import net.spy.memcached.MemcachedClient; import net.spy.memcached.MemcachedClient;
import org.elasticsearch.node.Node; import org.elasticsearch.node.Node;
import org.hamcrest.Matchers;
import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -31,6 +32,8 @@ import java.util.concurrent.TimeUnit;
import static org.elasticsearch.common.xcontent.XContentFactory.*; import static org.elasticsearch.common.xcontent.XContentFactory.*;
import static org.elasticsearch.node.NodeBuilder.*; import static org.elasticsearch.node.NodeBuilder.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.*;
/** /**
* @author kimchy (shay.banon) * @author kimchy (shay.banon)
@ -56,20 +59,29 @@ public abstract class AbstractMemcachedActionsTests {
} }
@Test public void testSimpleOperations() throws Exception { @Test public void testSimpleOperations() throws Exception {
Future setResult = memcachedClient.set("/test/person/1", 0, jsonBuilder().startObject().field("test", "value").endObject().copiedBytes()); Future<Boolean> setResult = memcachedClient.set("/test/person/1", 0, jsonBuilder().startObject().field("test", "value").endObject().copiedBytes());
setResult.get(10, TimeUnit.SECONDS); assertThat(setResult.get(10, TimeUnit.SECONDS), equalTo(true));
String getResult = (String) memcachedClient.get("/_refresh"); String getResult = (String) memcachedClient.get("/_refresh");
System.out.println("REFRESH " + getResult); System.out.println("REFRESH " + getResult);
assertThat(getResult, Matchers.containsString("\"total\":10"));
assertThat(getResult, Matchers.containsString("\"successful\":5"));
assertThat(getResult, Matchers.containsString("\"failed\":0"));
getResult = (String) memcachedClient.get("/test/person/1"); getResult = (String) memcachedClient.get("/test/person/1");
System.out.println("GET " + getResult); System.out.println("GET " + getResult);
assertThat(getResult, Matchers.containsString("\"_index\":\"test\""));
assertThat(getResult, Matchers.containsString("\"_type\":\"person\""));
assertThat(getResult, Matchers.containsString("\"_id\":\"1\""));
Future deleteResult = memcachedClient.delete("/test/person/1"); Future<Boolean> deleteResult = memcachedClient.delete("/test/person/1");
deleteResult.get(10, TimeUnit.SECONDS); assertThat(deleteResult.get(10, TimeUnit.SECONDS), equalTo(true));
getResult = (String) memcachedClient.get("/_refresh"); getResult = (String) memcachedClient.get("/_refresh");
System.out.println("REFRESH " + getResult); System.out.println("REFRESH " + getResult);
assertThat(getResult, Matchers.containsString("\"total\":10"));
assertThat(getResult, Matchers.containsString("\"successful\":5"));
assertThat(getResult, Matchers.containsString("\"failed\":0"));
getResult = (String) memcachedClient.get("/test/person/1"); getResult = (String) memcachedClient.get("/test/person/1");
System.out.println("GET " + getResult); System.out.println("GET " + getResult);