Example usage for io.netty.buffer Unpooled copiedBuffer

List of usage examples for io.netty.buffer Unpooled copiedBuffer

Introduction

In this page you can find the example usage for io.netty.buffer Unpooled copiedBuffer.

Prototype

private static ByteBuf copiedBuffer(CharBuffer buffer, Charset charset) 

Source Link

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.
 *///  ww  w  .j a v  a2s.c  o 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  v a 2s .  c o  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.
 */// www. java2s .  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.
 *//*from w  w  w  .j  a va  2  s.c  o 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 ww.  j  a v  a  2  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 .java 2 s.  c  om*/
    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 {//from  w w  w  . j ava 2 s .co  m
        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 shouldDictUpsertInExistingDocumentObject() {
    String subPath = "sub.value";
    ByteBuf fragment = Unpooled.copiedBuffer("\"mutated\"", CharsetUtil.UTF_8);
    ReferenceCountUtil.releaseLater(fragment);

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

    //mutate//  w ww.  ja v a 2s. 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"));
}

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

License:Apache License

@Test
public void shouldReturnPathInvalidOnDictUpsertInArray() {
    String subPath = "sub.array[1]";
    ByteBuf fragment = Unpooled.copiedBuffer("\"mutated\"", CharsetUtil.UTF_8);
    ReferenceCountUtil.releaseLater(fragment);

    //mutate//from   w ww.j  a  va  2  s  .  c o  m
    SubDictUpsertRequest upsertRequest = new SubDictUpsertRequest(testSubKey, subPath, fragment, bucket());
    SimpleSubdocResponse upsertResponse = cluster().<SimpleSubdocResponse>send(upsertRequest).toBlocking()
            .single();
    ReferenceCountUtil.releaseLater(upsertResponse.content());
    assertFalse(upsertResponse.status().isSuccess());
    assertEquals(0, upsertResponse.content().readableBytes());
    assertEquals(ResponseStatus.SUBDOC_PATH_INVALID, upsertResponse.status());
}

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

License:Apache License

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

    SubDictUpsertRequest upsertRequest = new SubDictUpsertRequest(testSubKey, subPath, fragment, bucket());
    SimpleSubdocResponse upsertResponse = cluster().<SimpleSubdocResponse>send(upsertRequest).toBlocking()
            .single();/*from   www .j  a  v  a  2s . c  o m*/
    ReferenceCountUtil.releaseLater(upsertResponse.content());
    assertValidMetadata(upsertResponse.mutationToken());
}