← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 22156: SystemSettingManager. Disabling cache (set max size to 0) during test phase

 

------------------------------------------------------------
revno: 22156
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2016-03-07 16:16:38 +0100
message:
  SystemSettingManager. Disabling cache (set max size to 0) during test phase
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/hibernate/HibernateEventListenerWiring.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/SystemUtils.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/hibernate/HibernateEventListenerWiring.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/hibernate/HibernateEventListenerWiring.java	2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/hibernate/HibernateEventListenerWiring.java	2016-03-07 15:16:38 +0000
@@ -41,6 +41,7 @@
 import org.hibernate.event.spi.PreCollectionUpdateEvent;
 import org.hibernate.event.spi.PreCollectionUpdateEventListener;
 import org.hibernate.internal.SessionFactoryImpl;
+import org.hibernate.persister.entity.EntityPersister;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -141,6 +142,12 @@
         {
             updateIdentifiableObjects();
         }
+
+        @Override
+        public boolean requiresPostCommitHanding( EntityPersister arg0 )
+        {
+            return false;
+        }
     };
 
     private PostInsertEventListener postInsertEventListener = new PostInsertEventListener()
@@ -150,6 +157,12 @@
         {
             updateIdentifiableObjects();
         }
+
+        @Override
+        public boolean requiresPostCommitHanding( EntityPersister arg0 )
+        {
+            return false;
+        }
     };
 
     private PostDeleteEventListener postDeleteEventListener = new PostDeleteEventListener()
@@ -159,6 +172,12 @@
         {
             updateIdentifiableObjects();
         }
+
+        @Override
+        public boolean requiresPostCommitHanding( EntityPersister arg0 )
+        {
+            return false;
+        }
     };
 
     private void updateIdentifiableObjects()

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java	2016-01-11 12:43:50 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/setting/DefaultSystemSettingManager.java	2016-03-07 15:16:38 +0000
@@ -34,6 +34,7 @@
 import org.apache.commons.lang3.StringUtils;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.i18n.I18nManager;
+import org.hisp.dhis.system.util.SystemUtils;
 import org.hisp.dhis.system.util.ValidationUtils;
 import org.jasypt.encryption.pbe.PBEStringEncryptor;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -55,12 +56,12 @@
     implements SystemSettingManager
 {
     /**
-     * Cache for system settings. Does not accept nulls.
+     * Cache for system settings. Does not accept nulls. Disabled during test phase.
      */
     private static final Cache<String, Optional<Serializable>> SETTING_CACHE = CacheBuilder.newBuilder()
         .expireAfterAccess( 1, TimeUnit.HOURS )
         .initialCapacity( 200 )
-        .maximumSize( 400 )
+        .maximumSize( SystemUtils.isTestRun() ? 0 : 400 )
         .build();
 
     private static final Map<String, SettingKey> NAME_KEY_MAP = Lists.newArrayList(
@@ -69,7 +70,7 @@
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
-
+    
     private SystemSettingStore systemSettingStore;
 
     public void setSystemSettingStore( SystemSettingStore systemSettingStore )
@@ -184,7 +185,7 @@
     }
 
     private Optional<Serializable> getSystemSettingOptional( String name, Serializable defaultValue )
-    {
+    {        
         SystemSetting setting = systemSettingStore.getByName( name );
 
         if ( setting != null && setting.hasValue() )

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/SystemUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/SystemUtils.java	2016-03-07 14:33:33 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/SystemUtils.java	2016-03-07 15:16:38 +0000
@@ -24,7 +24,8 @@
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) AR
+ * ISING IN ANY WAY OUT OF THE USE OF THIS
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
@@ -36,6 +37,15 @@
     private static final int FACTOR_MB = 1024 * 1024;
 
     /**
+     * Indicates whether the current thread is running for testing.
+     * @return true if test run.
+     */
+    public static boolean isTestRun()
+    {
+        return "true".equals( System.getProperty( "org.hisp.dhis.test", "false" ) );
+    }
+    
+    /**
      * Gets the number of CPU cores available to this JVM.
      * @return the number of available CPU cores.
      */
@@ -52,7 +62,6 @@
     {
         return "Mem Total in JVM: " + ( Runtime.getRuntime().totalMemory() / FACTOR_MB ) + 
             " Free in JVM: " + ( Runtime.getRuntime().freeMemory() / FACTOR_MB ) +
-            " Max Limit: " + ( Runtime.getRuntime().maxMemory() / FACTOR_MB );
-            
+            " Max Limit: " + ( Runtime.getRuntime().maxMemory() / FACTOR_MB );     
     }
 }