use of org.springframework.data.couchbase.domain.Airport in project spring-data-couchbase by spring-projects.
the class CouchbaseTemplateQueryIntegrationTests method distinctReactive.
@Test
void distinctReactive() {
String[] iatas = { "JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX" };
String[] icaos = { "ic0", "ic1", "ic0", "ic1", "ic0", "ic1", "ic0" };
try {
for (int i = 0; i < iatas.length; i++) {
Airport airport = new Airport("airports::" + iatas[i], iatas[i], /*iata*/
icaos[i]);
reactiveCouchbaseTemplate.insertById(Airport.class).one(airport).block();
}
// distinct and count(distinct(...)) calls. use as() and consistentWith to verify fluent api
// as the fluent api for Distinct is tricky
// distinct icao
List<Airport> airports1 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] { "icao" }).as(Airport.class).withConsistency(REQUEST_PLUS).all().collectList().block();
assertEquals(2, airports1.size());
// distinct all-fields-in-Airport.class
List<Airport> airports2 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] {}).as(Airport.class).withConsistency(REQUEST_PLUS).all().collectList().block();
assertEquals(7, airports2.size());
// count( distinct icao )
Long count1 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] { "icao" }).as(Airport.class).withConsistency(REQUEST_PLUS).count().block();
assertEquals(2, count1);
// count( distinct { icao, iata } )
Long count2 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] { "icao", "iata" }).withConsistency(REQUEST_PLUS).count().block();
assertEquals(7, count2);
} finally {
reactiveCouchbaseTemplate.removeById().all(Arrays.stream(iatas).map((iata) -> "airports::" + iata).collect(Collectors.toSet())).collectList().block();
}
}
use of org.springframework.data.couchbase.domain.Airport in project spring-data-couchbase by spring-projects.
the class CouchbaseTemplateQueryIntegrationTests method sortedTemplate.
@Test
void sortedTemplate() {
couchbaseTemplate.removeByQuery(Airport.class).withConsistency(REQUEST_PLUS).all();
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))).collect(Collectors.toSet()));
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();
String[] sortedIatas = iatas.clone();
System.out.println("" + iatas.length + " " + sortedIatas.length);
Arrays.sort(sortedIatas);
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()));
}
}
use of org.springframework.data.couchbase.domain.Airport in project spring-data-couchbase by spring-projects.
the class CouchbaseTemplateQueryCollectionIntegrationTests method findByAnalytics.
@Test
// needs analytics data set
@Disabled
public void findByAnalytics() {
// 2
AnalyticsOptions options = AnalyticsOptions.analyticsOptions().timeout(Duration.ofSeconds(10));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(scopeName).inCollection(collectionName).one(vie.withIcao("413"));
try {
List<Airport> found = couchbaseTemplate.findByAnalytics(Airport.class).inScope(scopeName).inCollection(collectionName).withOptions(options).all();
assertEquals(saved, found);
} finally {
couchbaseTemplate.removeById().inScope(scopeName).inCollection(collectionName).one(saved.getId());
}
}
use of org.springframework.data.couchbase.domain.Airport in project spring-data-couchbase by spring-projects.
the class CouchbaseTemplateQueryCollectionIntegrationTests method distinctReactive.
@Test
void distinctReactive() {
String[] iatas = { "JFK", "IAD", "SFO", "SJC", "SEA", "LAX", "PHX" };
String[] icaos = { "ic0", "ic1", "ic0", "ic1", "ic0", "ic1", "ic0" };
try {
for (int i = 0; i < iatas.length; i++) {
Airport airport = new Airport("airports::" + iatas[i], iatas[i], /*iata*/
icaos[i]);
reactiveCouchbaseTemplate.insertById(Airport.class).inCollection(collectionName).one(airport).block();
}
// distinct and count(distinct(...)) calls. use as() and consistentWith to verify fluent api
// as the fluent api for Distinct is tricky
// distinct icao
List<Airport> airports1 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] { "icao" }).as(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inCollection(collectionName).all().collectList().block();
assertEquals(2, airports1.size());
// distinct all-fields-in-Airport.class
List<Airport> airports2 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] {}).as(Airport.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).inCollection(collectionName).all().collectList().block();
assertEquals(7, airports2.size());
// count( distinct icao )
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 { iata, icao } )
Long count2 = reactiveCouchbaseTemplate.findByQuery(Airport.class).distinct(new String[] { "iata", "icao" }).withConsistency(QueryScanConsistency.REQUEST_PLUS).inCollection(collectionName).count().block();
assertEquals(7, count2);
} finally {
reactiveCouchbaseTemplate.removeById().inCollection(collectionName).all(Arrays.stream(iatas).map((iata) -> "airports::" + iata).collect(Collectors.toSet())).collectList().block();
}
}
use of org.springframework.data.couchbase.domain.Airport in project spring-data-couchbase by spring-projects.
the class CouchbaseTemplateQueryCollectionIntegrationTests method findFromReplicasByIdOptions.
@Test
public void findFromReplicasByIdOptions() {
// 5
GetAnyReplicaOptions options = GetAnyReplicaOptions.getAnyReplicaOptions().timeout(Duration.ofNanos(1000));
Airport saved = couchbaseTemplate.insertById(Airport.class).inScope(otherScope).inCollection(otherCollection).one(vie.withIcao("723"));
try {
Airport found = couchbaseTemplate.findFromReplicasById(Airport.class).inScope(otherScope).inCollection(otherCollection).withOptions(options).any(saved.getId());
assertNull(found, "should not have found document in short timeout");
} finally {
couchbaseTemplate.removeById().inScope(otherScope).inCollection(otherCollection).one(saved.getId());
}
}
Aggregations