You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2016/10/05 09:46:49 UTC

[4/8] isis git commit: EST-1507: fixes unit test for QueryResultsCache

EST-1507: fixes unit test for QueryResultsCache


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/f3f53f63
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/f3f53f63
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/f3f53f63

Branch: refs/heads/maint-1.13.1
Commit: f3f53f63cc20996ee2b45388b3ebdcf0460493d4
Parents: f6976b1
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Sep 30 09:09:25 2016 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Sep 30 09:11:24 2016 +0100

----------------------------------------------------------------------
 .../QueryResultsCacheTest.java                  | 43 ++++++++++++++++++--
 1 file changed, 40 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/f3f53f63/core/applib/src/test/java/org/apache/isis/applib/services/queryresultscache/QueryResultsCacheTest.java
----------------------------------------------------------------------
diff --git a/core/applib/src/test/java/org/apache/isis/applib/services/queryresultscache/QueryResultsCacheTest.java b/core/applib/src/test/java/org/apache/isis/applib/services/queryresultscache/QueryResultsCacheTest.java
index d5210dd..d0e99cf 100644
--- a/core/applib/src/test/java/org/apache/isis/applib/services/queryresultscache/QueryResultsCacheTest.java
+++ b/core/applib/src/test/java/org/apache/isis/applib/services/queryresultscache/QueryResultsCacheTest.java
@@ -16,22 +16,30 @@
  */
 package org.apache.isis.applib.services.queryresultscache;
 
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
-
 import java.util.concurrent.Callable;
 
 import org.junit.Before;
 import org.junit.Test;
 
+import org.apache.isis.applib.events.system.FixturesInstallingEvent;
+import org.apache.isis.applib.services.fixturespec.FixtureScriptsDefault;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
 public class QueryResultsCacheTest {
 
     private QueryResultsCache queryResultsCache;
 
+    QueryResultsCache.Control control;
+
     @Before
     public void setUp() throws Exception {
         queryResultsCache = new QueryResultsCache();
+        control = new QueryResultsCache.Control();
+        queryResultsCache.control = control;
     }
+
     @Test
     public void execute() {
         
@@ -80,4 +88,33 @@ public class QueryResultsCacheTest {
         assertThat(i[0], is(5));
     }
     
+    @Test
+    public void cachingDisabled() {
+
+        // given fixtures installing, hence caching disabled
+        control.on(new FixturesInstallingEvent(new FixtureScriptsDefault()));
+
+        final int[] i = new int[]{0};
+
+        Callable<String> callable = new Callable<String>(){
+
+            @Override
+            public String call() throws Exception {
+                i[0]++;
+                return "foo";
+            }
+
+        };
+
+        // when, then (a cache miss)
+        assertThat(i[0], is(0));
+        assertThat(queryResultsCache.execute(callable, QueryResultsCacheTest.class, "caching", "a","b",1,2), is("foo"));
+        assertThat(i[0], is(1));
+
+        // when, then should also be a cache miss - would've been a hit previously
+        assertThat(queryResultsCache.execute(callable, QueryResultsCacheTest.class, "caching", "a","b",1,2), is("foo"));
+        assertThat(i[0], is(2));
+
+    }
+
 }