Search in sources :

Example 1 with CollectionManager

use of com.couchbase.client.java.manager.collection.CollectionManager in project couchbase-jvm-clients by couchbase.

the class RateLimitingIntegrationTest method scopeQuotaLimitExceedMaxCollections.

@Test
void scopeQuotaLimitExceedMaxCollections() throws Exception {
    String scopeName = "exceedMaxCollections";
    ScopeRateLimits limits = new ScopeRateLimits();
    limits.clusterManager = new ClusterManagerScopeRateLimit(1);
    createLimitedScope(scopeName, config().bucketname(), limits);
    CollectionManager collectionManager = adminCluster.bucket(config().bucketname()).collections();
    try {
        collectionManager.createCollection(CollectionSpec.create("collection1", scopeName));
        assertThrows(QuotaLimitedException.class, () -> collectionManager.createCollection(CollectionSpec.create("collection2", scopeName)));
    } finally {
        collectionManager.dropScope(scopeName);
    }
}
Also used : CollectionManager(com.couchbase.client.java.manager.collection.CollectionManager) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with CollectionManager

use of com.couchbase.client.java.manager.collection.CollectionManager in project couchbase-jvm-clients by couchbase.

the class RateLimitingIntegrationTest method kvQuotaLimitScopesDataSize.

@Test
void kvQuotaLimitScopesDataSize() throws Exception {
    String scopeName = "ratelimitDataSize2";
    ScopeRateLimits limits = new ScopeRateLimits();
    limits.kv = new KeyValueScopeRateLimit(1024 * 1024);
    createLimitedScope(scopeName, config().bucketname(), limits);
    CollectionManager collectionManager = adminCluster.bucket(config().bucketname()).collections();
    collectionManager.createCollection(CollectionSpec.create(scopeName, scopeName));
    Collection collection = adminCluster.bucket(config().bucketname()).scope(scopeName).collection(scopeName);
    try {
        collection.upsert("ratelimitkvscope", randomString(512));
        assertThrows(QuotaLimitedException.class, () -> collection.upsert("ratelimitkvscope", randomString(2048)));
    } finally {
        collectionManager.dropScope(scopeName);
    }
}
Also used : CollectionManager(com.couchbase.client.java.manager.collection.CollectionManager) JavaIntegrationTest(com.couchbase.client.java.util.JavaIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with CollectionManager

use of com.couchbase.client.java.manager.collection.CollectionManager in project spring-data-couchbase by spring-projects.

the class CollectionAwareIntegrationTests method beforeAll.

@BeforeAll
public static void beforeAll() {
    callSuperBeforeAll(new Object() {
    });
    ClusterEnvironment environment = environment().build();
    Cluster cluster = Cluster.connect(seedNodes(), ClusterOptions.clusterOptions(authenticator()).environment(environment));
    Bucket bucket = cluster.bucket(config().bucketname());
    bucket.waitUntilReady(Duration.ofSeconds(5));
    waitForService(bucket, ServiceType.QUERY);
    waitForQueryIndexerToHaveBucket(cluster, config().bucketname());
    CollectionManager collectionManager = bucket.collections();
    setupScopeCollection(cluster, scopeName, collectionName, collectionManager);
    setupScopeCollection(cluster, scopeName, collectionName2, collectionManager);
    if (otherScope != null || otherCollection != null) {
        // afterAll should be undoing the creation of scope etc
        setupScopeCollection(cluster, otherScope, otherCollection, collectionManager);
    }
    try {
        // needs an index for this N1ql Join
        // create index ix2 on my_bucket(parent_id) where `_class` = 'org.springframework.data.couchbase.domain.Address';
        List<String> fieldList = new ArrayList<>();
        fieldList.add("parentId");
        cluster.query("CREATE INDEX `parent_idx` ON default:" + bucketName() + "." + scopeName + "." + collectionName2 + "(parentId)");
    } catch (IndexExistsException ife) {
        LOGGER.warn("IndexFailureException occurred - ignoring: ", ife.toString());
    }
    Config.setScopeName(scopeName);
    ApplicationContext ac = new AnnotationConfigApplicationContext(Config.class);
    // the Config class has been modified, these need to be loaded again
    couchbaseTemplate = (CouchbaseTemplate) ac.getBean(COUCHBASE_TEMPLATE);
    reactiveCouchbaseTemplate = (ReactiveCouchbaseTemplate) ac.getBean(REACTIVE_COUCHBASE_TEMPLATE);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) ClusterEnvironment(com.couchbase.client.java.env.ClusterEnvironment) IndexExistsException(com.couchbase.client.core.error.IndexExistsException) Bucket(com.couchbase.client.java.Bucket) CollectionManager(com.couchbase.client.java.manager.collection.CollectionManager) ArrayList(java.util.ArrayList) Cluster(com.couchbase.client.java.Cluster) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with CollectionManager

use of com.couchbase.client.java.manager.collection.CollectionManager 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)

Aggregations

CollectionManager (com.couchbase.client.java.manager.collection.CollectionManager)4 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)3 Test (org.junit.jupiter.api.Test)3 IndexExistsException (com.couchbase.client.core.error.IndexExistsException)1 QuotaLimitedException (com.couchbase.client.core.error.QuotaLimitedException)1 Bucket (com.couchbase.client.java.Bucket)1 Cluster (com.couchbase.client.java.Cluster)1 ClusterEnvironment (com.couchbase.client.java.env.ClusterEnvironment)1 JsonObject (com.couchbase.client.java.json.JsonObject)1 CollectionSpec (com.couchbase.client.java.manager.collection.CollectionSpec)1 SearchIndex (com.couchbase.client.java.manager.search.SearchIndex)1 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)1 ArrayList (java.util.ArrayList)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 ApplicationContext (org.springframework.context.ApplicationContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1