mirror of https://github.com/apache/openjpa.git
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@814295 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
558446dfe9
commit
e9b5c53fd0
|
@ -67,6 +67,7 @@ import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.StringTokenizer;
|
import java.util.StringTokenizer;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import javax.management.IntrospectionException;
|
import javax.management.IntrospectionException;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
@ -93,6 +94,7 @@ public abstract class AbstractTestCase extends AbstractCachedEMFTestCase {
|
||||||
private Map<Map,OpenJPAEntityManagerFactory> emfs =
|
private Map<Map,OpenJPAEntityManagerFactory> emfs =
|
||||||
new HashMap<Map,OpenJPAEntityManagerFactory>();
|
new HashMap<Map,OpenJPAEntityManagerFactory>();
|
||||||
private OpenJPAEntityManager currentEntityManager;
|
private OpenJPAEntityManager currentEntityManager;
|
||||||
|
private Object[] props;
|
||||||
|
|
||||||
protected enum Platform {
|
protected enum Platform {
|
||||||
EMPRESS,
|
EMPRESS,
|
||||||
|
@ -118,6 +120,18 @@ public abstract class AbstractTestCase extends AbstractCachedEMFTestCase {
|
||||||
persistenceXmlResource = computePersistenceXmlResource(s);
|
persistenceXmlResource = computePersistenceXmlResource(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use the given persistent types during the test.
|
||||||
|
*
|
||||||
|
* @param props
|
||||||
|
* list of persistent types used in testing and/or configuration values in the form
|
||||||
|
* key,value,key,value...
|
||||||
|
*/
|
||||||
|
protected void setUp(Object... props) throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
this.props = props;
|
||||||
|
}
|
||||||
|
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() throws Exception {
|
||||||
try {
|
try {
|
||||||
super.tearDown();
|
super.tearDown();
|
||||||
|
@ -194,11 +208,25 @@ public abstract class AbstractTestCase extends AbstractCachedEMFTestCase {
|
||||||
addProperties(map);
|
addProperties(map);
|
||||||
|
|
||||||
OpenJPAEntityManagerFactory emf = emfs.get(map);
|
OpenJPAEntityManagerFactory emf = emfs.get(map);
|
||||||
if (emf == null) {
|
if (emf != null) {
|
||||||
emf = OpenJPAPersistence.createEntityManagerFactory(
|
return emf;
|
||||||
"TestConv", persistenceXmlResource, map);
|
|
||||||
emfs.put(map, emf);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (props != null) {
|
||||||
|
// Join properties passed in setUp (usually entities) with the given map and use them to create EMF.
|
||||||
|
Object[] propsAndMap = new Object[props.length + map.size() * 2];
|
||||||
|
System.arraycopy(props, 0, propsAndMap, 0, props.length);
|
||||||
|
int i = props.length;
|
||||||
|
for (Object o : map.entrySet()) {
|
||||||
|
Entry mapEntry = (Entry) o;
|
||||||
|
propsAndMap[i++] = mapEntry.getKey();
|
||||||
|
propsAndMap[i++] = mapEntry.getValue();
|
||||||
|
}
|
||||||
|
emf = createEMF(propsAndMap);
|
||||||
|
} else {
|
||||||
|
emf = OpenJPAPersistence.createEntityManagerFactory("TestConv", persistenceXmlResource, map);
|
||||||
|
}
|
||||||
|
emfs.put(map, emf);
|
||||||
return emf;
|
return emf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,8 @@ public class TestCalendarFields extends BaseKernelTest {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
deleteAll(CalendarFields.class);
|
super.setUp(CalendarFields.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFieldDefaultTimeZone() {
|
public void testFieldDefaultTimeZone() {
|
||||||
|
@ -67,7 +67,7 @@ public class TestCalendarFields extends BaseKernelTest {
|
||||||
endEm(pm);
|
endEm(pm);
|
||||||
|
|
||||||
pm = getPM();
|
pm = getPM();
|
||||||
cal = (CalendarFields) pm.find(CalendarFields.class, id);
|
cal = pm.find(CalendarFields.class, id);
|
||||||
assertEquals(TimeZone.getTimeZone("Asia/Singapore"),
|
assertEquals(TimeZone.getTimeZone("Asia/Singapore"),
|
||||||
cal.getSingapore().getTimeZone());
|
cal.getSingapore().getTimeZone());
|
||||||
endEm(pm);
|
endEm(pm);
|
||||||
|
@ -90,9 +90,9 @@ public class TestCalendarFields extends BaseKernelTest {
|
||||||
endEm(pm);
|
endEm(pm);
|
||||||
|
|
||||||
pm = getPM();
|
pm = getPM();
|
||||||
c2 = (CalendarFields) pm.find(CalendarFields.class, id2);
|
c2 = pm.find(CalendarFields.class, id2);
|
||||||
assertTimeZonesEquals(c1, c2);
|
assertTimeZonesEquals(c1, c2);
|
||||||
assertTimeZonesEquals(c1, (CalendarFields) pm.detachCopy(c2));
|
assertTimeZonesEquals(c1, pm.detachCopy(c2));
|
||||||
endEm(pm);
|
endEm(pm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,8 @@ public class TestCheckConsistency extends BaseKernelTest {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
deleteAll(RuntimeTest1.class);
|
super.setUp(RuntimeTest1.class);
|
||||||
|
|
||||||
RuntimeTest1 pc = new RuntimeTest1();
|
RuntimeTest1 pc = new RuntimeTest1();
|
||||||
pc.setIntField(1);
|
pc.setIntField(1);
|
||||||
|
@ -61,7 +61,7 @@ public class TestCheckConsistency extends BaseKernelTest {
|
||||||
pm.validateChanges(); // no-op outside trans
|
pm.validateChanges(); // no-op outside trans
|
||||||
startTx(pm);
|
startTx(pm);
|
||||||
|
|
||||||
RuntimeTest1 pc = (RuntimeTest1) pm.find(RuntimeTest1.class, _oid);
|
RuntimeTest1 pc = pm.find(RuntimeTest1.class, _oid);
|
||||||
pc.setIntField1(100);
|
pc.setIntField1(100);
|
||||||
|
|
||||||
RuntimeTest1 npc = new RuntimeTest1();
|
RuntimeTest1 npc = new RuntimeTest1();
|
||||||
|
@ -89,7 +89,7 @@ public class TestCheckConsistency extends BaseKernelTest {
|
||||||
pm.validateChanges(); // no-op outside trans
|
pm.validateChanges(); // no-op outside trans
|
||||||
startTx(pm);
|
startTx(pm);
|
||||||
|
|
||||||
RuntimeTest1 pc = (RuntimeTest1) pm.find(RuntimeTest1.class, _oid);
|
RuntimeTest1 pc = pm.find(RuntimeTest1.class, _oid);
|
||||||
pc.setIntField1(100);
|
pc.setIntField1(100);
|
||||||
|
|
||||||
RuntimeTest1 npc = new RuntimeTest1();
|
RuntimeTest1 npc = new RuntimeTest1();
|
||||||
|
@ -112,7 +112,7 @@ public class TestCheckConsistency extends BaseKernelTest {
|
||||||
pm = getPM();
|
pm = getPM();
|
||||||
try {
|
try {
|
||||||
RuntimeTest1 temp =
|
RuntimeTest1 temp =
|
||||||
(RuntimeTest1) pm.find(RuntimeTest1.class, noid);
|
pm.find(RuntimeTest1.class, noid);
|
||||||
fail("Object should not exist." + temp.getIntField() + "::" +
|
fail("Object should not exist." + temp.getIntField() + "::" +
|
||||||
temp.getIntField1());
|
temp.getIntField1());
|
||||||
} catch (Exception jonfe) {
|
} catch (Exception jonfe) {
|
||||||
|
@ -176,7 +176,7 @@ try {
|
||||||
startTx(pm);
|
startTx(pm);
|
||||||
boolean hasConn = hasConnection(pm);
|
boolean hasConn = hasConnection(pm);
|
||||||
|
|
||||||
RuntimeTest1 pc = (RuntimeTest1) pm.find(RuntimeTest1.class, _oid);
|
RuntimeTest1 pc = pm.find(RuntimeTest1.class, _oid);
|
||||||
pc.setIntField1(100);
|
pc.setIntField1(100);
|
||||||
|
|
||||||
RuntimeTest1 npc = new RuntimeTest1();
|
RuntimeTest1 npc = new RuntimeTest1();
|
||||||
|
@ -212,7 +212,7 @@ try {
|
||||||
startTx(pm);
|
startTx(pm);
|
||||||
boolean hasConn = hasConnection(pm);
|
boolean hasConn = hasConnection(pm);
|
||||||
|
|
||||||
RuntimeTest1 pc = (RuntimeTest1) pm.find(RuntimeTest1.class, _oid);
|
RuntimeTest1 pc = pm.find(RuntimeTest1.class, _oid);
|
||||||
pc.setIntField1(100);
|
pc.setIntField1(100);
|
||||||
|
|
||||||
RuntimeTest1 npc = new RuntimeTest1();
|
RuntimeTest1 npc = new RuntimeTest1();
|
||||||
|
@ -238,7 +238,7 @@ try {
|
||||||
pm = getPM();
|
pm = getPM();
|
||||||
try {
|
try {
|
||||||
RuntimeTest1 temp =
|
RuntimeTest1 temp =
|
||||||
(RuntimeTest1) pm.find(RuntimeTest1.class, noid);
|
pm.find(RuntimeTest1.class, noid);
|
||||||
|
|
||||||
fail("Object should not exist." + temp.getIntField() + "::" +
|
fail("Object should not exist." + temp.getIntField() + "::" +
|
||||||
temp.getIntField1());
|
temp.getIntField1());
|
||||||
|
|
|
@ -41,8 +41,8 @@ public class TestClassStringConstructor extends BaseKernelTest {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
deleteAll(AppIdClassString.class);
|
super.setUp(AppIdClassString.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testConstructor() {
|
public void testConstructor() {
|
||||||
|
|
|
@ -60,7 +60,7 @@ public class TestDateQueries extends BaseKernelTest {
|
||||||
|
|
||||||
public void setUp()
|
public void setUp()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
super.setUp();
|
super.setUp(AllFieldTypesTest.class);
|
||||||
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("MMMMM dd, yyyy",
|
SimpleDateFormat sdf = new SimpleDateFormat("MMMMM dd, yyyy",
|
||||||
Locale.US);
|
Locale.US);
|
||||||
|
@ -69,9 +69,6 @@ public class TestDateQueries extends BaseKernelTest {
|
||||||
_after = sdf.parse("April 27, 1978");
|
_after = sdf.parse("April 27, 1978");
|
||||||
_pm = getPM();
|
_pm = getPM();
|
||||||
|
|
||||||
// delete all existing instances
|
|
||||||
deleteAll(AllFieldTypesTest.class);
|
|
||||||
|
|
||||||
// create some instances to query on
|
// create some instances to query on
|
||||||
startTx(_pm);
|
startTx(_pm);
|
||||||
AllFieldTypesTest test = new AllFieldTypesTest();
|
AllFieldTypesTest test = new AllFieldTypesTest();
|
||||||
|
|
|
@ -52,8 +52,8 @@ public class TestExtents extends BaseKernelTest {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
deleteAll(RuntimeTest1.class);
|
super.setUp(RuntimeTest1.class, RuntimeTest2.class);
|
||||||
|
|
||||||
OpenJPAEntityManager pm = getPM();
|
OpenJPAEntityManager pm = getPM();
|
||||||
startTx(pm);
|
startTx(pm);
|
||||||
|
@ -101,7 +101,7 @@ public class TestExtents extends BaseKernelTest {
|
||||||
|
|
||||||
public void testExtent4() {
|
public void testExtent4() {
|
||||||
OpenJPAEntityManager pm = getPM();
|
OpenJPAEntityManager pm = getPM();
|
||||||
Extent ext = (Extent) pm.createExtent(RuntimeTest1.class, true);
|
Extent ext = pm.createExtent(RuntimeTest1.class, true);
|
||||||
|
|
||||||
List all = new LinkedList();
|
List all = new LinkedList();
|
||||||
for (Iterator i = ext.iterator(); i.hasNext();)
|
for (Iterator i = ext.iterator(); i.hasNext();)
|
||||||
|
|
|
@ -54,8 +54,8 @@ public class TestExtents2 extends BaseKernelTest {
|
||||||
public TestExtents2() {
|
public TestExtents2() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() throws Exception {
|
||||||
deleteAll(RuntimeTest1.class);
|
super.setUp(RuntimeTest1.class, RuntimeTest2.class, RuntimeTest3.class);
|
||||||
|
|
||||||
RuntimeTest1 test1 = new RuntimeTest1();
|
RuntimeTest1 test1 = new RuntimeTest1();
|
||||||
test1.setIntField(1);
|
test1.setIntField(1);
|
||||||
|
@ -170,7 +170,7 @@ public class TestExtents2 extends BaseKernelTest {
|
||||||
startTx(pm);
|
startTx(pm);
|
||||||
try {
|
try {
|
||||||
RuntimeTest2 test2 =
|
RuntimeTest2 test2 =
|
||||||
(RuntimeTest2) pm.find(RuntimeTest2.class, _oid2);
|
pm.find(RuntimeTest2.class, _oid2);
|
||||||
pm.remove(test2);
|
pm.remove(test2);
|
||||||
RuntimeTest1 test1 = new RuntimeTest1();
|
RuntimeTest1 test1 = new RuntimeTest1();
|
||||||
pm.persist(test1);
|
pm.persist(test1);
|
||||||
|
|
Loading…
Reference in New Issue