use of com.couchbase.client.core.error.InvalidArgumentException in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method unlockRequest.
/**
* Helper method to create the unlock request.
*
* @param id the id of the document.
* @param cas the CAS value which is needed to unlock it.
* @param options the options to customize.
* @return the unlock request.
*/
UnlockRequest unlockRequest(final String id, final long cas, final UnlockOptions options) {
notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
notNull(options, "UnlockOptions", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
if (cas == 0) {
throw new InvalidArgumentException("CAS cannot be 0", null, ReducedKeyValueErrorContext.create(id, collectionIdentifier));
}
UnlockOptions.Built opts = options.build();
Duration timeout = opts.timeout().orElse(environment.timeoutConfig().kvTimeout());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_UNLOCK, opts.parentSpan().orElse(null));
UnlockRequest request = new UnlockRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, cas, span);
request.context().clientContext(opts.clientContext());
return request;
}
use of com.couchbase.client.core.error.InvalidArgumentException in project couchbase-jvm-clients by couchbase.
the class BuilderPropertySetterTest method setDouble.
@Test
void setDouble() {
CoreEnvironment.Builder<?> builder = newEnvironmentBuilder();
setter.set(builder, "compression.minRatio", "3.14159");
CompressionConfig compression = builder.compressionConfig().build();
assertEquals(3.14159, compression.minRatio());
InvalidArgumentException e = assertThrows(InvalidArgumentException.class, () -> setter.set(builder, "compression.minRatio", "garbage"));
assertEquals("Expected a double but got \"garbage\".", e.getCause().getMessage());
}
use of com.couchbase.client.core.error.InvalidArgumentException in project couchbase-jvm-clients by couchbase.
the class BuilderPropertySetterTest method setEnumArray.
@Test
void setEnumArray() {
CoreEnvironment.Builder<?> builder = newEnvironmentBuilder();
setter.set(builder, "io.captureTraffic", " KV , ANALYTICS ");
IoConfig io = builder.ioConfig().build();
Set<ServiceType> expected = EnumSet.of(ServiceType.KV, ServiceType.ANALYTICS);
assertEquals(expected, io.servicesToCapture());
setter.set(builder, "io.captureTraffic", "");
assertEquals(EnumSet.allOf(ServiceType.class), builder.ioConfig().build().servicesToCapture());
InvalidArgumentException e = assertThrows(InvalidArgumentException.class, () -> setter.set(builder, "io.captureTraffic", "garbage"));
assertEquals("Expected one of " + EnumSet.allOf(ServiceType.class) + " but got \"garbage\"", e.getCause().getMessage());
}
use of com.couchbase.client.core.error.InvalidArgumentException in project couchbase-jvm-clients by couchbase.
the class BuilderPropertySetterTest method triesAllOverloads.
@Test
void triesAllOverloads() {
HasOverloads overloads = new HasOverloads();
setter.set(overloads, "value", "23");
setter.set(overloads, "value", "2s");
setter.set(overloads, "value", "{\"luckyNumber\":37}");
assertEquals(23, overloads.i);
assertEquals(Duration.ofSeconds(2), overloads.d);
assertEquals(singletonMap("luckyNumber", 37), overloads.m);
InvalidArgumentException e = assertThrows(InvalidArgumentException.class, () -> setter.set(overloads, "value", "garbage"));
assertTrue(e.getCause().getMessage().startsWith("Found multiple one-arg setters"));
final Set<String> suppressedMessages = Arrays.stream(e.getCause().getSuppressed()).map(Throwable::getMessage).collect(toSet());
final Set<String> expectedSuppressedMessages = new HashSet<>(Arrays.asList("Expected an int but got \"garbage\".", "Expected a duration qualified by a time unit (like \"2.5s\" or \"300ms\") but got \"garbage\".", "Expected a value Jackson can bind to java.util.Map<java.lang.String, java.lang.Integer> but got \"garbage\"."));
assertEquals(expectedSuppressedMessages, suppressedMessages);
}
use of com.couchbase.client.core.error.InvalidArgumentException in project couchbase-jvm-clients by couchbase.
the class JsonArrayTest method shouldThrowOnBadSubMap.
@Test
void shouldThrowOnBadSubMap() {
Map<Integer, String> badMap1 = mapOf(1, "test");
Map<String, Object> badMap2 = mapOf("key1", new CloneNotSupportedException());
InvalidArgumentException e = assertThrows(InvalidArgumentException.class, () -> JsonArray.from(listOf(badMap1)));
assertTrue(e.getCause() instanceof ClassCastException);
assertThrows(InvalidArgumentException.class, () -> JsonArray.from(listOf(badMap2)));
}
Aggregations