Example usage for org.apache.commons.httpclient HttpStatus SC_NO_CONTENT

List of usage examples for org.apache.commons.httpclient HttpStatus SC_NO_CONTENT

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpStatus SC_NO_CONTENT.

Prototype

int SC_NO_CONTENT

To view the source code for org.apache.commons.httpclient HttpStatus SC_NO_CONTENT.

Click Source Link

Document

<tt>204 No Content</tt> (HTTP/1.0 - RFC 1945)

Usage

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();/*from  ww  w .  j  ava  2s .  co  m*/
    }

    // 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();/*from   www  .j  a  v a2s  . com*/
    }

    // 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 w w . j a v a2 s .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();/*  www.jav  a 2 s  .  c om*/
    }

    // 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.  ja  v  a  2 s  .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();/*from  w ww.j av  a2 s.  c om*/
    }

    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);//from  w w w . jav  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  v a2  s. c o 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);
}

From source file:terrastore.metrics.PerformanceTest.java

private void warmUp(int warmup, String bucket, String payload) throws RuntimeException {
    System.err.println("Warming up...");
    for (int i = 0; i < warmup; i++) {
        try {//from   www  .j  a v a  2s  . c o  m
            PutMethod putValue = null;
            putValue = makePutMethod(NODE1_PORT, bucket + "/value" + i);
            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);
        }
    }
}

From source file:terrastore.server.impl.JsonHttpServerTest.java

@Test
public void testImportBackup() throws Exception {
    UpdateService updateService = createMock(UpdateService.class);
    QueryService queryService = createMock(QueryService.class);
    BackupService backupService = createMock(BackupService.class);
    StatsService statsService = createMock(StatsService.class);

    backupService.importBackup("bucket", "source", "secret");
    expectLastCall().once();/*w w  w. ja v  a 2 s .co  m*/

    replay(updateService, queryService, backupService, statsService);

    JsonHttpServer server = startServerWith(updateService, queryService, backupService, statsService);

    HttpClient client = new HttpClient();
    PostMethod method = new PostMethod("http://localhost:8080/bucket/import?source=source&secret=secret");
    method.setRequestEntity(new StringRequestEntity("", "application/json", null));
    client.executeMethod(method);

    assertEquals(HttpStatus.SC_NO_CONTENT, method.getStatusCode());

    method.releaseConnection();

    stopServer(server);

    verify(updateService, queryService, backupService, statsService);
}