Java Code Examples for com.couchbase.client.core.message.ResponseStatus#SUCCESS

The following examples show how to use com.couchbase.client.core.message.ResponseStatus#SUCCESS . 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: ObserveTest.java    From couchbase-jvm-core with Apache License 2.0 6 votes vote down vote up
@Test(expected = ReplicaNotConfiguredException.class)
public void shouldFailFastWhenReplicateToGreaterThanBucketReplicas() {
    ClusterFacade cluster = mock(ClusterFacade.class);

    // Setup a mocked config which returns no replica configured
    CouchbaseBucketConfig bucketConfig = mock(CouchbaseBucketConfig.class);
    when(bucketConfig.numberOfReplicas()).thenReturn(0);
    ClusterConfig clusterConfig = mock(ClusterConfig.class);
    when(clusterConfig.bucketConfig("bucket")).thenReturn(bucketConfig);
    GetClusterConfigResponse clusterConfigResponse = new GetClusterConfigResponse(
        clusterConfig, ResponseStatus.SUCCESS
    );
    when(cluster.send(any(GetClusterConfigRequest.class))).thenReturn(
            Observable.just((CouchbaseResponse) clusterConfigResponse)
    );

    Observable<Boolean> result = Observe.call(
            cluster, "bucket", "id", 1234, false, Observe.PersistTo.NONE, Observe.ReplicateTo.ONE,
            BestEffortRetryStrategy.INSTANCE
    );
    result.toBlocking().single();
}
 
Example 2
Source File: ObserveTest.java    From couchbase-jvm-core with Apache License 2.0 6 votes vote down vote up
@Test(expected = ReplicaNotConfiguredException.class)
public void shouldFailFastWhenPersistToGreaterThanBucketReplicas() {
    ClusterFacade cluster = mock(ClusterFacade.class);

    // Setup a mocked config which returns no replica configured
    CouchbaseBucketConfig bucketConfig = mock(CouchbaseBucketConfig.class);
    when(bucketConfig.numberOfReplicas()).thenReturn(2);
    ClusterConfig clusterConfig = mock(ClusterConfig.class);
    when(clusterConfig.bucketConfig("bucket")).thenReturn(bucketConfig);
    GetClusterConfigResponse clusterConfigResponse = new GetClusterConfigResponse(
            clusterConfig, ResponseStatus.SUCCESS
    );
    when(cluster.send(any(GetClusterConfigRequest.class))).thenReturn(
            Observable.just((CouchbaseResponse) clusterConfigResponse)
    );

    Observable<Boolean> result = Observe.call(
            cluster, "bucket", "id", 1234, false, Observe.PersistTo.FOUR, Observe.ReplicateTo.NONE,
            BestEffortRetryStrategy.INSTANCE
    );
    result.toBlocking().single();
}
 
Example 3
Source File: MultiMutationResponse.java    From couchbase-jvm-core with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an successful {@link MultiMutationResponse}.
 *
 * @param bucket the bucket on which the request happened.
 * @param request the original {@link BinarySubdocMultiMutationRequest}.
 * @param cas the CAS value of the document after mutations.
 * @param token the {@link MutationToken} of the document after mutations, if available. Null otherwise.
 * @param responses the list of {@link MultiResult MultiResult&lt;Mutation&gt;} for each command. Some may include a value.
 */
public MultiMutationResponse(String bucket, BinarySubdocMultiMutationRequest request, long cas, MutationToken token,
                             List<MultiResult<Mutation>> responses) {
    super(ResponseStatus.SUCCESS, KeyValueStatus.SUCCESS.code(), bucket, Unpooled.EMPTY_BUFFER, request);
    this.cas = cas;
    this.mutationToken = token;
    this.firstErrorIndex = -1;
    this.firstErrorStatus = ResponseStatus.SUCCESS;
    this.responses = responses;
}
 
Example 4
Source File: ResponseStatusConverter.java    From couchbase-jvm-core with Apache License 2.0 5 votes vote down vote up
/**
 * Convert the http protocol status in a typesafe enum that can be acted upon later.
 *
 * @param code the status to convert.
 * @return the converted response status.
 */
public static ResponseStatus fromHttp(final int code) {
    ResponseStatus status;
    switch (code) {
        case HTTP_OK:
        case HTTP_CREATED:
        case HTTP_ACCEPTED:
            status = ResponseStatus.SUCCESS;
            break;
        case HTTP_NOT_FOUND:
            status = ResponseStatus.NOT_EXISTS;
            break;
        case HTTP_BAD_REQUEST:
            status = ResponseStatus.INVALID_ARGUMENTS;
            break;
        case HTTP_INTERNAL_ERROR:
            status = ResponseStatus.INTERNAL_ERROR;
            break;
        case HTTP_UNAUTHORIZED:
            status = ResponseStatus.ACCESS_ERROR;
            break;
        case HTTP_TOO_MANY_REQUESTS:
            status = ResponseStatus.FAILURE;
            break;
        default:
            LOGGER.warn("Unknown ResponseStatus with Protocol HTTP: {}", code);
            status = ResponseStatus.FAILURE;
    }
    return status;
}
 
Example 5
Source File: ObserveTest.java    From couchbase-jvm-core with Apache License 2.0 5 votes vote down vote up
/**
 * When the returned observe response is from the master but it contains a different cas
 * than requested, it is an indication that the document has been concurrently modified.
 */
@Test(expected = DocumentConcurrentlyModifiedException.class)
public void shouldFailWhenConcurrentlyModified() {
    CoreContext ctx = new CoreContext(ENV, null);
    ClusterFacade cluster = mock(ClusterFacade.class);
    when(cluster.ctx()).thenReturn(ctx);

    // Setup a mocked config which returns no replica configured
    CouchbaseBucketConfig bucketConfig = mock(CouchbaseBucketConfig.class);
    when(bucketConfig.numberOfReplicas()).thenReturn(1);
    ClusterConfig clusterConfig = mock(ClusterConfig.class);
    when(clusterConfig.bucketConfig("bucket")).thenReturn(bucketConfig);
    GetClusterConfigResponse clusterConfigResponse = new GetClusterConfigResponse(
            clusterConfig, ResponseStatus.SUCCESS
    );
    when(cluster.send(isA(GetClusterConfigRequest.class))).thenReturn(
            Observable.just((CouchbaseResponse) clusterConfigResponse)
    );
    ObserveResponse observeResponse = new ObserveResponse(
            ResponseStatus.SUCCESS, KeyValueStatus.SUCCESS.code(),
            ObserveResponse.ObserveStatus.FOUND_NOT_PERSISTED.value(),
            true,
            45678,
            "bucket",
            mock(CouchbaseRequest.class)
    );
    when(cluster.send(isA(ObserveRequest.class))).thenReturn(
            Observable.just((CouchbaseResponse) observeResponse)
    );

    Observable<Boolean> result = Observe.call(
            cluster, "bucket", "id", 1234, false, Observe.PersistTo.NONE, Observe.ReplicateTo.ONE,
            BestEffortRetryStrategy.INSTANCE
    );
    result
        .timeout(5, TimeUnit.SECONDS)
        .toBlocking()
        .single();
}
 
Example 6
Source File: ObserveTest.java    From couchbase-jvm-core with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldAlwaysAskActiveNode() {
    CoreContext ctx = new CoreContext(ENV, null);
    ClusterFacade cluster = mock(ClusterFacade.class);
    when(cluster.ctx()).thenReturn(ctx);

    // Setup a mocked config which returns no replica configured
    CouchbaseBucketConfig bucketConfig = mock(CouchbaseBucketConfig.class);
    when(bucketConfig.numberOfReplicas()).thenReturn(1);
    ClusterConfig clusterConfig = mock(ClusterConfig.class);
    when(clusterConfig.bucketConfig("bucket")).thenReturn(bucketConfig);
    GetClusterConfigResponse clusterConfigResponse = new GetClusterConfigResponse(
        clusterConfig, ResponseStatus.SUCCESS
    );
    when(cluster.send(isA(GetClusterConfigRequest.class))).thenReturn(
        Observable.just((CouchbaseResponse) clusterConfigResponse)
    );
    ObserveResponse observeResponse = new ObserveResponse(
        ResponseStatus.SUCCESS, KeyValueStatus.SUCCESS.code(),
        ObserveResponse.ObserveStatus.FOUND_NOT_PERSISTED.value(),
        false,
        45678,
        "bucket",
        mock(CouchbaseRequest.class)
    );
    when(cluster.send(isA(ObserveRequest.class))).thenReturn(
        Observable.just((CouchbaseResponse) observeResponse)
    );

    Observable<Boolean> result = Observe.call(
        cluster, "bucket", "id", 45678, false, Observe.PersistTo.NONE, Observe.ReplicateTo.ONE,
        BestEffortRetryStrategy.INSTANCE
    );
    result
        .timeout(5, TimeUnit.SECONDS)
        .toBlocking()
        .single();

    verify(cluster, times(2)).send(isA(ObserveRequest.class));
}
 
Example 7
Source File: DiagnosticsResponse.java    From couchbase-jvm-core with Apache License 2.0 4 votes vote down vote up
public DiagnosticsResponse(final DiagnosticsReport diagnosticsReport) {
    super(ResponseStatus.SUCCESS, null);
    this.diagnosticsReport = diagnosticsReport;
}
 
Example 8
Source File: GetConfigProviderResponse.java    From couchbase-jvm-core with Apache License 2.0 4 votes vote down vote up
public GetConfigProviderResponse(ConfigurationProvider provider) {
    super(ResponseStatus.SUCCESS, null);
    this.provider = provider;
}
 
Example 9
Source File: ResponseStatusConverter.java    From couchbase-jvm-core with Apache License 2.0 4 votes vote down vote up
/**
 * Convert the binary protocol status in a typesafe enum that can be acted upon later.
 *
 * @param code the status to convert.
 * @return the converted response status.
 */
public static ResponseStatus fromBinary(final short code) {
    KeyValueStatus status = KeyValueStatus.valueOf(code);
    switch (status) {
        case SUCCESS:
            return ResponseStatus.SUCCESS;
        case ERR_EXISTS:
            return ResponseStatus.EXISTS;
        case ERR_NOT_FOUND:
            return ResponseStatus.NOT_EXISTS;
        case ERR_NOT_MY_VBUCKET:
            return ResponseStatus.RETRY;
        case ERR_NOT_STORED:
            return ResponseStatus.NOT_STORED;
        case ERR_TOO_BIG:
            return ResponseStatus.TOO_BIG;
        case ERR_TEMP_FAIL:
            return ResponseStatus.TEMPORARY_FAILURE;
        case ERR_BUSY:
            return ResponseStatus.SERVER_BUSY;
        case ERR_NO_MEM:
            return ResponseStatus.OUT_OF_MEMORY;
        case ERR_UNKNOWN_COMMAND:
            return ResponseStatus.COMMAND_UNAVAILABLE;
        case ERR_NOT_SUPPORTED:
            return ResponseStatus.COMMAND_UNAVAILABLE;
        case ERR_ACCESS:
            return ResponseStatus.ACCESS_ERROR;
        case ERR_INTERNAL:
            return ResponseStatus.INTERNAL_ERROR;
        case ERR_INVALID:
            return ResponseStatus.INVALID_ARGUMENTS;
        case ERR_DELTA_BADVAL:
            return ResponseStatus.INVALID_ARGUMENTS;
        case ERR_RANGE:
            return ResponseStatus.RANGE_ERROR;
        case ERR_ROLLBACK:
            return ResponseStatus.ROLLBACK;
        //== the following codes are for subdocument API ==
        case ERR_SUBDOC_PATH_NOT_FOUND:
            return ResponseStatus.SUBDOC_PATH_NOT_FOUND;
        case ERR_SUBDOC_PATH_MISMATCH:
            return ResponseStatus.SUBDOC_PATH_MISMATCH;
        case ERR_SUBDOC_PATH_INVALID:
            return ResponseStatus.SUBDOC_PATH_INVALID;
        case ERR_SUBDOC_PATH_TOO_BIG:
            return ResponseStatus.SUBDOC_PATH_TOO_BIG;
        case ERR_SUBDOC_DOC_TOO_DEEP:
            return ResponseStatus.SUBDOC_DOC_TOO_DEEP;
        case ERR_SUBDOC_VALUE_CANTINSERT:
            return ResponseStatus.SUBDOC_VALUE_CANTINSERT;
        case ERR_SUBDOC_DOC_NOT_JSON:
            return ResponseStatus.SUBDOC_DOC_NOT_JSON;
        case ERR_SUBDOC_NUM_RANGE:
            return ResponseStatus.SUBDOC_NUM_RANGE;
        case ERR_SUBDOC_DELTA_RANGE:
            return ResponseStatus.SUBDOC_DELTA_RANGE;
        case ERR_SUBDOC_PATH_EXISTS:
            return ResponseStatus.SUBDOC_PATH_EXISTS;
        case ERR_SUBDOC_VALUE_TOO_DEEP:
            return ResponseStatus.SUBDOC_VALUE_TOO_DEEP;
        case ERR_SUBDOC_INVALID_COMBO:
            return ResponseStatus.SUBDOC_INVALID_COMBO;
        case ERR_SUBDOC_MULTI_PATH_FAILURE:
            return ResponseStatus.SUBDOC_MULTI_PATH_FAILURE;
        case ERR_SUBDOC_XATTR_INVALID_FLAG_COMBO:
            return ResponseStatus.INTERNAL_ERROR;
        case ERR_SUBDOC_XATTR_UNKNOWN_MACRO:
            return ResponseStatus.SUBDOC_XATTR_UNKNOWN_MACRO;
        case ERR_SUBDOC_XATTR_INVALID_KEY_COMBO:
            return ResponseStatus.SUBDOC_XATTR_INVALID_KEY_COMBO;
        //== end of subdocument API codes ==
    }
    return ResponseStatus.FAILURE;
}