Search in sources :

Example 1 with SubdocGetResponse

use of com.couchbase.client.core.msg.kv.SubdocGetResponse in project couchbase-jvm-clients by couchbase.

the class SubDocumentGetIntegrationTest method existsDoesExistSingle.

@Test
void existsDoesExistSingle() {
    List<SubdocGetRequest.Command> commands = Collections.singletonList(new SubdocGetRequest.Command(SubdocCommandType.EXISTS, "foo", false, 0));
    SubdocGetResponse response = checkExpectedSuccess("{\"foo\":\"bar\"}", commands);
    assertTrue(response.values()[0].status().success());
}
Also used : SubdocGetResponse(com.couchbase.client.core.msg.kv.SubdocGetResponse) SubdocGetRequest(com.couchbase.client.core.msg.kv.SubdocGetRequest) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with SubdocGetResponse

use of com.couchbase.client.core.msg.kv.SubdocGetResponse in project couchbase-jvm-clients by couchbase.

the class SubDocumentGetIntegrationTest method pathNotFoundMulti.

@Test
void pathNotFoundMulti() {
    List<SubdocGetRequest.Command> commands = Arrays.asList(new SubdocGetRequest.Command(SubdocCommandType.GET, "foo", false, 0), new SubdocGetRequest.Command(SubdocCommandType.GET, "no_exist", false, 1));
    SubdocGetResponse response = checkExpectedSuccess("{\"foo\":\"bar\"}", commands);
    assertTrue(response.values()[0].status().success());
    assertEquals(SubDocumentOpResponseStatus.PATH_NOT_FOUND, response.values()[1].status());
    assertTrue(response.values()[1].error().get() instanceof PathNotFoundException);
    assertEquals(SubdocCommandType.GET, response.values()[0].type());
    assertEquals(SubdocCommandType.GET, response.values()[1].type());
}
Also used : SubdocGetResponse(com.couchbase.client.core.msg.kv.SubdocGetResponse) PathNotFoundException(com.couchbase.client.core.error.subdoc.PathNotFoundException) SubdocGetRequest(com.couchbase.client.core.msg.kv.SubdocGetRequest) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with SubdocGetResponse

use of com.couchbase.client.core.msg.kv.SubdocGetResponse in project couchbase-jvm-clients by couchbase.

the class SubDocumentGetIntegrationTest method checkExpectedFailure.

/**
 * Perform subdoc operations and assert the result is the expected exception
 */
private void checkExpectedFailure(String input, List<SubdocGetRequest.Command> commands, Class<?> expected) {
    String id = UUID.randomUUID().toString();
    insertContent(id, input);
    SubdocGetRequest request = new SubdocGetRequest(kvTimeout, core.context(), CollectionIdentifier.fromDefault(config().bucketname()), env.retryStrategy(), id, (byte) 0, commands, null);
    core.send(request);
    SubdocGetResponse response = null;
    try {
        response = request.response().get();
    } catch (InterruptedException | ExecutionException e) {
        fail("Failed with " + e);
    }
    assertFalse(response.status().success());
    assertEquals(ResponseStatus.SUBDOC_FAILURE, response.status());
    assertTrue(response.error().isPresent());
    CouchbaseException err = response.error().get();
    assertTrue(expected.isInstance(err));
}
Also used : SubdocGetResponse(com.couchbase.client.core.msg.kv.SubdocGetResponse) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) ExecutionException(java.util.concurrent.ExecutionException) SubdocGetRequest(com.couchbase.client.core.msg.kv.SubdocGetRequest)

Example 4 with SubdocGetResponse

use of com.couchbase.client.core.msg.kv.SubdocGetResponse in project couchbase-jvm-clients by couchbase.

the class SubDocumentGetIntegrationTest method existsDoesNotExistSingle.

@Test
void existsDoesNotExistSingle() {
    List<SubdocGetRequest.Command> commands = Collections.singletonList(new SubdocGetRequest.Command(SubdocCommandType.EXISTS, "cat", false, 0));
    SubdocGetResponse response = checkExpectedSuccess("{\"foo\":\"bar\"}", commands);
    assertFalse(response.values()[0].status().success());
    assertEquals(SubdocCommandType.EXISTS, response.values()[0].type());
}
Also used : SubdocGetResponse(com.couchbase.client.core.msg.kv.SubdocGetResponse) SubdocGetRequest(com.couchbase.client.core.msg.kv.SubdocGetRequest) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with SubdocGetResponse

use of com.couchbase.client.core.msg.kv.SubdocGetResponse in project couchbase-jvm-clients by couchbase.

the class SubDocumentGetIntegrationTest method pathMismatchMulti.

@Test
void pathMismatchMulti() {
    List<SubdocGetRequest.Command> commands = Arrays.asList(new SubdocGetRequest.Command(SubdocCommandType.GET, "foo", false, 0), new SubdocGetRequest.Command(SubdocCommandType.GET, "foo.bar[0].baz", false, 1));
    SubdocGetResponse response = checkExpectedSuccess("{\"foo\":\"bar\"}", commands);
    assertTrue(response.values()[0].status().success());
    assertEquals(SubDocumentOpResponseStatus.PATH_MISMATCH, response.values()[1].status());
    assertTrue(response.values()[1].error().get() instanceof PathMismatchException);
}
Also used : SubdocGetResponse(com.couchbase.client.core.msg.kv.SubdocGetResponse) PathMismatchException(com.couchbase.client.core.error.subdoc.PathMismatchException) SubdocGetRequest(com.couchbase.client.core.msg.kv.SubdocGetRequest) CoreIntegrationTest(com.couchbase.client.core.util.CoreIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

SubdocGetRequest (com.couchbase.client.core.msg.kv.SubdocGetRequest)7 SubdocGetResponse (com.couchbase.client.core.msg.kv.SubdocGetResponse)7 CoreIntegrationTest (com.couchbase.client.core.util.CoreIntegrationTest)5 Test (org.junit.jupiter.api.Test)5 ExecutionException (java.util.concurrent.ExecutionException)2 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)1 PathMismatchException (com.couchbase.client.core.error.subdoc.PathMismatchException)1 PathNotFoundException (com.couchbase.client.core.error.subdoc.PathNotFoundException)1