use of com.couchbase.client.java.manager.collection.CollectionSpec in project couchbase-jvm-clients by couchbase.
the class KeyValueCollectionIntegrationTest method recognizesCollectionAfterCreation.
@Test
@IgnoreWhen(clusterTypes = ClusterType.CAVES)
void recognizesCollectionAfterCreation() {
String collId = UUID.randomUUID().toString().substring(0, 10);
CollectionSpec collectionSpec = CollectionSpec.create(collId, CollectionIdentifier.DEFAULT_SCOPE);
bucket.collections().createCollection(collectionSpec);
Collection collection = bucket.collection(collId);
String id = UUID.randomUUID().toString();
String content = "bar";
MutationResult upsertResult = collection.upsert(id, content);
GetResult getResult = collection.get(id);
assertEquals(upsertResult.cas(), getResult.cas());
assertEquals(content, getResult.contentAs(String.class));
}
use of com.couchbase.client.java.manager.collection.CollectionSpec in project spring-data-couchbase by spring-projects.
the class JavaIntegrationTests method setupScopeCollection.
public static void setupScopeCollection(Cluster cluster, String scopeName, String collectionName, CollectionManager collectionManager) {
// Create the scope.collection (borrowed from CollectionManagerIntegrationTest )
ScopeSpec scopeSpec = ScopeSpec.create(scopeName);
CollectionSpec collSpec = CollectionSpec.create(collectionName, scopeName);
if (!scopeName.equals(CollectionIdentifier.DEFAULT_SCOPE)) {
try {
collectionManager.createScope(scopeName);
waitUntilCondition(() -> scopeExists(collectionManager, scopeName));
ScopeSpec found = collectionManager.getScope(scopeName);
assertEquals(scopeSpec, found);
} catch (CouchbaseException e) {
if (!e.toString().contains("already exists")) {
e.printStackTrace();
throw e;
}
}
}
try {
collectionManager.createCollection(collSpec);
} catch (CouchbaseException e) {
if (!e.toString().contains("already exists")) {
e.printStackTrace();
throw e;
}
}
waitUntilCondition(() -> collectionExists(collectionManager, collSpec));
waitUntilCondition(() -> collectionReady(cluster.bucket(config().bucketname()).scope(scopeName).collection(collectionName)));
assertNotEquals(scopeSpec, collectionManager.getScope(scopeName));
assertTrue(collectionManager.getScope(scopeName).collections().contains(collSpec));
waitForQueryIndexerToHaveBucket(cluster, collectionName);
try {
block(createPrimaryIndex(cluster, config().bucketname(), scopeName, collectionName));
} catch (Exception e) {
e.printStackTrace();
}
waitUntilCondition(() -> collectionReadyQuery(cluster.bucket(config().bucketname()).scope(scopeName), collectionName));
}
use of com.couchbase.client.java.manager.collection.CollectionSpec in project couchbase-jvm-clients by couchbase.
the class EventingFunctionManagerIntegrationTest method setup.
@BeforeAll
static void setup() {
cluster = Cluster.connect(seedNodes(), clusterOptions());
functions = cluster.eventingFunctions();
cluster.waitUntilReady(Duration.ofSeconds(5));
Bucket bucket = cluster.bucket(config().bucketname());
bucket.collections().createScope("eventing");
bucket.collections().createCollection(CollectionSpec.create("source", "eventing"));
bucket.collections().createCollection(CollectionSpec.create("meta", "eventing"));
sourceCollection = bucket.scope("eventing").collection("source");
metaCollection = bucket.scope("eventing").collection("meta");
waitUntilCondition(() -> bucket.collections().getAllScopes().stream().anyMatch(s -> {
if (s.name().equals("eventing")) {
boolean sourceFound = false;
boolean metaFound = false;
for (CollectionSpec c : s.collections()) {
if (c.name().equals("source")) {
sourceFound = true;
} else if (c.name().equals("meta")) {
metaFound = true;
}
}
return sourceFound && metaFound;
}
return false;
}));
}
use of com.couchbase.client.java.manager.collection.CollectionSpec in project couchbase-jvm-clients by couchbase.
the class RateLimitingIntegrationTest method searchQuotaLimitScopesMaxIndexes.
@Test
@IgnoreWhen(missesCapabilities = Capabilities.SEARCH)
void searchQuotaLimitScopesMaxIndexes() throws Exception {
String scopeName = "ratelimitSearch";
String collectionName = "searchCollection";
ScopeRateLimits limits = new ScopeRateLimits();
limits.fts = new SearchScopeRateLimit(1);
createLimitedScope(scopeName, config().bucketname(), limits);
CollectionManager collectionManager = adminCluster.bucket(config().bucketname()).collections();
Map<String, Object> params = mapOf("mapping", mapOf("types", mapOf(scopeName + "." + collectionName, mapOf("enabled", true, "dynamic", true)), "default_mapping", mapOf("enabled", false), "default_type", "_default", "default_analyzer", "standard", "default_field", "_all"), "doc_config", mapOf("mode", "scope.collection.type_field", "type_field", "type"));
try {
CollectionSpec collectionSpec = CollectionSpec.create(collectionName, scopeName);
collectionManager.createCollection(collectionSpec);
waitUntilCondition(() -> collectionExists(collectionManager, collectionSpec));
waitForService(adminCluster.bucket(config().bucketname()), ServiceType.SEARCH);
adminCluster.searchIndexes().upsertIndex(new SearchIndex("ratelimits1", config().bucketname()).params(params));
QuotaLimitedException ex = assertThrows(QuotaLimitedException.class, () -> adminCluster.searchIndexes().upsertIndex(new SearchIndex("ratelimits2", config().bucketname()).params(params)));
} finally {
collectionManager.dropScope(scopeName);
}
}
use of com.couchbase.client.java.manager.collection.CollectionSpec in project couchbase-jvm-clients by couchbase.
the class QueryCollectionIntegrationTest method beforeAll.
@BeforeAll
static void beforeAll() {
cluster = createCluster();
Bucket bucket = cluster.bucket(config().bucketname());
bucket.waitUntilReady(Duration.ofSeconds(5));
waitForService(bucket, ServiceType.QUERY);
waitForQueryIndexerToHaveKeyspace(cluster, config().bucketname());
collectionManager = bucket.collections();
// Create the scope.collection (borrowed from CollectionManagerIntegrationTest )
CollectionSpec collSpec = CollectionSpec.create(COLLECTION_NAME, SCOPE_NAME);
collectionManager.createScope(SCOPE_NAME);
waitUntilCondition(() -> scopeExists(collectionManager, SCOPE_NAME));
collectionManager.createCollection(collSpec);
waitUntilCondition(() -> collectionExists(collectionManager, collSpec));
waitForQueryIndexerToHaveKeyspace(cluster, COLLECTION_NAME);
// the call to createPrimaryIndex takes about 60 seconds
block(createPrimaryIndex(config().bucketname(), SCOPE_NAME, COLLECTION_NAME));
}
Aggregations