use of com.couchbase.client.java.kv.GetResult in project couchbase-jvm-clients by couchbase.
the class KeyValueIntegrationTest method fullDocWithExpirationAndCustomTranscoder.
@Test
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
void fullDocWithExpirationAndCustomTranscoder() {
String id = UUID.randomUUID().toString();
JsonObject content = JsonObject.create().put("foo", "bar").put("created", true).put("age", 12);
MutationResult mutationResult = collection.upsert(id, content.toBytes(), upsertOptions().expiry(Duration.ofSeconds(5)).transcoder(RawBinaryTranscoder.INSTANCE));
assertTrue(mutationResult.cas() != 0);
GetResult getResult = collection.get(id, getOptions().withExpiry(true).transcoder(RawBinaryTranscoder.INSTANCE));
assertTrue(getResult.expiryTime().isPresent());
assertTrue(getResult.expiryTime().get().toEpochMilli() > 0);
assertEquals(content, JsonObject.fromJson(getResult.contentAs(byte[].class)));
}
use of com.couchbase.client.java.kv.GetResult in project couchbase-jvm-clients by couchbase.
the class KeyValueIntegrationTest method fullDocWithExpiration.
/**
* Right now the mock does not support xattr/macro expansion so this test is
* ignored on the mock. Once the mock supports it, please remove the ignore
* annotation.
*
* <p>See https://github.com/couchbase/CouchbaseMock/issues/46</p>
*/
@Test
@IgnoreWhen(clusterTypes = { ClusterType.MOCKED })
void fullDocWithExpiration() {
String id = UUID.randomUUID().toString();
JsonObject content = JsonObject.create().put("foo", "bar").put("created", true).put("age", 12);
MutationResult mutationResult = collection.upsert(id, content, upsertOptions().expiry(Duration.ofSeconds(5)));
assertTrue(mutationResult.cas() != 0);
GetResult getResult = collection.get(id, getOptions().withExpiry(true));
assertTrue(getResult.expiryTime().isPresent());
assertTrue(getResult.expiryTime().get().toEpochMilli() > 0);
assertEquals(content, getResult.contentAsObject());
}
use of com.couchbase.client.java.kv.GetResult in project couchbase-jvm-clients by couchbase.
the class KeyValueIntegrationTest method getWithProjection.
@Test
void getWithProjection() {
String id = UUID.randomUUID().toString();
JsonObject content = JsonObject.create().put("foo", "bar").put("created", true).put("age", 12);
MutationResult mutationResult = collection.upsert(id, content);
assertTrue(mutationResult.cas() != 0);
GetResult getResult = collection.get(id, getOptions().project("foo", "created", "notfound"));
assertTrue(getResult.cas() != 0);
assertFalse(getResult.expiryTime().isPresent());
JsonObject decoded = getResult.contentAsObject();
assertEquals("bar", decoded.getString("foo"));
assertEquals(true, decoded.getBoolean("created"));
assertFalse(decoded.containsKey("age"));
}
use of com.couchbase.client.java.kv.GetResult in project couchbase-jvm-clients by couchbase.
the class KeyValueIntegrationTest method assertExpiry.
void assertExpiry(String documentId, Duration expiryDuration) {
GetResult result = collection.get(documentId, GetOptions.getOptions().withExpiry(true));
Instant actualExpiry = result.expiryTime().orElseThrow(() -> new AssertionError("expected expiry"));
Instant expectedExpiry = Instant.ofEpochMilli(System.currentTimeMillis()).plus(expiryDuration);
long secondsDifference = actualExpiry.getEpochSecond() - expectedExpiry.getEpochSecond();
long acceptanceThresholdSeconds = Duration.ofMinutes(5).getSeconds();
assertTrue(Math.abs(secondsDifference) < acceptanceThresholdSeconds);
}
use of com.couchbase.client.java.kv.GetResult in project couchbase-jvm-clients by couchbase.
the class KeyValueIntegrationTest method projectionWithExpiration.
/**
* Right now the mock does not support xattr/macro expansion so this test is
* ignored on the mock. Once the mock supports it, please remove the ignore
* annotation.
*
* <p>See https://github.com/couchbase/CouchbaseMock/issues/46</p>
*/
@Test
@IgnoreWhen(clusterTypes = { ClusterType.MOCKED })
void projectionWithExpiration() {
String id = UUID.randomUUID().toString();
JsonObject content = JsonObject.create().put("foo", "bar").put("created", true).put("age", 12);
MutationResult mutationResult = collection.upsert(id, content, upsertOptions().expiry(Duration.ofSeconds(5)));
assertTrue(mutationResult.cas() != 0);
GetResult getResult = collection.get(id, getOptions().project("foo", "created").withExpiry(true));
assertTrue(getResult.cas() != 0);
assertTrue(getResult.expiryTime().isPresent());
assertTrue(getResult.expiryTime().get().toEpochMilli() > 0);
JsonObject decoded = getResult.contentAsObject();
assertEquals("bar", decoded.getString("foo"));
assertEquals(true, decoded.getBoolean("created"));
assertFalse(decoded.containsKey("age"));
}
Aggregations