Skip to content

Commit 91895a7

Browse files
committed
Test default consistency being used with CouchbaseRepository findAll.
Related tickets #1243
1 parent 50dfed7 commit 91895a7

File tree

1 file changed

+42
-15
lines changed

1 file changed

+42
-15
lines changed

src/test/java/org/springframework/data/couchbase/repository/CouchbaseRepositoryQueryIntegrationTests.java

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,13 @@
5757
import org.springframework.data.couchbase.core.query.N1QLExpression;
5858
import org.springframework.data.couchbase.core.query.Query;
5959
import org.springframework.data.couchbase.core.query.QueryCriteria;
60-
import org.springframework.data.couchbase.domain.Address;
61-
import org.springframework.data.couchbase.domain.Airport;
62-
import org.springframework.data.couchbase.domain.AirportRepository;
63-
import org.springframework.data.couchbase.domain.Iata;
64-
import org.springframework.data.couchbase.domain.NaiveAuditorAware;
65-
import org.springframework.data.couchbase.domain.Person;
66-
import org.springframework.data.couchbase.domain.PersonRepository;
67-
import org.springframework.data.couchbase.domain.User;
68-
import org.springframework.data.couchbase.domain.UserRepository;
60+
import org.springframework.data.couchbase.domain.*;
6961
import org.springframework.data.couchbase.domain.time.AuditingDateTimeProvider;
7062
import org.springframework.data.couchbase.repository.auditing.EnableCouchbaseAuditing;
7163
import org.springframework.data.couchbase.repository.config.EnableCouchbaseRepositories;
7264
import org.springframework.data.couchbase.repository.query.CouchbaseQueryMethod;
7365
import org.springframework.data.couchbase.repository.query.CouchbaseRepositoryQuery;
66+
import org.springframework.data.couchbase.repository.support.SimpleCouchbaseRepository;
7467
import org.springframework.data.couchbase.util.Capabilities;
7568
import org.springframework.data.couchbase.util.ClusterAwareIntegrationTests;
7669
import org.springframework.data.couchbase.util.ClusterType;
@@ -92,6 +85,7 @@
9285
* @author Michael Nitschinger
9386
* @author Michael Reiche
9487
* @author Jens Schauder
88+
* @author Jonathan Massuchetti
9589
*/
9690
@SpringJUnitConfig(CouchbaseRepositoryQueryIntegrationTests.Config.class)
9791
@IgnoreWhen(missesCapabilities = Capabilities.QUERY, clusterTypes = ClusterType.MOCKED)
@@ -101,6 +95,9 @@ public class CouchbaseRepositoryQueryIntegrationTests extends ClusterAwareIntegr
10195

10296
@Autowired AirportRepository airportRepository;
10397

98+
@Autowired
99+
AirportDefaultConsistencyRepository airportDefaultConsistencyRepository;
100+
104101
@Autowired UserRepository userRepository;
105102

106103
@Autowired CouchbaseTemplate couchbaseTemplate;
@@ -212,9 +209,9 @@ public void saveNotBounded() {
212209
Airport airport2 = null;
213210
for (int i = 1; i <= 100; i++) {
214211
// set version == 0 so save() will be an upsert, not a replace
215-
Airport saved = airportRepository.save(vie.clearVersion());
212+
Airport saved = airportDefaultConsistencyRepository.save(vie.clearVersion());
216213
try {
217-
airport2 = airportRepository.iata(saved.getIata());
214+
airport2 = airportDefaultConsistencyRepository.iata(saved.getIata());
218215
if (airport2 == null) {
219216
break;
220217
}
@@ -227,14 +224,14 @@ public void saveNotBounded() {
227224
assertEquals(vie.getId(), removeResult.getId());
228225
assertTrue(removeResult.getCas() != 0);
229226
assertTrue(removeResult.getMutationToken().isPresent());
230-
Airport airport3 = airportRepository.iata(vie.getIata());
227+
Airport airport3 = airportDefaultConsistencyRepository.iata(vie.getIata());
231228
assertNull(airport3, "should have been removed");
232229
}
233230
}
234231
assertNull(airport2, "airport2 should have likely been null at least once");
235-
Airport saved = airportRepository.save(vie.clearVersion());
232+
Airport saved = airportDefaultConsistencyRepository.save(vie.clearVersion());
236233
couchbaseTemplate.findByQuery(Airport.class).withConsistency(REQUEST_PLUS).all();
237-
airport2 = airportRepository.iata(vie.getIata());
234+
airport2 = airportDefaultConsistencyRepository.iata(vie.getIata());
238235
RemoveResult removeResult = couchbaseTemplate.removeById().one(saved.getId());
239236
assertNotNull(airport2, "airport2 should have been found");
240237
}
@@ -244,7 +241,7 @@ public void saveNotBoundedRequestPlus() {
244241
ApplicationContext ac = new AnnotationConfigApplicationContext(ConfigRequestPlus.class);
245242
// the Config class has been modified, these need to be loaded again
246243
CouchbaseTemplate couchbaseTemplateRP = (CouchbaseTemplate) ac.getBean(COUCHBASE_TEMPLATE);
247-
AirportRepository airportRepositoryRP = (AirportRepository) ac.getBean("airportRepository");
244+
AirportDefaultConsistencyRepository airportRepositoryRP = (AirportDefaultConsistencyRepository) ac.getBean("airportDefaultConsistencyRepository");
248245

249246
// save() followed by query with NOT_BOUNDED will result in not finding the document
250247
Airport vie = new Airport("airports::vie", "vie", "low9");
@@ -277,6 +274,36 @@ public void saveNotBoundedRequestPlus() {
277274
assertFalse(!airports.isEmpty(), "airports should have been empty");
278275
}
279276

277+
278+
@Test
279+
public void saveNotBoundedRequestPlusWithDefaultRepository() {
280+
ApplicationContext ac = new AnnotationConfigApplicationContext(ConfigRequestPlus.class);
281+
// the Config class has been modified, these need to be loaded again
282+
CouchbaseTemplate couchbaseTemplateRP = (CouchbaseTemplate) ac.getBean(COUCHBASE_TEMPLATE);
283+
AirportDefaultConsistencyRepository airportRepositoryRP = (AirportDefaultConsistencyRepository) ac.getBean("airportDefaultConsistencyRepository");
284+
285+
List<Airport> sizeBeforeTest = airportRepositoryRP.findAll();
286+
assertEquals(0, sizeBeforeTest.size());
287+
288+
List<String> idsToRemove = new ArrayList<>(100);
289+
for (int i = 1; i <= 100; i++) {
290+
Airport vie = new Airport("airports::vie" + i, "vie" + i, "low9");
291+
Airport saved = airportRepositoryRP.save(vie);
292+
idsToRemove.add(saved.getId());
293+
}
294+
295+
List<Airport> allSaved = airportRepositoryRP.findAll();
296+
297+
boolean success = allSaved.size() == 100;
298+
299+
for (String idToRemove : idsToRemove) {
300+
couchbaseTemplateRP.removeById().one(idToRemove);
301+
}
302+
303+
assertTrue(success);
304+
}
305+
306+
280307
@Test
281308
void findByTypeAlias() {
282309
Airport vie = null;

0 commit comments

Comments
 (0)