mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
The BaseTestCase ensures, that the threadLocal is cleared after each test. (#1712)
* The BaseTestCase ensures, that the threadLocal is cleared after each test. * Change JdbcTransaction.toString to distingush between active and inactive transaction
This commit is contained in:
committed by
Rob Bygrave
parent
2678f85506
commit
895b5ee4ff
@@ -9,12 +9,18 @@ import io.ebean.meta.ServerMetrics;
|
||||
import io.ebean.util.StringHelper;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.api.SpiQuery;
|
||||
import io.ebeaninternal.api.SpiTransaction;
|
||||
import io.ebeaninternal.server.core.HelpCreateQueryRequest;
|
||||
import io.ebeaninternal.server.core.OrmQueryRequest;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
import io.ebeaninternal.server.expression.platform.DbExpressionHandler;
|
||||
import io.ebeaninternal.server.expression.platform.DbExpressionHandlerFactory;
|
||||
import io.ebeaninternal.server.transaction.DefaultTransactionThreadLocal;
|
||||
|
||||
import org.avaje.agentloader.AgentLoader;
|
||||
import org.junit.After;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TestName;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -22,15 +28,32 @@ import org.tests.model.basic.Country;
|
||||
|
||||
import java.sql.Types;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@RunWith(ConditionalTestRunner.class)
|
||||
public abstract class BaseTestCase {
|
||||
|
||||
protected static Logger logger = LoggerFactory.getLogger(BaseTestCase.class);
|
||||
|
||||
@Rule public TestName name = new TestName();
|
||||
|
||||
@After
|
||||
public void checkForLeak() {
|
||||
Map<String, SpiTransaction> trans = DefaultTransactionThreadLocal.currentTransactions();
|
||||
if (trans != null) {
|
||||
if (!trans.isEmpty()) {
|
||||
String msg = getClass().getSimpleName() + "." + name.getMethodName() + " did not clear threadScope:" + trans;
|
||||
trans.clear(); // clear for next test
|
||||
fail(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* this is the clock delta that may occur between testing machine and db server.
|
||||
* If the clock delta of DB server is in future, an "asOf" query may not find the
|
||||
|
||||
Reference in New Issue
Block a user