01: /*
02: * (C) 2003 ppi Media
03: * User: om
04: */
05:
06: package org.apache.ojb.broker.sqlcount;
07:
08: import org.apache.ojb.broker.Identity;
09: import org.apache.ojb.broker.PersistenceBroker;
10: import org.apache.ojb.broker.PersistenceBrokerFactory;
11: import org.apache.ojb.broker.cloneable.CloneableGroup;
12: import org.apache.ojb.broker.util.configuration.impl.OjbConfiguration;
13: import org.apache.ojb.broker.util.configuration.impl.OjbConfigurator;
14:
15: /**
16: * @author <a href="mailto:om@ppi.de">Oliver Matz</a>
17: * @version $Id: TwoLevelSimpleTest.java,v 1.1.4.2 2005/08/16 15:04:39 aclute Exp $
18: */
19: public class TwoLevelSimpleTest extends AbstractCountTest {
20: private Class old_ObjectCache;
21: private String[] old_CacheFilter;
22:
23: private OjbConfiguration getConfig() {
24: return (OjbConfiguration) OjbConfigurator.getInstance()
25: .getConfigurationFor(null);
26: }
27:
28: /**
29: * switch cache to {@link org.apache.ojb.broker.cache.ObjectCacheTwoLevelImpl}.
30: * @throws Exception
31: */
32: protected void setUp() throws Exception {
33: //ObjectCacheFactory.getInstance().setClassToServe(ObjectCacheTwoLevelImpl.class);
34: //ObjectCacheFactory.getInstance().setClassToServe(org.apache.ojb.broker.cache.ObjectCachePerBrokerImpl.class);
35: super .setUp();
36: //old_CacheFilter = getConfig().getCacheFilters();
37: //old_ObjectCache = ObjectCacheFactory.getInstance().getClassToServe();
38: }
39:
40: /**
41: * undo Cache change.
42: * @throws Exception
43: */
44: protected void tearDown() throws Exception {
45: //getConfig().setCacheFilters(old_CacheFilter);
46: //ObjectCacheFactory.getInstance().setClassToServe(old_ObjectCache);
47: super .tearDown();
48: }
49:
50: /**
51: * retrieve one CdArticle twice.
52: */
53: public void testAccessArticleTwice() {
54: PersistenceBroker pb0, pb1;
55: pb0 = PersistenceBrokerFactory.defaultPersistenceBroker();
56: pb1 = PersistenceBrokerFactory.defaultPersistenceBroker();
57: assertNotSame(pb0, pb1);
58:
59: resetStmtCount();
60: pb0.clearCache();
61: pb0.beginTransaction();
62: Identity id = new Identity(null, CloneableGroup.class,
63: new Object[] { new Integer(1) });
64: logger.info(id.toString());
65: assertNull(id.getObjectsRealClass());
66: Object group0 = pb0.getObjectByIdentity(id);
67: assertNotNull(group0);
68: assertEquals(CloneableGroup.class, id.getObjectsRealClass());
69: assertStmtCount("access one group", 1);
70: pb0.commitTransaction();
71:
72: resetStmtCount();
73: pb1.beginTransaction();
74: Object group1 = pb1.getObjectByIdentity(id);
75: assertStmtCount("access one group again", 0); // lookup again, 2nd level hit, no SQL access.
76: assertNotSame(group0, group1);
77: pb1.commitTransaction();
78: }
79: }
|