Bump couchbase sdk to 3_4_3. (#1663)

Requires some refactoring around @Stability.Internal APIs.
Also fixed a test to get it to pass.

Closes #1661,#1662.
This commit is contained in:
Michael Reiche
2023-02-17 14:03:44 -08:00
committed by GitHub
parent ddd19744d8
commit 02afaeef8d
7 changed files with 80 additions and 51 deletions

View File

@@ -55,7 +55,7 @@ import com.couchbase.client.java.query.QueryOptions;
import com.couchbase.client.java.query.QueryScanConsistency;
/**
* KV tests Theses tests rely on a cb server running.
* KV test - these tests rely on a cb server running.
*
* @author Michael Nitschinger
* @author Michael Reiche
@@ -81,11 +81,11 @@ class CouchbaseTemplateKeyValueIntegrationTests extends JavaIntegrationTests {
@Test
void findByIdWithLock() {
try {
User user = new User(UUID.randomUUID().toString(), "user1", "user1");
User user = new User("1", "user1", "user1");
couchbaseTemplate.upsertById(User.class).one(user);
User foundUser = couchbaseTemplate.findById(User.class).withLock(Duration.ofSeconds(2)).one(user.getId());
User foundUser = couchbaseTemplate.findById(User.class).withLock(Duration.ofSeconds(5)).one(user.getId());
user.setVersion(foundUser.getVersion());// version will have changed
assertEquals(user, foundUser);
@@ -94,8 +94,15 @@ class CouchbaseTemplateKeyValueIntegrationTests extends JavaIntegrationTests {
);
assertTrue(exception.retryReasons().contains(RetryReason.KV_LOCKED), "should have been locked");
} finally {
sleepSecs(2);
couchbaseTemplate.removeByQuery(User.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).all();
for(int i=0; i< 10; i++) {
sleepSecs(2);
try {
couchbaseTemplate.removeByQuery(User.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).all();
break;
} catch (Exception e) {
e.printStackTrace(); // gives IndexFailureException if the lock is still active
}
}
}
}

View File

@@ -25,6 +25,8 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import com.couchbase.client.core.deps.com.fasterxml.jackson.databind.node.ArrayNode;
import com.couchbase.client.java.query.QueryOptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.couchbase.core.convert.CouchbaseConverter;
@@ -32,6 +34,7 @@ import org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter
import org.springframework.data.couchbase.core.mapping.CouchbaseMappingContext;
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentEntity;
import org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty;
import org.springframework.data.couchbase.core.query.OptionsBuilder;
import org.springframework.data.couchbase.core.query.Query;
import org.springframework.data.couchbase.domain.Person;
import org.springframework.data.couchbase.domain.PersonRepository;
@@ -119,18 +122,17 @@ class N1qlQueryCreatorTests {
QueryMethod queryMethod = new QueryMethod(method, new DefaultRepositoryMetadata(UserRepository.class),
new SpelAwareProxyProjectionFactory());
Query expected = (new Query()).addCriteria(where(i("firstname")).in("Oliver", "Charles"));
JsonArray parameters = JsonArray.create().add(JsonArray.create().add("Oliver").add("Charles"));
QueryOptions expectedQOptions = QueryOptions.queryOptions().parameters(parameters);
N1qlQueryCreator creator = new N1qlQueryCreator(tree,
getAccessor(getParameters(method), new Object[] { new Object[] { "Oliver", "Charles" } }), queryMethod,
converter, bucketName);
Query query = creator.createQuery();
// Query expected = (new Query()).addCriteria(where("firstname").in("Oliver", "Charles"));
assertEquals(" WHERE `firstname` in $1", query.export(new int[1]));
JsonObject expectedOptions = JsonObject.create();
expected.buildQueryOptions(null, null).build().injectParams(expectedOptions);
JsonObject actualOptions = JsonObject.create();
expected.buildQueryOptions(null, null).build().injectParams(actualOptions);
assertEquals(expectedOptions.removeKey("client_context_id"), actualOptions.removeKey("client_context_id"));
ArrayNode expectedOptions = expected.buildQueryOptions(expectedQOptions, null).build().positionalParameters();
ArrayNode actualOptions = query.buildQueryOptions(null, null).build().positionalParameters();
assertEquals(expectedOptions.toString(), actualOptions.toString());
}
@Test
@@ -148,12 +150,12 @@ class N1qlQueryCreatorTests {
Query query = creator.createQuery();
Query expected = (new Query()).addCriteria(where(i("firstname")).in("Oliver", "Charles"));
JsonArray parameters = JsonArray.create().add(JsonArray.create().add("Oliver").add("Charles"));
QueryOptions expectedQOptions = QueryOptions.queryOptions().parameters(parameters);
assertEquals(" WHERE `firstname` in $1", query.export(new int[1]));
JsonObject expectedOptions = JsonObject.create();
expected.buildQueryOptions(null, null).build().injectParams(expectedOptions);
JsonObject actualOptions = JsonObject.create();
expected.buildQueryOptions(null, null).build().injectParams(actualOptions);
assertEquals(expectedOptions.removeKey("client_context_id"), actualOptions.removeKey("client_context_id"));
ArrayNode expectedOptions = expected.buildQueryOptions(expectedQOptions, null).build().positionalParameters();
ArrayNode actualOptions = query.buildQueryOptions(null, null).build().positionalParameters();
assertEquals(expectedOptions.toString(), actualOptions.toString());
}
@Test
@@ -171,13 +173,13 @@ class N1qlQueryCreatorTests {
Query query = creator.createQuery();
Query expected = (new Query()).addCriteria(where(i("firstname")).in("Oliver", "Charles"));
JsonArray parameters = JsonArray.create().add(JsonArray.create().add("Oliver").add("Charles"));
QueryOptions expectedQOptions = QueryOptions.queryOptions().parameters(parameters);
assertEquals(" WHERE `firstname` in $1", query.export(new int[1]));
JsonObject expectedOptions = JsonObject.create();
expected.buildQueryOptions(null, null).build().injectParams(expectedOptions);
JsonObject actualOptions = JsonObject.create();
expected.buildQueryOptions(null, null).build().injectParams(actualOptions);
assertEquals(expectedOptions.removeKey("client_context_id"), actualOptions.removeKey("client_context_id"));
ArrayNode expectedOptions = expected.buildQueryOptions(expectedQOptions, null).build().positionalParameters();
ArrayNode actualOptions = query.buildQueryOptions(null, null).build().positionalParameters();
assertEquals(expectedOptions.toString(), actualOptions.toString());
}
@Test

View File

@@ -285,7 +285,7 @@ public class JavaIntegrationTests extends ClusterAwareIntegrationTests {
options.timeout(Duration.ofSeconds(300));
options.ignoreIfExists(true);
final CreatePrimaryQueryIndexOptions.Built builtOpts = options.build();
final String indexName = builtOpts.indexName().orElse(null);
final String indexName = builtOpts.indexName();
String keyspace = "default:`" + bucketName + "`.`" + scopeName + "`.`" + collectionName + "`";
String statement = "CREATE PRIMARY INDEX ";