mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Remove the deprecated methods: - DB.commitTransaction() - DB.rollbackTransaction() - DB.endTransaction() - database.commitTransaction() - database.rollbackTransaction() - database.endTransaction() Migrate to using try-with-resources and transaction.commit(), transaction.rollback()
75 lines
1.6 KiB
Java
75 lines
1.6 KiB
Java
package org.tests.query;
|
|
|
|
import io.ebean.Transaction;
|
|
import io.ebean.xtest.BaseTestCase;
|
|
import io.ebean.DB;
|
|
import io.ebean.Query;
|
|
import org.junit.jupiter.api.Test;
|
|
import org.tests.model.basic.Customer;
|
|
|
|
import static org.junit.jupiter.api.Assertions.fail;
|
|
|
|
public class TestConnectionCloseOnSqlerr extends BaseTestCase {
|
|
|
|
static boolean runManuallyNow = true;
|
|
|
|
@Test
|
|
public void test() {
|
|
|
|
if (runManuallyNow) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
for (int i = 0; i < 100; i++) {
|
|
try {
|
|
Query<Customer> q0 = DB.find(Customer.class).where().icontains("namexxx", "Rob")
|
|
.query();
|
|
|
|
q0.findList();
|
|
} catch (Exception e) {
|
|
if (e.getMessage().contains("Unsuccessfully waited")) {
|
|
fail();
|
|
} else {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
|
|
@Test
|
|
public void testTransactional() {
|
|
|
|
if (runManuallyNow) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
for (int i = 0; i < 100; i++) {
|
|
try (Transaction txn = DB.beginTransaction()) {
|
|
Query<Customer> q0 = DB.find(Customer.class).where().icontains("namexxx", "Rob")
|
|
.query();
|
|
|
|
q0.findList();
|
|
txn.commit();
|
|
} catch (Exception e) {
|
|
if (e.getMessage().contains("Unsuccessfully waited")) {
|
|
fail("No connections found while only one thread is running. (after " + i + " queries)");
|
|
} else {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
|
|
}
|
|
}
|