Skip to content

Commit df97182

Browse files
committed
Cleanup of test classes.
1 parent b0805ad commit df97182

9 files changed

+231
-347
lines changed

src/main/java/org/springframework/data/couchbase/core/ExecutableFindByIdOperationSupport.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ static class ExecutableFindByIdSupport<T> implements ExecutableFindById<T> {
6767

6868
@Override
6969
public T one(final String id) {
70-
//Mono.deferContextual(ctx -> { System.err.println("ExecutableFindById.ctx: "+ctx); return Mono.empty();}).block();
71-
return reactiveSupport.one(id)/*.contextWrite(TransactionContextManager.getOrCreateContext())
72-
.contextWrite(TransactionContextManager.getOrCreateContextHolder())*/.block();
70+
return reactiveSupport.one(id).block();
7371
}
7472

7573
@Override

src/main/java/org/springframework/data/couchbase/core/ReactiveFindByIdOperationSupport.java

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ static class ReactiveFindByIdSupport<T> implements ReactiveFindById<T> {
6969
private final Duration expiry;
7070

7171
ReactiveFindByIdSupport(ReactiveCouchbaseTemplate template, Class<T> domainType, String scope, String collection,
72-
CommonOptions<?> options, List<String> fields, Duration expiry, CouchbaseTransactionalOperator txCtx,
73-
ReactiveTemplateSupport support) {
72+
CommonOptions<?> options, List<String> fields, Duration expiry, CouchbaseTransactionalOperator txCtx,
73+
ReactiveTemplateSupport support) {
7474
this.template = template;
7575
this.domainType = domainType;
7676
this.scope = scope;
@@ -95,28 +95,24 @@ public Mono<T> one(final String id) {
9595
// this will get me a template with a session holding tx
9696
Mono<ReactiveCouchbaseTemplate> tmpl = template.doGetTemplate();
9797

98-
Mono<T> reactiveEntity = tmpl.flatMap(tp -> tp.getCouchbaseClientFactory().getResourceHolderMono()
99-
.flatMap(s -> {
100-
System.err.println("Session: "+s);
101-
//Mono<T> reactiveEntity = Mono.defer(() -> {
102-
if (s == null || s.getCore() == null) {
103-
if (pArgs.getOptions() instanceof GetAndTouchOptions) {
104-
return rc.getAndTouch(id, expiryToUse(), (GetAndTouchOptions) pArgs.getOptions())
105-
.flatMap(result -> support.decodeEntity(id, result.contentAs(String.class), result.cas(), domainType,
106-
pArgs.getScope(), pArgs.getCollection(), null));
107-
} else {
108-
return rc.get(id, (GetOptions) pArgs.getOptions())
109-
.flatMap(result -> support.decodeEntity(id, result.contentAs(String.class), result.cas(), domainType,
110-
pArgs.getScope(), pArgs.getCollection(), null));
111-
}
112-
} else {
113-
return s.getCore().get(makeCollectionIdentifier(rc.async()), id)
114-
.flatMap( result -> {
115-
return support.decodeEntity(id, new String(result.contentAsBytes(), StandardCharsets.UTF_8), result.cas(), domainType, pArgs.getScope(),
116-
pArgs.getCollection(), new TransactionResultHolder(result), null);
117-
});
118-
}
119-
}));
98+
Mono<T> reactiveEntity = tmpl.flatMap(tp -> tp.getCouchbaseClientFactory().getResourceHolderMono().flatMap(s -> {
99+
if (s == null || s.getCore() == null) {
100+
if (pArgs.getOptions() instanceof GetAndTouchOptions) {
101+
return rc.getAndTouch(id, expiryToUse(), (GetAndTouchOptions) pArgs.getOptions())
102+
.flatMap(result -> support.decodeEntity(id, result.contentAs(String.class), result.cas(), domainType,
103+
pArgs.getScope(), pArgs.getCollection(), null));
104+
} else {
105+
return rc.get(id, (GetOptions) pArgs.getOptions())
106+
.flatMap(result -> support.decodeEntity(id, result.contentAs(String.class), result.cas(), domainType,
107+
pArgs.getScope(), pArgs.getCollection(), null));
108+
}
109+
} else {
110+
return s.getCore().get(makeCollectionIdentifier(rc.async()), id)
111+
.flatMap(result -> support.decodeEntity(id, new String(result.contentAsBytes(), StandardCharsets.UTF_8),
112+
result.cas(), domainType, pArgs.getScope(), pArgs.getCollection(),
113+
new TransactionResultHolder(result), null));
114+
}
115+
}));
120116

121117
return reactiveEntity.onErrorResume(throwable -> {
122118
if (throwable instanceof DocumentNotFoundException) {

src/test/java/org/springframework/data/couchbase/transactions/CouchbasePersonTransactionIntegrationTests.java

Lines changed: 65 additions & 56 deletions
Large diffs are not rendered by default.

src/test/java/org/springframework/data/couchbase/transactions/CouchbasePersonTransactionReactiveIntegrationTests.java

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -81,29 +81,22 @@
8181
* @author Michael Reiche
8282
*/
8383
@IgnoreWhen(missesCapabilities = Capabilities.QUERY, clusterTypes = ClusterType.MOCKED)
84-
@SpringJUnitConfig(CouchbasePersonTransactionReactiveIntegrationTests.Config.class)
85-
//@Transactional(transactionManager = BeanNames.COUCHBASE_TRANSACTION_MANAGER)
84+
@SpringJUnitConfig(classes = { CouchbasePersonTransactionReactiveIntegrationTests.Config.class, CouchbasePersonTransactionReactiveIntegrationTests.PersonService.class } )
8685
public class CouchbasePersonTransactionReactiveIntegrationTests extends JavaIntegrationTests {
87-
86+
// intellij flags "Could not autowire" when config classes are specified with classes={...}. But they are populated.
8887
@Autowired CouchbaseClientFactory couchbaseClientFactory;
8988
@Autowired ReactiveCouchbaseTransactionManager reactiveCouchbaseTransactionManager;
9089
@Autowired CouchbaseSimpleCallbackTransactionManager couchbaseTransactionManager;
9190
@Autowired ReactivePersonRepository rxRepo;
9291
@Autowired PersonRepository repo;
9392
@Autowired ReactiveCouchbaseTemplate rxCBTmpl;
94-
9593
@Autowired Cluster myCluster;
96-
97-
/* DO NOT @Autowired */ PersonService personService;
98-
99-
static GenericApplicationContext context;
94+
@Autowired PersonService personService;
10095
@Autowired ReactiveCouchbaseTemplate operations;
10196

10297
@BeforeAll
10398
public static void beforeAll() {
10499
callSuperBeforeAll(new Object() {});
105-
context = new AnnotationConfigApplicationContext(CouchbasePersonTransactionReactiveIntegrationTests.Config.class,
106-
CouchbasePersonTransactionReactiveIntegrationTests.PersonService.class);
107100
}
108101

109102
@AfterAll
@@ -113,28 +106,24 @@ public static void afterAll() {
113106

114107
@BeforeEach
115108
public void beforeEachTest() {
116-
personService = context.getBean(CouchbasePersonTransactionReactiveIntegrationTests.PersonService.class); // getting it via autowired results in no @Transactional
117109
operations.removeByQuery(Person.class).withConsistency(REQUEST_PLUS).all().collectList().block();
118110
operations.removeByQuery(EventLog.class).withConsistency(REQUEST_PLUS).all().collectList().block();
119111
operations.findByQuery(Person.class).withConsistency(REQUEST_PLUS).all().collectList().block();
120112
operations.findByQuery(EventLog.class).withConsistency(REQUEST_PLUS).all().collectList().block();
121113
}
122114

123-
124-
@Test // DATAMONGO-2265
115+
@Test
125116
public void shouldRollbackAfterException() {
126117
personService.savePersonErrors(new Person(null, "Walter", "White")) //
127118
.as(StepVerifier::create) //
128119
.verifyError(RuntimeException.class);
129-
// operations.findByQuery(Person.class).withConsistency(QueryScanConsistency.REQUEST_PLUS).count().block();
130-
// sleepMs(5000);
131120
operations.count(new Query(), Person.class) //
132121
.as(StepVerifier::create) //
133122
.expectNext(0L) //
134123
.verifyComplete();
135124
}
136125

137-
@Test // DATAMONGO-2265
126+
@Test
138127
// @Rollback(false)
139128
public void shouldRollbackAfterExceptionOfTxAnnotatedMethod() {
140129
Person p = new Person(null, "Walter", "White");
@@ -153,7 +142,7 @@ public void shouldRollbackAfterExceptionOfTxAnnotatedMethod() {
153142

154143
}
155144

156-
@Test // DATAMONGO-2265
145+
@Test
157146
public void commitShouldPersistTxEntries() {
158147

159148
personService.savePerson(new Person(null, "Walter", "White")) //
@@ -169,7 +158,7 @@ public void commitShouldPersistTxEntries() {
169158
.verifyComplete();
170159
}
171160

172-
@Test // DATAMONGO-2265
161+
@Test
173162
public void commitShouldPersistTxEntriesOfTxAnnotatedMethod() {
174163

175164
personService.declarativeSavePerson(new Person(null, "Walter", "White")).as(StepVerifier::create) //
@@ -183,7 +172,7 @@ public void commitShouldPersistTxEntriesOfTxAnnotatedMethod() {
183172

184173
}
185174

186-
@Test // DATAMONGO-2265
175+
@Test
187176
public void commitShouldPersistTxEntriesAcrossCollections() {
188177

189178
personService.saveWithLogs(new Person(null, "Walter", "White")) //
@@ -202,7 +191,7 @@ public void commitShouldPersistTxEntriesAcrossCollections() {
202191
.verifyComplete();
203192
}
204193

205-
@Test // DATAMONGO-2265
194+
@Test
206195
public void rollbackShouldAbortAcrossCollections() {
207196

208197
personService.saveWithErrorLogs(new Person(null, "Walter", "White")) //
@@ -221,16 +210,15 @@ public void rollbackShouldAbortAcrossCollections() {
221210
.verifyComplete();
222211
}
223212

224-
@Test // DATAMONGO-2265
213+
@Test
225214
public void countShouldWorkInsideTransaction() {
226-
227215
personService.countDuringTx(new Person(null, "Walter", "White")) //
228216
.as(StepVerifier::create) //
229217
.expectNext(1L) //
230218
.verifyComplete();
231219
}
232220

233-
@Test // DATAMONGO-2265
221+
@Test
234222
public void emitMultipleElementsDuringTransaction() {
235223

236224
try {
@@ -244,21 +232,14 @@ public void emitMultipleElementsDuringTransaction() {
244232
}
245233
}
246234

247-
@Test // DATAMONGO-2265
235+
@Test
248236
public void errorAfterTxShouldNotAffectPreviousStep() {
249237

250238
Person p = new Person(1, "Walter", "White");
251-
//remove(couchbaseTemplate, "_default", p.getId().toString());
252239
personService.savePerson(p) //
253-
//.delayElement(Duration.ofMillis(100)) //
254240
.then(Mono.error(new RuntimeException("my big bad evil error"))).as(StepVerifier::create) //
255241
.expectError()
256242
.verify();
257-
//.expectError() //
258-
//.as(StepVerifier::create)
259-
//.expectNext(p)
260-
//.verifyComplete();
261-
262243
operations.findByQuery(Person.class).withConsistency(REQUEST_PLUS).count() //
263244
.as(StepVerifier::create) //
264245
.expectNext(1L) //

0 commit comments

Comments
 (0)