DATACOUCH-577 - Fix tests that run only when using UNMANAGED couchbase server.
Some of the tests that run as UNMANAGED and pass when ran from intellij were failing when ran from the command-line mvn, or when ran together will other tests.
This commit is contained in:
@@ -82,8 +82,7 @@ class CouchbaseTemplateKeyValueIntegrationTests extends ClusterAwareIntegrationT
|
||||
|
||||
@Test
|
||||
void findDocWhichDoesNotExist() {
|
||||
assertThrows(DataRetrievalFailureException.class,
|
||||
() -> couchbaseTemplate.findById(User.class).one(UUID.randomUUID().toString()));
|
||||
assertNull(couchbaseTemplate.findById(User.class).one(UUID.randomUUID().toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -113,7 +112,7 @@ class CouchbaseTemplateKeyValueIntegrationTests extends ClusterAwareIntegrationT
|
||||
assertTrue(removeResult.getCas() != 0);
|
||||
assertTrue(removeResult.getMutationToken().isPresent());
|
||||
|
||||
assertThrows(DataRetrievalFailureException.class, () -> couchbaseTemplate.findById(User.class).one(user.getId()));
|
||||
assertNull(couchbaseTemplate.findById(User.class).one(user.getId()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -47,4 +47,6 @@ public interface AirportRepository extends PagingAndSortingRepository<Airport, S
|
||||
|
||||
long countByIcaoAndIataIn(String icao, String... iata);
|
||||
|
||||
long countByIcaoOrIataIn(String icao, String... iata);
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ package org.springframework.data.couchbase.repository;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -68,21 +70,32 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
|
||||
|
||||
@Test
|
||||
void shouldSaveAndFindAll() {
|
||||
Airport vie = new Airport("airports::vie", "vie", "loww");
|
||||
airportRepository.save(vie);
|
||||
|
||||
List<Airport> all = StreamSupport.stream(airportRepository.findAll().spliterator(), false)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertFalse(all.isEmpty());
|
||||
assertTrue(all.stream().anyMatch(a -> a.getId().equals("airports::vie")));
|
||||
Airport vie = null;
|
||||
try {
|
||||
vie = new Airport("airports::vie", "vie", "loww");
|
||||
airportRepository.save(vie);
|
||||
List<Airport> all = new ArrayList<>();
|
||||
airportRepository.findAll().forEach(all::add);
|
||||
assertFalse(all.isEmpty());
|
||||
assertTrue(all.stream().anyMatch(a -> a.getId().equals("airports::vie")));
|
||||
} finally {
|
||||
airportRepository.delete(vie);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void findBySimpleProperty() {
|
||||
List<Airport> airports = airportRepository.findAllByIata("vie");
|
||||
// TODO
|
||||
System.err.println(airports);
|
||||
Airport vie = null;
|
||||
try {
|
||||
vie = new Airport("airports::vie", "vie", "loww");
|
||||
airportRepository.save(vie);
|
||||
sleep(1000);
|
||||
List<Airport> airports = airportRepository.findAllByIata("vie");
|
||||
assertEquals(vie.getId(), airports.get(0).getId());
|
||||
} finally {
|
||||
airportRepository.delete(vie);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -94,12 +107,11 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
|
||||
try {
|
||||
Callable<Boolean>[] suppliers = new Callable[iatas.length];
|
||||
for (int i = 0; i < iatas.length; i++) {
|
||||
Airport airport = new Airport("airports::" + iatas[i], iatas[i] /*iata*/, iatas[i].toLowerCase() /* lcao */);
|
||||
Airport airport = new Airport("airports::" + iatas[i], iatas[i] /*iata*/,
|
||||
iatas[i].toLowerCase(Locale.ROOT) /* lcao */);
|
||||
airportRepository.save(airport);
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ie) {}
|
||||
sleep(1000);
|
||||
long airportCount = 0;
|
||||
airportCount = airportRepository.count();
|
||||
assertEquals(7, airportCount);
|
||||
@@ -110,6 +122,9 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
|
||||
airportCount = airportRepository.countByIcaoAndIataIn("jfk", "JFK", "IAD", "SFO", "XXX");
|
||||
assertEquals(1, airportCount);
|
||||
|
||||
airportCount = airportRepository.countByIcaoOrIataIn("jfk", "LAX", "IAD", "SFO");
|
||||
assertEquals(4, airportCount);
|
||||
|
||||
airportCount = airportRepository.countByIataIn("XXX");
|
||||
assertEquals(0, airportCount);
|
||||
|
||||
@@ -128,29 +143,30 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(iatas.length);
|
||||
|
||||
try {
|
||||
Callable<Boolean>[] suppliers = new Callable[iatas.length];
|
||||
for (int i = 0; i < iatas.length; i++) {
|
||||
Airport airport = new Airport("airports::" + iatas[i], iatas[i] /*iata*/, iatas[i].toLowerCase() /* lcao */);
|
||||
Airport airport = new Airport("airports::" + iatas[i], iatas[i] /*iata*/,
|
||||
iatas[i].toLowerCase(Locale.ROOT) /* lcao */);
|
||||
airportRepository.save(airport);
|
||||
final int idx = i;
|
||||
suppliers[i] = () -> {
|
||||
System.out.println(Thread.currentThread() + " " + iatas[idx] + " ->");
|
||||
try {
|
||||
Thread.sleep(iatas.length - idx); // so they are executed out-of-order
|
||||
} catch (InterruptedException ie) {
|
||||
;
|
||||
}
|
||||
String foundName = airportRepository.findAllByIata(iatas[idx]).get(0).getIata();
|
||||
System.out.println(Thread.currentThread() + " " + iatas[idx] + " <- ");
|
||||
assertEquals(iatas[idx], foundName);
|
||||
return iatas[idx].equals(foundName);
|
||||
};
|
||||
}
|
||||
for (int i = 0; i < iatas.length; i++) {
|
||||
future[i] = executorService.submit(suppliers[i]);
|
||||
}
|
||||
for (int i = 0; i < iatas.length; i++) {
|
||||
future[i].get();
|
||||
sleep(1000);
|
||||
for (int k = 0; k < 50; k++) {
|
||||
Callable<Boolean>[] suppliers = new Callable[iatas.length];
|
||||
for (int i = 0; i < iatas.length; i++) {
|
||||
final int idx = i;
|
||||
suppliers[i] = () -> {
|
||||
sleep(iatas.length - idx); // so they are executed out-of-order
|
||||
List<Airport> airports = airportRepository.findAllByIata(iatas[idx]);
|
||||
String foundName = airportRepository.findAllByIata(iatas[idx]).get(0).getIata();
|
||||
assertEquals(iatas[idx], foundName);
|
||||
return iatas[idx].equals(foundName);
|
||||
};
|
||||
}
|
||||
for (int i = 0; i < iatas.length; i++) {
|
||||
future[i] = executorService.submit(suppliers[i]);
|
||||
}
|
||||
for (int i = 0; i < iatas.length; i++) {
|
||||
future[i].get(); // check is done in Callable
|
||||
}
|
||||
}
|
||||
|
||||
} finally {
|
||||
@@ -163,35 +179,34 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
|
||||
}
|
||||
|
||||
@Test
|
||||
void threadSafeStringParametersTest() throws Exception {
|
||||
void threadSafeStringParametersTest() throws Exception {
|
||||
String[] iatas = { "JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX" };
|
||||
Future[] future = new Future[iatas.length];
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(iatas.length);
|
||||
|
||||
try {
|
||||
Callable<Boolean>[] suppliers = new Callable[iatas.length];
|
||||
for (int i = 0; i < iatas.length; i++) {
|
||||
Airport airport = new Airport("airports::" + iatas[i], iatas[i] /*iata*/, iatas[i] /* lcao */);
|
||||
Airport airport = new Airport("airports::" + iatas[i], iatas[i] /*iata*/, iatas[i].toLowerCase() /* lcao */);
|
||||
airportRepository.save(airport);
|
||||
final int idx = i;
|
||||
suppliers[i] = () -> {
|
||||
System.out.println(Thread.currentThread() + " " + iatas[idx] + " ->");
|
||||
try {
|
||||
Thread.sleep(iatas.length - idx); // so they are executed out-of-order
|
||||
} catch (InterruptedException ie) {
|
||||
;
|
||||
}
|
||||
String foundName = airportRepository.getAllByIata(iatas[idx]).get(0).getIata();
|
||||
System.out.println(Thread.currentThread() + " " + iatas[idx] + " <- ");
|
||||
assertEquals(iatas[idx], foundName);
|
||||
return iatas[idx].equals(foundName);
|
||||
};
|
||||
}
|
||||
for (int i = 0; i < iatas.length; i++) {
|
||||
future[i] = executorService.submit(suppliers[i]);
|
||||
}
|
||||
for (int i = 0; i < iatas.length; i++) {
|
||||
future[i].get();
|
||||
sleep(1000);
|
||||
for (int k = 0; k < 100; k++) {
|
||||
Callable<Boolean>[] suppliers = new Callable[iatas.length];
|
||||
for (int i = 0; i < iatas.length; i++) {
|
||||
final int idx = i;
|
||||
suppliers[i] = () -> {
|
||||
sleep(iatas.length - idx); // so they are executed out-of-order
|
||||
String foundName = airportRepository.getAllByIata(iatas[idx]).get(0).getIata();
|
||||
assertEquals(iatas[idx], foundName);
|
||||
return iatas[idx].equals(foundName);
|
||||
};
|
||||
}
|
||||
for (int i = 0; i < iatas.length; i++) {
|
||||
future[i] = executorService.submit(suppliers[i]);
|
||||
}
|
||||
for (int i = 0; i < iatas.length; i++) {
|
||||
future[i].get(); // check is done in Callable
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
executorService.shutdown();
|
||||
@@ -202,6 +217,14 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
|
||||
}
|
||||
}
|
||||
|
||||
private void sleep(int millis) {
|
||||
try {
|
||||
Thread.sleep(millis); // so they are executed out-of-order
|
||||
} catch (InterruptedException ie) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@EnableCouchbaseRepositories("org.springframework.data.couchbase")
|
||||
static class Config extends AbstractCouchbaseConfiguration {
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ReactiveCouchbaseRepositoryQueryIntegrationTests extends ClusterAwa
|
||||
|
||||
@Autowired CouchbaseClientFactory clientFactory;
|
||||
|
||||
@Autowired ReactiveAirportRepository airportRepository;
|
||||
@Autowired ReactiveAirportRepository airportRepository; // intellij flags "Could not Autowire", but it runs ok.
|
||||
|
||||
@BeforeEach
|
||||
void beforeEach() {
|
||||
@@ -67,20 +67,32 @@ public class ReactiveCouchbaseRepositoryQueryIntegrationTests extends ClusterAwa
|
||||
|
||||
@Test
|
||||
void shouldSaveAndFindAll() {
|
||||
Airport vie = new Airport("airports::vie", "vie", "loww");
|
||||
airportRepository.save(vie).block();
|
||||
Airport vie = null;
|
||||
try {
|
||||
vie = new Airport("airports::vie", "vie", "loww");
|
||||
airportRepository.save(vie).block();
|
||||
|
||||
List<Airport> all = airportRepository.findAll().toStream().collect(Collectors.toList());
|
||||
List<Airport> all = airportRepository.findAll().toStream().collect(Collectors.toList());
|
||||
|
||||
assertFalse(all.isEmpty());
|
||||
assertTrue(all.stream().anyMatch(a -> a.getId().equals("airports::vie")));
|
||||
assertFalse(all.isEmpty());
|
||||
assertTrue(all.stream().anyMatch(a -> a.getId().equals("airports::vie")));
|
||||
} finally {
|
||||
airportRepository.delete(vie).block();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void findBySimpleProperty() {
|
||||
List<Airport> airports = airportRepository.findAllByIata("vie").collectList().block();
|
||||
// TODO
|
||||
System.err.println(airports);
|
||||
Airport vie = null;
|
||||
try {
|
||||
vie = new Airport("airports::vie", "vie", "loww");
|
||||
airportRepository.save(vie).block();
|
||||
List<Airport> airports = airportRepository.findAllByIata("vie").collectList().block();
|
||||
// TODO
|
||||
System.err.println(airports);
|
||||
} finally {
|
||||
airportRepository.delete(vie).block();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,7 +126,7 @@ public class ReactiveCouchbaseRepositoryQueryIntegrationTests extends ClusterAwa
|
||||
} finally {
|
||||
for (int i = 0; i < iatas.length; i++) {
|
||||
Airport airport = new Airport("airports::" + iatas[i], iatas[i] /*iata*/, iatas[i] /* lcao */);
|
||||
airportRepository.delete(airport);
|
||||
airportRepository.delete(airport).block();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,6 @@ import static org.springframework.data.couchbase.config.BeanNames.COUCHBASE_TEMP
|
||||
* @author Michael Nitschinger
|
||||
* @author Michael Reiche
|
||||
*/
|
||||
@IgnoreWhen(clusterTypes = ClusterType.UNMANAGED)
|
||||
class StringN1qlQueryCreatorMockedTests extends ClusterAwareIntegrationTests {
|
||||
|
||||
MappingContext<? extends CouchbasePersistentEntity<?>, CouchbasePersistentProperty> context;
|
||||
@@ -83,9 +82,8 @@ class StringN1qlQueryCreatorMockedTests extends ClusterAwareIntegrationTests {
|
||||
new DefaultRepositoryMetadata(UserRepository.class), new SpelAwareProxyProjectionFactory(),
|
||||
converter.getMappingContext());
|
||||
|
||||
StringN1qlQueryCreator creator = new StringN1qlQueryCreator(
|
||||
getAccessor(getParameters(method), "Oliver", "Twist"), queryMethod, converter, "travel-sample",
|
||||
QueryMethodEvaluationContextProvider.DEFAULT, namedQueries);
|
||||
StringN1qlQueryCreator creator = new StringN1qlQueryCreator(getAccessor(getParameters(method), "Oliver", "Twist"),
|
||||
queryMethod, converter, "travel-sample", QueryMethodEvaluationContextProvider.DEFAULT, namedQueries);
|
||||
|
||||
Query query = creator.createQuery();
|
||||
assertEquals(
|
||||
@@ -102,9 +100,8 @@ class StringN1qlQueryCreatorMockedTests extends ClusterAwareIntegrationTests {
|
||||
new DefaultRepositoryMetadata(UserRepository.class), new SpelAwareProxyProjectionFactory(),
|
||||
converter.getMappingContext());
|
||||
|
||||
StringN1qlQueryCreator creator = new StringN1qlQueryCreator(
|
||||
getAccessor(getParameters(method), "Oliver", "Twist"), queryMethod, converter, "travel-sample",
|
||||
QueryMethodEvaluationContextProvider.DEFAULT, namedQueries);
|
||||
StringN1qlQueryCreator creator = new StringN1qlQueryCreator(getAccessor(getParameters(method), "Oliver", "Twist"),
|
||||
queryMethod, converter, "travel-sample", QueryMethodEvaluationContextProvider.DEFAULT, namedQueries);
|
||||
|
||||
Query query = creator.createQuery();
|
||||
assertEquals(
|
||||
@@ -123,8 +120,7 @@ class StringN1qlQueryCreatorMockedTests extends ClusterAwareIntegrationTests {
|
||||
|
||||
try {
|
||||
StringN1qlQueryCreator creator = new StringN1qlQueryCreator(getAccessor(getParameters(method), "Oliver"),
|
||||
queryMethod, converter, "travel-sample", QueryMethodEvaluationContextProvider.DEFAULT,
|
||||
namedQueries);
|
||||
queryMethod, converter, "travel-sample", QueryMethodEvaluationContextProvider.DEFAULT, namedQueries);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return;
|
||||
}
|
||||
@@ -141,15 +137,13 @@ class StringN1qlQueryCreatorMockedTests extends ClusterAwareIntegrationTests {
|
||||
|
||||
try {
|
||||
StringN1qlQueryCreator creator = new StringN1qlQueryCreator(getAccessor(getParameters(method), "Oliver"),
|
||||
queryMethod, converter, "travel-sample", QueryMethodEvaluationContextProvider.DEFAULT,
|
||||
namedQueries);
|
||||
queryMethod, converter, "travel-sample", QueryMethodEvaluationContextProvider.DEFAULT, namedQueries);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return;
|
||||
}
|
||||
fail("should have failed with IllegalArgumentException: query has no inline Query or named Query not found");
|
||||
}
|
||||
|
||||
|
||||
private ParameterAccessor getAccessor(Parameters<?, ?> params, Object... values) {
|
||||
return new ParametersParameterAccessor(params, values);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user