com.couchbase.client.core.message.ResponseStatus Java Examples
The following examples show how to use
com.couchbase.client.core.message.ResponseStatus.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfigHandlerTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldDecodeSuccessBucketConfigResponse() throws Exception { HttpResponse responseHeader = new DefaultHttpResponse(HttpVersion.HTTP_1_1, new HttpResponseStatus(200, "OK")); HttpContent responseChunk1 = new DefaultHttpContent(Unpooled.copiedBuffer("foo", CHARSET)); HttpContent responseChunk2 = new DefaultLastHttpContent(Unpooled.copiedBuffer("bar", CHARSET)); BucketConfigRequest requestMock = mock(BucketConfigRequest.class); requestQueue.add(requestMock); channel.writeInbound(responseHeader, responseChunk1, responseChunk2); channel.readInbound(); assertEquals(1, eventSink.responseEvents().size()); BucketConfigResponse event = (BucketConfigResponse) eventSink.responseEvents().get(0).getMessage(); assertEquals(ResponseStatus.SUCCESS, event.status()); assertEquals("foobar", event.config()); assertTrue(requestQueue.isEmpty()); }
Example #2
Source File: ConfigHandlerTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldDecodeInitialBucketStreamingResponse() throws Exception { HttpResponse responseHeader = new DefaultHttpResponse(HttpVersion.HTTP_1_1, new HttpResponseStatus(200, "OK")); BucketStreamingRequest requestMock = mock(BucketStreamingRequest.class); requestQueue.add(requestMock); channel.writeInbound(responseHeader); assertEquals(1, eventSink.responseEvents().size()); BucketStreamingResponse event = (BucketStreamingResponse) eventSink.responseEvents().get(0).getMessage(); assertEquals(ResponseStatus.SUCCESS, event.status()); assertNotNull(event.configs()); assertNotNull(event.host()); assertEquals(0, requestQueue.size()); ReferenceCountUtil.releaseLater(event); ReferenceCountUtil.releaseLater(responseHeader); }
Example #3
Source File: YasjlQueryResponseParser.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
/** * Initialize this parser for a response parsing cycle. * * * @param responseContent the raw content to parse from. * @param responseStatus the status of the response. * @param request the original request. */ public void initialize(final ByteBuf responseContent, final ResponseStatus responseStatus, final CouchbaseRequest request) { this.requestID = ""; this.clientContextID = ""; //initialize to empty string instead of null as it is optional on the wire this.sentResponse = false; this.response = null; this.status = responseStatus; this.responseContent = responseContent; this.currentRequest = request; queryRowObservable = UnicastAutoReleaseSubject.create(ttl, TimeUnit.MILLISECONDS, scheduler); queryErrorObservable = UnicastAutoReleaseSubject.create(ttl, TimeUnit.MILLISECONDS, scheduler); queryStatusObservable = AsyncSubject.create(); queryInfoObservable = UnicastAutoReleaseSubject.create(ttl, TimeUnit.MILLISECONDS, scheduler); querySignatureObservable = UnicastAutoReleaseSubject.create(ttl, TimeUnit.MILLISECONDS, scheduler); queryProfileInfoObservable = UnicastAutoReleaseSubject.create(ttl, TimeUnit.MILLISECONDS, scheduler); parser.initialize(responseContent); initialized = true; }
Example #4
Source File: SubdocumentDocumentFlagsTests.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldAccessDeletedDocumentIfSet() { assumeTrue(!useMock()); String subPath = "_hello"; ByteBuf fragment = Unpooled.copiedBuffer("\"world\"", CharsetUtil.UTF_8); ReferenceCountUtil.releaseLater(fragment); SubDictAddRequest insertRequest = new SubDictAddRequest("shouldAccessDeletedDocumentIfSet", subPath, fragment, bucket()); insertRequest.upsertDocument(true); insertRequest.xattr(true); insertRequest.createIntermediaryPath(true); SimpleSubdocResponse insertResponse = cluster().<SimpleSubdocResponse>send(insertRequest).toBlocking().single(); ReferenceCountUtil.releaseLater(insertResponse.content()); assertTrue(insertResponse.status().isSuccess()); RemoveResponse response = cluster().<RemoveResponse>send(new RemoveRequest("shouldAccessDeletedDocumentIfSet", bucket())).toBlocking().single(); assertEquals(response.status(), ResponseStatus.SUCCESS); SubGetRequest getRequest = new SubGetRequest("shouldAccessDeletedDocumentIfSet", subPath, bucket()); getRequest.xattr(true); getRequest.accessDeleted(true); SimpleSubdocResponse getResponse = cluster().<SimpleSubdocResponse>send(getRequest).toBlocking().single(); assertEquals(getResponse.status(), ResponseStatus.SUCCESS); }
Example #5
Source File: SubdocumentDocumentFlagsTests.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldFailOnInsertDocumentIfSetOnDocExists() { String subPath = "hello"; ByteBuf fragment = Unpooled.copiedBuffer("\"world\"", CharsetUtil.UTF_8); ReferenceCountUtil.releaseLater(fragment); SubDictAddRequest insertRequest = new SubDictAddRequest("shouldFailOnInsertDocumentIfSetOnDocExists", subPath, fragment, bucket()); insertRequest.insertDocument(true); SimpleSubdocResponse insertResponse = cluster().<SimpleSubdocResponse>send(insertRequest).toBlocking().single(); ReferenceCountUtil.releaseLater(insertResponse.content()); assertTrue(insertResponse.status().isSuccess()); SubDictAddRequest insertRequest2 = new SubDictAddRequest("shouldFailOnInsertDocumentIfSetOnDocExists", subPath, Unpooled.EMPTY_BUFFER, bucket()); insertRequest2.insertDocument(false); SimpleSubdocResponse insertResponse2 = cluster().<SimpleSubdocResponse>send(insertRequest2).toBlocking().single(); ReferenceCountUtil.releaseLater(insertResponse2.content()); assertFalse(insertResponse2.status().isSuccess()); RemoveResponse removeResponse = cluster().<RemoveResponse>send(new RemoveRequest("shouldFailOnInsertDocumentIfSetOnDocExists", bucket())).toBlocking().single(); assertEquals(removeResponse.status(), ResponseStatus.SUCCESS); }
Example #6
Source File: YasjlAnalyticsResponseParser.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
/** * Initialize this parser for a response parsing cycle. * * * @param responseContent the raw content to parse from. * @param responseStatus the status of the response. * @param request the original request. */ public void initialize(final ByteBuf responseContent, final ResponseStatus responseStatus, final CouchbaseRequest request) { this.requestID = ""; this.clientContextID = ""; //initialize to empty string instead of null as it is optional on the wire this.handle = ""; this.sentResponse = false; this.response = null; this.status = responseStatus; this.responseContent = responseContent; this.currentRequest = request; queryRowObservable = UnicastAutoReleaseSubject.create(ttl, TimeUnit.MILLISECONDS, scheduler); queryErrorObservable = UnicastAutoReleaseSubject.create(ttl, TimeUnit.MILLISECONDS, scheduler); queryStatusObservable = AsyncSubject.create(); queryInfoObservable = UnicastAutoReleaseSubject.create(ttl, TimeUnit.MILLISECONDS, scheduler); querySignatureObservable = UnicastAutoReleaseSubject.create(ttl, TimeUnit.MILLISECONDS, scheduler); queryProfileInfoObservable = UnicastAutoReleaseSubject.create(ttl, TimeUnit.MILLISECONDS, scheduler); parser.initialize(responseContent); initialized = true; }
Example #7
Source File: SubdocumentMessageTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldDeleteExistingObjectPath() { String path = "sub.value"; SubDeleteRequest request = new SubDeleteRequest(testSubKey, path, 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\": {\"array\": [\"array1\", 2, true]}}"; assertMutation(testSubKey, expected); }
Example #8
Source File: SubdocumentMessageTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@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); }
Example #9
Source File: CarrierLoaderTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldUsePortsFromConfigIfPresentWithoutAlternateNetwork() { ClusterFacade cluster = mock(ClusterFacade.class); CarrierLoader loader = new CarrierLoader(cluster, environment); ClusterConfig clusterConfig = new DefaultClusterConfig(); String raw = Resources.read("config_with_external.json", DefaultCouchbaseBucketConfigTest.class); CouchbaseBucketConfig config = (CouchbaseBucketConfig) BucketConfigParser.parse(raw, mock(CoreEnvironment.class), "127.0.0.1"); clusterConfig.setBucketConfig("foo", config); when(cluster.send(any(GetClusterConfigRequest.class))).thenReturn(Observable.just( (CouchbaseResponse) new GetClusterConfigResponse(clusterConfig, ResponseStatus.SUCCESS) )); assertEquals(11210, loader.port("172.17.0.2")); }
Example #10
Source File: AbstractLoaderTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldLoadConfigForOneSeedNode() { ClusterFacade cluster = mock(ClusterFacade.class); when(cluster.send(isA(AddNodeRequest.class))).thenReturn( Observable.just((CouchbaseResponse) new AddNodeResponse(ResponseStatus.SUCCESS, host)) ); when(cluster.send(isA(AddServiceRequest.class))).thenReturn( Observable.just((CouchbaseResponse) new AddServiceResponse(ResponseStatus.SUCCESS, host)) ); when(cluster.send(any(GetClusterConfigRequest.class))).thenReturn(Observable.just( (CouchbaseResponse) new GetClusterConfigResponse(new DefaultClusterConfig(), ResponseStatus.SUCCESS) )); InstrumentedLoader loader = new InstrumentedLoader(99, localhostConfig, cluster, environment); Observable<Tuple2<LoaderType, BucketConfig>> configObservable = loader.loadConfig(host, "default", "password"); BucketConfig loadedConfig = configObservable.toBlocking().single().value2(); assertEquals("default", loadedConfig.name()); assertEquals(1, loadedConfig.nodes().size()); }
Example #11
Source File: ConfigHandlerTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldDecodeListDesignDocumentsResponse() throws Exception { HttpResponse responseHeader = new DefaultHttpResponse(HttpVersion.HTTP_1_1, new HttpResponseStatus(200, "OK")); HttpContent responseChunk1 = new DefaultHttpContent(Unpooled.copiedBuffer("foo", CharsetUtil.UTF_8)); HttpContent responseChunk2 = new DefaultLastHttpContent(Unpooled.copiedBuffer("bar", CharsetUtil.UTF_8)); GetDesignDocumentsRequest requestMock = mock(GetDesignDocumentsRequest.class); requestQueue.add(requestMock); channel.writeInbound(responseHeader, responseChunk1, responseChunk2); assertEquals(1, eventSink.responseEvents().size()); GetDesignDocumentsResponse event = (GetDesignDocumentsResponse) eventSink.responseEvents().get(0).getMessage(); assertEquals(ResponseStatus.SUCCESS, event.status()); assertEquals("foobar", event.content()); assertTrue(requestQueue.isEmpty()); }
Example #12
Source File: HttpLoaderTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldUsePortsFromConfigIfPresentWithAlternateNetwork() { ClusterFacade cluster = mock(ClusterFacade.class); HttpLoader loader = new HttpLoader(cluster, environment); ClusterConfig clusterConfig = new DefaultClusterConfig(); String raw = Resources.read("config_with_external.json", DefaultCouchbaseBucketConfigTest.class); CouchbaseBucketConfig config = (CouchbaseBucketConfig) BucketConfigParser.parse(raw, mock(CoreEnvironment.class), "127.0.0.1"); config.useAlternateNetwork("external"); clusterConfig.setBucketConfig("foo", config); when(cluster.send(any(GetClusterConfigRequest.class))).thenReturn(Observable.just( (CouchbaseResponse) new GetClusterConfigResponse(clusterConfig, ResponseStatus.SUCCESS) )); assertEquals(32790, loader.port("172.17.0.2")); }
Example #13
Source File: ResponseHandlerTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldSendProposedConfigToProvider() throws Exception { ClusterFacade clusterMock = mock(ClusterFacade.class); ConfigurationProvider providerMock = mock(ConfigurationProvider.class); ResponseHandler handler = new ResponseHandler(ENVIRONMENT, clusterMock, providerMock); ByteBuf config = Unpooled.copiedBuffer("{\"json\": true}", CharsetUtil.UTF_8); ResponseEvent retryEvent = new ResponseEvent(); retryEvent.setMessage(new InsertResponse(ResponseStatus.RETRY, KeyValueStatus.ERR_TEMP_FAIL.code(), 0, "bucket", config, null, mock(InsertRequest.class))); retryEvent.setObservable(mock(Subject.class)); handler.onEvent(retryEvent, 1, true); ProposedBucketConfigContext ctx = new ProposedBucketConfigContext("bucket", "{\"json\": true}", null); verify(providerMock, times(1)).proposeBucketConfig(ctx); assertEquals(0, config.refCnt()); assertNull(retryEvent.getMessage()); assertNull(retryEvent.getObservable()); }
Example #14
Source File: ConfigHandler.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
/** * Decodes a {@link BucketStreamingResponse}. * * @param ctx the handler context. * @param header the received header. * @return a initialized {@link CouchbaseResponse}. */ private CouchbaseResponse handleBucketStreamingResponse(final ChannelHandlerContext ctx, final HttpResponse header) { SocketAddress addr = ctx.channel().remoteAddress(); String host = addr instanceof InetSocketAddress ? ((InetSocketAddress) addr).getAddress().getHostAddress() : addr.toString(); ResponseStatus status = ResponseStatusConverter.fromHttp(header.getStatus().code()); Observable<String> scheduledObservable = null; if (status.isSuccess()) { streamingConfigObservable = BehaviorSubject.create(); scheduledObservable = streamingConfigObservable.onBackpressureBuffer().observeOn(env().scheduler()); } return new BucketStreamingResponse( scheduledObservable, host, status, currentRequest() ); }
Example #15
Source File: ViewHandler.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
/** * Creates a {@link ViewQueryResponse} from its request based on the returned info. * * Note that observables are attached to this response which are completed later in the response cycle. * * @return the initial response. */ private CouchbaseResponse handleViewQueryResponse() { int code = responseHeader.getStatus().code(); String phrase = responseHeader.getStatus().reasonPhrase(); ResponseStatus status = ResponseStatusConverter.fromHttp(responseHeader.getStatus().code()); Scheduler scheduler = env().scheduler(); long ttl = env().autoreleaseAfter(); viewRowObservable = UnicastAutoReleaseSubject.create(ttl, TimeUnit.MILLISECONDS, scheduler); viewInfoObservable = UnicastAutoReleaseSubject.create(ttl, TimeUnit.MILLISECONDS, scheduler); viewErrorObservable = AsyncSubject.create(); //set up trace ids on all these UnicastAutoReleaseSubjects, so that if they get in a bad state // (multiple subscribers or subscriber coming in too late) we can trace back to here viewRowObservable.withTraceIdentifier("viewRow"); viewInfoObservable.withTraceIdentifier("viewInfo"); return new ViewQueryResponse( viewRowObservable.onBackpressureBuffer().observeOn(scheduler), viewInfoObservable.onBackpressureBuffer().observeOn(scheduler), viewErrorObservable.observeOn(scheduler), code, phrase, status, currentRequest() ); }
Example #16
Source File: ConfigHandlerTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldDecodeNotFoundBucketConfigResponse() throws Exception { HttpResponse responseHeader = new DefaultHttpResponse(HttpVersion.HTTP_1_1, new HttpResponseStatus(404, "Object Not Found")); HttpContent responseChunk = new DefaultLastHttpContent(Unpooled.copiedBuffer("Not found.", CharsetUtil.UTF_8)); BucketConfigRequest requestMock = mock(BucketConfigRequest.class); requestQueue.add(requestMock); channel.writeInbound(responseHeader, responseChunk); assertEquals(1, eventSink.responseEvents().size()); BucketConfigResponse event = (BucketConfigResponse) eventSink.responseEvents().get(0).getMessage(); assertEquals(ResponseStatus.NOT_EXISTS, event.status()); assertEquals("Not found.", event.config()); assertTrue(requestQueue.isEmpty()); }
Example #17
Source File: HttpLoaderTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldUsePortsFromConfigIfPresentWithoutAlternateNetwork() { ClusterFacade cluster = mock(ClusterFacade.class); HttpLoader loader = new HttpLoader(cluster, environment); ClusterConfig clusterConfig = new DefaultClusterConfig(); String raw = Resources.read("config_with_external.json", DefaultCouchbaseBucketConfigTest.class); CouchbaseBucketConfig config = (CouchbaseBucketConfig) BucketConfigParser.parse(raw, mock(CoreEnvironment.class), "127.0.0.1"); clusterConfig.setBucketConfig("foo", config); when(cluster.send(any(GetClusterConfigRequest.class))).thenReturn(Observable.just( (CouchbaseResponse) new GetClusterConfigResponse(clusterConfig, ResponseStatus.SUCCESS) )); assertEquals(8091, loader.port("172.17.0.2")); }
Example #18
Source File: KeyValueMessageTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldTouch() throws Exception { String key = "touch"; UpsertRequest request = new UpsertRequest(key, Unpooled.copiedBuffer("content", CharsetUtil.UTF_8), 3, 0, bucket()); UpsertResponse response = cluster().<UpsertResponse>send(request).toBlocking().single(); assertEquals(ResponseStatus.SUCCESS, response.status()); ReferenceCountUtil.releaseLater(response.content()); Thread.sleep(2000); TouchResponse touchResponse = cluster().<TouchResponse>send(new TouchRequest(key, 3, bucket())).toBlocking().single(); assertEquals(ResponseStatus.SUCCESS, touchResponse.status()); ReferenceCountUtil.releaseLater(touchResponse.content()); Thread.sleep(2000); GetResponse getResponse = cluster().<GetResponse>send(new GetRequest(key, bucket())).toBlocking().single(); assertEquals(ResponseStatus.SUCCESS, getResponse.status()); assertEquals("content", getResponse.content().toString(CharsetUtil.UTF_8)); ReferenceCountUtil.releaseLater(getResponse.content()); }
Example #19
Source File: KeyValueHandlerTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldDecodeObserveResponseDuringRebalance() throws Exception { ByteBuf content = Unpooled.copiedBuffer("{someconfig...}", CharsetUtil.UTF_8); FullBinaryMemcacheResponse response = new DefaultFullBinaryMemcacheResponse(new byte[] {}, Unpooled.EMPTY_BUFFER, content.copy()); response.setStatus(KeyValueStatus.ERR_NOT_MY_VBUCKET.code()); ObserveRequest requestMock = mock(ObserveRequest.class); requestQueue.add(requestMock); channel.writeInbound(response); assertEquals(1, eventSink.responseEvents().size()); ObserveResponse event = (ObserveResponse) eventSink.responseEvents().get(0).getMessage(); assertEquals(ResponseStatus.RETRY, event.status()); assertEquals(ObserveResponse.ObserveStatus.UNKNOWN, event.observeStatus()); }
Example #20
Source File: KeyValueMessageTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldRemoveDocumentWithoutCAS() throws Exception { String key = "remove-key"; String content = "Hello World!"; UpsertRequest upsert = new UpsertRequest(key, Unpooled.copiedBuffer(content, CharsetUtil.UTF_8), bucket()); UpsertResponse upsertResponse = cluster().<UpsertResponse>send(upsert).toBlocking().single(); assertEquals(ResponseStatus.SUCCESS, upsertResponse.status()); ReferenceCountUtil.releaseLater(upsertResponse.content()); assertValidMetadata(upsertResponse.mutationToken()); RemoveRequest remove = new RemoveRequest(key, bucket()); RemoveResponse response = cluster().<RemoveResponse>send(remove).toBlocking().single(); assertEquals(ResponseStatus.SUCCESS, response.status()); assertTrue(response.cas() != upsertResponse.cas()); ReferenceCountUtil.releaseLater(response.content()); assertValidMetadata(response.mutationToken()); assertMetadataSequence(upsertResponse.mutationToken(), response.mutationToken()); GetRequest get = new GetRequest(key, bucket()); GetResponse getResponse = cluster().<GetResponse>send(get).toBlocking().single(); assertEquals(ResponseStatus.NOT_EXISTS, getResponse.status()); ReferenceCountUtil.releaseLater(getResponse.content()); }
Example #21
Source File: KeyValueMessageTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldHandleDoubleInsert() throws Exception { String key = "insert-key"; String content = "Hello World!"; InsertRequest insert = new InsertRequest(key, Unpooled.copiedBuffer(content, CharsetUtil.UTF_8), bucket()); InsertResponse insertResponse = cluster().<InsertResponse>send(insert).toBlocking().single(); assertEquals(ResponseStatus.SUCCESS, insertResponse.status()); ReferenceCountUtil.releaseLater(insertResponse.content()); assertValidMetadata(insertResponse.mutationToken()); insert = new InsertRequest(key, Unpooled.copiedBuffer(content, CharsetUtil.UTF_8), bucket()); insertResponse = cluster().<InsertResponse>send(insert).toBlocking().single(); assertEquals(ResponseStatus.EXISTS, insertResponse.status()); ReferenceCountUtil.releaseLater(insertResponse.content()); assertNull(insertResponse.mutationToken()); }
Example #22
Source File: ConfigHandlerTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldDecodeFlushNotEnabledResponse() throws Exception { String content = "{\"_\":\"Flush is disabled for the bucket\"}"; HttpResponse responseHeader = new DefaultHttpResponse(HttpVersion.HTTP_1_1, new HttpResponseStatus(400, "Bad Request")); HttpContent responseChunk = new DefaultLastHttpContent(Unpooled.copiedBuffer(content, CharsetUtil.UTF_8)); FlushRequest requestMock = mock(FlushRequest.class); requestQueue.add(requestMock); channel.writeInbound(responseHeader, responseChunk); assertEquals(1, eventSink.responseEvents().size()); FlushResponse event = (FlushResponse) eventSink.responseEvents().get(0).getMessage(); assertEquals(ResponseStatus.INVALID_ARGUMENTS, event.status()); assertEquals("{\"_\":\"Flush is disabled for the bucket\"}", event.content()); assertTrue(requestQueue.isEmpty()); }
Example #23
Source File: SubdocumentMessageTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldHaveIndividualResultsOnFullySuccessfulMultiLookup() { String expected = "EXIST(sub): SUCCESS\n" + "GET(sub.array[1]): SUCCESS = 2\n"; SubMultiLookupRequest request = new SubMultiLookupRequest(testSubKey, bucket(), new LookupCommandBuilder(Lookup.EXIST, "sub").build(), new LookupCommandBuilder(Lookup.GET, "sub.array[1]").build()); MultiLookupResponse response = cluster().<MultiLookupResponse>send(request).toBlocking().single(); assertEquals(Unpooled.EMPTY_BUFFER, response.content()); StringBuilder body = new StringBuilder(); for (MultiResult r : response.responses()) { body.append(r.toString()).append('\n'); ReferenceCountUtil.release(r.value()); } assertTrue(response.cas() != 0); assertEquals(ResponseStatus.SUCCESS, response.status()); assertEquals(expected, body.toString()); }
Example #24
Source File: SubdocumentMessageTest.java From couchbase-jvm-core with Apache License 2.0 | 6 votes |
@Test public void shouldAddUniqueIfValueNotAlreadyInArray() { SubArrayRequest.ArrayOperation arrayOp = SubArrayRequest.ArrayOperation.ADD_UNIQUE; String path = "sub.array"; 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()); String expected = useMock() ? jsonContent.replace("[", "[99, ") : jsonContent.replace("]", ", 99]"); assertMutation(testSubKey, expected); }
Example #25
Source File: SubdocumentMessageTest.java From couchbase-jvm-core with Apache License 2.0 | 5 votes |
@Test public void shouldReturnDeltaRangeOnCounterDeltaOverflow() { String path = "counter"; long prepareOverFlow = 1L; long delta = Long.MAX_VALUE; //first request will bring the value to +1 SubCounterRequest request = new SubCounterRequest(testSubKey, path, prepareOverFlow, bucket()); SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single(); ReferenceCountUtil.releaseLater(response.content()); String result = response.content().toString(CharsetUtil.UTF_8); assertEquals("1", result); //second request will overflow request = new SubCounterRequest(testSubKey, path, delta, bucket()); response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single(); ReferenceCountUtil.releaseLater(response.content()); result = response.content().toString(CharsetUtil.UTF_8); assertEquals(result, 0, result.length()); /* * Was SUBDOC_DELTA_RANGE, but changed to VALUE_CANTINSERT between 4.5 dp and BETA. * See https://issues.couchbase.com/browse/JCBC-931, https://issues.couchbase.com/browse/MB-18169 */ assertEquals(ResponseStatus.SUBDOC_VALUE_CANTINSERT, response.status()); }
Example #26
Source File: AbstractKeyValueResponse.java From couchbase-jvm-core with Apache License 2.0 | 5 votes |
protected AbstractKeyValueResponse(ResponseStatus status, short serverStatusCode, String bucket, ByteBuf content, CouchbaseRequest request) { super(status, request); this.content = content == null ? Unpooled.EMPTY_BUFFER : content; this.bucket = bucket; this.serverStatusCode = serverStatusCode; }
Example #27
Source File: SubdocumentMessageTest.java From couchbase-jvm-core with Apache License 2.0 | 5 votes |
@Test public void shouldReturnPathInvalidOnArrayInsertAtNegativeIndex() { 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.SUBDOC_PATH_INVALID, response.status()); }
Example #28
Source File: SubdocumentMessageTest.java From couchbase-jvm-core with Apache License 2.0 | 5 votes |
@Test public void shouldReturnPathExistOnDictAddOnSubValue() { String subPath = "sub.value"; ByteBuf fragment = Unpooled.copiedBuffer("\"mutated\"", CharsetUtil.UTF_8); ReferenceCountUtil.releaseLater(fragment); //mutate 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()); }
Example #29
Source File: SubdocumentMessageTest.java From couchbase-jvm-core with Apache License 2.0 | 5 votes |
@Test public void shouldDecrementOnCounterWithNegativeDelta() { String path = "sub.array[1]"; long delta = -100L; long expected = -98L; SubCounterRequest request = new SubCounterRequest(testSubKey, path, delta, bucket()); SimpleSubdocResponse response = cluster().<SimpleSubdocResponse>send(request).toBlocking().single(); ReferenceCountUtil.releaseLater(response.content()); String result = response.content().toString(CharsetUtil.UTF_8); assertEquals(ResponseStatus.SUCCESS, response.status()); assertEquals(""+expected, result); assertEquals(expected, Long.parseLong(result)); }
Example #30
Source File: SubdocumentMessageTest.java From couchbase-jvm-core with Apache License 2.0 | 5 votes |
@Test public void shouldReturnPathExistOnArrayAddUniqueWithDuplicateValue() { SubArrayRequest.ArrayOperation arrayOp = SubArrayRequest.ArrayOperation.ADD_UNIQUE; String path = "sub.array"; ByteBuf fragment = Unpooled.copiedBuffer("2", 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_EXISTS, response.status()); }