tamaya-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ple...@apache.org
Subject [12/50] [abbrv] incubator-tamaya-extensions git commit: TAMAYA-156: Added feature to enable and clear usage stats.
Date Fri, 16 Sep 2016 22:03:22 GMT
TAMAYA-156: Added feature to enable and clear usage stats.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/commit/89196100
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/tree/89196100
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/diff/89196100

Branch: refs/heads/master
Commit: 89196100847d6d1faf5ae1a192c66a21b8778550
Parents: 58647a4
Author: anatole <anatole@apache.org>
Authored: Sat Apr 30 21:49:15 2016 +0200
Committer: anatole <anatole@apache.org>
Committed: Sat Apr 30 21:49:15 2016 +0200

----------------------------------------------------------------------
 .../apache/tamaya/model/ConfigModelManager.java | 10 ++++++-
 .../model/internal/DefaultUsageTracker.java     | 20 ++++++++++++-
 .../tamaya/model/spi/UsageTrackerSpi.java       |  4 +++
 .../tamaya/model/TestConfigModelProvider.java   | 30 ++++++++++++++++++--
 4 files changed, 60 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89196100/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
----------------------------------------------------------------------
diff --git a/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java b/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
index 8139310..b066366 100644
--- a/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
+++ b/model/src/main/java/org/apache/tamaya/model/ConfigModelManager.java
@@ -291,6 +291,14 @@ public final class ConfigModelManager {
      * @return the recorded usge references, never null.
      */
     public static Collection<Usage> getUsages() {
-        return usageTracker.getUsages();
+        return Objects.requireNonNull(usageTracker, "No UsageTrackerSpi component available.").getUsages();
+    }
+
+    /**
+     * Clears all collected usage statistics.
+     */
+    public static void clearUsageStats() {
+        Objects.requireNonNull(usageTracker, "No UsageTrackerSpi component available.")
+                .clearUsageStats();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89196100/model/src/main/java/org/apache/tamaya/model/internal/DefaultUsageTracker.java
----------------------------------------------------------------------
diff --git a/model/src/main/java/org/apache/tamaya/model/internal/DefaultUsageTracker.java
b/model/src/main/java/org/apache/tamaya/model/internal/DefaultUsageTracker.java
index b9575a2..03b5bd5 100644
--- a/model/src/main/java/org/apache/tamaya/model/internal/DefaultUsageTracker.java
+++ b/model/src/main/java/org/apache/tamaya/model/internal/DefaultUsageTracker.java
@@ -42,7 +42,20 @@ public class DefaultUsageTracker implements UsageTrackerSpi{
     private Map<String, Usage> usages = new ConcurrentHashMap<>();
 
     /** By default usage tracking is not enabled. */
-    private boolean usageTrackingEnabled = false;
+    private boolean usageTrackingEnabled = initEnabled();
+
+    /**
+     * Method that checks the 'tamaya.usage-report' system property for
+     * enabling tamaya usage reporting initially.
+     * @return
+     */
+    private boolean initEnabled() {
+        String val = System.getProperty("tamaya.usage-report");
+        if(Boolean.parseBoolean(val)){
+            return true;
+        }
+        return false;
+    }
 
     public DefaultUsageTracker(){
         ignoredPackages.add("com.intellij");
@@ -145,4 +158,9 @@ public class DefaultUsageTracker implements UsageTrackerSpi{
         return b.toString();
     }
 
+    @Override
+    public void clearUsageStats() {
+        this.usages.clear();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89196100/model/src/main/java/org/apache/tamaya/model/spi/UsageTrackerSpi.java
----------------------------------------------------------------------
diff --git a/model/src/main/java/org/apache/tamaya/model/spi/UsageTrackerSpi.java b/model/src/main/java/org/apache/tamaya/model/spi/UsageTrackerSpi.java
index ed6e12b..d84b636 100644
--- a/model/src/main/java/org/apache/tamaya/model/spi/UsageTrackerSpi.java
+++ b/model/src/main/java/org/apache/tamaya/model/spi/UsageTrackerSpi.java
@@ -76,4 +76,8 @@ public interface UsageTrackerSpi {
      */
     String getUsageInfo();
 
+    /**
+     * Clears all collected usage statistics.
+     */
+    void clearUsageStats();
 }

http://git-wip-us.apache.org/repos/asf/incubator-tamaya-extensions/blob/89196100/model/src/test/java/org/apache/tamaya/model/TestConfigModelProvider.java
----------------------------------------------------------------------
diff --git a/model/src/test/java/org/apache/tamaya/model/TestConfigModelProvider.java b/model/src/test/java/org/apache/tamaya/model/TestConfigModelProvider.java
index 2c7e753..70ca611 100644
--- a/model/src/test/java/org/apache/tamaya/model/TestConfigModelProvider.java
+++ b/model/src/test/java/org/apache/tamaya/model/TestConfigModelProvider.java
@@ -32,7 +32,9 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 /**
  * Created by Anatole on 09.08.2015.
@@ -70,12 +72,13 @@ public class TestConfigModelProvider implements ModelProviderSpi {
     }
 
     @Test
-    public void testUsage(){
+    public void testUsageWhenEnabled(){
+        ConfigModelManager.enableUsageTracking(true);
         TestConfigAccessor.readConfiguration();
         Configuration config = ConfigurationProvider.getConfiguration();
         String info = ConfigModelManager.getUsageInfo();
+        assertFalse(info.contains("java.version"));
         assertNotNull(info);
-        System.out.println(info);
         config = TestConfigAccessor.readConfiguration();
         config.getProperties();
         TestConfigAccessor.readProperty(config, "java.locale");
@@ -84,6 +87,29 @@ public class TestConfigModelProvider implements ModelProviderSpi {
         config.get("java.version");
         info = ConfigModelManager.getUsageInfo();
         System.out.println(info);
+        assertTrue(info.contains("java.version"));
+        assertNotNull(info);
+        ConfigModelManager.enableUsageTracking(false);
+    }
+
+    @Test
+    public void testUsageWhenDisabled(){
+        ConfigModelManager.enableUsageTracking(false);
+        ConfigModelManager.clearUsageStats();
+        TestConfigAccessor.readConfiguration();
+        Configuration config = ConfigurationProvider.getConfiguration();
+        String info = ConfigModelManager.getUsageInfo();
+        assertNotNull(info);
+        assertFalse(info.contains("java.version"));
+        config = TestConfigAccessor.readConfiguration();
+        config.getProperties();
+        TestConfigAccessor.readProperty(config, "java.locale");
+        TestConfigAccessor.readProperty(config, "java.version");
+        TestConfigAccessor.readProperty(config, "java.version");
+        config.get("java.version");
+        info = ConfigModelManager.getUsageInfo();
+        assertFalse(info.contains("java.version"));
         assertNotNull(info);
+        ConfigModelManager.enableUsageTracking(false);
     }
 }


Mime
View raw message