Have tests remove the documents they insert. (#1336)

Closes #1335.
This commit is contained in:
Michael Reiche
2022-02-09 21:56:22 -08:00
committed by GitHub
parent ede82d65ff
commit e20ebae10e
9 changed files with 173 additions and 118 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors
* Copyright 2012-2022 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.time.Duration;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
@@ -289,13 +288,16 @@ class CouchbaseTemplateKeyValueIntegrationTests extends JavaIntegrationTests {
User found = couchbaseTemplate.findById(user.getClass()).one(user.getId());
if (user.getId().endsWith(UserAnnotated3.class.getSimpleName())) {
if (found == null) {
errorList.add("\nfound should be non null as it was set to have no expiry " + user.getId() );
errorList.add("\nfound should be non null as it was set to have no expiry " + user.getId());
}
} else {
if (found != null) {
errorList.add("\nfound should have been null as document should be expired " + user.getId());
}
}
if (found != null) {
couchbaseTemplate.removeById(user.getClass()).one(user.getId());
}
}
if (!errorList.isEmpty()) {
@@ -310,7 +312,7 @@ class CouchbaseTemplateKeyValueIntegrationTests extends JavaIntegrationTests {
@Test
void upsertAndReplaceById() {
User user = new User(UUID.randomUUID().toString(), "firstname", "lastname");
User user = new User(UUID.randomUUID().toString(), "firstname_upsertAndReplaceById", "lastname");
User modified = couchbaseTemplate.upsertById(User.class).one(user);
assertEquals(user, modified);
@@ -335,7 +337,6 @@ class CouchbaseTemplateKeyValueIntegrationTests extends JavaIntegrationTests {
assertEquals(user.getId(), removeResult.getId());
assertTrue(removeResult.getCas() != 0);
assertTrue(removeResult.getMutationToken().isPresent());
assertNull(couchbaseTemplate.findById(User.class).one(user.getId()));
}
{
@@ -360,6 +361,7 @@ class CouchbaseTemplateKeyValueIntegrationTests extends JavaIntegrationTests {
User inserted = couchbaseTemplate.insertById(User.class).one(user);
assertEquals(user, inserted);
assertThrows(DuplicateKeyException.class, () -> couchbaseTemplate.insertById(User.class).one(user));
couchbaseTemplate.removeById(User.class).one(user.getId());
}
@Test
@@ -384,6 +386,7 @@ class CouchbaseTemplateKeyValueIntegrationTests extends JavaIntegrationTests {
}
assertEquals(user, inserted);
assertThrows(DuplicateKeyException.class, () -> couchbaseTemplate.insertById(User.class).one(user));
couchbaseTemplate.removeById(User.class).one(user.getId());
}
@Test
@@ -395,12 +398,13 @@ class CouchbaseTemplateKeyValueIntegrationTests extends JavaIntegrationTests {
User inserted = couchbaseTemplate.insertById(User.class).one(user);
assertEquals(user, inserted);
assertTrue(couchbaseTemplate.existsById().one(id));
couchbaseTemplate.removeById(User.class).one(user.getId());
}
@Test
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
void saveAndFindImmutableById() {
PersonValue personValue = new PersonValue(UUID.randomUUID().toString(), 123, "f", "l");
PersonValue personValue = new PersonValue(UUID.randomUUID().toString(), 123, "408", "l");
PersonValue inserted = null;
PersonValue upserted = null;
PersonValue replaced = null;
@@ -431,7 +435,7 @@ class CouchbaseTemplateKeyValueIntegrationTests extends JavaIntegrationTests {
PersonValue foundReplaced = couchbaseTemplate.findById(PersonValue.class).one(replaced.getId());
assertNotNull(foundReplaced, "replaced personValue not found");
assertEquals(replaced, foundReplaced);
couchbaseTemplate.removeById(PersonValue.class).one(replaced.getId());
}
private void sleepSecs(int i) {

View File

@@ -103,13 +103,16 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
// first call the super method
super.beforeEach();
// then do processing for this class
couchbaseTemplate.removeByQuery(User.class).inCollection(collectionName).all();
couchbaseTemplate.removeByQuery(User.class).withConsistency(QueryScanConsistency.REQUEST_PLUS)
.inCollection(collectionName).all();
couchbaseTemplate.findByQuery(User.class).withConsistency(QueryScanConsistency.REQUEST_PLUS)
.inCollection(collectionName).all();
couchbaseTemplate.removeByQuery(Airport.class).inScope(scopeName).inCollection(collectionName).all();
couchbaseTemplate.removeByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName)
.inCollection(collectionName).all();
couchbaseTemplate.findByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName)
.inCollection(collectionName).all();
couchbaseTemplate.removeByQuery(Airport.class).inScope(otherScope).inCollection(otherCollection).all();
couchbaseTemplate.removeByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS)
.inScope(otherScope).inCollection(otherCollection).all();
couchbaseTemplate.findByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(otherScope)
.inCollection(otherCollection).all();
}
@@ -355,7 +358,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
assertEquals(2, count1);
// count (distinct { iata, icao } )
Long count2 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] {"iata", "icao"})
Long count2 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] { "iata", "icao" })
.withConsistency(QueryScanConsistency.REQUEST_PLUS).inCollection(collectionName).count().block();
assertEquals(7, count2);
@@ -384,7 +387,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
ExistsOptions existsOptions = ExistsOptions.existsOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName)
.one(vie);
.one(vie.withIcao("398"));
try {
Boolean exists = couchbaseTemplate.existsById().inScope(scopeName).inCollection(collectionName)
.withOptions(existsOptions).one(saved.getId());
@@ -399,7 +402,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
public void findByAnalytics() { // 2
AnalyticsOptions options = AnalyticsOptions.analyticsOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName)
.one(vie);
.one(vie.withIcao("413"));
try {
List<Airport> found = couchbaseTemplate.findByAnalytics(Airport.class).inScope(scopeName)
.inCollection(collectionName).withOptions(options).all();
@@ -413,7 +416,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
public void findById() { // 3
GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName)
.one(vie);
.one(vie.withIcao("427"));
try {
Airport found = couchbaseTemplate.findById(Airport.class).inScope(scopeName).inCollection(collectionName)
.withOptions(options).one(saved.getId());
@@ -427,7 +430,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
public void findByQuery() { // 4
QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName)
.one(vie);
.one(vie.withIcao("441"));
try {
List<Airport> found = couchbaseTemplate.findByQuery(Airport.class)
.withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName).inCollection(collectionName)
@@ -442,7 +445,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
public void findFromReplicasById() { // 5
GetAnyReplicaOptions options = GetAnyReplicaOptions.getAnyReplicaOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName)
.one(vie);
.one(vie.withIcao("456"));
try {
Airport found = couchbaseTemplate.findFromReplicasById(Airport.class).inScope(scopeName)
.inCollection(collectionName).withOptions(options).any(saved.getId());
@@ -471,7 +474,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
public void removeById() { // 7
RemoveOptions options = RemoveOptions.removeOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName)
.one(vie);
.one(vie.withIcao("485"));
RemoveResult removeResult = couchbaseTemplate.removeById().inScope(scopeName).inCollection(collectionName)
.withOptions(options).one(saved.getId());
assertEquals(saved.getId(), removeResult.getId());
@@ -481,7 +484,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
public void removeByQuery() { // 8
QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName)
.one(vie);
.one(vie.withIcao("495"));
List<RemoveResult> removeResults = couchbaseTemplate.removeByQuery(Airport.class)
.withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName).inCollection(collectionName)
.withOptions(options).matching(Query.query(QueryCriteria.where("iata").is(vie.getIata()))).all();
@@ -494,7 +497,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
ReplaceOptions options = ReplaceOptions.replaceOptions().timeout(Duration.ofSeconds(10));
GetOptions getOptions = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName)
.withOptions(insertOptions).one(vie);
.withOptions(insertOptions).one(vie.withIcao("508"));
Airport replaced = couchbaseTemplate.replaceById(Airport.class).inScope(scopeName).inCollection(collectionName)
.withOptions(options).one(vie.withIcao("newIcao"));
try {
@@ -512,7 +515,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
GetOptions getOptions = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.upsertById(Airport.class).inScope(scopeName).inCollection(collectionName)
.withOptions(options).one(vie);
.withOptions(options).one(vie.withIcao("526"));
try {
Airport found = couchbaseTemplate.findById(Airport.class).inScope(scopeName).inCollection(collectionName)
.withOptions(getOptions).one(saved.getId());
@@ -527,13 +530,14 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
ExistsOptions existsOptions = ExistsOptions.existsOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie);
.one(vie.withIcao("lowg"));
try {
Boolean exists = couchbaseTemplate.existsById().inScope(otherScope).inCollection(otherCollection)
.withOptions(existsOptions).one(saved.getId());
assertTrue(exists, "Airport should exist: " + saved.getId());
.withOptions(existsOptions).one(vie.getId());
assertTrue(exists, "Airport should exist: " + vie.getId());
} finally {
couchbaseTemplate.removeById().inScope(otherScope).inCollection(otherCollection).one(saved.getId());
couchbaseTemplate.removeById().inScope(otherScope).inCollection(otherCollection).one(vie.getId());
}
}
@@ -542,7 +546,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
public void findByAnalyticsOther() { // 2
AnalyticsOptions options = AnalyticsOptions.analyticsOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie);
.one(vie.withIcao("566"));
try {
List<Airport> found = couchbaseTemplate.findByAnalytics(Airport.class).inScope(otherScope)
.inCollection(otherCollection).withOptions(options).all();
@@ -556,7 +560,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
public void findByIdOther() { // 3
GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie);
.one(vie.withIcao("580"));
try {
Airport found = couchbaseTemplate.findById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.withOptions(options).one(saved.getId());
@@ -570,7 +574,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
public void findByQueryOther() { // 4
QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie);
.one(vie.withIcao("594"));
try {
List<Airport> found = couchbaseTemplate.findByQuery(Airport.class)
.withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(otherScope).inCollection(otherCollection)
@@ -585,7 +589,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
public void findFromReplicasByIdOther() { // 5
GetAnyReplicaOptions options = GetAnyReplicaOptions.getAnyReplicaOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie);
.one(vie.withIcao("609"));
try {
Airport found = couchbaseTemplate.findFromReplicasById(Airport.class).inScope(otherScope)
.inCollection(otherCollection).withOptions(options).any(saved.getId());
@@ -614,7 +618,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
public void removeByIdOther() { // 7
RemoveOptions options = RemoveOptions.removeOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie);
.one(vie.withIcao("638"));
RemoveResult removeResult = couchbaseTemplate.removeById().inScope(otherScope).inCollection(otherCollection)
.withOptions(options).one(saved.getId());
assertEquals(saved.getId(), removeResult.getId());
@@ -624,7 +628,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
public void removeByQueryOther() { // 8
QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie);
.one(vie.withIcao("648"));
List<RemoveResult> removeResults = couchbaseTemplate.removeByQuery(Airport.class)
.withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(otherScope).inCollection(otherCollection)
.withOptions(options).matching(Query.query(QueryCriteria.where("iata").is(vie.getIata()))).all();
@@ -637,7 +641,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
ReplaceOptions options = ReplaceOptions.replaceOptions().timeout(Duration.ofSeconds(10));
GetOptions getOptions = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.withOptions(insertOptions).one(vie);
.withOptions(insertOptions).one(vie.withIcao("661"));
Airport replaced = couchbaseTemplate.replaceById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.withOptions(options).one(vie.withIcao("newIcao"));
try {
@@ -655,7 +659,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
GetOptions getOptions = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.upsertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.withOptions(options).one(vie);
.withOptions(options).one(vie.withIcao("679"));
try {
Airport found = couchbaseTemplate.findById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.withOptions(getOptions).one(saved.getId());
@@ -699,7 +703,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
public void findFromReplicasByIdOptions() { // 5
GetAnyReplicaOptions options = GetAnyReplicaOptions.getAnyReplicaOptions().timeout(Duration.ofNanos(1000));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie);
.one(vie.withIcao("723"));
try {
Airport found = couchbaseTemplate.findFromReplicasById(Airport.class).inScope(otherScope)
.inCollection(otherCollection).withOptions(options).any(saved.getId());
@@ -719,7 +723,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
@Test
public void removeByIdOptions() { // 7 - options
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie);
.one(vie.withIcao("743"));
RemoveOptions options = RemoveOptions.removeOptions().timeout(Duration.ofNanos(10));
assertThrows(AmbiguousTimeoutException.class, () -> couchbaseTemplate.removeById().inScope(otherScope)
.inCollection(otherCollection).withOptions(options).one(vie.getId()));
@@ -746,7 +750,7 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
public void upsertByIdOptions() { // 10 - options
UpsertOptions options = UpsertOptions.upsertOptions().timeout(Duration.ofNanos(10));
assertThrows(AmbiguousTimeoutException.class, () -> couchbaseTemplate.upsertById(Airport.class).inScope(otherScope)
.inCollection(otherCollection).withOptions(options).one(vie));
.inCollection(otherCollection).withOptions(options).one(vie.withIcao("770")));
}
@Test

View File

@@ -31,7 +31,6 @@ import java.util.Locale;
import java.util.UUID;
import java.util.stream.Collectors;
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.query.Query;
@@ -51,8 +50,6 @@ import org.springframework.data.couchbase.util.Capabilities;
import org.springframework.data.couchbase.util.ClusterType;
import org.springframework.data.couchbase.util.IgnoreWhen;
import org.springframework.data.couchbase.util.JavaIntegrationTests;
import com.couchbase.client.java.query.QueryScanConsistency;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
@@ -90,8 +87,7 @@ class CouchbaseTemplateQueryIntegrationTests extends JavaIntegrationTests {
couchbaseTemplate.upsertById(User.class).all(Arrays.asList(user1, user2));
final List<User> foundUsers = couchbaseTemplate.findByQuery(User.class)
.withConsistency(REQUEST_PLUS).all();
final List<User> foundUsers = couchbaseTemplate.findByQuery(User.class).withConsistency(REQUEST_PLUS).all();
for (User u : foundUsers) {
if (!(u.equals(user1) || u.equals(user2))) {
@@ -133,8 +129,8 @@ class CouchbaseTemplateQueryIntegrationTests extends JavaIntegrationTests {
couchbaseTemplate.upsertById(User.class).all(Arrays.asList(user1, user2, specialUser));
Query specialUsers = new Query(QueryCriteria.where(i("firstname")).like("special"));
final List<User> foundUsers = couchbaseTemplate.findByQuery(User.class)
.withConsistency(REQUEST_PLUS).matching(specialUsers).all();
final List<User> foundUsers = couchbaseTemplate.findByQuery(User.class).withConsistency(REQUEST_PLUS)
.matching(specialUsers).all();
assertEquals(1, foundUsers.size());
}
@@ -152,6 +148,7 @@ class CouchbaseTemplateQueryIntegrationTests extends JavaIntegrationTests {
assertEquals("123", foundUsers.get(0).getId(), "id");
assertEquals("44444444", foundUsers.get(0).getDocumentId(), "documentId");
assertEquals(ado, foundUsers.get(0));
couchbaseTemplate.removeById(AssessmentDO.class).one(ado.getDocumentId());
}
@Test
@@ -196,10 +193,10 @@ class CouchbaseTemplateQueryIntegrationTests extends JavaIntegrationTests {
assertEquals(1, foundUsers.size());
final List<UserJustLastName> foundUsersReactive = reactiveCouchbaseTemplate.findByQuery(User.class)
.as(UserJustLastName.class).withConsistency(REQUEST_PLUS).matching(specialUsers).all()
.collectList().block();
.as(UserJustLastName.class).withConsistency(REQUEST_PLUS).matching(specialUsers).all().collectList().block();
assertEquals(1, foundUsersReactive.size());
couchbaseTemplate.removeById(User.class).all(Arrays.asList(user1.getId(), user2.getId(), specialUser.getId()));
}
@Test
@@ -233,8 +230,7 @@ class CouchbaseTemplateQueryIntegrationTests extends JavaIntegrationTests {
Query nonSpecialUsers = new Query(QueryCriteria.where(i("firstname")).notLike("special"));
couchbaseTemplate.removeByQuery(User.class).withConsistency(REQUEST_PLUS)
.matching(nonSpecialUsers).all();
couchbaseTemplate.removeByQuery(User.class).withConsistency(REQUEST_PLUS).matching(nonSpecialUsers).all();
assertNull(couchbaseTemplate.findById(User.class).one(user1.getId()));
assertNull(couchbaseTemplate.findById(User.class).one(user2.getId()));
@@ -324,24 +320,27 @@ class CouchbaseTemplateQueryIntegrationTests extends JavaIntegrationTests {
String[] iatas = { "JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX" };
try {
couchbaseTemplate.insertById(Airport.class).all(
Arrays.stream(iatas).map((iata) -> new Airport("airports::" + iata, iata, iata.toLowerCase(Locale.ROOT)))
couchbaseTemplate.insertById(Airport.class)
.all(Arrays.stream(iatas).map((iata) -> new Airport("airports::" + iata, iata, iata.toLowerCase(Locale.ROOT)))
.collect(Collectors.toSet()));
org.springframework.data.couchbase.core.query.Query query = org.springframework.data.couchbase.core.query.Query.query(QueryCriteria.where("iata").isNotNull());
org.springframework.data.couchbase.core.query.Query query = org.springframework.data.couchbase.core.query.Query
.query(QueryCriteria.where("iata").isNotNull());
Pageable pageableWithSort = PageRequest.of(0, 7, Sort.by("iata"));
query.with(pageableWithSort);
List<Airport> airports = couchbaseTemplate.findByQuery(Airport.class).withConsistency(REQUEST_PLUS).matching(query).all();
List<Airport> airports = couchbaseTemplate.findByQuery(Airport.class).withConsistency(REQUEST_PLUS)
.matching(query).all();
String[] sortedIatas = iatas.clone();
System.out.println(""+iatas.length+" "+sortedIatas.length);
System.out.println("" + iatas.length + " " + sortedIatas.length);
Arrays.sort(sortedIatas);
for(int i=0; i< pageableWithSort.getPageSize(); i++){
for (int i = 0; i < pageableWithSort.getPageSize(); i++) {
System.out.println(airports.get(i).getIata());
assertEquals(sortedIatas[i], airports.get(i).getIata());
}
} finally {
couchbaseTemplate.removeById(Airport.class).all(Arrays.stream(iatas).map((iata) -> "airports::" + iata).collect(Collectors.toSet()));
couchbaseTemplate.removeById(Airport.class)
.all(Arrays.stream(iatas).map((iata) -> "airports::" + iata).collect(Collectors.toSet()));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors
* Copyright 2012-2022 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,6 +37,9 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import com.couchbase.client.java.kv.GetResult;
/**
* @author Michael Reiche
*/
@SpringJUnitConfig(CustomTypeKeyIntegrationTests.Config.class)
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
public class CustomTypeKeyIntegrationTests extends ClusterAwareIntegrationTests {
@@ -62,6 +65,7 @@ public class CustomTypeKeyIntegrationTests extends ClusterAwareIntegrationTests
assertEquals("org.springframework.data.couchbase.domain.User",
getResult.contentAsObject().getString(CUSTOM_TYPE_KEY));
assertFalse(getResult.contentAsObject().containsKey(DefaultCouchbaseTypeMapper.DEFAULT_TYPE_KEY));
operations.removeById(User.class).one(user.getId());
}
@Configuration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors
* Copyright 2012-2022 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -232,6 +232,9 @@ class ReactiveCouchbaseTemplateKeyValueIntegrationTests extends JavaIntegrationT
errorList.add("\nfound should have been null as document should be expired " + user.getId());
}
}
if (found != null) {
couchbaseTemplate.removeById(user.getClass()).one(user.getId());
}
}
if (!errorList.isEmpty()) {
@@ -323,7 +326,7 @@ class ReactiveCouchbaseTemplateKeyValueIntegrationTests extends JavaIntegrationT
@Test
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
void saveAndFindImmutableById() {
PersonValue personValue = new PersonValue(UUID.randomUUID().toString(), 123, "f", "l");
PersonValue personValue = new PersonValue(UUID.randomUUID().toString(), 123, "329", "l");
PersonValue inserted;
PersonValue upserted;
PersonValue replaced;
@@ -354,7 +357,7 @@ class ReactiveCouchbaseTemplateKeyValueIntegrationTests extends JavaIntegrationT
PersonValue foundReplaced = reactiveCouchbaseTemplate.findById(PersonValue.class).one(replaced.getId()).block();
assertNotNull(foundReplaced, "replaced personValue not found");
assertEquals(replaced, foundReplaced);
couchbaseTemplate.removeById(PersonValue.class).one(replaced.getId());
}
private void sleepSecs(int i) {

View File

@@ -76,7 +76,7 @@ import com.couchbase.client.java.query.QueryScanConsistency;
@IgnoreWhen(missesCapabilities = { Capabilities.QUERY, Capabilities.COLLECTIONS }, clusterTypes = ClusterType.MOCKED)
class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIntegrationTests {
Airport vie = new Airport("airports::vie", "vie", "low7");
Airport vie = new Airport("airports::vie", "vie", "low80");
ReactiveCouchbaseTemplate template = reactiveCouchbaseTemplate;
@BeforeAll
@@ -101,13 +101,16 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
// first call the super method
super.beforeEach();
// then do processing for this class
couchbaseTemplate.removeByQuery(User.class).inCollection(collectionName).all();
couchbaseTemplate.removeByQuery(User.class).withConsistency(QueryScanConsistency.REQUEST_PLUS)
.inCollection(collectionName).all();
couchbaseTemplate.findByQuery(User.class).withConsistency(QueryScanConsistency.REQUEST_PLUS)
.inCollection(collectionName).all();
couchbaseTemplate.removeByQuery(Airport.class).inScope(scopeName).inCollection(collectionName).all();
couchbaseTemplate.removeByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName)
.inCollection(collectionName).all();
couchbaseTemplate.findByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName)
.inCollection(collectionName).all();
couchbaseTemplate.removeByQuery(Airport.class).inScope(otherScope).inCollection(otherCollection).all();
couchbaseTemplate.removeByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS)
.inScope(otherScope).inCollection(otherCollection).all();
couchbaseTemplate.findByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(otherScope)
.inCollection(otherCollection).all();
}
@@ -350,7 +353,7 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
assertEquals(2, count1);
// count( distinct { iata, icao } )
Long count2 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] {"iata","icao"})
Long count2 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] { "iata", "icao" })
.withConsistency(QueryScanConsistency.REQUEST_PLUS).inCollection(collectionName).count().block();
assertEquals(7, count2);
@@ -378,7 +381,8 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
public void existsById() { // 1
GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
ExistsOptions existsOptions = ExistsOptions.existsOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("low7")).block();
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName)
.one(vie.withIcao("low7")).block();
try {
Boolean exists = template.existsById().inScope(scopeName).inCollection(collectionName).withOptions(existsOptions)
.one(saved.getId()).block();
@@ -392,7 +396,8 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
@Disabled // needs analytics data set
public void findByAnalytics() { // 2
AnalyticsOptions options = AnalyticsOptions.analyticsOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("low8")).block();
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName)
.one(vie.withIcao("low8")).block();
try {
List<Airport> found = template.findByAnalytics(Airport.class).inScope(scopeName).inCollection(collectionName)
.withOptions(options).all().collectList().block();
@@ -405,7 +410,8 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
@Test
public void findById() { // 3
GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("low9")).block();
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName)
.one(vie.withIcao("low9")).block();
try {
Airport found = template.findById(Airport.class).inScope(scopeName).inCollection(collectionName)
.withOptions(options).one(saved.getId()).block();
@@ -418,7 +424,8 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
@Test
public void findByQuery() { // 4
QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("lowa")).block();
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName)
.one(vie.withIcao("lowa")).block();
try {
List<Airport> found = template.findByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS)
.inScope(scopeName).inCollection(collectionName).withOptions(options).all().collectList().block();
@@ -431,7 +438,8 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
@Test
public void findFromReplicasById() { // 5
GetAnyReplicaOptions options = GetAnyReplicaOptions.getAnyReplicaOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("lowb")).block();
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName)
.one(vie.withIcao("lowb")).block();
try {
Airport found = template.findFromReplicasById(Airport.class).inScope(scopeName).inCollection(collectionName)
.withOptions(options).any(saved.getId()).block();
@@ -459,7 +467,8 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
@Test
public void removeById() { // 7
RemoveOptions options = RemoveOptions.removeOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("lowd")).block();
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName)
.one(vie.withIcao("lowd")).block();
RemoveResult removeResult = template.removeById().inScope(scopeName).inCollection(collectionName)
.withOptions(options).one(saved.getId()).block();
assertEquals(saved.getId(), removeResult.getId());
@@ -468,7 +477,8 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
@Test
public void removeByQuery() { // 8
QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("lowe")).block();
Airport saved = template.insertById(Airport.class).inScope(scopeName).inCollection(collectionName)
.one(vie.withIcao("lowe")).block();
List<RemoveResult> removeResults = template.removeByQuery(Airport.class)
.withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(scopeName).inCollection(collectionName)
.withOptions(options).matching(Query.query(QueryCriteria.where("iata").is(vie.getIata()))).all().collectList()
@@ -514,14 +524,15 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
public void existsByIdOther() { // 1
GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
ExistsOptions existsOptions = ExistsOptions.existsOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lowg"))
.block();
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie.withIcao("lowg")).block();
try {
Boolean exists = template.existsById().inScope(otherScope).inCollection(otherCollection)
.withOptions(existsOptions).one(saved.getId()).block();
assertTrue(exists, "Airport should exist: " + saved.getId());
.withOptions(existsOptions).one(vie.getId()).block();
assertTrue(exists, "Airport should exist: " + vie.getId());
} finally {
template.removeById().inScope(otherScope).inCollection(otherCollection).one(saved.getId()).block();
template.removeById().inScope(otherScope).inCollection(otherCollection).one(vie.getId()).block();
}
}
@@ -529,8 +540,8 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
@Disabled // needs analytics data set
public void findByAnalyticsOther() { // 2
AnalyticsOptions options = AnalyticsOptions.analyticsOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lowh"))
.block();
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie.withIcao("lowh")).block();
try {
List<Airport> found = template.findByAnalytics(Airport.class).inScope(otherScope).inCollection(otherCollection)
.withOptions(options).all().collectList().block();
@@ -543,8 +554,8 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
@Test
public void findByIdOther() { // 3
GetOptions options = GetOptions.getOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lowi"))
.block();
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie.withIcao("lowi")).block();
try {
Airport found = template.findById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.withOptions(options).one(saved.getId()).block();
@@ -557,8 +568,8 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
@Test
public void findByQueryOther() { // 4
QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lowj"))
.block();
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie.withIcao("lowj")).block();
try {
List<Airport> found = template.findByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS)
.inScope(otherScope).inCollection(otherCollection).withOptions(options).all().collectList().block();
@@ -571,8 +582,8 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
@Test
public void findFromReplicasByIdOther() { // 5
GetAnyReplicaOptions options = GetAnyReplicaOptions.getAnyReplicaOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lowk"))
.block();
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie.withIcao("lowk")).block();
try {
Airport found = template.findFromReplicasById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.withOptions(options).any(saved.getId()).block();
@@ -600,8 +611,8 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
@Test
public void removeByIdOther() { // 7
RemoveOptions options = RemoveOptions.removeOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lowm"))
.block();
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie.withIcao("lowm")).block();
RemoveResult removeResult = template.removeById().inScope(otherScope).inCollection(otherCollection)
.withOptions(options).one(saved.getId()).block();
assertEquals(saved.getId(), removeResult.getId());
@@ -610,8 +621,8 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
@Test
public void removeByQueryOther() { // 8
QueryOptions options = QueryOptions.queryOptions().timeout(Duration.ofSeconds(10));
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("lown"))
.block();
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie.withIcao("lown")).block();
List<RemoveResult> removeResults = template.removeByQuery(Airport.class)
.withConsistency(QueryScanConsistency.REQUEST_PLUS).inScope(otherScope).inCollection(otherCollection)
.withOptions(options).matching(Query.query(QueryCriteria.where("iata").is(vie.getIata()))).all().collectList()
@@ -686,8 +697,8 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
@Test
public void findFromReplicasByIdOptions() { // 5
GetAnyReplicaOptions options = GetAnyReplicaOptions.getAnyReplicaOptions().timeout(Duration.ofNanos(1000));
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie)
.block();
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie.withIcao("low712")).block();
try {
Airport found = template.findFromReplicasById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.withOptions(options).any(saved.getId()).block();
@@ -706,8 +717,8 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
@Test
public void removeByIdOptions() { // 7 - options
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie)
.block();
Airport saved = template.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection)
.one(vie.withIcao("732")).block();
RemoveOptions options = RemoveOptions.removeOptions().timeout(Duration.ofNanos(10));
assertThrows(AmbiguousTimeoutException.class, () -> template.removeById().inScope(otherScope)
.inCollection(otherCollection).withOptions(options).one(vie.getId()).block());
@@ -734,7 +745,7 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
public void upsertByIdOptions() { // 10 - options
UpsertOptions options = UpsertOptions.upsertOptions().timeout(Duration.ofNanos(10));
assertThrows(AmbiguousTimeoutException.class, () -> template.upsertById(Airport.class).inScope(otherScope)
.inCollection(otherCollection).withOptions(options).one(vie).block());
.inCollection(otherCollection).withOptions(options).one(vie.withIcao("760")).block());
}
}

View File

@@ -1,20 +1,23 @@
/*
* Copyright 2012-2022 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.couchbase.domain;
import com.couchbase.client.java.query.QueryOptions;
import com.couchbase.client.java.query.QueryProfile;
import com.couchbase.client.java.query.QueryResult;
import com.couchbase.client.java.query.QueryScanConsistency;
import org.junit.jupiter.api.AfterAll;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.data.couchbase.config.BeanNames;
import org.springframework.data.couchbase.core.CouchbaseTemplate;
import org.springframework.data.couchbase.core.ReactiveCouchbaseTemplate;
import org.springframework.data.couchbase.core.RemoveResult;
import org.springframework.data.couchbase.util.Capabilities;
import org.springframework.data.couchbase.util.ClusterType;
import org.springframework.data.couchbase.util.IgnoreWhen;
import org.springframework.data.util.Pair;
import static org.junit.jupiter.api.Assertions.assertEquals;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.publisher.ParallelFlux;
@@ -27,23 +30,39 @@ import java.util.Random;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
import org.springframework.data.couchbase.config.BeanNames;
import org.springframework.data.couchbase.core.CouchbaseTemplate;
import org.springframework.data.couchbase.core.ReactiveCouchbaseTemplate;
import org.springframework.data.couchbase.core.RemoveResult;
import org.springframework.data.couchbase.repository.config.EnableReactiveCouchbaseRepositories;
import org.springframework.data.couchbase.util.Capabilities;
import org.springframework.data.couchbase.util.ClusterType;
import org.springframework.data.couchbase.util.IgnoreWhen;
import org.springframework.data.couchbase.util.JavaIntegrationTests;
import org.springframework.data.util.Pair;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import com.couchbase.client.java.Collection;
import com.couchbase.client.java.ReactiveCollection;
import com.couchbase.client.java.json.JsonObject;
import com.couchbase.client.java.kv.GetResult;
import com.couchbase.client.java.query.QueryOptions;
import com.couchbase.client.java.query.QueryProfile;
import com.couchbase.client.java.query.QueryResult;
import com.couchbase.client.java.query.QueryScanConsistency;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Michael Reiche
*/
@SpringJUnitConfig(FluxTest.Config.class)
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
public class FluxTest extends JavaIntegrationTests {
@@ -69,6 +88,9 @@ public class FluxTest extends JavaIntegrationTests {
public static void afterEverthing() {
couchbaseTemplate.removeByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).all();
couchbaseTemplate.findByQuery(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).all();
for (String k : keyList) {
couchbaseTemplate.getCouchbaseClientFactory().getBucket().defaultCollection().remove(k);
}
}
@BeforeEach

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors
* Copyright 2012-2022 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,17 +16,18 @@
package org.springframework.data.couchbase.repository;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import com.couchbase.client.java.kv.GetResult;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
@@ -50,6 +51,8 @@ import org.springframework.data.couchbase.util.ClusterType;
import org.springframework.data.couchbase.util.IgnoreWhen;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import com.couchbase.client.java.kv.GetResult;
/**
* Repository KV tests
*
@@ -76,12 +79,13 @@ public class CouchbaseRepositoryKeyValueIntegrationTests extends ClusterAwareInt
GetResult jdkResult = couchbaseTemplate.getCouchbaseClientFactory().getDefaultCollection().get(st.getId());
assertNotEquals(0, st.getVersion());
assertEquals(jdkResult.cas(), st.getVersion());
subscriptionTokenRepository.delete(st);
}
@Test
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
void saveAndFindById() {
User user = new User(UUID.randomUUID().toString(), "f", "l");
User user = new User(UUID.randomUUID().toString(), "saveAndFindById", "l");
// this currently fails when using mocked in integration.properties with status "UNKNOWN"
assertFalse(userRepository.existsById(user.getId()));
@@ -98,7 +102,7 @@ public class CouchbaseRepositoryKeyValueIntegrationTests extends ClusterAwareInt
@Test
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
void saveAndFindImmutableById() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
PersonValue personValue = new PersonValue(null, 0, "f", "l");
PersonValue personValue = new PersonValue(null, 0, "saveAndFindImmutableById", "l");
personValue = personValueRepository.save(personValue);
Optional<PersonValue> found = personValueRepository.findById(personValue.getId());
assertTrue(found.isPresent());
@@ -138,7 +142,7 @@ public class CouchbaseRepositoryKeyValueIntegrationTests extends ClusterAwareInt
user.setCourses(Arrays.asList(new Course(UUID.randomUUID().toString(), user.getId(), "581")));
// this currently fails when using mocked in integration.properties with status "UNKNOWN"
assertFalse(userRepository.existsById(user.getId()));
assertFalse(userSubmissionRepository.existsById(user.getId()));
userSubmissionRepository.save(user);
@@ -146,7 +150,7 @@ public class CouchbaseRepositoryKeyValueIntegrationTests extends ClusterAwareInt
assertTrue(found.isPresent());
found.ifPresent(u -> assertEquals(user, u));
assertTrue(userRepository.existsById(user.getId()));
assertTrue(userSubmissionRepository.existsById(user.getId()));
assertEquals(user.getSubmissions().get(0).getId(), found.get().getSubmissions().get(0).getId());
assertEquals(user.getCourses().get(0).getId(), found.get().getCourses().get(0).getId());
assertEquals(user, found.get());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors
* Copyright 2012-2022 the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -42,6 +42,9 @@ import org.springframework.data.couchbase.util.ClusterType;
import org.springframework.data.couchbase.util.IgnoreWhen;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
* @author Michael Reiche
*/
@SpringJUnitConfig(ReactiveCouchbaseRepositoryKeyValueIntegrationTests.Config.class)
@IgnoreWhen(clusterTypes = ClusterType.MOCKED)
public class ReactiveCouchbaseRepositoryKeyValueIntegrationTests extends ClusterAwareIntegrationTests {
@@ -52,7 +55,7 @@ public class ReactiveCouchbaseRepositoryKeyValueIntegrationTests extends Cluster
@Test
void saveAndFindById() {
User user = new User(UUID.randomUUID().toString(), "f", "l");
User user = new User(UUID.randomUUID().toString(), "saveAndFindById_reactive", "l");
assertFalse(userRepository.existsById(user.getId()).block());
@@ -63,6 +66,7 @@ public class ReactiveCouchbaseRepositoryKeyValueIntegrationTests extends Cluster
found.ifPresent(u -> assertEquals(save, u));
assertTrue(userRepository.existsById(user.getId()).block());
userRepository.delete(user).block();
}
@Test