You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by tk...@apache.org on 2015/12/26 16:12:56 UTC

nifi git commit: NIFI-1289 reverted new method of NiFiProperties in favor of the localized reflection call in test to refresh properties.

Repository: nifi
Updated Branches:
  refs/heads/master 2845e9381 -> ebcefaac2


NIFI-1289 reverted new method of NiFiProperties in favor of the localized reflection call in test to refresh properties.

Reviewed and Amended (added comments) by Tony Kurc (tkurc@apache.org). This closes #150


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

Branch: refs/heads/master
Commit: ebcefaac23a890233703fe1fd7f43997cb4541c6
Parents: 2845e93
Author: Oleg Zhurakousky <ol...@suitcase.io>
Authored: Sat Dec 26 09:58:08 2015 -0500
Committer: Tony Kurc <tr...@gmail.com>
Committed: Sat Dec 26 09:58:08 2015 -0500

----------------------------------------------------------------------
 .../org/apache/nifi/util/NiFiProperties.java    | 21 ++++----------------
 .../TestStandardProcessScheduler.java           | 13 +++++++++++-
 2 files changed, 16 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi/blob/ebcefaac/nifi-commons/nifi-properties/src/main/java/org/apache/nifi/util/NiFiProperties.java
----------------------------------------------------------------------
diff --git a/nifi-commons/nifi-properties/src/main/java/org/apache/nifi/util/NiFiProperties.java b/nifi-commons/nifi-properties/src/main/java/org/apache/nifi/util/NiFiProperties.java
index 4da8601..c82a220 100644
--- a/nifi-commons/nifi-properties/src/main/java/org/apache/nifi/util/NiFiProperties.java
+++ b/nifi-commons/nifi-properties/src/main/java/org/apache/nifi/util/NiFiProperties.java
@@ -241,29 +241,16 @@ public class NiFiProperties extends Properties {
     }
 
     /**
-     * Factory method to create and return a new instance of
-     * {@link NiFiProperties}. Unlike its {@link #getInstance()} counterpart
-     * which may return you a cached instance of {@link NiFiProperties} this
-     * method creates new instance every time it's called. It is suitable for
-     * cases where properties may change at runtime.
-     *
-     * @return new instance of {@link NiFiProperties}
-     */
-    public static synchronized NiFiProperties getNewInstance() {
-        instance = null;
-        return getInstance();
-    }
-
-    /**
-     * Factory method to create and return a new instance of
-     * {@link NiFiProperties}. Unlike its {@link #getNewInstance()} counterpart
-     * which always creates a new instance of {@link NiFiProperties}, this
+     * Factory method to create an instance of the {@link NiFiProperties}. This
      * method employs a standard singleton pattern by caching the instance if it
      * was already obtained
      *
      * @return instance of {@link NiFiProperties}
      */
     public static synchronized NiFiProperties getInstance() {
+        // NOTE: unit tests can set instance to null (with reflection) to effectively create a new singleton.
+        //       changing the below as a check for whether the instance was initialized will break those
+        //       unit tests.
         if (null == instance) {
             final NiFiProperties suspectInstance = new NiFiProperties();
             final String nfPropertiesFilePath = System

http://git-wip-us.apache.org/repos/asf/nifi/blob/ebcefaac/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/scheduling/TestStandardProcessScheduler.java
----------------------------------------------------------------------
diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/scheduling/TestStandardProcessScheduler.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/scheduling/TestStandardProcessScheduler.java
index 3b0bb50..5575a23 100644
--- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/scheduling/TestStandardProcessScheduler.java
+++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/scheduling/TestStandardProcessScheduler.java
@@ -18,6 +18,7 @@ package org.apache.nifi.controller.scheduling;
 
 import static org.junit.Assert.assertTrue;
 
+import java.lang.reflect.Field;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.UUID;
@@ -61,7 +62,7 @@ public class TestStandardProcessScheduler {
     @Before
     public void setup() throws InitializationException {
         System.setProperty("nifi.properties.file.path", "src/test/resources/nifi.properties");
-        NiFiProperties.getNewInstance(); // ensures that properties have been reloaded
+        this.refreshNiFiProperties();
         scheduler = new StandardProcessScheduler(Mockito.mock(Heartbeater.class), Mockito.mock(ControllerServiceProvider.class), null);
         scheduler.setSchedulingAgent(SchedulingStrategy.TIMER_DRIVEN, Mockito.mock(SchedulingAgent.class));
 
@@ -158,4 +159,14 @@ public class TestStandardProcessScheduler {
         public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
         }
     }
+
+    private void refreshNiFiProperties() {
+        try {
+            Field instanceField = NiFiProperties.class.getDeclaredField("instance");
+            instanceField.setAccessible(true);
+            instanceField.set(null, null);
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        }
+    }
 }