You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2006/07/27 23:31:30 UTC
svn commit: r426255 - in
/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access:
DataContextNamedQueryCachingTst.java DataContextQueryCachingTst.java
ObjectStoreTst.java
Author: aadamchik
Date: Thu Jul 27 14:31:30 2006
New Revision: 426255
URL: http://svn.apache.org/viewvc?rev=426255&view=rev
Log:
CAY-613 - removing deprecated API from the unit tests
Modified:
incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/DataContextNamedQueryCachingTst.java
incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/DataContextQueryCachingTst.java
incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/ObjectStoreTst.java
Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/DataContextNamedQueryCachingTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/DataContextNamedQueryCachingTst.java?rev=426255&r1=426254&r2=426255&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/DataContextNamedQueryCachingTst.java (original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/DataContextNamedQueryCachingTst.java Thu Jul 27 14:31:30 2006
@@ -37,12 +37,18 @@
DataContext context = createDataContext();
- String cacheKey = "ParameterizedQueryWithSharedCache";
+ QueryMetadata cacheKey = new MockQueryMetadata() {
+
+ public String getCacheKey() {
+ return "ParameterizedQueryWithSharedCache";
+ }
+ };
- assertNull(context.getObjectStore().getCachedQueryResult(cacheKey));
+ assertNull(context.getQueryCache().get(cacheKey));
context.performQuery("ParameterizedQueryWithSharedCache", false);
- Object cached = getDomain().getSharedSnapshotCache().getCachedSnapshots(cacheKey);
+ Object cached = getDomain().getSharedSnapshotCache().getCachedSnapshots(
+ cacheKey.getCacheKey());
assertEquals(4, ((Collection) cached).size());
assertNotNull(
@@ -53,7 +59,7 @@
context.performQuery("ParameterizedQueryWithSharedCache", false);
assertSame(cached, getDomain().getSharedSnapshotCache().getCachedSnapshots(
- cacheKey));
+ cacheKey.getCacheKey()));
// delete one record
int[] counts = context.performNonSelectingQuery(new SQLTemplate(
@@ -64,9 +70,8 @@
// refresh
List objects1 = context.performQuery("ParameterizedQueryWithSharedCache", true);
- Object cached1 = getDomain()
- .getSharedSnapshotCache()
- .getCachedSnapshots(cacheKey);
+ Object cached1 = getDomain().getSharedSnapshotCache().getCachedSnapshots(
+ cacheKey.getCacheKey());
assertNotNull(
"Failed to cache results of refreshing NamedQuery that points to a caching query",
cached1);
@@ -129,12 +134,13 @@
DataContext context = createDataContext();
NamedQuery q1 = new NamedQuery("ParameterizedQueryWithSharedCache");
- String cacheKey = q1.getMetaData(context.getEntityResolver()).getCacheKey();
+ QueryMetadata cacheKey = q1.getMetaData(context.getEntityResolver());
- assertNull(context.getObjectStore().getCachedQueryResult(cacheKey));
+ assertNull(context.getQueryCache().get(cacheKey));
context.performQuery(q1);
- Object cached = getDomain().getSharedSnapshotCache().getCachedSnapshots(cacheKey);
+ Object cached = getDomain().getSharedSnapshotCache().getCachedSnapshots(
+ cacheKey.getCacheKey());
assertNotNull(
"Failed to cache results of a NamedQuery that points to a caching query",
@@ -144,16 +150,15 @@
context.performQuery(q1);
assertSame(cached, getDomain().getSharedSnapshotCache().getCachedSnapshots(
- cacheKey));
+ cacheKey.getCacheKey()));
// refresh
q1.setForceNoCache(true);
context.performQuery(q1);
- Object cached1 = getDomain()
- .getSharedSnapshotCache()
- .getCachedSnapshots(cacheKey);
+ Object cached1 = getDomain().getSharedSnapshotCache().getCachedSnapshots(
+ cacheKey.getCacheKey());
assertNotNull(
"Failed to cache results of refreshing NamedQuery that points to a caching query",
cached1);
@@ -168,12 +173,12 @@
DataContext context = createDataContext();
NamedQuery q1 = new NamedQuery("ParameterizedQueryWithLocalCache");
- String cacheKey = q1.getMetaData(context.getEntityResolver()).getCacheKey();
+ QueryMetadata cacheKey = q1.getMetaData(context.getEntityResolver());
- assertNull(context.getObjectStore().getCachedQueryResult(cacheKey));
+ assertNull(context.getQueryCache().get(cacheKey));
context.performQuery(q1);
- Object cached = context.getObjectStore().getCachedQueryResult(cacheKey);
+ Object cached = context.getQueryCache().get(cacheKey);
assertNotNull(
"Failed to cache results of a NamedQuery that points to a caching query",
@@ -182,14 +187,14 @@
// get from cache
context.performQuery(q1);
- assertSame(cached, context.getObjectStore().getCachedQueryResult(cacheKey));
+ assertSame(cached, context.getQueryCache().get(cacheKey));
// refresh
q1.setForceNoCache(true);
context.performQuery(q1);
- Object cached1 = context.getObjectStore().getCachedQueryResult(cacheKey);
+ Object cached1 = context.getQueryCache().get(cacheKey);
assertNotNull(
"Failed to cache results of refreshing NamedQuery that points to a caching query",
cached1);
Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/DataContextQueryCachingTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/DataContextQueryCachingTst.java?rev=426255&r1=426254&r2=426255&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/DataContextQueryCachingTst.java (original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/DataContextQueryCachingTst.java Thu Jul 27 14:31:30 2006
@@ -25,6 +25,7 @@
import org.apache.art.Artist;
import org.apache.cayenne.DataObject;
import org.apache.cayenne.DataRow;
+import org.apache.cayenne.query.MockQueryMetadata;
import org.apache.cayenne.query.QueryMetadata;
import org.apache.cayenne.query.SelectQuery;
import org.apache.cayenne.unit.CayenneTestCase;
@@ -70,7 +71,15 @@
assertEquals(1, engine.getRunCount());
assertEquals(rows, resultRows);
assertNull(dataRowCache.getCachedSnapshots("c"));
- assertEquals(rows, context.getObjectStore().getCachedQueryResult("c"));
+
+ QueryMetadata cacheKey = new MockQueryMetadata() {
+
+ public String getCacheKey() {
+ return "c";
+ }
+ };
+
+ assertEquals(rows, context.getQueryCache().get(cacheKey));
// now the query with the same name must run from cache
engine.reset();
@@ -102,7 +111,14 @@
assertEquals(1, engine.getRunCount());
assertEquals(rows1, resultRows);
assertNull(dataRowCache.getCachedSnapshots("c"));
- assertEquals(rows1, context.getObjectStore().getCachedQueryResult("c"));
+
+ QueryMetadata cacheKey = new MockQueryMetadata() {
+
+ public String getCacheKey() {
+ return "c";
+ }
+ };
+ assertEquals(rows1, context.getQueryCache().get(cacheKey));
// second run, must refresh the cache
List rows2 = mockupDataRows(4);
@@ -113,7 +129,7 @@
assertEquals(1, engine.getRunCount());
assertEquals(rows2, freshResultRows);
assertNull(dataRowCache.getCachedSnapshots("c"));
- assertEquals(rows2, context.getObjectStore().getCachedQueryResult("c"));
+ assertEquals(rows2, context.getQueryCache().get(cacheKey));
}
finally {
engine.stopInterceptNode();
@@ -138,7 +154,14 @@
List resultRows = context.performQuery(select);
assertEquals(1, engine.getRunCount());
assertEquals(rows, resultRows);
- assertNull(context.getObjectStore().getCachedQueryResult("c"));
+ QueryMetadata cacheKey = new MockQueryMetadata() {
+
+ public String getCacheKey() {
+ return "c";
+ }
+ };
+
+ assertNull(context.getQueryCache().get(cacheKey));
assertEquals(rows, dataRowCache.getCachedSnapshots("c"));
// now the query with the same name must run from cache
@@ -177,7 +200,13 @@
assertEquals(1, engine.getRunCount());
assertEquals(rows1, resultRows);
assertEquals(rows1, dataRowCache.getCachedSnapshots("c"));
- assertNull(context.getObjectStore().getCachedQueryResult("c"));
+ QueryMetadata cacheKey = new MockQueryMetadata() {
+
+ public String getCacheKey() {
+ return "c";
+ }
+ };
+ assertNull(context.getQueryCache().get(cacheKey));
// second run, must refresh the cache
List rows2 = mockupDataRows(5);
@@ -188,7 +217,7 @@
assertEquals(1, engine.getRunCount());
assertEquals(rows2, freshResultRows);
assertEquals(rows2, dataRowCache.getCachedSnapshots("c"));
- assertNull(context.getObjectStore().getCachedQueryResult("c"));
+ assertNull(context.getQueryCache().get(cacheKey));
}
finally {
engine.stopInterceptNode();
@@ -214,7 +243,13 @@
assertEquals(2, resultRows.size());
assertTrue(resultRows.get(0) instanceof DataObject);
assertNull(dataRowCache.getCachedSnapshots("c"));
- assertEquals(resultRows, context.getObjectStore().getCachedQueryResult("c"));
+ QueryMetadata cacheKey = new MockQueryMetadata() {
+
+ public String getCacheKey() {
+ return "c";
+ }
+ };
+ assertEquals(resultRows, context.getQueryCache().get(cacheKey));
// second run, must refresh the cache
List rows2 = mockupDataRows(4);
@@ -227,8 +262,7 @@
assertEquals(4, freshResultRows.size());
assertTrue(resultRows.get(0) instanceof DataObject);
assertNull(dataRowCache.getCachedSnapshots("c"));
- assertEquals(freshResultRows, context.getObjectStore().getCachedQueryResult(
- "c"));
+ assertEquals(freshResultRows, context.getQueryCache().get(cacheKey));
}
finally {
engine.stopInterceptNode();
@@ -255,7 +289,13 @@
assertEquals(2, resultRows.size());
assertTrue(resultRows.get(0) instanceof DataObject);
assertNull(dataRowCache.getCachedSnapshots("c"));
- assertEquals(resultRows, context.getObjectStore().getCachedQueryResult("c"));
+ QueryMetadata cacheKey = new MockQueryMetadata() {
+
+ public String getCacheKey() {
+ return "c";
+ }
+ };
+ assertEquals(resultRows, context.getQueryCache().get(cacheKey));
// now the query with the same name must run from cache
engine.reset();
@@ -287,7 +327,13 @@
assertEquals(1, engine.getRunCount());
assertEquals(2, resultRows.size());
assertTrue(resultRows.get(0) instanceof DataObject);
- assertNull(context.getObjectStore().getCachedQueryResult("c"));
+ QueryMetadata cacheKey = new MockQueryMetadata() {
+
+ public String getCacheKey() {
+ return "c";
+ }
+ };
+ assertNull(context.getQueryCache().get(cacheKey));
assertEquals(rows, dataRowCache.getCachedSnapshots("c"));
// now the query with the same name must run from cache
@@ -326,20 +372,20 @@
assertEquals(1, objects1.size());
Artist a1 = (Artist) objects1.get(0);
assertEquals("aaa", a1.getArtistName());
-
+
// cache, but force refresh
-
+
createTestData("testLocalCacheRefreshObjectsRefresh_Update1");
List objects2 = context.performQuery(select);
assertEquals(1, objects2.size());
Artist a2 = (Artist) objects2.get(0);
assertSame(a1, a2);
assertEquals("bbb", a2.getArtistName());
-
+
// cache, no refresh
select.setRefreshingObjects(false);
createTestData("testLocalCacheRefreshObjectsRefresh_Update1");
-
+
List objects3 = context.performQuery(select);
assertEquals(1, objects3.size());
Artist a3 = (Artist) objects3.get(0);
Modified: incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/ObjectStoreTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/ObjectStoreTst.java?rev=426255&r1=426254&r2=426255&view=diff
==============================================================================
--- incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/ObjectStoreTst.java (original)
+++ incubator/cayenne/main/trunk/cayenne/cayenne-java/src/tests/java/org/apache/cayenne/access/ObjectStoreTst.java Thu Jul 27 14:31:30 2006
@@ -62,6 +62,9 @@
assertEquals(2, context.getObjectStore().registeredObjectsCount());
}
+ /**
+ * @deprecated since 3.0
+ */
public void testCachedQueriesCount() throws Exception {
DataContext context = createDataContext();
assertEquals(0, context.getObjectStore().cachedQueriesCount());
@@ -78,6 +81,9 @@
assertEquals(2, context.getObjectStore().cachedQueriesCount());
}
+ /**
+ * @deprecated since 3.0
+ */
public void testCachedQueryResult() throws Exception {
DataContext context = createDataContext();
assertNull(context.getObjectStore().getCachedQueryResult("result"));