List of usage examples for io.netty.buffer Unpooled copiedBuffer
private static ByteBuf copiedBuffer(CharBuffer buffer, Charset charset)
From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java
License:Apache License
@Test public void shouldNotGetMutationTokenWithGet() throws Exception { String subPath = "sub.value"; ByteBuf fragment = Unpooled.copiedBuffer("\"mutated\"", CharsetUtil.UTF_8); ReferenceCountUtil.releaseLater(fragment); SubGetRequest getRequest = new SubGetRequest(testSubKey, subPath, bucket()); SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(getRequest).toBlocking().single(); ReferenceCountUtil.releaseLater(response.content()); assertNull(response.mutationToken()); }
From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java
License:Apache License
@Test public void shouldDictAddOnSubObject() { String subPath = "sub.otherValue"; ByteBuf fragment = Unpooled.copiedBuffer("\"inserted\"", CharsetUtil.UTF_8); ReferenceCountUtil.releaseLater(fragment); //mutate/* w ww .j a v a 2s . com*/ SubDictAddRequest insertRequest = new SubDictAddRequest(testSubKey, subPath, fragment, bucket()); SimpleSubdocResponse insertResponse = cluster().<SimpleSubdocResponse>send(insertRequest).toBlocking() .single(); ReferenceCountUtil.releaseLater(insertResponse.content()); assertTrue(insertResponse.status().isSuccess()); assertEquals(0, insertResponse.content().readableBytes()); //check the insertion at the end of "sub" object String expected = "{\"value\":\"stringValue\", \"sub\": {\"value\": \"subStringValue\",\"array\": [\"array1\", 2, true]" + ",\"otherValue\":\"inserted\"}}"; assertMutation(testSubKey, expected); }
From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java
License:Apache License
@Test public void shouldReturnPathExistOnDictAddOnSubValue() { String subPath = "sub.value"; ByteBuf fragment = Unpooled.copiedBuffer("\"mutated\"", CharsetUtil.UTF_8); ReferenceCountUtil.releaseLater(fragment); //mutate/* ww w . ja v a2 s .com*/ SubDictAddRequest insertRequest = new SubDictAddRequest(testSubKey, subPath, fragment, bucket()); SimpleSubdocResponse insertResponse = cluster().<SimpleSubdocResponse>send(insertRequest).toBlocking() .single(); ReferenceCountUtil.releaseLater(insertResponse.content()); assertFalse(insertResponse.status().isSuccess()); assertEquals(0, insertResponse.content().readableBytes()); assertEquals(ResponseStatus.SUBDOC_PATH_EXISTS, insertResponse.status()); }
From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java
License:Apache License
@Test public void shouldReturnPathNotFoundOnDictAddForNewDeepPath() { String subPath = "sub2.value"; ByteBuf fragment = Unpooled.copiedBuffer("\"insertedPath\"", CharsetUtil.UTF_8); ReferenceCountUtil.releaseLater(fragment); //mutate// w w w. j a v a2s . c om SubDictAddRequest insertRequest = new SubDictAddRequest(testSubKey, subPath, fragment, bucket()); assertFalse(insertRequest.createIntermediaryPath()); SimpleSubdocResponse insertResponse = cluster().<SimpleSubdocResponse>send(insertRequest).toBlocking() .single(); ReferenceCountUtil.releaseLater(insertResponse.content()); assertFalse(insertResponse.status().isSuccess()); assertEquals(0, insertResponse.content().readableBytes()); assertEquals(ResponseStatus.SUBDOC_PATH_NOT_FOUND, insertResponse.status()); }
From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java
License:Apache License
@Test public void shouldReturnPathInvalidOnDictAddForArrayPath() { String subPath = "sub.array[1]"; ByteBuf fragment = Unpooled.copiedBuffer("\"insertedPath\"", CharsetUtil.UTF_8); ReferenceCountUtil.releaseLater(fragment); //mutate/* w ww.jav a2 s .c o m*/ SubDictAddRequest insertRequest = new SubDictAddRequest(testSubKey, subPath, fragment, bucket()); assertFalse(insertRequest.createIntermediaryPath()); SimpleSubdocResponse insertResponse = cluster().<SimpleSubdocResponse>send(insertRequest).toBlocking() .single(); ReferenceCountUtil.releaseLater(insertResponse.content()); assertFalse(insertResponse.status().isSuccess()); assertEquals(0, insertResponse.content().readableBytes()); assertEquals(ResponseStatus.SUBDOC_PATH_INVALID, insertResponse.status()); }
From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java
License:Apache License
@Test public void shouldCreateIntermediaryNodesOnDictAddForNewDeepPathIfForced() { String subPath = "sub2.value"; ByteBuf fragment = Unpooled.copiedBuffer("\"insertedPath\"", CharsetUtil.UTF_8); ReferenceCountUtil.releaseLater(fragment); //mutate//from w w w . j ava 2 s .c o m SubDictAddRequest insertRequest = new SubDictAddRequest(testSubKey, subPath, fragment, bucket()); insertRequest.createIntermediaryPath(true); SimpleSubdocResponse insertResponse = cluster().<SimpleSubdocResponse>send(insertRequest).toBlocking() .single(); ReferenceCountUtil.releaseLater(insertResponse.content()); assertTrue(insertResponse.status().isSuccess()); assertEquals(0, insertResponse.content().readableBytes()); }
From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java
License:Apache License
@Test public void shouldNotCreateIntermediaryNodesOnDictAddForNewDeepPathByDefault() { String subPath = "sub2.value"; ByteBuf fragment = Unpooled.copiedBuffer("\"insertedPath\"", CharsetUtil.UTF_8); ReferenceCountUtil.releaseLater(fragment); SubDictAddRequest insertRequest = new SubDictAddRequest(testSubKey, subPath, fragment, bucket()); SimpleSubdocResponse insertResponse = cluster().<SimpleSubdocResponse>send(insertRequest).toBlocking() .single();// w w w. jav a 2s .c o m ReferenceCountUtil.releaseLater(insertResponse.content()); assertFalse(insertResponse.status().isSuccess()); assertEquals(0, insertResponse.content().readableBytes()); assertEquals(ResponseStatus.SUBDOC_PATH_NOT_FOUND, insertResponse.status()); }
From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java
License:Apache License
@Test public void shouldReplaceValueInSubObject() { String path = "sub.value"; ByteBuf fragment = Unpooled.copiedBuffer("\"mutated\"", CharsetUtil.UTF_8); ReferenceCountUtil.releaseLater(fragment); SubReplaceRequest request = new SubReplaceRequest(testSubKey, path, fragment, bucket()); SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single(); ReferenceCountUtil.releaseLater(response.content()); assertTrue(response.status().isSuccess()); assertEquals(0, response.content().readableBytes()); assertEquals(ResponseStatus.SUCCESS, response.status()); //assert the mutation String expected = "{\"value\":\"stringValue\", \"sub\": {\"value\": \"mutated\",\"array\": [\"array1\", 2, true]}}"; assertMutation(testSubKey, expected); }
From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java
License:Apache License
@Test public void shouldReplaceEntryInArray() { String path = "sub.array[0]"; ByteBuf fragment = Unpooled.copiedBuffer("\"mutated\"", CharsetUtil.UTF_8); ReferenceCountUtil.releaseLater(fragment); SubReplaceRequest request = new SubReplaceRequest(testSubKey, path, fragment, bucket()); SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single(); ReferenceCountUtil.releaseLater(response.content()); assertTrue(response.status().isSuccess()); assertEquals(0, response.content().readableBytes()); assertEquals(ResponseStatus.SUCCESS, response.status()); assertMutation(testSubKey,//from w w w. j a v a 2 s. c om "{\"value\":\"stringValue\", \"sub\": {\"value\": \"subStringValue\",\"array\": [\"mutated\", 2, true]}}"); }
From source file:com.couchbase.client.core.cluster.SubdocumentMessageTest.java
License:Apache License
@Test public void shouldReturnPathNotFoundOnReplaceNonExistingPath() { String path = "sub.value2"; ByteBuf fragment = Unpooled.copiedBuffer("\"mutated\"", CharsetUtil.UTF_8); ReferenceCountUtil.releaseLater(fragment); SubReplaceRequest request = new SubReplaceRequest(testSubKey, path, fragment, bucket()); SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single(); ReferenceCountUtil.releaseLater(response.content()); assertFalse(response.status().isSuccess()); assertEquals(0, response.content().readableBytes()); assertEquals(ResponseStatus.SUBDOC_PATH_NOT_FOUND, response.status()); }