Search in sources :

Example 71 with IgnoreWhen

use of com.couchbase.client.test.IgnoreWhen in project couchbase-jvm-clients by couchbase.

the class KeyValueIntegrationTest method checkExpiryBeyond2038.

/**
 *  It seems the mock will not actually upsert a doc when the expiry exceeds 30 days.
 *  So https://github.com/couchbase/CouchbaseMock/issues/58 needs to be fixed, at
 *  which time we can remove the restriction on not running this test when mocked.
 */
@Test
@IgnoreWhen(clusterTypes = { ClusterType.MOCKED })
void checkExpiryBeyond2038() {
    // The server interprets the 32-bit expiry field as an unsigned
    // integer. This means the maximum value is 4294967295 seconds,
    // which corresponds to 2106-02-07T06:28:15Z.
    // 
    // This test will start to fail when the current time is less than
    // 30 years from that maximum expiration instant.
    int expiryYears = 30;
    // make sure we are not time travelers.
    LocalDate expirationDate = LocalDate.now().plusYears(expiryYears);
    assertTrue(expirationDate.getYear() > 2038);
    checkExpiry(Duration.ofDays(365 * expiryYears));
}
Also used : LocalDate(java.time.LocalDate) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 72 with IgnoreWhen

use of com.couchbase.client.test.IgnoreWhen 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"));
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) JsonObject(com.couchbase.client.java.json.JsonObject) MutationResult(com.couchbase.client.java.kv.MutationResult) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 73 with IgnoreWhen

use of com.couchbase.client.test.IgnoreWhen in project couchbase-jvm-clients by couchbase.

the class KeyValueIntegrationTest method getAndLock.

/**
 * We need to ignore this test on the mock because the mock returns TMPFAIL instead of LOCKED when the
 * document is locked (which used to be the old functionality but now since XERROR is negotiated it
 * returns LOCKED properly).
 *
 * <p>Once the mock is modified to return LOCKED, this test can also be run on the mock again.</p>
 */
@Test
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
void getAndLock() {
    String id = UUID.randomUUID().toString();
    JsonObject expected = JsonObject.create().put("foo", true);
    MutationResult insert = collection.insert(id, expected);
    assertTrue(insert.cas() != 0);
    GetResult getAndLock = collection.getAndLock(id, Duration.ofSeconds(30));
    assertTrue(getAndLock.cas() != 0);
    assertNotEquals(insert.cas(), getAndLock.cas());
    assertEquals(expected, getAndLock.contentAsObject());
    TimeoutException exception = assertThrows(TimeoutException.class, () -> collection.getAndLock(id, Duration.ofSeconds(30), getAndLockOptions().timeout(Duration.ofMillis(100))));
    assertEquals(EnumSet.of(RetryReason.KV_LOCKED), exception.context().requestContext().retryReasons());
    assertThrows(DocumentNotFoundException.class, () -> collection.getAndLock("some_doc", Duration.ofSeconds(30)));
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) JsonObject(com.couchbase.client.java.json.JsonObject) MutationResult(com.couchbase.client.java.kv.MutationResult) TimeoutException(com.couchbase.client.core.error.TimeoutException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 74 with IgnoreWhen

use of com.couchbase.client.test.IgnoreWhen in project couchbase-jvm-clients by couchbase.

the class KeyValueReactiveCollectionIntegrationTest method reactiveTouch.

@Test
@IgnoreWhen(clusterTypes = { ClusterType.MOCKED })
void reactiveTouch() {
    StepVerifier.create(docIds.concatMap(key -> reactiveCollection.touch(key, Duration.ofSeconds(1)))).expectError(DocumentNotFoundException.class).verify();
    // Insert docs with expiry of 10s
    InsertOptions firstOpts = InsertOptions.insertOptions().expiry(Duration.ofSeconds(10));
    List<MutationResult> insertResults = docIds.concatMap(key -> reactiveCollection.insert(key, JsonObject.create().put("key", key), firstOpts)).collectList().block();
    // Touch docs and update the expiry to 1s
    List<MutationResult> touchResults = docIds.concatMap(key -> reactiveCollection.touch(key, Duration.ofSeconds(1))).collectList().block();
    // Assert cas of insert and touch results differ
    StepVerifier.create(Flux.range(0, numDocs)).thenConsumeWhile(i -> insertResults.get(i).cas() != touchResults.get(i).cas()).verifyComplete();
    List<GetResult> getResults = docIds.concatMap(reactiveCollection::get).collectList().block();
    StepVerifier.create(Flux.range(0, numDocs)).thenConsumeWhile(i -> getResults.get(i).cas() == touchResults.get(i).cas()).verifyComplete();
}
Also used : JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) GetResult(com.couchbase.client.java.kv.GetResult) BeforeEach(org.junit.jupiter.api.BeforeEach) InsertOptions(com.couchbase.client.java.kv.InsertOptions) StepVerifier(reactor.test.StepVerifier) Iterator(java.util.Iterator) MutationResult(com.couchbase.client.java.kv.MutationResult) ExistsResult(com.couchbase.client.java.kv.ExistsResult) ClusterType(com.couchbase.client.test.ClusterType) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) List(java.util.List) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) JsonObject(com.couchbase.client.java.json.JsonObject) DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) DocumentExistsException(com.couchbase.client.core.error.DocumentExistsException) DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) GetResult(com.couchbase.client.java.kv.GetResult) InsertOptions(com.couchbase.client.java.kv.InsertOptions) MutationResult(com.couchbase.client.java.kv.MutationResult) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 75 with IgnoreWhen

use of com.couchbase.client.test.IgnoreWhen in project couchbase-jvm-clients by couchbase.

the class QueryIntegrationTest method preserveExpiryThrowsFeatureNotAvailable.

@Test
@IgnoreWhen(hasCapabilities = Capabilities.QUERY_PRESERVE_EXPIRY)
void preserveExpiryThrowsFeatureNotAvailable() {
    FeatureNotAvailableException ex = assertThrows(FeatureNotAvailableException.class, () -> cluster.query("select 1=1", queryOptions().preserveExpiry(true)));
    assertTrue(ex.getMessage().contains("Preserving expiry for the query service is not supported"));
}
Also used : FeatureNotAvailableException(com.couchbase.client.core.error.FeatureNotAvailableException) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

IgnoreWhen (com.couchbase.client.test.IgnoreWhen)79 Test (org.junit.jupiter.api.Test)78 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)70 JsonObject (com.couchbase.client.java.json.JsonObject)41 GetResult (com.couchbase.client.java.kv.GetResult)15 MutationResult (com.couchbase.client.java.kv.MutationResult)13 CoreIntegrationTest (com.couchbase.client.core.util.CoreIntegrationTest)9 RateLimitedException (com.couchbase.client.core.error.RateLimitedException)8 TimeoutException (com.couchbase.client.core.error.TimeoutException)7 LookupInResult (com.couchbase.client.java.kv.LookupInResult)7 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)6 ReplaceBodyWithXattr (com.couchbase.client.java.kv.ReplaceBodyWithXattr)6 SearchIndex (com.couchbase.client.java.manager.search.SearchIndex)5 CasMismatchException (com.couchbase.client.core.error.CasMismatchException)4 MutateInResult (com.couchbase.client.java.kv.MutateInResult)4 TestNodeConfig (com.couchbase.client.test.TestNodeConfig)4 DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)3 FeatureNotAvailableException (com.couchbase.client.core.error.FeatureNotAvailableException)3 UnambiguousTimeoutException (com.couchbase.client.core.error.UnambiguousTimeoutException)3 Core (com.couchbase.client.core.Core)2