committed by
mikereiche
parent
6eccb39e95
commit
ce57f76ea4
@@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.springframework.data.couchbase.transactions.util.TransactionTestUtil.assertNotInTransaction;
|
||||
import static org.springframework.data.couchbase.util.Util.assertInAnnotationTransaction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -483,20 +484,4 @@ public class CouchbaseTransactionalTemplateCollectionDefaultScopeIntegrationTest
|
||||
|
||||
}
|
||||
|
||||
static void assertInAnnotationTransaction(boolean inTransaction) {
|
||||
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
|
||||
for (StackTraceElement ste : stack) {
|
||||
if (ste.getClassName().startsWith("org.springframework.transaction.interceptor")) {
|
||||
if (inTransaction) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!inTransaction) {
|
||||
return;
|
||||
}
|
||||
throw new RuntimeException(
|
||||
"in transaction = " + (!inTransaction) + " but expected in annotation transaction = " + inTransaction);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.springframework.data.couchbase.transactions.util.TransactionTestUtil.assertNotInTransaction;
|
||||
import static org.springframework.data.couchbase.util.Util.assertInAnnotationTransaction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -450,10 +451,10 @@ public class CouchbaseTransactionalTemplateCollectionIntegrationTests extends Co
|
||||
}
|
||||
|
||||
@Transactional(timeout = 2)
|
||||
|
||||
public Person replace(Person person, AtomicInteger tryCount) {
|
||||
assertInAnnotationTransaction(true);
|
||||
tryCount.incrementAndGet();
|
||||
System.err.println("try: " + tryCount.get());
|
||||
return personOperations.replaceById(Person.class).inScope(scopeName).inCollection(collectionName).one(person);
|
||||
}
|
||||
|
||||
@@ -483,20 +484,4 @@ public class CouchbaseTransactionalTemplateCollectionIntegrationTests extends Co
|
||||
|
||||
}
|
||||
|
||||
static void assertInAnnotationTransaction(boolean inTransaction) {
|
||||
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
|
||||
for (StackTraceElement ste : stack) {
|
||||
if (ste.getClassName().startsWith("org.springframework.transaction.interceptor")) {
|
||||
if (inTransaction) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!inTransaction) {
|
||||
return;
|
||||
}
|
||||
throw new RuntimeException(
|
||||
"in transaction = " + (!inTransaction) + " but expected in annotation transaction = " + inTransaction);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,9 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.springframework.data.couchbase.transactions.util.TransactionTestUtil.assertInReactiveTransaction;
|
||||
import static org.springframework.data.couchbase.transactions.util.TransactionTestUtil.assertNotInTransaction;
|
||||
import static org.springframework.data.couchbase.util.Util.assertInAnnotationTransaction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -394,6 +396,7 @@ public class CouchbaseTransactionalTemplateIntegrationTests extends JavaIntegrat
|
||||
@Transactional
|
||||
public Person declarativeSavePersonWithThread(Person person, Thread thread) {
|
||||
assertInAnnotationTransaction(true);
|
||||
assertInReactiveTransaction();
|
||||
long currentThreadId = Thread.currentThread().getId();
|
||||
System.out.printf("Thread %d %s, started from %d %s%n", Thread.currentThread().getId(),
|
||||
Thread.currentThread().getName(), thread.getId(), thread.getName());
|
||||
@@ -483,20 +486,4 @@ public class CouchbaseTransactionalTemplateIntegrationTests extends JavaIntegrat
|
||||
|
||||
}
|
||||
|
||||
static void assertInAnnotationTransaction(boolean inTransaction) {
|
||||
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
|
||||
for (StackTraceElement ste : stack) {
|
||||
if (ste.getClassName().startsWith("org.springframework.transaction.interceptor")) {
|
||||
if (inTransaction) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!inTransaction) {
|
||||
return;
|
||||
}
|
||||
throw new RuntimeException(
|
||||
"in transaction = " + (!inTransaction) + " but expected in annotation transaction = " + inTransaction);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -155,7 +155,8 @@ public class Util {
|
||||
public static void assertInAnnotationTransaction(boolean inTransaction) {
|
||||
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
|
||||
for (StackTraceElement ste : stack) {
|
||||
if (ste.getClassName().startsWith("org.springframework.transaction.interceptor")
|
||||
if (ste.getClassName()
|
||||
.startsWith("org.springframework.data.couchbase.transaction.CouchbaseCallbackTransactionManager")
|
||||
|| ste.getClassName().startsWith("org.springframework.data.couchbase.transaction.interceptor")) {
|
||||
if (inTransaction) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user