Incorporate changes from 5.0.x and bump Couchbase SDK. (#1287)

Closes #1286.

Co-authored-by: mikereiche <michael.reiche@couchbase.com>
This commit is contained in:
Michael Reiche
2022-01-06 15:00:49 -08:00
committed by GitHub
parent 6c6acf8ae2
commit 3a216a83b4
50 changed files with 356 additions and 260 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2021 the original author or authors
* Copyright 2021-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.
@@ -349,20 +349,15 @@ class CouchbaseTemplateQueryCollectionIntegrationTests extends CollectionAwareIn
assertEquals(7, airports2.size());
// count( distinct icao )
// not currently possible to have multiple fields in COUNT(DISTINCT field1, field2, ... ) due to MB43475
Long count1 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] { "icao" })
.as(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inCollection(collectionName).count()
.block();
assertEquals(2, count1);
// count( distinct (all fields in icaoClass) // which only has one field
// not currently possible to have multiple fields in COUNT(DISTINCT field1, field2, ... ) due to MB43475
Class icaoClass = (new Object() {
String icao;
}).getClass();
long count2 = (long) reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] {}).as(icaoClass)
// count (distinct { iata, icao } )
Long count2 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] {"iata", "icao"})
.withConsistency(QueryScanConsistency.REQUEST_PLUS).inCollection(collectionName).count().block();
assertEquals(2, count2);
assertEquals(7, count2);
} finally {
reactiveCouchbaseTemplate.removeById().inCollection(collectionName)

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.
@@ -265,15 +265,6 @@ class CouchbaseTemplateQueryIntegrationTests extends JavaIntegrationTests {
.as(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).count();
assertEquals(7, count1);
// count( distinct (all fields in icaoClass)
Class icaoClass = (new Object() {
String iata;
String icao;
}).getClass();
long count2 = couchbaseTemplate.findByQuery(Airport.class).distinct(new String[] {}).as(icaoClass)
.withConsistency(QueryScanConsistency.REQUEST_PLUS).count();
assertEquals(7, count2);
} finally {
couchbaseTemplate.removeById()
.all(Arrays.stream(iatas).map((iata) -> "airports::" + iata).collect(Collectors.toSet()));
@@ -305,19 +296,14 @@ class CouchbaseTemplateQueryIntegrationTests extends JavaIntegrationTests {
assertEquals(7, airports2.size());
// count( distinct icao )
// not currently possible to have multiple fields in COUNT(DISTINCT field1, field2, ... ) due to MB43475
long count1 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] { "icao" })
Long count1 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] { "icao" })
.as(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).count().block();
assertEquals(2, count1);
// count( distinct (all fields in icaoClass) // which only has one field
// not currently possible to have multiple fields in COUNT(DISTINCT field1, field2, ... ) due to MB43475
Class icaoClass = (new Object() {
String icao;
}).getClass();
long count2 = (long) reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] {}).as(icaoClass)
// count( distinct { icao, iata } )
Long count2 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] { "icao", "iata" })
.withConsistency(QueryScanConsistency.REQUEST_PLUS).count().block();
assertEquals(2, count2);
assertEquals(7, count2);
} finally {
reactiveCouchbaseTemplate.removeById()

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 the original author or authors.
* Copyright 2017-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.
@@ -24,12 +24,12 @@ import static org.springframework.data.couchbase.core.query.N1QLExpression.x;
import static org.springframework.data.couchbase.core.query.QueryCriteria.where;
import static org.springframework.data.couchbase.repository.query.support.N1qlUtils.escapedBucket;
import java.util.Arrays;
import org.junit.jupiter.api.Test;
import com.couchbase.client.java.json.JsonArray;
import java.util.Arrays;
/**
* @author Mauro Monti
*/
@@ -85,8 +85,9 @@ class QueryCriteriaTests {
void testNestedNotIn() {
QueryCriteria c = where(i("name")).is("Bubba").or(where(i("age")).gt(12).or(i("country")).is("Austria"))
.and(where(i("state")).notIn(new String[] { "Alabama", "Florida" }));
assertEquals("`name` = \"Bubba\" or (`age` > 12 or `country` = \"Austria\") and "
+ "(not( (`state` in ( [\"Alabama\",\"Florida\"] )) ))", c.export());
JsonArray parameters = JsonArray.create();
assertEquals("`name` = $1 or (`age` > $2 or `country` = $3) and (not( (`state` in ( $4, $5 )) ))",
c.export(new int[1], parameters, null));
}
@Test
@@ -224,21 +225,22 @@ class QueryCriteriaTests {
@Test
void testIn() {
String[] args = new String[] { "gump", "davis" };
QueryCriteria c = where(i("name")).in((Object)args);
assertEquals("`name` in ( [\"gump\",\"davis\"] )", c.export());
QueryCriteria c = where(i("name")).in((Object) args);
assertEquals("`name` in ( \"gump\", \"davis\" )", c.export());
JsonArray parameters = JsonArray.create();
assertEquals("`name` in ( $1 )", c.export(new int[1], parameters, null));
assertEquals(arrayToString(args), parameters.get(0).toString());
assertEquals("`name` in ( $1, $2 )", c.export(new int[1], parameters, null));
assertEquals(arrayToString(args), parameters.toString());
}
@Test
void testNotIn() {
String[] args = new String[] { "gump", "davis" };
QueryCriteria c = where(i("name")).notIn((Object)args);
assertEquals("not( (`name` in ( [\"gump\",\"davis\"] )) )", c.export());
QueryCriteria c = where(i("name")).notIn((Object) args);
assertEquals("not( (`name` in ( \"gump\", \"davis\" )) )", c.export());
// this tests creating parameters from the args.
JsonArray parameters = JsonArray.create();
assertEquals("not( (`name` in ( $1 )) )", c.export(new int[1], parameters, null));
assertEquals(arrayToString(args), parameters.get(0).toString());
assertEquals("not( (`name` in ( $1, $2 )) )", c.export(new int[1], parameters, null));
assertEquals(arrayToString(args), parameters.toString());
}
@Test
@@ -261,7 +263,6 @@ class QueryCriteriaTests {
assertEquals(" USE KEYS []", expression.keys(Arrays.asList()).toString());
}
@Test // https://github.com/spring-projects/spring-data-couchbase/issues/1066
void testCriteriaCorrectlyEscapedWhenUsingMetaOnLHS() {
final String bucketName = "sample-bucket";

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2021 the original author or authors
* Copyright 2021-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.
@@ -344,20 +344,15 @@ class ReactiveCouchbaseTemplateQueryCollectionIntegrationTests extends Collectio
assertEquals(7, airports2.size());
// count( distinct icao )
// not currently possible to have multiple fields in COUNT(DISTINCT field1, field2, ... ) due to MB43475
Long count1 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] { "icao" })
.as(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inCollection(collectionName).count()
.block();
assertEquals(2, count1);
// count( distinct (all fields in icaoClass) // which only has one field
// not currently possible to have multiple fields in COUNT(DISTINCT field1, field2, ... ) due to MB43475
Class icaoClass = (new Object() {
String icao;
}).getClass();
long count2 = (long) reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] {}).as(icaoClass)
// count( distinct { iata, icao } )
Long count2 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] {"iata","icao"})
.withConsistency(QueryScanConsistency.REQUEST_PLUS).inCollection(collectionName).count().block();
assertEquals(2, count2);
assertEquals(7, count2);
} finally {
reactiveCouchbaseTemplate.removeById().inCollection(collectionName)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 the original author or authors.
* Copyright 2017-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.
@@ -95,11 +95,11 @@ public interface AirportRepository extends CouchbaseRepository<Airport, String>,
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
List<RemoveResult> deleteByIata(String iata);
@Query("SELECT __cas, * from `#{#n1ql.bucket}` where iata = $1")
@Query("SELECT __cas, * from #{#n1ql.bucket} where iata = $1")
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
List<Airport> getAllByIataNoID(String iata);
@Query("SELECT __id, * from `#{#n1ql.bucket}` where iata = $1")
@Query("SELECT __id, * from #{#n1ql.bucket} where iata = $1")
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
List<Airport> getAllByIataNoCAS(String iata);
@@ -122,10 +122,10 @@ public interface AirportRepository extends CouchbaseRepository<Airport, String>,
Long countFancyExpression(@Param("projectIds") List<String> projectIds, @Param("planIds") List<String> planIds,
@Param("active") Boolean active);
@Query("SELECT 1 FROM `#{#n1ql.bucket}` WHERE anything = 'count(*)'") // looks like count query, but is not
@Query("SELECT 1 FROM #{#n1ql.bucket} WHERE anything = 'count(*)'") // looks like count query, but is not
Long countBad();
@Query("SELECT count(*) FROM `#{#n1ql.bucket}`")
@Query("SELECT count(*) FROM #{#n1ql.bucket}")
Long countGood();
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
@@ -135,6 +135,18 @@ public interface AirportRepository extends CouchbaseRepository<Airport, String>,
@Query("#{#n1ql.selectEntity} WHERE #{#n1ql.filter} AND iata != $1")
Page<Airport> getAllByIataNot(String iata, Pageable pageable);
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
@Query("SELECT iata, \"\" as __id, 0 as __cas from #{#n1ql.bucket} WHERE #{#n1ql.filter} order by meta().id")
List<String> getStrings();
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
@Query("SELECT length(iata), \"\" as __id, 0 as __cas from #{#n1ql.bucket} WHERE #{#n1ql.filter} order by meta().id")
List<Long> getLongs();
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
@Query("SELECT iata, icao, \"\" as __id, 0 as __cas from #{#n1ql.bucket} WHERE #{#n1ql.filter} order by meta().id")
List<String[]> getStringArrays();
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
Optional<Airport> findByIdAndIata(String id, String iata);
@@ -150,7 +162,7 @@ public interface AirportRepository extends CouchbaseRepository<Airport, String>,
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
Long countDistinctIcaoBy();
@Query("SELECT 1 FROM `#{#n1ql.bucket}` WHERE #{#n1ql.filter} " + " #{#projectIds != null ? 'AND blah IN $1' : ''} "
@Query("SELECT 1 FROM #{#n1ql.bucket} WHERE #{#n1ql.filter} " + " #{#projectIds != null ? 'AND blah IN $1' : ''} "
+ " #{#planIds != null ? 'AND blahblah IN $2' : ''} " + " #{#active != null ? 'AND false = $3' : ''} ")
Long countOne();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 the original author or authors.
* Copyright 2017-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.
@@ -102,7 +102,6 @@ import com.couchbase.client.core.error.IndexFailureException;
import com.couchbase.client.java.env.ClusterEnvironment;
import com.couchbase.client.java.json.JsonArray;
import com.couchbase.client.java.kv.GetResult;
import com.couchbase.client.java.kv.MutationState;
import com.couchbase.client.java.kv.UpsertOptions;
import com.couchbase.client.java.query.QueryOptions;
import com.couchbase.client.java.query.QueryScanConsistency;
@@ -276,6 +275,7 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
@Test
public void saveNotBoundedRequestPlus() {
airportRepository.withOptions(QueryOptions.queryOptions().scanConsistency(REQUEST_PLUS)).deleteAll();
ApplicationContext ac = new AnnotationConfigApplicationContext(ConfigRequestPlus.class);
// the Config class has been modified, these need to be loaded again
CouchbaseTemplate couchbaseTemplateRP = (CouchbaseTemplate) ac.getBean(COUCHBASE_TEMPLATE);
@@ -314,20 +314,21 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
@Test
public void saveNotBoundedWithDefaultRepository() {
airportRepository.withOptions(QueryOptions.queryOptions().scanConsistency(REQUEST_PLUS)).deleteAll();
ApplicationContext ac = new AnnotationConfigApplicationContext(Config.class);
// the Config class has been modified, these need to be loaded again
CouchbaseTemplate couchbaseTemplateRP = (CouchbaseTemplate) ac.getBean(COUCHBASE_TEMPLATE);
AirportRepositoryScanConsistencyTest airportRepositoryRP = (AirportRepositoryScanConsistencyTest) ac.getBean("airportRepositoryScanConsistencyTest");
AirportRepositoryScanConsistencyTest airportRepositoryRP = (AirportRepositoryScanConsistencyTest) ac
.getBean("airportRepositoryScanConsistencyTest");
List<Airport> sizeBeforeTest = airportRepositoryRP.findAll();
assertEquals(0, sizeBeforeTest.size());
Airport vie = new Airport("airports::vie", "vie" , "low9");
Airport vie = new Airport("airports::vie", "vie", "low9");
Airport saved = airportRepositoryRP.save(vie);
List<Airport> allSaved = airportRepositoryRP.findAll();
couchbaseTemplate.removeById(Airport.class).one(saved.getId());
assertNotEquals( 1, allSaved.size(),"should not have found 1 airport");
assertNotEquals(1, allSaved.size(), "should not have found 1 airport");
}
@Test
@@ -335,19 +336,19 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
ApplicationContext ac = new AnnotationConfigApplicationContext(ConfigRequestPlus.class);
// the Config class has been modified, these need to be loaded again
AirportRepositoryScanConsistencyTest airportRepositoryRP = (AirportRepositoryScanConsistencyTest) ac.getBean("airportRepositoryScanConsistencyTest");
AirportRepositoryScanConsistencyTest airportRepositoryRP = (AirportRepositoryScanConsistencyTest) ac
.getBean("airportRepositoryScanConsistencyTest");
List<Airport> sizeBeforeTest = airportRepositoryRP.findAll();
assertEquals(0, sizeBeforeTest.size());
Airport vie = new Airport("airports::vie", "vie" , "low9");
Airport vie = new Airport("airports::vie", "vie", "low9");
Airport saved = airportRepositoryRP.save(vie);
List<Airport> allSaved = airportRepositoryRP.findAll();
couchbaseTemplate.removeById(Airport.class).one(saved.getId());
assertEquals( 1, allSaved.size(),"should have found 1 airport");
assertEquals(1, allSaved.size(), "should have found 1 airport");
}
@Test
void findByTypeAlias() {
Airport vie = null;
@@ -374,15 +375,14 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
Airport airport2 = airportRepository.findByIata(Iata.vie);
assertNotNull(airport2, "should have found " + vie);
assertEquals(airport2.getId(), vie.getId());
Airport airport3 = airportRepository.findByIataIn(new Iata[]{Iata.vie, Iata.xxx});
Airport airport3 = airportRepository.findByIataIn(new Iata[] { Iata.vie, Iata.xxx });
assertNotNull(airport3, "should have found " + vie);
assertEquals(airport3.getId(), vie.getId());
java.util.Collection<Iata> iatas = new ArrayList<>();
iatas.add(Iata.vie);
iatas.add(Iata.xxx);
Airport airport4 = airportRepository.findByIataIn( iatas );
Airport airport4 = airportRepository.findByIataIn(iatas);
assertNotNull(airport4, "should have found " + vie);
assertEquals(airport4.getId(), vie.getId());
@@ -557,8 +557,29 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
assertThrows(DataRetrievalFailureException.class, () -> userRepository.delete(user));
}
@Test
void stringQueryReturnsSimpleType() {
Airport airport1 = new Airport("1", "myIata1", "MyIcao");
airportRepository.save(airport1);
Airport airport2 = new Airport("2", "myIata2__", "MyIcao");
airportRepository.save(airport2);
List<String> iatas = airportRepository.getStrings();
assertEquals(Arrays.asList(airport1.getIata(), airport2.getIata()), iatas);
List<Long> iataLengths = airportRepository.getLongs();
assertEquals(Arrays.asList(airport1.getIata().length(), airport2.getIata().length()).toString(),
iataLengths.toString());
// this is somewhat broken, because decode is told that each "row" is just a String instead of a String[]
// As such, only the first element is returned. (QueryExecutionConverts.unwrapWrapperTypes)
List<String[]> iataAndIcaos = airportRepository.getStringArrays();
assertEquals(airport1.getIata(), iataAndIcaos.get(0)[0]);
assertEquals(airport2.getIata(), iataAndIcaos.get(1)[0]);
airportRepository.deleteById(airport1.getId());
airportRepository.deleteById(airport2.getId());
}
@Test
void count() {
airportRepository.withOptions(QueryOptions.queryOptions().scanConsistency(REQUEST_PLUS)).deleteAll();
String[] iatas = { "JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX" };
airportRepository.countOne();
@@ -657,6 +678,7 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
void distinct() {
String[] iatas = { "JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX" };
String[] icaos = { "ic0", "ic1", "ic0", "ic1", "ic0", "ic1", "ic0" };
airportRepository.withOptions(QueryOptions.queryOptions().scanConsistency(REQUEST_PLUS)).deleteAll();
try {
for (int i = 0; i < iatas.length; i++) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2021 the original author or authors.
* Copyright 2017-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.
@@ -109,7 +109,7 @@ class N1qlQueryCreatorTests {
Query query = creator.createQuery();
// Query expected = (new Query()).addCriteria(where("firstname").in("Oliver", "Charles"));
assertEquals(expected.export(new int[1]), query.export(new int[1]));
assertEquals(" WHERE `firstname` in ( $1, $2 )", query.export(new int[1]));
JsonObject expectedOptions = JsonObject.create();
expected.buildQueryOptions(null, null).build().injectParams(expectedOptions);
JsonObject actualOptions = JsonObject.create();
@@ -132,7 +132,7 @@ class N1qlQueryCreatorTests {
Query query = creator.createQuery();
Query expected = (new Query()).addCriteria(where(i("firstname")).in("Oliver", "Charles"));
assertEquals(expected.export(new int[1]), query.export(new int[1]));
assertEquals(" WHERE `firstname` in ( $1, $2 )", query.export(new int[1]));
JsonObject expectedOptions = JsonObject.create();
expected.buildQueryOptions(null, null).build().injectParams(expectedOptions);
JsonObject actualOptions = JsonObject.create();
@@ -156,7 +156,7 @@ class N1qlQueryCreatorTests {
Query expected = (new Query()).addCriteria(where(i("firstname")).in("Oliver", "Charles"));
assertEquals(expected.export(new int[1]), query.export(new int[1]));
assertEquals(" WHERE `firstname` in ( $1, $2 )", query.export(new int[1]));
JsonObject expectedOptions = JsonObject.create();
expected.buildQueryOptions(null, null).build().injectParams(expectedOptions);
JsonObject actualOptions = JsonObject.create();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019 the original author or authors.
* Copyright 2017-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.
@@ -85,7 +85,7 @@ class StringN1qlQueryCreatorMockedTests extends ClusterAwareIntegrationTests {
Query query = creator.createQuery();
assertEquals(
"SELECT META(`travel-sample`).id AS __id, META(`travel-sample`).cas AS __cas, `travel-sample`.* FROM `travel-sample` where `_class` = \"org.springframework.data.couchbase.domain.User\" and firstname = $1 and lastname = $2",
"SELECT META(`travel-sample`).id AS __id, META(`travel-sample`).cas AS __cas, `firstname`, `lastname`, `createdBy`, `createdDate`, `lastModifiedBy`, `lastModifiedDate` FROM `travel-sample` where `_class` = \"org.springframework.data.couchbase.domain.User\" and firstname = $1 and lastname = $2",
query.toN1qlSelectString(couchbaseTemplate.reactive(), User.class, false));
}
@@ -104,7 +104,7 @@ class StringN1qlQueryCreatorMockedTests extends ClusterAwareIntegrationTests {
Query query = creator.createQuery();
assertEquals(
"SELECT META(`travel-sample`).id AS __id, META(`travel-sample`).cas AS __cas, `travel-sample`.* FROM `travel-sample` where `_class` = \"org.springframework.data.couchbase.domain.User\" and (firstname = $first or lastname = $last)",
"SELECT META(`travel-sample`).id AS __id, META(`travel-sample`).cas AS __cas, `firstname`, `lastname`, `createdBy`, `createdDate`, `lastModifiedBy`, `lastModifiedDate` FROM `travel-sample` where `_class` = \"org.springframework.data.couchbase.domain.User\" and (firstname = $first or lastname = $last)",
query.toN1qlSelectString(couchbaseTemplate.reactive(), User.class, false));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2020-2021 the original author or authors
* Copyright 2020-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,6 +27,12 @@ import static org.springframework.data.couchbase.config.BeanNames.COUCHBASE_TEMP
import static org.springframework.data.couchbase.config.BeanNames.REACTIVE_COUCHBASE_TEMPLATE;
import static org.springframework.data.couchbase.util.Util.waitUntilCondition;
import okhttp3.Credentials;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
import java.time.Duration;
import java.util.Collections;
@@ -39,7 +45,6 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.function.Predicate;
import com.couchbase.client.core.io.CollectionIdentifier;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Timeout;
import org.springframework.context.ApplicationContext;
@@ -60,6 +65,7 @@ import com.couchbase.client.core.error.ParsingFailureException;
import com.couchbase.client.core.error.QueryException;
import com.couchbase.client.core.error.ScopeNotFoundException;
import com.couchbase.client.core.error.UnambiguousTimeoutException;
import com.couchbase.client.core.io.CollectionIdentifier;
import com.couchbase.client.core.json.Mapper;
import com.couchbase.client.core.service.ServiceType;
import com.couchbase.client.java.Bucket;
@@ -200,6 +206,7 @@ public class JavaIntegrationTests extends ClusterAwareIntegrationTests {
}
if (!ready) {
createAndDeleteBucket();// need to do this because of https://issues.couchbase.com/browse/MB-50132
try {
Thread.sleep(50);
} catch (InterruptedException e) {}
@@ -211,6 +218,32 @@ public class JavaIntegrationTests extends ClusterAwareIntegrationTests {
}
}
private static void createAndDeleteBucket() {
final OkHttpClient httpClient = new OkHttpClient.Builder().connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS).writeTimeout(30, TimeUnit.SECONDS).build();
String hostPort = connectionString().replace("11210", "8091");
String bucketname = UUID.randomUUID().toString();
try {
Response postResponse = httpClient.newCall(new Request.Builder()
.header("Authorization", Credentials.basic(config().adminUsername(), config().adminPassword()))
.url("http://" + hostPort + "/pools/default/buckets/")
.post(new FormBody.Builder().add("name", bucketname).add("bucketType", "membase").add("ramQuotaMB", "100")
.add("replicaNumber", Integer.toString(0)).add("flushEnabled", "1").build())
.build()).execute();
if (postResponse.code() != 202) {
throw new IOException("Could not create bucket: " + postResponse + ", Reason: " + postResponse.body().string());
}
Response deleteResponse = httpClient.newCall(new Request.Builder()
.header("Authorization", Credentials.basic(config().adminUsername(), config().adminPassword()))
.url("http://" + hostPort + "/pools/default/buckets/" + bucketname).delete().build()).execute();
System.out.println("deleteResponse: " + deleteResponse);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
/**
* Improve test stability by waiting for a given service to report itself ready.
*/