Search in sources :

Example 1 with CounterResult

use of com.couchbase.client.java.kv.CounterResult in project couchbase-jvm-clients by couchbase.

the class KeyValueIntegrationTest method increment.

@Test
void increment() {
    String id = UUID.randomUUID().toString();
    assertThrows(DocumentNotFoundException.class, () -> collection.binary().increment(id));
    CounterResult result = collection.binary().increment(id, incrementOptions().initial(5L));
    assertTrue(result.cas() != 0);
    assertEquals(5L, result.content());
    result = collection.binary().increment(id, incrementOptions().delta(2));
    assertTrue(result.cas() != 0);
    assertEquals(7L, result.content());
    result = collection.binary().increment(id, incrementOptions());
    assertTrue(result.cas() != 0);
    assertEquals(8L, result.content());
}
Also used : CounterResult(com.couchbase.client.java.kv.CounterResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with CounterResult

use of com.couchbase.client.java.kv.CounterResult in project couchbase-jvm-clients by couchbase.

the class MutationTokenIntegrationTest method tokenOnDecrement.

@Test
void tokenOnDecrement() {
    String id = UUID.randomUUID().toString();
    CounterResult result = collection.binary().decrement(id, decrementOptions().initial(1L));
    assertMutationToken(result.mutationToken());
}
Also used : CounterResult(com.couchbase.client.java.kv.CounterResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with CounterResult

use of com.couchbase.client.java.kv.CounterResult in project couchbase-jvm-clients by couchbase.

the class KeyValueIntegrationTest method decrement.

/**
 * Right now the mock allows the value to be decremented below zero, which is against the server
 * spec/protocol. Once https://github.com/couchbase/CouchbaseMock/issues/51 is fixed, this
 * ignore annotation can be removed.
 */
@Test
@IgnoreWhen(clusterTypes = { ClusterType.MOCKED })
void decrement() {
    String id = UUID.randomUUID().toString();
    assertThrows(DocumentNotFoundException.class, () -> collection.binary().decrement(id));
    CounterResult result = collection.binary().decrement(id, decrementOptions().initial(2L));
    assertTrue(result.cas() != 0);
    assertEquals(2L, result.content());
    result = collection.binary().decrement(id);
    assertTrue(result.cas() != 0);
    assertEquals(1L, result.content());
    result = collection.binary().decrement(id);
    assertTrue(result.cas() != 0);
    assertEquals(0L, result.content());
    result = collection.binary().decrement(id);
    assertTrue(result.cas() != 0);
    assertEquals(0L, result.content());
}
Also used : CounterResult(com.couchbase.client.java.kv.CounterResult) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with CounterResult

use of com.couchbase.client.java.kv.CounterResult in project couchbase-jvm-clients by couchbase.

the class MutationTokenIntegrationTest method tokenOnIncrement.

@Test
void tokenOnIncrement() {
    String id = UUID.randomUUID().toString();
    CounterResult result = collection.binary().increment(id, incrementOptions().initial(1L));
    assertMutationToken(result.mutationToken());
}
Also used : CounterResult(com.couchbase.client.java.kv.CounterResult) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

CounterResult (com.couchbase.client.java.kv.CounterResult)4 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)4 Test (org.junit.jupiter.api.Test)4 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)1