Skip to content

Commit 5633181

Browse files
Datacouch 1145 transaction support (#1448)
* Move CouchbaseTransactionalOperator to use SLF4J, same as rest of the code. * Handle all propagation levels * Adding new tests for repository calls inside @transactional One test is failure due to what looks like a bug elsewhere. * Rename CouchbaseTransactionalIntegrationTests, and check after each test that we're not in a transaction. * Remove unnecessary methods From ReactiveCouchbaseClientFactory. Also rationalized naming of methods and other changes. * Cleanup of test classes. * Removing unused classes (Reducing the cognitive burden) * Removing version from CouchbaseDocument This change was done previously - it must have slipped back in a merge. * Adding and removing TODOs * Adding and removing TODOs * DRYing CouchbaseTransactionalPropagationIntegrationTests * Check propagation tests retry as expected * Tidy up PersonWithoutVersion to the minimum required * Removing unused code This should all be non-destructive. Just removing code IntelliJ declares unused. Intent is to make it easier to figure out how the CoreTransactionAttemptContext TLS is working. * Adding tests for @transactional removeByQuery and findByQuery Failing as they aren't being executed transactionally - investigating why. Co-authored-by: Michael Reiche <[email protected]>
1 parent df97182 commit 5633181

File tree

43 files changed

+149
-2333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+149
-2333
lines changed

src/main/java/com/couchbase/client/java/transactions/AttemptContextReactiveAccessor.java

+1-76
Original file line numberDiff line numberDiff line change
@@ -66,22 +66,6 @@ public static ReactiveTransactionAttemptContext reactive(TransactionAttemptConte
6666
return new ReactiveTransactionAttemptContext(getCore(atr), serializer);
6767
}
6868

69-
public static TransactionAttemptContext blocking(ReactiveTransactionAttemptContext atr) {
70-
JsonSerializer serializer;
71-
try {
72-
Field field = ReactiveTransactionAttemptContext.class.getDeclaredField("serializer");
73-
field.setAccessible(true);
74-
serializer = (JsonSerializer) field.get(atr);
75-
} catch (Throwable err) {
76-
throw new RuntimeException(err);
77-
}
78-
return new TransactionAttemptContext(getCore(atr), serializer);
79-
}
80-
81-
public static CoreTransactionLogger getLogger(ReactiveTransactionAttemptContext attemptContextReactive) {
82-
return attemptContextReactive.logger();
83-
}
84-
8569
public static CoreTransactionLogger getLogger(TransactionAttemptContext attemptContextReactive) {
8670
return attemptContextReactive.logger();
8771
}
@@ -100,6 +84,7 @@ public static CoreTransactionAttemptContext newCoreTranactionAttemptContext(Reac
10084
throw new RuntimeException(err);
10185
}
10286

87+
// todo gpx options need to be loaded from Cluster and TransactionOptions (from TransactionsWrapper)
10388
CoreTransactionOptions perConfig = new CoreTransactionOptions(Optional.empty(), Optional.empty(), Optional.empty(),
10489
Optional.of(Duration.ofMinutes(10)), Optional.empty(), Optional.empty());
10590

@@ -115,16 +100,6 @@ public static CoreTransactionAttemptContext newCoreTranactionAttemptContext(Reac
115100
return coreTransactionAttemptContext;
116101
}
117102

118-
private static Duration now() {
119-
return Duration.of(System.nanoTime(), ChronoUnit.NANOS);
120-
}
121-
122-
public static ReactiveTransactionAttemptContext from(CoreTransactionAttemptContext coreTransactionAttemptContext,
123-
JsonSerializer serializer) {
124-
TransactionAttemptContext tac = new TransactionAttemptContext(coreTransactionAttemptContext, serializer);
125-
return reactive(tac);
126-
}
127-
128103
public static CoreTransactionAttemptContext getCore(ReactiveTransactionAttemptContext atr) {
129104
CoreTransactionAttemptContext coreTransactionsReactive;
130105
try {
@@ -147,61 +122,11 @@ public static CoreTransactionAttemptContext getCore(TransactionAttemptContext at
147122
}
148123
}
149124

150-
public static Mono<Void> implicitCommit(ReactiveTransactionAttemptContext atr, boolean b) {
151-
CoreTransactionAttemptContext coreTransactionsReactive = getCore(atr);
152-
try {
153-
// getDeclaredMethod() does not find it (because of primitive arg?)
154-
// CoreTransactionAttemptContext.class.getDeclaredMethod("implicitCommit", Boolean.class);
155-
Method[] methods = CoreTransactionAttemptContext.class.getDeclaredMethods();
156-
Method method = null;
157-
for (Method m : methods) {
158-
if (m.getName().equals("implicitCommit")) {
159-
method = m;
160-
break;
161-
}
162-
}
163-
if (method == null) {
164-
throw new RuntimeException("did not find implicitCommit method");
165-
}
166-
method.setAccessible(true);
167-
return (Mono<Void>) method.invoke(coreTransactionsReactive, b);
168-
} catch (Throwable err) {
169-
throw new RuntimeException(err);
170-
}
171-
172-
}
173-
174-
public static AttemptState getState(ReactiveTransactionAttemptContext atr) {
175-
CoreTransactionAttemptContext coreTransactionsReactive = getCore(atr);
176-
try {
177-
Field field = CoreTransactionAttemptContext.class.getDeclaredField("state");
178-
field.setAccessible(true);
179-
return (AttemptState) field.get(coreTransactionsReactive);
180-
} catch (Throwable err) {
181-
throw new RuntimeException(err);
182-
}
183-
}
184-
185125
public static ReactiveTransactionAttemptContext createReactiveTransactionAttemptContext(
186126
CoreTransactionAttemptContext core, JsonSerializer jsonSerializer) {
187127
return new ReactiveTransactionAttemptContext(core, jsonSerializer);
188128
}
189129

190-
public static CoreTransactionsReactive getCoreTransactionsReactive(ReactiveTransactions transactions) {
191-
try {
192-
Field field = ReactiveTransactions.class.getDeclaredField("internal");
193-
field.setAccessible(true);
194-
return (CoreTransactionsReactive) field.get(transactions);
195-
} catch (Throwable err) {
196-
throw new RuntimeException(err);
197-
}
198-
}
199-
200-
public static TransactionAttemptContext newTransactionAttemptContext(CoreTransactionAttemptContext ctx,
201-
JsonSerializer jsonSerializer) {
202-
return new TransactionAttemptContext(ctx, jsonSerializer);
203-
}
204-
205130
public static TransactionResult run(Transactions transactions, Consumer<TransactionAttemptContext> transactionLogic, CoreTransactionOptions coreTransactionOptions) {
206131
return reactive(transactions).runBlocking(transactionLogic, coreTransactionOptions);
207132
}

0 commit comments

Comments
 (0)