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/09/30 08:36:16 UTC

[1/3] isis git commit: ISIS-1507: switches off the QueryResultsCache while fixtures are being installed.

Repository: isis
Updated Branches:
  refs/heads/master 6e4478010 -> a5dfef8f8


ISIS-1507: switches off the QueryResultsCache while fixtures are being installed.


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

Branch: refs/heads/master
Commit: eea96e273bbc7f4acd28e652e23c22e584bd978c
Parents: 6e44780
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Sep 30 08:54:27 2016 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Sep 30 09:34:50 2016 +0100

----------------------------------------------------------------------
 .../guides/_rgsvc_api_EventBusService.adoc      |  2 +-
 core/applib/pom.xml                             |  6 ++
 .../events/system/FixturesInstalledEvent.java   | 32 +++++++++
 .../events/system/FixturesInstallingEvent.java  | 32 +++++++++
 .../fixturespec/FixtureScriptsDefault.java      | 15 +++-
 .../queryresultscache/QueryResultsCache.java    | 73 +++++++++++++++++++-
 core/pom.xml                                    |  6 ++
 7 files changed, 160 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/eea96e27/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_EventBusService.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_EventBusService.adoc b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_EventBusService.adoc
index c7ed940..e8b6763 100644
--- a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_EventBusService.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_EventBusService.adoc
@@ -131,7 +131,7 @@ or if using Axonframework, the subscriber uses a different annotation:
 @DomainService(nature=NatureOfService.DOMAIN)
 public class MySubscribingDomainService
     @Programmatic
-    @org.axonframework.eventhandling.annotation.EventHandle
+    @org.axonframework.eventhandling.annotation.EventHandler
     public void on(ActionDomainEvent ev) { ... }
     ...
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/eea96e27/core/applib/pom.xml
----------------------------------------------------------------------
diff --git a/core/applib/pom.xml b/core/applib/pom.xml
index 7e93ae8..0679a79 100644
--- a/core/applib/pom.xml
+++ b/core/applib/pom.xml
@@ -114,6 +114,12 @@
             <artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.axonframework</groupId>
+            <artifactId>axon-core</artifactId>
+            <optional>true</optional>
+        </dependency>
+
         <!-- DataNucleus' standard JDO support -->
         <dependency>
             <groupId>javax.jdo</groupId>

http://git-wip-us.apache.org/repos/asf/isis/blob/eea96e27/core/applib/src/main/java/org/apache/isis/applib/events/system/FixturesInstalledEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/events/system/FixturesInstalledEvent.java b/core/applib/src/main/java/org/apache/isis/applib/events/system/FixturesInstalledEvent.java
new file mode 100644
index 0000000..83060c3
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/events/system/FixturesInstalledEvent.java
@@ -0,0 +1,32 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.applib.events.system;
+
+import java.util.EventObject;
+
+public class FixturesInstalledEvent extends EventObject {
+
+    private static final long serialVersionUID = 1L;
+
+    public FixturesInstalledEvent(final Object source) {
+        super(source);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/eea96e27/core/applib/src/main/java/org/apache/isis/applib/events/system/FixturesInstallingEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/events/system/FixturesInstallingEvent.java b/core/applib/src/main/java/org/apache/isis/applib/events/system/FixturesInstallingEvent.java
new file mode 100644
index 0000000..812c4e6
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/events/system/FixturesInstallingEvent.java
@@ -0,0 +1,32 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+
+package org.apache.isis.applib.events.system;
+
+import java.util.EventObject;
+
+public class FixturesInstallingEvent extends EventObject {
+
+    private static final long serialVersionUID = 1L;
+
+    public FixturesInstallingEvent(final Object source) {
+        super(source);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/eea96e27/core/applib/src/main/java/org/apache/isis/applib/services/fixturespec/FixtureScriptsDefault.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/fixturespec/FixtureScriptsDefault.java b/core/applib/src/main/java/org/apache/isis/applib/services/fixturespec/FixtureScriptsDefault.java
index 6401aab..ae88f38 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/fixturespec/FixtureScriptsDefault.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/fixturespec/FixtureScriptsDefault.java
@@ -21,7 +21,6 @@ package org.apache.isis.applib.services.fixturespec;
 import java.util.List;
 
 import javax.annotation.PostConstruct;
-import javax.inject.Inject;
 
 import org.apache.isis.applib.annotation.Action;
 import org.apache.isis.applib.annotation.ActionLayout;
@@ -32,9 +31,12 @@ import org.apache.isis.applib.annotation.Optionality;
 import org.apache.isis.applib.annotation.Parameter;
 import org.apache.isis.applib.annotation.ParameterLayout;
 import org.apache.isis.applib.annotation.RestrictTo;
+import org.apache.isis.applib.events.system.FixturesInstalledEvent;
+import org.apache.isis.applib.events.system.FixturesInstallingEvent;
 import org.apache.isis.applib.fixturescripts.FixtureResult;
 import org.apache.isis.applib.fixturescripts.FixtureScript;
 import org.apache.isis.applib.fixturescripts.FixtureScripts;
+import org.apache.isis.applib.services.eventbus.EventBusService;
 
 /**
  * Default instance of {@link FixtureScripts}, instantiated automatically by the framework if no custom user-defined instance was
@@ -101,7 +103,12 @@ public class FixtureScriptsDefault extends FixtureScripts {
                 multiLine = 10)
             @Parameter(optionality = Optionality.OPTIONAL)
             final String parameters) {
-        return super.runFixtureScript(fixtureScript, parameters);
+        try {
+            eventBusService.post(new FixturesInstallingEvent(this));
+            return super.runFixtureScript(fixtureScript, parameters);
+        } finally {
+            eventBusService.post(new FixturesInstalledEvent(this));
+        }
     }
 
     /**
@@ -216,7 +223,9 @@ public class FixtureScriptsDefault extends FixtureScripts {
 
     //region > injected services
     @javax.inject.Inject
-    private FixtureScriptsSpecificationProvider fixtureScriptsSpecificationProvider;
+    FixtureScriptsSpecificationProvider fixtureScriptsSpecificationProvider;
+    @javax.inject.Inject
+    EventBusService eventBusService;
     //endregion
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/eea96e27/core/applib/src/main/java/org/apache/isis/applib/services/queryresultscache/QueryResultsCache.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/queryresultscache/QueryResultsCache.java b/core/applib/src/main/java/org/apache/isis/applib/services/queryresultscache/QueryResultsCache.java
index 12accb1..82b45a8 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/queryresultscache/QueryResultsCache.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/queryresultscache/QueryResultsCache.java
@@ -20,9 +20,13 @@ import java.util.Arrays;
 import java.util.Map;
 import java.util.concurrent.Callable;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
 import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
 
 import com.google.common.collect.Maps;
+import com.google.common.eventbus.Subscribe;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -30,7 +34,10 @@ import org.slf4j.LoggerFactory;
 import org.apache.isis.applib.annotation.DomainService;
 import org.apache.isis.applib.annotation.NatureOfService;
 import org.apache.isis.applib.annotation.Programmatic;
+import org.apache.isis.applib.events.system.FixturesInstalledEvent;
+import org.apache.isis.applib.events.system.FixturesInstallingEvent;
 import org.apache.isis.applib.services.WithTransactionScope;
+import org.apache.isis.applib.services.eventbus.EventBusService;
 
 /**
  * This service (API and implementation) provides a mechanism by which idempotent query results can be cached for the duration of an interaction.
@@ -48,6 +55,7 @@ public class QueryResultsCache implements WithTransactionScope {
 
     private static final Logger LOG = LoggerFactory.getLogger(QueryResultsCache.class);
 
+
     public static class Key {
         private final Class<?> callingClass;
         private final String methodName;
@@ -134,17 +142,35 @@ public class QueryResultsCache implements WithTransactionScope {
 
     @Programmatic
     public <T> T execute(final Callable<T> callable, final Class<?> callingClass, final String methodName, final Object... keys) {
+        if(control.isFixturesInstalling()) {
+            try {
+                return callable.call();
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
         final Key cacheKey = new Key(callingClass, methodName, keys);
-        return execute(callable, cacheKey);
+        return executeWithCaching(callable, cacheKey);
     }
 
     @Programmatic
     @SuppressWarnings("unchecked")
     public <T> T execute(final Callable<T> callable, final Key cacheKey) {
+        if(control.isFixturesInstalling()) {
+            try {
+                return callable.call();
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+        return executeWithCaching(callable, cacheKey);
+    }
+
+    protected <T> T executeWithCaching(final Callable<T> callable, final Key cacheKey) {
         try {
             final Value<?> cacheValue = cache.get(cacheKey);
             logHitOrMiss(cacheKey, cacheValue);
-            if(cacheValue != null) { 
+            if(cacheValue != null) {
                 return (T) cacheValue.getResult();
             }
 
@@ -208,4 +234,47 @@ public class QueryResultsCache implements WithTransactionScope {
         cache.clear();
     }
 
+    /**
+     * In separate class because {@link QueryResultsCache} itself is request-scoped
+     */
+    @DomainService(nature = NatureOfService.DOMAIN)
+    public static class Control {
+
+        @PostConstruct
+        public void postConstruct() {
+            eventBusService.register(this);
+        }
+
+        @PreDestroy
+        public void preDestroy() {
+            eventBusService.unregister(this);
+        }
+
+        @Subscribe
+        @org.axonframework.eventhandling.annotation.EventHandler
+        public void on(FixturesInstallingEvent ev) {
+            fixturesInstalling = true;
+        }
+
+        @Subscribe
+        @org.axonframework.eventhandling.annotation.EventHandler
+        public void on(FixturesInstalledEvent ev) {
+            fixturesInstalling = false;
+        }
+
+        private boolean fixturesInstalling;
+
+        public boolean isFixturesInstalling() {
+            return fixturesInstalling;
+        }
+
+        @Inject
+        EventBusService eventBusService;
+    }
+
+
+    @Inject
+    Control control;
+
+
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/eea96e27/core/pom.xml
----------------------------------------------------------------------
diff --git a/core/pom.xml b/core/pom.xml
index ec91458..a02eaad 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -152,6 +152,7 @@
         <guice.version>4.1.0</guice.version>
         <picocontainer.version>2.15</picocontainer.version>
 
+
         <dom4j.version>1.6.1</dom4j.version>
         <jdom.version>2.0.2</jdom.version>
         <xstream.version>1.4.9</xstream.version>
@@ -1305,6 +1306,11 @@ ${license.additional-notes}
                 <artifactId>guava</artifactId>
                 <version>${guava.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.axonframework</groupId>
+                <artifactId>axon-core</artifactId>
+                <version>${axon-core.version}</version>
+            </dependency>
 
             <!-- Logging -->
             <dependency>


[3/3] isis git commit: ISIS-1508: makes the clean up functionality within IsisTransactionRule (as used by integ tests) more robust to a badly behaving test.

Posted by da...@apache.org.
ISIS-1508: makes the clean up functionality within IsisTransactionRule (as used by integ tests) more robust to a badly behaving test.


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

Branch: refs/heads/master
Commit: a5dfef8f8a29cb17845f7cf3a726cab5133773e4
Parents: ff52db2
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Sep 30 09:03:59 2016 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Sep 30 09:35:03 2016 +0100

----------------------------------------------------------------------
 .../IntegrationTestAbstract.java                | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/a5dfef8f/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract.java
----------------------------------------------------------------------
diff --git a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract.java b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract.java
index c9ee2ea..935577d 100644
--- a/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract.java
+++ b/core/integtestsupport/src/main/java/org/apache/isis/core/integtestsupport/IntegrationTestAbstract.java
@@ -39,6 +39,7 @@ import org.apache.isis.applib.services.scratchpad.Scratchpad;
 import org.apache.isis.applib.services.sessmgmt.SessionManagementService;
 import org.apache.isis.applib.services.wrapper.WrapperFactory;
 import org.apache.isis.applib.services.xactn.TransactionService;
+import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
 import org.apache.isis.core.specsupport.scenarios.ScenarioExecution;
 import org.apache.isis.core.specsupport.specs.CukeGlueAbstract;
 import org.apache.isis.core.unittestsupport.jmocking.JUnitRuleMockery2;
@@ -214,6 +215,10 @@ public abstract class IntegrationTestAbstract {
                         isft.endTran();
                         isft.nextSession();
                     } catch(final Throwable e) {
+
+                        // if test failed to clean up after itself, then take care of it here.
+                        endTransactionTilDone();
+
                         isft.nextSession();
                         final List<Throwable> causalChain = Throwables.getCausalChain(e);
                         // if underlying cause is an applib-defined exception, throw that rather than Isis' wrapper exception
@@ -226,6 +231,21 @@ public abstract class IntegrationTestAbstract {
                         throw e;
                     }
                 }
+
+                protected void endTransactionTilDone() {
+                    IsisTransactionManager tranMgr = isft.getIsisSessionFactory().getCurrentSession()
+                                                         .getPersistenceSession().getTransactionManager();
+                    int count = 0;
+                    while(tranMgr.getTransactionLevel() > 0 &&
+                          count++ < 10              // just in case, to prevent an infinite loop...
+                            ) {
+                        try {
+                            tranMgr.endTransaction();
+                        } catch(Exception ignore) {
+                            // ignore
+                        }
+                    }
+                }
             };
         }
     }


[2/3] isis git commit: EST-1507: fixes unit test for QueryResultsCache

Posted by da...@apache.org.
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/ff52db2a
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/ff52db2a
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/ff52db2a

Branch: refs/heads/master
Commit: ff52db2af32cc76d5fed0916b65d6380e6b39632
Parents: eea96e2
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:34:57 2016 +0100

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


http://git-wip-us.apache.org/repos/asf/isis/blob/ff52db2a/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));
+
+    }
+
 }