use of com.couchbase.client.core.error.InvalidArgumentException in project couchbase-jvm-clients by couchbase.
the class BuilderPropertySetterTest method setBoolean.
@Test
void setBoolean() {
CoreEnvironment.Builder<?> builder = newEnvironmentBuilder();
setter.set(builder, "io.queryCircuitBreaker.enabled", "true");
setter.set(builder, "io.analyticsCircuitBreaker.enabled", "1");
setter.set(builder, "io.viewCircuitBreaker.enabled", "false");
setter.set(builder, "io.kvCircuitBreaker.enabled", "0");
IoConfig io = builder.ioConfig().build();
assertTrue(io.queryCircuitBreakerConfig().enabled());
assertTrue(io.analyticsCircuitBreakerConfig().enabled());
assertFalse(io.viewCircuitBreakerConfig().enabled());
assertFalse(io.kvCircuitBreakerConfig().enabled());
InvalidArgumentException e = assertThrows(InvalidArgumentException.class, () -> setter.set(builder, "io.kvCircuitBreaker.enabled", "TRUE"));
assertEquals("Expected a boolean (\"true\", \"false\", \"1\", or \"0\") but got \"TRUE\".", e.getCause().getMessage());
}
use of com.couchbase.client.core.error.InvalidArgumentException in project couchbase-jvm-clients by couchbase.
the class BuilderPropertySetterTest method setInt.
@Test
void setInt() {
CoreEnvironment.Builder<?> builder = newEnvironmentBuilder();
setter.set(builder, "io.maxHttpConnections", "76");
IoConfig io = builder.ioConfig().build();
assertEquals(76, io.maxHttpConnections());
InvalidArgumentException e = assertThrows(InvalidArgumentException.class, () -> setter.set(builder, "io.maxHttpConnections", "garbage"));
assertEquals("Expected an int but got \"garbage\".", e.getCause().getMessage());
}
use of com.couchbase.client.core.error.InvalidArgumentException in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method subdocGetRequest.
/**
* Helper method to create a get request for a subdoc fetch.
*
* @param id the document id which is used to uniquely identify it.
* @param opts custom options to change the default behavior.
* @return the subdoc get request.
*/
@Stability.Internal
SubdocGetRequest subdocGetRequest(final String id, final GetOptions.Built opts) {
try {
notNullOrEmpty(id, "Id");
if (opts.withExpiry()) {
if (opts.projections().size() > 15) {
throw InvalidArgumentException.fromMessage("Only a maximum of 16 fields can be " + "projected per request due to a server limitation (includes the expiration macro as one field).");
}
} else {
if (opts.projections().size() > 16) {
throw InvalidArgumentException.fromMessage("Only a maximum of 16 fields can be " + "projected per request due to a server limitation.");
}
}
} catch (Exception cause) {
throw new InvalidArgumentException("Argument validation failed", cause, ReducedKeyValueErrorContext.create(id, collectionIdentifier));
}
Duration timeout = opts.timeout().orElse(environment.timeoutConfig().kvTimeout());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
List<SubdocGetRequest.Command> commands = new ArrayList<>(16);
if (!opts.projections().isEmpty()) {
if (opts.projections().size() > 16) {
throw new UnsupportedOperationException("Only a maximum of 16 fields can be " + "projected per request.");
}
List<String> projections = opts.projections();
for (int i = 0; i < projections.size(); i++) {
commands.add(new SubdocGetRequest.Command(SubdocCommandType.GET, projections.get(i), false, commands.size()));
}
} else {
commands.add(new SubdocGetRequest.Command(SubdocCommandType.GET_DOC, "", false, commands.size()));
}
if (opts.withExpiry()) {
// xattrs must go first
commands.add(0, new SubdocGetRequest.Command(SubdocCommandType.GET, LookupInMacro.EXPIRY_TIME, true, commands.size()));
// JSON compat flags.
if (opts.projections().isEmpty()) {
commands.add(1, new SubdocGetRequest.Command(SubdocCommandType.GET, LookupInMacro.FLAGS, true, commands.size()));
}
}
RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_LOOKUP_IN, opts.parentSpan().orElse(null));
SubdocGetRequest request = new SubdocGetRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, (byte) 0x00, commands, 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 JsonObjectTest 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, () -> JsonObject.from(mapOf("subMap", badMap1)));
assertTrue(e.getCause() instanceof ClassCastException);
assertThrows(InvalidArgumentException.class, () -> JsonObject.from(mapOf("subMap", badMap2)));
}
use of com.couchbase.client.core.error.InvalidArgumentException in project couchbase-jvm-clients by couchbase.
the class EventingFunction method fromExportedFunctions.
/**
* Creates a list of {@link EventingFunction}s from a raw JSON, usually exported from the server UI.
*
* @param encoded the encoded functions to load.
* @return the created list of {@link EventingFunction}s.
*/
@Stability.Volatile
public static List<EventingFunction> fromExportedFunctions(final byte[] encoded) {
JsonNode encodedFunctions = Mapper.decodeIntoTree(encoded);
if (!encodedFunctions.isArray()) {
throw new InvalidArgumentException("The encoded JSON must be a JSON array of functions", null, null);
}
List<EventingFunction> functions = new ArrayList<>();
for (JsonNode function : encodedFunctions) {
functions.add(fromFunction(Mapper.encodeAsBytes(function)));
}
return functions;
}
Aggregations