List of usage examples for org.apache.commons.httpclient.methods PutMethod setRequestEntity
public void setRequestEntity(RequestEntity paramRequestEntity)
From source file:terrastore.integration.IntegrationTest.java
@Test public void testRangeQueryWithNoEndKeyAndNoLimit() throws Exception { String bucket = UUID.randomUUID().toString(); int size = 10; for (int i = 1; i <= size; i++) { TestValue value = new TestValue("value" + i, i); PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value" + (char) ('a' + i)); putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null)); HTTP_CLIENT.executeMethod(putValue); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); putValue.releaseConnection();//from w w w . jav a 2 s . c o m } // Sleep to wait for terracotta broadcasting keys: Thread.sleep(1000); GetMethod doRangeQuery = makeGetMethodWithRange(NODE2_PORT, bucket + "/range", "valuej", 0, "lexical-asc"); HTTP_CLIENT.executeMethod(doRangeQuery); assertEquals(HttpStatus.SC_OK, doRangeQuery.getStatusCode()); Map<String, Object> values = fromJsonToMap(doRangeQuery.getResponseBodyAsString()); System.err.println(doRangeQuery.getResponseBodyAsString()); doRangeQuery.releaseConnection(); assertEquals(2, values.size()); assertEquals("valuej", values.keySet().toArray()[0]); assertEquals("valuek", values.keySet().toArray()[1]); }
From source file:terrastore.integration.IntegrationTest.java
@Test public void testRangeQueryWithPredicate() throws Exception { String bucket = UUID.randomUUID().toString(); int size = 10; for (int i = 1; i <= size; i++) { TestValue value = new TestValue("value" + i, i); PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value" + (char) ('a' + i)); putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null)); HTTP_CLIENT.executeMethod(putValue); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); putValue.releaseConnection();//from w w w . jav a 2 s . c o m } // Sleep to wait for terracotta broadcasting keys: Thread.sleep(1000); GetMethod doRangeQuery = makeGetMethodWithRange(NODE2_PORT, bucket + "/range", "valueb", "valued", "lexical-asc", "jxpath:/stringField[.='value1']"); HTTP_CLIENT.executeMethod(doRangeQuery); assertEquals(HttpStatus.SC_OK, doRangeQuery.getStatusCode()); Map<String, Object> values = fromJsonToMap(doRangeQuery.getResponseBodyAsString()); System.err.println(doRangeQuery.getResponseBodyAsString()); doRangeQuery.releaseConnection(); assertEquals(1, values.size()); assertEquals("valueb", values.keySet().toArray()[0]); }
From source file:terrastore.integration.IntegrationTest.java
@Test public void testPredicateQuery() throws Exception { String bucket = UUID.randomUUID().toString(); int size = 10; for (int i = 1; i <= size; i++) { TestValue value = new TestValue("value" + i, i); PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value" + (char) ('a' + i)); putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null)); HTTP_CLIENT.executeMethod(putValue); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); putValue.releaseConnection();/* w ww . j a v a 2s .c om*/ } // Sleep to wait for terracotta broadcasting keys: Thread.sleep(1000); GetMethod doRangeQuery = makeGetMethodWithPredicate(NODE2_PORT, bucket + "/predicate", "jxpath:/stringField[.='value2']"); HTTP_CLIENT.executeMethod(doRangeQuery); assertEquals(HttpStatus.SC_OK, doRangeQuery.getStatusCode()); Map<String, Object> values = fromJsonToMap(doRangeQuery.getResponseBodyAsString()); System.err.println(doRangeQuery.getResponseBodyAsString()); doRangeQuery.releaseConnection(); assertEquals(1, values.size()); assertEquals("valuec", values.keySet().toArray()[0]); }
From source file:terrastore.integration.IntegrationTest.java
@Test public void testMapReduceQueryWithRange() throws Exception { String bucket = UUID.randomUUID().toString(); int size = 10; for (int i = 1; i <= size; i++) { TestValue value = new TestValue("value" + i, i); PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value" + (char) ('a' + i)); putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null)); HTTP_CLIENT.executeMethod(putValue); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); putValue.releaseConnection();/* w w w . ja va2 s.co m*/ } // Sleep to wait for terracotta broadcasting keys: Thread.sleep(1000); PostMethod doMapReduceQuery = makePostMethodForMapReduce(NODE2_PORT, bucket + "/mapReduce", "{\"range\":{\"startKey\":\"valueb\",\"endKey\":\"valuef\",\"timeToLive\":10000},\"task\":{\"mapper\":\"size\",\"reducer\":\"size\",\"timeout\":10000}}"); HTTP_CLIENT.executeMethod(doMapReduceQuery); assertEquals(HttpStatus.SC_OK, doMapReduceQuery.getStatusCode()); Map<String, Object> values = fromJsonToMap(doMapReduceQuery.getResponseBodyAsString()); System.err.println(doMapReduceQuery.getResponseBodyAsString()); doMapReduceQuery.releaseConnection(); assertEquals(1, values.size()); assertEquals(5, values.get("size")); }
From source file:terrastore.integration.IntegrationTest.java
@Test public void testMapReduceQueryWithEmptyRange() throws Exception { String bucket = UUID.randomUUID().toString(); int size = 10; for (int i = 1; i <= size; i++) { TestValue value = new TestValue("value" + i, i); PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value" + (char) ('a' + i)); putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null)); HTTP_CLIENT.executeMethod(putValue); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); putValue.releaseConnection();//from w ww .j a v a2s .c o m } // Sleep to wait for terracotta broadcasting keys: Thread.sleep(1000); PostMethod doMapReduceQuery = makePostMethodForMapReduce(NODE2_PORT, bucket + "/mapReduce", "{\"range\":{\"startKey\":\"valuez\",\"timeToLive\":10000},\"task\":{\"mapper\":\"size\",\"reducer\":\"size\",\"timeout\":10000}}"); HTTP_CLIENT.executeMethod(doMapReduceQuery); assertEquals(HttpStatus.SC_OK, doMapReduceQuery.getStatusCode()); Map<String, Object> values = fromJsonToMap(doMapReduceQuery.getResponseBodyAsString()); System.err.println(doMapReduceQuery.getResponseBodyAsString()); doMapReduceQuery.releaseConnection(); assertEquals(1, values.size()); assertEquals(0, values.get("size")); }
From source file:terrastore.integration.IntegrationTest.java
@Test public void testMapReduceQueryWithNoRange() throws Exception { String bucket = UUID.randomUUID().toString(); int size = 10; for (int i = 1; i <= size; i++) { TestValue value = new TestValue("value" + i, i); PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value" + (char) ('a' + i)); putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null)); HTTP_CLIENT.executeMethod(putValue); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); putValue.releaseConnection();//from w w w .jav a2 s .c o m } // Sleep to wait for terracotta broadcasting keys: Thread.sleep(1000); PostMethod doMapReduceQuery = makePostMethodForMapReduce(NODE2_PORT, bucket + "/mapReduce", "{\"task\":{\"mapper\":\"size\",\"reducer\":\"size\",\"timeout\":10000}}"); HTTP_CLIENT.executeMethod(doMapReduceQuery); assertEquals(HttpStatus.SC_OK, doMapReduceQuery.getStatusCode()); Map<String, Object> values = fromJsonToMap(doMapReduceQuery.getResponseBodyAsString()); System.err.println(doMapReduceQuery.getResponseBodyAsString()); doMapReduceQuery.releaseConnection(); assertEquals(1, values.size()); assertEquals(10, values.get("size")); }
From source file:terrastore.integration.IntegrationTest.java
@Test public void testUpdateValue() throws Exception { String bucket = UUID.randomUUID().toString(); TestValue value = new TestValue("value", 1); PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value"); putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null)); HTTP_CLIENT.executeMethod(putValue); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); putValue.releaseConnection();/*from w w w.j ava 2s.c o m*/ TestValue params = new TestValue("value2", 2); PostMethod postUpdate = makePostMethodForUpdate(NODE2_PORT, bucket + "/value/update", 1000, "replace"); postUpdate.setRequestEntity(new StringRequestEntity(fromObjectToJson(params), "application/json", null)); HTTP_CLIENT.executeMethod(postUpdate); assertEquals(HttpStatus.SC_OK, postUpdate.getStatusCode()); assertEquals(new TestValue("value2", 2), fromJsonToObject(postUpdate.getResponseBodyAsString())); System.err.println(postUpdate.getResponseBodyAsString()); postUpdate.releaseConnection(); GetMethod getValue = makeGetMethod(NODE2_PORT, bucket + "/value"); HTTP_CLIENT.executeMethod(getValue); assertEquals(HttpStatus.SC_OK, getValue.getStatusCode()); TestValue returned = fromJsonToObject(getValue.getResponseBodyAsString()); assertEquals("value2", returned.getStringField()); assertEquals(2, returned.getNumField()); getValue.releaseConnection(); }
From source file:terrastore.integration.IntegrationTest.java
@Test public void testBackup() throws Exception { String bucket = UUID.randomUUID().toString(); int size = 10; for (int i = 1; i <= size; i++) { TestValue value = new TestValue("value" + i, i); PutMethod putValue = makePutMethod(NODE1_PORT, bucket + "/value" + (char) ('a' + i)); putValue.setRequestEntity(new StringRequestEntity(fromObjectToJson(value), "application/json", null)); HTTP_CLIENT.executeMethod(putValue); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); putValue.releaseConnection();// w w w.j a v a 2 s.c o m } PostMethod postUpdate = makePostMethodForBackupExport(NODE1_PORT, bucket + "/export", "test.bak", "SECRET-KEY"); postUpdate.setRequestEntity(new StringRequestEntity("", "application/json", null)); HTTP_CLIENT.executeMethod(postUpdate); assertEquals(HttpStatus.SC_NO_CONTENT, postUpdate.getStatusCode()); postUpdate.releaseConnection(); postUpdate = makePostMethodForBackupImport(NODE1_PORT, bucket + "/import", "test.bak", "SECRET-KEY"); postUpdate.setRequestEntity(new StringRequestEntity("", "application/json", null)); HTTP_CLIENT.executeMethod(postUpdate); assertEquals(HttpStatus.SC_NO_CONTENT, postUpdate.getStatusCode()); postUpdate.releaseConnection(); GetMethod getAllValues = makeGetMethod(NODE1_PORT, bucket); HTTP_CLIENT.executeMethod(getAllValues); assertEquals(HttpStatus.SC_OK, getAllValues.getStatusCode()); Map<String, Object> allValues = fromJsonToMap(getAllValues.getResponseBodyAsString()); System.err.println(getAllValues.getResponseBodyAsString()); getAllValues.releaseConnection(); assertEquals(size, allValues.size()); for (int i = 1; i <= size; i++) { assertTrue(allValues.containsKey("value" + (char) ('a' + i))); } }
From source file:terrastore.metrics.PerformanceTest.java
@Test public void writeOnly() throws Exception { final String bucket = UUID.randomUUID().toString(); int warmup = 1000; int writes = 1000; final ExecutorService threadPool = Executors.newFixedThreadPool(CONCURRENCY); final CountDownLatch termination = new CountDownLatch(writes); final String payload = getPayload(); warmUp(warmup, bucket, payload);/* w ww . j a v a 2 s .c o m*/ System.err.println("Starting writeOnly performance test."); long start = System.currentTimeMillis(); for (int i = warmup; i < warmup + writes; i++) { final int index = i; threadPool.execute(new Runnable() { public void run() { try { PutMethod putValue = null; putValue = makePutMethod(NODE1_PORT, bucket + "/value" + index); putValue.setRequestEntity(new StringRequestEntity(payload, "application/json", null)); HTTP_CLIENT.executeMethod(putValue); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); putValue.releaseConnection(); termination.countDown(); } catch (Exception ex) { throw new RuntimeException(ex); } } }); } threadPool.shutdown(); termination.await(Integer.MAX_VALUE, TimeUnit.SECONDS); long elapsed = System.currentTimeMillis() - start; System.err.println("Elapsed time in millis: " + elapsed); }
From source file:terrastore.metrics.PerformanceTest.java
@Test public void writeThenRead() throws Exception { final String bucket = UUID.randomUUID().toString(); final String payload = getPayload(); int warmup = 1000; int writes = 1000; warmUp(warmup, bucket, payload);//from w w w. ja va 2 s .co m System.err.println("Starting writeThenRead performance test."); ExecutorService threadPool = Executors.newFixedThreadPool(CONCURRENCY); long start = System.currentTimeMillis(); for (int i = warmup; i < warmup + writes; i++) { final int index = i; threadPool.execute(new Runnable() { public void run() { try { PutMethod putValue = null; putValue = makePutMethod(NODE1_PORT, bucket + "/value" + index); putValue.setRequestEntity(new StringRequestEntity(payload, "application/json", null)); HTTP_CLIENT.executeMethod(putValue); assertEquals(HttpStatus.SC_NO_CONTENT, putValue.getStatusCode()); putValue.releaseConnection(); } catch (Exception ex) { throw new RuntimeException(ex); } } }); } threadPool.shutdown(); threadPool.awaitTermination(Integer.MAX_VALUE, TimeUnit.SECONDS); long elapsed = System.currentTimeMillis() - start; System.err.println("Elapsed write time in millis: " + elapsed); threadPool = Executors.newFixedThreadPool(CONCURRENCY); start = System.currentTimeMillis(); for (int i = warmup; i < warmup + writes; i++) { final int index = i; threadPool.execute(new Runnable() { public void run() { try { GetMethod getValue = null; getValue = makeGetMethod(NODE1_PORT, bucket + "/value" + index); HTTP_CLIENT.executeMethod(getValue); assertEquals(HttpStatus.SC_OK, getValue.getStatusCode()); getValue.releaseConnection(); } catch (Exception ex) { throw new RuntimeException(ex); } } }); } threadPool.shutdown(); threadPool.awaitTermination(Integer.MAX_VALUE, TimeUnit.SECONDS); elapsed = System.currentTimeMillis() - start; System.err.println("Elapsed read time in millis: " + elapsed); }