OPENJPA-1153: Speed tests up by using only needed entities rather than all entities from persistence.xml

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@826264 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Milosz Tylenda 2009-10-17 14:49:54 +00:00
parent 18f0e74899
commit c95593d8e2
6 changed files with 35 additions and 38 deletions

View File

@ -23,19 +23,18 @@ import javax.persistence.EntityManager;
import org.apache.openjpa.persistence.kernel.common.apps.AImplB; import org.apache.openjpa.persistence.kernel.common.apps.AImplB;
import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1; import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest2;
import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest3;
import org.apache.openjpa.persistence.common.utils.AbstractTestCase; import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
public class TestEJBGetObjectByIdValue extends AbstractTestCase { public class TestEJBGetObjectByIdValue extends AbstractTestCase {
private Object[] oids;
public TestEJBGetObjectByIdValue(String name) { public TestEJBGetObjectByIdValue(String name) {
super(name, "kernelcactusapp"); super(name, "kernelcactusapp");
} }
public void setUp() throws Exception { public void setUp() throws Exception {
deleteAll(RuntimeTest1.class); super.setUp(RuntimeTest1.class, RuntimeTest2.class, RuntimeTest3.class, AImplB.class);
deleteAll(AImplB.class);
EntityManager em = currentEntityManager(); EntityManager em = currentEntityManager();
startTx(em); startTx(em);
@ -56,12 +55,12 @@ public class TestEJBGetObjectByIdValue extends AbstractTestCase {
endEm(em); endEm(em);
em = currentEntityManager(); em = currentEntityManager();
pc = (RuntimeTest1) em.find(RuntimeTest1.class, 1); pc = em.find(RuntimeTest1.class, 1);
assertEquals("foo", pc.getStringField()); assertEquals("foo", pc.getStringField());
em.close(); em.close();
em = currentEntityManager(); em = currentEntityManager();
pc = (RuntimeTest1) em.find(RuntimeTest1.class, pc.getIntField()); pc = em.find(RuntimeTest1.class, pc.getIntField());
assertEquals("foo", pc.getStringField()); assertEquals("foo", pc.getStringField());
endEm(em); endEm(em);
} }
@ -78,12 +77,12 @@ public class TestEJBGetObjectByIdValue extends AbstractTestCase {
endEm(em); endEm(em);
em = currentEntityManager(); em = currentEntityManager();
pc = (AImplB) em.find(AImplB.class, oid); pc = em.find(AImplB.class, oid);
assertEquals("foo", pc.getName()); assertEquals("foo", pc.getName());
endEm(em); endEm(em);
em = currentEntityManager(); em = currentEntityManager();
pc = (AImplB) em.find(AImplB.class, oid.toString()); pc = em.find(AImplB.class, oid.toString());
assertEquals("foo", pc.getName()); assertEquals("foo", pc.getName());
endEm(em); endEm(em);
} }

View File

@ -24,6 +24,7 @@ import javax.persistence.EntityManager;
import org.apache.openjpa.persistence.kernel.common.apps.InterfaceHolder; import org.apache.openjpa.persistence.kernel.common.apps.InterfaceHolder;
import org.apache.openjpa.persistence.kernel.common.apps.InterfaceTestImpl1; import org.apache.openjpa.persistence.kernel.common.apps.InterfaceTestImpl1;
import org.apache.openjpa.persistence.kernel.common.apps.InterfaceTestImpl2; import org.apache.openjpa.persistence.kernel.common.apps.InterfaceTestImpl2;
import org.apache.openjpa.persistence.kernel.common.apps.InterfaceTestImpl3;
import org.apache.openjpa.persistence.common.utils.AbstractTestCase; import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
/** /**
@ -37,16 +38,14 @@ public class TestEJBInterfaces extends AbstractTestCase {
super(name, "kernelcactusapp"); super(name, "kernelcactusapp");
} }
@Override
public void setUp() throws Exception {
super.setUp(InterfaceTestImpl1.class, InterfaceTestImpl2.class, InterfaceTestImpl3.class,
InterfaceHolder.class);
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testInterfaceField() { public void testInterfaceField() {
try {
deleteAll(InterfaceTestImpl1.class);
deleteAll(InterfaceTestImpl2.class);
deleteAll(InterfaceHolder.class);
}
catch (Exception e) {
}
EntityManager em2 = currentEntityManager(); EntityManager em2 = currentEntityManager();
startTx(em2); startTx(em2);
@ -65,8 +64,7 @@ public class TestEJBInterfaces extends AbstractTestCase {
em = currentEntityManager(); em = currentEntityManager();
startTx(em); startTx(em);
InterfaceHolder hold = InterfaceHolder hold = em.find(InterfaceHolder.class, 1);
(InterfaceHolder) em.find(InterfaceHolder.class, 1);
assertNotNull(hold.getIntf()); assertNotNull(hold.getIntf());
assertEquals("intf-1-field", hold.getIntf().getStringField()); assertEquals("intf-1-field", hold.getIntf().getStringField());
endTx(em); endTx(em);
@ -74,7 +72,7 @@ public class TestEJBInterfaces extends AbstractTestCase {
em = currentEntityManager(); em = currentEntityManager();
startTx(em); startTx(em);
hold = (InterfaceHolder) em.find(InterfaceHolder.class, 1); hold = em.find(InterfaceHolder.class, 1);
hold.setIntf(null); hold.setIntf(null);
assertNull(hold.getIntf()); assertNull(hold.getIntf());
endTx(em); endTx(em);
@ -82,14 +80,14 @@ public class TestEJBInterfaces extends AbstractTestCase {
em = currentEntityManager(); em = currentEntityManager();
startTx(em); startTx(em);
hold = (InterfaceHolder) em.find(InterfaceHolder.class, 1); hold = em.find(InterfaceHolder.class, 1);
assertNull(hold.getIntf()); assertNull(hold.getIntf());
endTx(em); endTx(em);
endEm(em); endEm(em);
em = currentEntityManager(); em = currentEntityManager();
startTx(em); startTx(em);
hold = (InterfaceHolder) em.find(InterfaceHolder.class, 1); hold = em.find(InterfaceHolder.class, 1);
hold.setIntf(new InterfaceTestImpl2("intf-2-field")); hold.setIntf(new InterfaceTestImpl2("intf-2-field"));
assertEquals("intf-2-field", hold.getIntf().getStringField()); assertEquals("intf-2-field", hold.getIntf().getStringField());
endTx(em); endTx(em);
@ -97,7 +95,7 @@ public class TestEJBInterfaces extends AbstractTestCase {
em = currentEntityManager(); em = currentEntityManager();
startTx(em); startTx(em);
hold = (InterfaceHolder) em.find(InterfaceHolder.class, 1); hold = em.find(InterfaceHolder.class, 1);
assertNotNull(hold.getIntf()); assertNotNull(hold.getIntf());
assertEquals("intf-2-field", hold.getIntf().getStringField()); assertEquals("intf-2-field", hold.getIntf().getStringField());
endTx(em); endTx(em);
@ -105,7 +103,7 @@ public class TestEJBInterfaces extends AbstractTestCase {
em = currentEntityManager(); em = currentEntityManager();
startTx(em); startTx(em);
hold = (InterfaceHolder) em.find(InterfaceHolder.class, 1); hold = em.find(InterfaceHolder.class, 1);
hold.getIntfs().add(new InterfaceTestImpl1("intf-1-set")); hold.getIntfs().add(new InterfaceTestImpl1("intf-1-set"));
endTx(em); endTx(em);
endEm(em); endEm(em);

View File

@ -25,6 +25,8 @@ import javax.persistence.EntityManager;
import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1; import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest1;
import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest2;
import org.apache.openjpa.persistence.kernel.common.apps.RuntimeTest3;
import org.apache.openjpa.persistence.common.utils.AbstractTestCase; import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
public class TestEJBLocales extends AbstractTestCase { public class TestEJBLocales extends AbstractTestCase {
@ -33,8 +35,8 @@ public class TestEJBLocales extends AbstractTestCase {
super(name, "kernelcactusapp"); super(name, "kernelcactusapp");
} }
public void setUp() { public void setUp() throws Exception {
deleteAll(RuntimeTest1.class); super.setUp(RuntimeTest1.class, RuntimeTest2.class, RuntimeTest3.class);
} }
public void testLocales() { public void testLocales() {

View File

@ -30,8 +30,8 @@ public class TestEJBNullValues extends AbstractTestCase {
super(name, "kernelcactusapp"); super(name, "kernelcactusapp");
} }
public void setUp() { public void setUp() throws Exception {
deleteAll(Inner.class); super.setUp(Inner.class);
} }
public void testException() { public void testException() {

View File

@ -27,14 +27,12 @@ import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
public class TestEJBState extends AbstractTestCase { public class TestEJBState extends AbstractTestCase {
private static final int INSERT_COUNT = 20;
public TestEJBState(String name) { public TestEJBState(String name) {
super(name, "kernelcactusapp"); super(name, "kernelcactusapp");
} }
public void setUp() { public void setUp() throws Exception {
deleteAll(AllFieldsTypeTest.class); super.setUp(AllFieldsTypeTest.class);
} }
public void testBigDecimalsLoseTrailingZeros() { public void testBigDecimalsLoseTrailingZeros() {

View File

@ -20,14 +20,13 @@ package org.apache.openjpa.persistence.kernel;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import org.apache.openjpa.persistence.kernel.common.apps.UnAnnotPojo;
import org.apache.openjpa.persistence.common.utils.AbstractTestCase; import org.apache.openjpa.persistence.common.utils.AbstractTestCase;
/* import org.apache.openjpa.persistence.kernel.common.apps.UnAnnotPojo;
* @author Afam Okeke
* Ensures that pojo that is not persistent capable cannot be persisted.
*/
/**
* Ensures that pojo that is not persistent capable cannot be persisted.
* @author Afam Okeke
*/
public class TestPojoWithoutAnnotationsCannotBePersisted public class TestPojoWithoutAnnotationsCannotBePersisted
extends AbstractTestCase { extends AbstractTestCase {
@ -37,7 +36,8 @@ public class TestPojoWithoutAnnotationsCannotBePersisted
super(name, "kernelcactusapp"); super(name, "kernelcactusapp");
} }
public void setUp() { public void setUp() throws Exception {
super.setUp(new Object[] {});
pojo = new UnAnnotPojo(); pojo = new UnAnnotPojo();
pojo.setName("failure"); pojo.setName("failure");
pojo.setNum(0); pojo.setNum(0);