mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-25 15:18:59 +00:00
#1119 - Deprecate TxRunnable and TxCallable - migrate to plan JDK Runnable and Callable. Add explicit executeCall() method
This commit is contained in:
1 parent
9a7646195c
commit
f77f3c3d6e
7 files changed
+127
-59
No files matched your search
@@ -2,31 +2,47 @@ package org.tests.transaction;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.TxRunnable;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestNested extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
public void testRunnableFail() {
|
||||
|
||||
try {
|
||||
Ebean.execute(() -> willFail());
|
||||
} catch (RuntimeException e) {
|
||||
Assert.assertEquals(e.getMessage(), "test rollback");
|
||||
Ebean.execute(this::willFail);
|
||||
} catch (PersistenceException e) {
|
||||
assertThat(e.getMessage()).contains("test runnable rollback");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCallableFail() {
|
||||
|
||||
try {
|
||||
Ebean.execute(this::willFailCallable);
|
||||
} catch (PersistenceException e) {
|
||||
assertThat(e.getMessage()).contains("test callable rollback");
|
||||
}
|
||||
}
|
||||
|
||||
private void willFail() {
|
||||
Ebean.execute(new TxRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
String msg = "test rollback";
|
||||
throw new RuntimeException(msg);
|
||||
|
||||
Ebean.executeCall(() -> {
|
||||
if (false) {
|
||||
return 123;
|
||||
}
|
||||
throw new RuntimeException("test runnable rollback");
|
||||
});
|
||||
}
|
||||
|
||||
private void willFailCallable() {
|
||||
Ebean.executeCall((Callable<String>) () -> {
|
||||
throw new Exception("test callable rollback");
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user