use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.
the class RateLimitingIntegrationTest method searchRateLimitMaxIngress.
@Test
@IgnoreWhen(missesCapabilities = Capabilities.SEARCH)
void searchRateLimitMaxIngress() throws Exception {
String username = "searchRateLimitIngress";
Limits limits = new Limits();
limits.searchLimits = new SearchLimits(10, 100, 1, 10);
createRateLimitedUser(username, limits);
adminCluster.searchIndexes().upsertIndex(new SearchIndex("ratelimits-ingress", config().bucketname()));
Cluster cluster = createTestCluster(username);
try {
cluster.waitUntilReady(Duration.ofSeconds(10));
String content = repeatString(1024 * 1024, "a");
RateLimitedException ex = assertThrows(RateLimitedException.class, () -> {
for (int i = 0; i < 10; i++) {
try {
SearchResult res = cluster.searchQuery("ratelimits-ingress", QueryStringQuery.match(content), SearchOptions.searchOptions().timeout(Duration.ofSeconds(10)).limit(1));
} catch (TimeoutException e) {
// continue
} catch (CouchbaseException e) {
if (e.getMessage().contains("no planPIndexes")) {
continue;
}
throw e;
}
}
});
assertTrue(ex.getMessage().contains("ingress_mib_per_min"));
} finally {
cluster.disconnect();
adminCluster.users().dropUser(username);
adminCluster.searchIndexes().dropIndex("ratelimits-ingress");
}
}
use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.
the class RateLimitingIntegrationTest method searchRateLimitMaxCommands.
@Test
@IgnoreWhen(missesCapabilities = Capabilities.SEARCH)
void searchRateLimitMaxCommands() throws Exception {
String username = "searchRateLimit";
Limits limits = new Limits();
limits.searchLimits = new SearchLimits(10, 1, 10, 10);
createRateLimitedUser(username, limits);
adminCluster.searchIndexes().upsertIndex(new SearchIndex("ratelimits", config().bucketname()));
Cluster cluster = createTestCluster(username);
try {
cluster.waitUntilReady(Duration.ofSeconds(10));
RateLimitedException ex = assertThrows(RateLimitedException.class, () -> {
for (int i = 0; i < 50; i++) {
try {
cluster.searchQuery("ratelimits", QueryStringQuery.queryString("a"), SearchOptions.searchOptions().timeout(Duration.ofSeconds(1)));
} catch (TimeoutException e) {
// continue
} catch (CouchbaseException e) {
if (e.getMessage().contains("no planPIndexes")) {
continue;
}
throw e;
}
}
});
assertTrue(ex.getMessage().contains("num_queries_per_min"));
} finally {
cluster.disconnect();
adminCluster.users().dropUser(username);
adminCluster.searchIndexes().dropIndex("ratelimits");
}
}
use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.
the class RateLimitingIntegrationTest method searchRateLimitMaxEgress.
@Test
@IgnoreWhen(missesCapabilities = Capabilities.SEARCH)
void searchRateLimitMaxEgress() throws Exception {
String username = "searchRateLimitEgress";
Limits limits = new Limits();
limits.searchLimits = new SearchLimits(10, 100, 10, 1);
createRateLimitedUser(username, limits);
adminCluster.searchIndexes().upsertIndex(new SearchIndex("ratelimits-egress", config().bucketname()));
Cluster cluster = createTestCluster(username);
try {
cluster.waitUntilReady(Duration.ofSeconds(10));
String content = repeatString(1024 * 1024, "a");
MutationResult mutationResult = cluster.bucket(config().bucketname()).defaultCollection().upsert("fts-egress", JsonObject.create().put("content", content), UpsertOptions.upsertOptions().timeout(Duration.ofSeconds(10)));
RateLimitedException ex = assertThrows(RateLimitedException.class, () -> {
for (int i = 0; i < 10; i++) {
try {
cluster.searchQuery("ratelimits-egress", SearchQuery.wildcard("a*"), SearchOptions.searchOptions().timeout(Duration.ofSeconds(10)).fields("content").consistentWith(MutationState.from(mutationResult.mutationToken().get())).highlight(HighlightStyle.HTML, "content"));
} catch (TimeoutException e) {
// continue
} catch (CouchbaseException e) {
if (e.getMessage().contains("no planPIndexes")) {
continue;
}
throw e;
}
}
});
assertTrue(ex.getMessage().contains("egress_mib_per_min"));
} finally {
cluster.disconnect();
adminCluster.users().dropUser(username);
adminCluster.searchIndexes().dropIndex("ratelimits-egress");
}
}
use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.
the class Sdk2CompatibleLegacyTranscoder method decode.
@Override
@SuppressWarnings("unchecked")
public <T> T decode(final Class<T> target, byte[] input, final int flags) {
Object decoded;
if ((flags & COMPRESSED) != 0) {
input = decompress(input);
}
int maskedFlags = flags & SPECIAL_MASK;
if ((flags & SERIALIZED) != 0 && input != null) {
decoded = deserialize(input);
} else if (maskedFlags != 0 && input != null) {
switch(maskedFlags) {
case SPECIAL_BOOLEAN:
decoded = input[0] == '1';
break;
case SPECIAL_INT:
decoded = (int) decodeLong(input);
break;
case SPECIAL_LONG:
decoded = decodeLong(input);
break;
case SPECIAL_DATE:
decoded = new Date(decodeLong(input));
break;
case SPECIAL_BYTE:
decoded = input[0];
break;
case SPECIAL_FLOAT:
decoded = Float.intBitsToFloat((int) decodeLong(input));
break;
case SPECIAL_DOUBLE:
decoded = Double.longBitsToDouble(decodeLong(input));
break;
case SPECIAL_BYTEARRAY:
decoded = input;
break;
default:
throw new CouchbaseException("Undecodeable with flags " + flags);
}
} else {
decoded = new String(input, StandardCharsets.UTF_8);
}
return (T) decoded;
}
use of com.couchbase.client.core.error.CouchbaseException in project couchbase-jvm-clients by couchbase.
the class CouchbaseArrayList method remove.
@Override
public E remove(int index) {
// fail fast on negative values, as they are interpreted as "starting from the back of the array" otherwise
if (index < 0) {
throw new IndexOutOfBoundsException("Index: " + index);
}
String idx = "[" + index + "]";
for (int i = 0; i < arrayListOptions.casMismatchRetries(); i++) {
try {
// this loop will allow us to _know_ what element we really did remove.
LookupInResult current = collection.lookupIn(id, Collections.singletonList(LookupInSpec.get(idx)), lookupInOptions);
long returnCas = current.cas();
E result = current.contentAs(0, entityTypeClass);
collection.mutateIn(id, Collections.singletonList(MutateInSpec.remove(idx)), arrayListOptions.mutateInOptions().cas(returnCas));
return result;
} catch (DocumentNotFoundException e) {
// ArrayList will throw if underlying list was cleared before a remove.
throw new IndexOutOfBoundsException("Index:" + index);
} catch (CasMismatchException ex) {
// will have to retry get-and-remove
} catch (PathNotFoundException e) {
throw new IndexOutOfBoundsException("Index: " + index);
}
}
throw new CouchbaseException("CouchbaseArrayList remove failed", new RetryExhaustedException("Couldn't perform remove in less than " + arrayListOptions.casMismatchRetries() + " iterations. It is likely concurrent modifications of this document are the reason"));
}
Aggregations