Search in sources :

Example 1 with CollectionSpec

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));
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) CollectionSpec(com.couchbase.client.java.manager.collection.CollectionSpec) 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 2 with CollectionSpec

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));
}
Also used : ScopeSpec(com.couchbase.client.java.manager.collection.ScopeSpec) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) CollectionSpec(com.couchbase.client.java.manager.collection.CollectionSpec) UnambiguousTimeoutException(com.couchbase.client.core.error.UnambiguousTimeoutException) IndexExistsException(com.couchbase.client.core.error.IndexExistsException) ParsingFailureException(com.couchbase.client.core.error.ParsingFailureException) DocumentNotFoundException(com.couchbase.client.core.error.DocumentNotFoundException) CollectionNotFoundException(com.couchbase.client.core.error.CollectionNotFoundException) CouchbaseException(com.couchbase.client.core.error.CouchbaseException) QueryException(com.couchbase.client.core.error.QueryException) ScopeNotFoundException(com.couchbase.client.core.error.ScopeNotFoundException) IOException(java.io.IOException)

Example 3 with CollectionSpec

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;
    }));
}
Also used : JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Util.waitUntilCondition(com.couchbase.client.test.Util.waitUntilCondition) Capabilities(com.couchbase.client.test.Capabilities) CollectionSpec(com.couchbase.client.java.manager.collection.CollectionSpec) ClusterType(com.couchbase.client.test.ClusterType) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) UUID(java.util.UUID) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) Collection(com.couchbase.client.java.Collection) Bucket(com.couchbase.client.java.Bucket) BeforeAll(org.junit.jupiter.api.BeforeAll) AssertionFailedError(org.opentest4j.AssertionFailedError) Cluster(com.couchbase.client.java.Cluster) Duration(java.time.Duration) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) com.couchbase.client.core.error(com.couchbase.client.core.error) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Bucket(com.couchbase.client.java.Bucket) CollectionSpec(com.couchbase.client.java.manager.collection.CollectionSpec) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with CollectionSpec

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);
    }
}
Also used : QuotaLimitedException(com.couchbase.client.core.error.QuotaLimitedException) CollectionManager(com.couchbase.client.java.manager.collection.CollectionManager) CollectionSpec(com.couchbase.client.java.manager.collection.CollectionSpec) SearchIndex(com.couchbase.client.java.manager.search.SearchIndex) JsonObject(com.couchbase.client.java.json.JsonObject) IgnoreWhen(com.couchbase.client.test.IgnoreWhen) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with CollectionSpec

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));
}
Also used : CollectionSpec(com.couchbase.client.java.manager.collection.CollectionSpec) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

CollectionSpec (com.couchbase.client.java.manager.collection.CollectionSpec)6 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)3 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)3 BeforeAll (org.junit.jupiter.api.BeforeAll)3 Test (org.junit.jupiter.api.Test)3 IndexExistsException (com.couchbase.client.core.error.IndexExistsException)2 com.couchbase.client.core.error (com.couchbase.client.core.error)1 CollectionNotFoundException (com.couchbase.client.core.error.CollectionNotFoundException)1 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)1 DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)1 ParsingFailureException (com.couchbase.client.core.error.ParsingFailureException)1 QueryException (com.couchbase.client.core.error.QueryException)1 QuotaLimitedException (com.couchbase.client.core.error.QuotaLimitedException)1 ScopeNotFoundException (com.couchbase.client.core.error.ScopeNotFoundException)1 UnambiguousTimeoutException (com.couchbase.client.core.error.UnambiguousTimeoutException)1 Bucket (com.couchbase.client.java.Bucket)1 Cluster (com.couchbase.client.java.Cluster)1 Collection (com.couchbase.client.java.Collection)1 JsonObject (com.couchbase.client.java.json.JsonObject)1 GetResult (com.couchbase.client.java.kv.GetResult)1