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.SubdocumentMessageTest.java

License:Apache License

@Test
public void shouldAllowArrayOperationOnDocumentRootIfArray() {
    SubArrayRequest.ArrayOperation arrayOp = SubArrayRequest.ArrayOperation.PUSH_FIRST;

    ByteBuf fragment = Unpooled.copiedBuffer("\"arrayElement\"", CharsetUtil.UTF_8);
    ReferenceCountUtil.releaseLater(fragment);

    SubArrayRequest request = new SubArrayRequest(testArrayRoot, "", arrayOp, fragment, bucket());
    SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();

    assertEquals(ResponseStatus.SUCCESS, response.status());
}

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

License:Apache License

@Test
public void shouldNotAllowArrayOperationOnDocumentRootIfNotArray() {
    SubArrayRequest.ArrayOperation arrayOp = SubArrayRequest.ArrayOperation.PUSH_LAST;

    ByteBuf fragment = Unpooled.copiedBuffer("\"arrayElement\"", CharsetUtil.UTF_8);
    ReferenceCountUtil.releaseLater(fragment);

    SubArrayRequest request = new SubArrayRequest(testSubKey, "", arrayOp, fragment, bucket());
    SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();

    assertEquals(ResponseStatus.SUBDOC_PATH_MISMATCH, response.status());
}

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

License:Apache License

@Test
public void shouldReturnPathMismatchForArrayOperationOnNonArrayFinalElement() {
    SubArrayRequest.ArrayOperation arrayOp = SubArrayRequest.ArrayOperation.PUSH_FIRST;
    String path = "sub";

    ByteBuf fragment = Unpooled.copiedBuffer("\"arrayElement\"", CharsetUtil.UTF_8);
    ReferenceCountUtil.releaseLater(fragment);

    SubArrayRequest request = new SubArrayRequest(testSubKey, path, arrayOp, fragment, bucket());
    SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();

    assertEquals(ResponseStatus.SUBDOC_PATH_MISMATCH, response.status());
}

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

License:Apache License

@Test
public void shouldPushLastInArray() {
    SubArrayRequest.ArrayOperation arrayOp = SubArrayRequest.ArrayOperation.PUSH_LAST;
    String path = "sub.array";

    ByteBuf fragment = Unpooled.copiedBuffer("\"arrayElement\"", CharsetUtil.UTF_8);
    ReferenceCountUtil.releaseLater(fragment);

    SubArrayRequest request = new SubArrayRequest(testSubKey, path, arrayOp, fragment, bucket());
    SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();

    assertEquals(ResponseStatus.SUCCESS, response.status());
    assertMutation(testSubKey, jsonContent.replace("]", ", \"arrayElement\"]"));
}

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

License:Apache License

@Test
public void shouldReturnPathNotFoundOnPushLastOnNonExistingPath() {
    SubArrayRequest.ArrayOperation arrayOp = SubArrayRequest.ArrayOperation.PUSH_LAST;
    String path = "sub.array2";

    ByteBuf fragment = Unpooled.copiedBuffer("\"arrayElement\"", CharsetUtil.UTF_8);
    ReferenceCountUtil.releaseLater(fragment);

    SubArrayRequest request = new SubArrayRequest(testSubKey, path, arrayOp, fragment, bucket());
    SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();

    assertEquals(ResponseStatus.SUBDOC_PATH_NOT_FOUND, response.status());
}

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

License:Apache License

@Test
public void shouldPushFirstInArray() {
    SubArrayRequest.ArrayOperation arrayOp = SubArrayRequest.ArrayOperation.PUSH_FIRST;
    String path = "sub.array";

    ByteBuf fragment = Unpooled.copiedBuffer("\"arrayElement\"", CharsetUtil.UTF_8);
    ReferenceCountUtil.releaseLater(fragment);

    SubArrayRequest request = new SubArrayRequest(testSubKey, path, arrayOp, fragment, bucket());
    SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();

    assertEquals(ResponseStatus.SUCCESS, response.status());
    assertMutation(testSubKey, jsonContent.replace("[", "[\"arrayElement\", "));
}

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

License:Apache License

@Test
public void shouldReturnPathNotFoundOnPushFirstOnNonExistingPath() {
    SubArrayRequest.ArrayOperation arrayOp = SubArrayRequest.ArrayOperation.PUSH_FIRST;
    String path = "sub.array2";

    ByteBuf fragment = Unpooled.copiedBuffer("\"arrayElement\"", CharsetUtil.UTF_8);
    ReferenceCountUtil.releaseLater(fragment);

    SubArrayRequest request = new SubArrayRequest(testSubKey, path, arrayOp, fragment, bucket());
    SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();

    assertEquals(ResponseStatus.SUBDOC_PATH_NOT_FOUND, response.status());
}

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

License:Apache License

@Test
public void shouldShiftArrayByOneOnArrayInsert() {
    SubArrayRequest.ArrayOperation arrayOp = SubArrayRequest.ArrayOperation.INSERT;
    String path = "sub.array[1]";

    ByteBuf fragment = Unpooled.copiedBuffer("99", CharsetUtil.UTF_8);
    ReferenceCountUtil.releaseLater(fragment);

    SubArrayRequest request = new SubArrayRequest(testSubKey, path, arrayOp, fragment, bucket());
    SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();

    assertEquals(ResponseStatus.SUCCESS, response.status());
    assertMutation(testSubKey, jsonContent.replace("2", "99, 2"));
}

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

License:Apache License

@Test
public void shouldPrependIfArrayInsertIndexIsZero() {
    SubArrayRequest.ArrayOperation arrayOp = SubArrayRequest.ArrayOperation.INSERT;
    String path = "sub.array[0]";

    ByteBuf fragment = Unpooled.copiedBuffer("99", CharsetUtil.UTF_8);
    ReferenceCountUtil.releaseLater(fragment);

    SubArrayRequest request = new SubArrayRequest(testSubKey, path, arrayOp, fragment, bucket());
    SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();

    assertEquals(ResponseStatus.SUCCESS, response.status());
    assertMutation(testSubKey, jsonContent.replace("[", "[99, "));
}

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

License:Apache License

@Test
public void shouldAppendIfArrayInsertIndexIsSize() {
    SubArrayRequest.ArrayOperation arrayOp = SubArrayRequest.ArrayOperation.INSERT;
    String path = "sub.array[3]";

    ByteBuf fragment = Unpooled.copiedBuffer("99", CharsetUtil.UTF_8);
    ReferenceCountUtil.releaseLater(fragment);

    SubArrayRequest request = new SubArrayRequest(testSubKey, path, arrayOp, fragment, bucket());
    SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single();

    assertEquals(ResponseStatus.SUCCESS, response.status());
    assertMutation(testSubKey, jsonContent.replace("]", ", 99]"));
}