Example usage for io.netty.util CharsetUtil UTF_8

List of usage examples for io.netty.util CharsetUtil UTF_8

Introduction

In this page you can find the example usage for io.netty.util CharsetUtil UTF_8.

Prototype

Charset UTF_8

To view the source code for io.netty.util CharsetUtil UTF_8.

Click Source Link

Document

8-bit UTF (UCS Transformation Format)

Usage

From source file:com.couchbase.client.core.cluster.ObserveTest.java

License:Apache License

/**
 * Test that a previously inserted document is correctly persisted to disk on the master node.
 */// w  w w .j  a v  a2 s. co  m
@Test
public void shouldObservePersistToMaster() {
    InsertRequest request = new InsertRequest("persInsDoc1", Unpooled.copiedBuffer("test", CharsetUtil.UTF_8),
            bucket());
    InsertResponse response = cluster().<InsertResponse>send(request).toBlocking().single();
    assertTrue(response.status().isSuccess());
    ReferenceCountUtil.release(response);

    Boolean observeSuccess = Observe
            .call(cluster(), bucket(), "persInsDoc1", response.cas(), false, Observe.PersistTo.MASTER,
                    Observe.ReplicateTo.NONE, BestEffortRetryStrategy.INSTANCE)
            .timeout(5, TimeUnit.SECONDS).toBlocking().single();

    assertTrue(observeSuccess);
}

From source file:com.couchbase.client.core.cluster.ObserveTest.java

License:Apache License

@Test
public void shouldObservePersistToMasterOnRemoval() {
    InsertRequest request = new InsertRequest("persRemDoc1", Unpooled.copiedBuffer("test", CharsetUtil.UTF_8),
            bucket());// w  w  w.j a  va  2 s.  co  m
    InsertResponse response = cluster().<InsertResponse>send(request).toBlocking().single();
    assertTrue(response.status().isSuccess());
    ReferenceCountUtil.release(response);

    RemoveRequest removeRequest = new RemoveRequest("persRemDoc1", bucket());
    RemoveResponse removeResponse = cluster().<RemoveResponse>send(removeRequest).toBlocking().single();
    assertTrue(removeResponse.status().isSuccess());
    ReferenceCountUtil.release(removeResponse);

    Boolean observeSuccess = Observe
            .call(cluster(), bucket(), "persRemDoc1", removeResponse.cas(), true, Observe.PersistTo.MASTER,
                    Observe.ReplicateTo.NONE, BestEffortRetryStrategy.INSTANCE)
            .timeout(5, TimeUnit.SECONDS).toBlocking().single();

    assertTrue(observeSuccess);
}

From source file:com.couchbase.client.core.cluster.ObserveTest.java

License:Apache License

/**
 * Test that a previously inserted document is replicated to at least one replica.
 *
 * This test assumes a cluster setup where at least one replica is configured on the bucket and more or equal
 * to two nodes are available in order to correctly complete the test.
 *///from   w w w .j  ava 2 s .  c  o  m
@Test
public void shouldObserveReplicateToOne() {
    Assume.assumeTrue(numberOfReplicas >= 1 && numberOfNodes >= 2);

    InsertRequest request = new InsertRequest("persInsDoc2", Unpooled.copiedBuffer("test", CharsetUtil.UTF_8),
            bucket());
    InsertResponse response = cluster().<InsertResponse>send(request).toBlocking().single();
    assertTrue(response.status().isSuccess());
    ReferenceCountUtil.release(response);

    Boolean observeSuccess = Observe
            .call(cluster(), bucket(), "persInsDoc2", response.cas(), false, Observe.PersistTo.NONE,
                    Observe.ReplicateTo.ONE, BestEffortRetryStrategy.INSTANCE)
            .timeout(5, TimeUnit.SECONDS).toBlocking().single();

    assertTrue(observeSuccess);
}

From source file:com.couchbase.client.core.cluster.ObserveTest.java

License:Apache License

/**
 * Test that both persistence and replication are working against a previously inserted doc.
 *
 * This test assumes a cluster setup where at least one replica is configured on the bucket and more or equal
 * to two nodes are available in order to correctly complete the test.
 *//*  ww  w.  j a  v a2 s .  co m*/
@Test
public void shouldObserveReplicateToOneAndPersistToMaster() {
    Assume.assumeTrue(numberOfReplicas >= 1 && numberOfNodes >= 2);

    InsertRequest request = new InsertRequest("persInsDoc3", Unpooled.copiedBuffer("test", CharsetUtil.UTF_8),
            bucket());
    InsertResponse response = cluster().<InsertResponse>send(request).toBlocking().single();
    assertTrue(response.status().isSuccess());
    ReferenceCountUtil.release(response);

    Boolean observeSuccess = Observe
            .call(cluster(), bucket(), "persInsDoc3", response.cas(), false, Observe.PersistTo.MASTER,
                    Observe.ReplicateTo.ONE, BestEffortRetryStrategy.INSTANCE)
            .timeout(5, TimeUnit.SECONDS).toBlocking().single();

    assertTrue(observeSuccess);
}

From source file:com.couchbase.client.core.cluster.ObserveTest.java

License:Apache License

/**
 * Test the persisting requirement on any node (either master or replica), whoever is first.
 *//*from   w w  w .jav  a2  s . c om*/
@Test
public void shouldObservePersistToOne() {
    InsertRequest request = new InsertRequest("persInsDoc4", Unpooled.copiedBuffer("test", CharsetUtil.UTF_8),
            bucket());
    InsertResponse response = cluster().<InsertResponse>send(request).toBlocking().single();
    assertTrue(response.status().isSuccess());
    ReferenceCountUtil.release(response);

    Boolean observeSuccess = Observe
            .call(cluster(), bucket(), "persInsDoc4", response.cas(), false, Observe.PersistTo.ONE,
                    Observe.ReplicateTo.NONE, BestEffortRetryStrategy.INSTANCE)
            .timeout(5, TimeUnit.SECONDS).toBlocking().single();

    assertTrue(observeSuccess);
}

From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java

License:Apache License

@Before
public void prepareData() {
    UpsertRequest upsert = new UpsertRequest(testSubKey, Unpooled.copiedBuffer(jsonContent, CharsetUtil.UTF_8),
            bucket(), true);/*from   ww  w .j av  a2s.co  m*/
    UpsertResponse response = cluster().<UpsertResponse>send(upsert).toBlocking().single();
    ReferenceCountUtil.releaseLater(response.content());
    assertTrue("Couldn't insert " + testSubKey, response.status().isSuccess());

    upsert = new UpsertRequest(testArrayRoot, Unpooled.copiedBuffer(jsonArrayContent, CharsetUtil.UTF_8),
            bucket(), true);
    response = cluster().<UpsertResponse>send(upsert).toBlocking().single();
    ReferenceCountUtil.releaseLater(response.content());
    assertTrue("Couldn't insert " + testArrayRoot, response.status().isSuccess());

    upsert = new UpsertRequest(testComplexSubArray,
            Unpooled.copiedBuffer(jsonComplexSubArrayContent, CharsetUtil.UTF_8), bucket(), true);
    response = cluster().<UpsertResponse>send(upsert).toBlocking().single();
    ReferenceCountUtil.releaseLater(response.content());
    assertTrue("Couldn't insert " + testComplexSubArray, response.status().isSuccess());
}

From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java

License:Apache License

@Test
public void shouldThrowNullPointerIfPathIsNull() {
    boolean npeOnGet = false;
    boolean npeOnMutation = false;
    try {// w  ww  .jav a 2 s .  c  om
        new SubGetRequest(testSubKey, null, bucket());
    } catch (NullPointerException e) {
        npeOnGet = true;
    }

    try {
        new SubReplaceRequest(testSubKey, null, Unpooled.copiedBuffer("test", CharsetUtil.UTF_8), bucket());
    } catch (NullPointerException e) {
        npeOnMutation = true;
    }

    assertTrue("Expected null path get to fail with NPE", npeOnGet);
    assertTrue("Expected null path mutation to fail with NPE", npeOnMutation);
}

From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java

License:Apache License

@Test
public void shouldSubGetValueInExistingDocumentObject() throws Exception {
    String subValuePath = "sub.value";

    SubGetRequest valueRequest = new SubGetRequest(testSubKey, subValuePath, bucket());
    SimpleSubdocResponse valueResponse = cluster().<SimpleSubdocResponse>send(valueRequest).toBlocking()
            .single();// w w w .j a va2  s .c  om
    String raw = valueResponse.content().toString(CharsetUtil.UTF_8);
    ReferenceCountUtil.releaseLater(valueResponse.content());
    assertNotNull(raw);
    assertEquals("\"subStringValue\"", raw);
}

From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java

License:Apache License

@Test
public void shouldSubGetValueInExistingDocumentArray() throws Exception {
    String subArrayPath = "sub.array[1]";

    SubGetRequest arrayRequest = new SubGetRequest(testSubKey, subArrayPath, bucket());
    SimpleSubdocResponse arrayResponse = cluster().<SimpleSubdocResponse>send(arrayRequest).toBlocking()
            .single();/* w  w w .  j  a  v a2 s .com*/
    String raw = arrayResponse.content().toString(CharsetUtil.UTF_8);
    ReferenceCountUtil.releaseLater(arrayResponse.content());
    assertNotNull(raw);
    assertEquals("2", raw);
}

From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java

License:Apache License

@Test
public void shouldDictUpsertInExistingDocumentObject() {
    String subPath = "sub.value";
    ByteBuf fragment = Unpooled.copiedBuffer("\"mutated\"", CharsetUtil.UTF_8);
    ReferenceCountUtil.releaseLater(fragment);

    //verify initial state
    assertMutation(testSubKey, jsonContent);

    //mutate/* ww w.j  av a 2 s.  c  om*/
    SubDictUpsertRequest upsertRequest = new SubDictUpsertRequest(testSubKey, subPath, fragment, bucket());
    SimpleSubdocResponse upsertResponse = cluster().<SimpleSubdocResponse>send(upsertRequest).toBlocking()
            .single();
    ReferenceCountUtil.releaseLater(upsertResponse.content());
    assertTrue(upsertResponse.status().isSuccess());

    //verify mutated state
    assertMutation(testSubKey, jsonContent.replace("subStringValue", "mutated"));
}