bookkeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From si...@apache.org
Subject bookkeeper git commit: BOOKKEEPER-933: ClientConfiguration always inherits System properties
Date Sun, 31 Jul 2016 05:53:35 GMT
Repository: bookkeeper
Updated Branches:
  refs/heads/master 1f7e47005 -> 8324632b2


BOOKKEEPER-933: ClientConfiguration always inherits System properties

Author: eolivelli <eolivelli@gmail.com>

Reviewers: Sijie Guo <sijie@apache.org>

Closes #50 from eolivelli/BOOKKEEPER-933 and squashes the following commits:

0bcae1e [eolivelli] BOOKKEEPER-933 ClientConfiguration always inherits System properties
beb68fb [eolivelli] BOOKKEEPER-933 ClientConfiguration always inherits System properties


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

Branch: refs/heads/master
Commit: 8324632b2983beba1528ab53a999340756c7f563
Parents: 1f7e470
Author: eolivelli <eolivelli@gmail.com>
Authored: Sat Jul 30 22:53:28 2016 -0700
Committer: Sijie Guo <sijie@apache.org>
Committed: Sat Jul 30 22:53:28 2016 -0700

----------------------------------------------------------------------
 .../bookkeeper/conf/AbstractConfiguration.java  | 13 ++++++-
 .../NoSystemPropertiesConfigurationTest.java    | 40 +++++++++++++++++++
 .../conf/SystemPropertiesConfigurationTest.java | 41 ++++++++++++++++++++
 .../bookkeeper/test/ConfigurationTest.java      |  8 ++++
 4 files changed, 100 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/8324632b/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/AbstractConfiguration.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/AbstractConfiguration.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/AbstractConfiguration.java
index 2e66806..314290e 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/AbstractConfiguration.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/AbstractConfiguration.java
@@ -37,6 +37,13 @@ import org.slf4j.LoggerFactory;
 public abstract class AbstractConfiguration extends CompositeConfiguration {
 
     static final Logger LOG = LoggerFactory.getLogger(AbstractConfiguration.class);
+    public static final String READ_SYSTEM_PROPERTIES_PROPERTY
+                            = "org.apache.bookkeeper.conf.readsystemproperties";
+    /**
+     * Enable the use of System Properties, which was the default behaviour till 4.4.0
+     */
+    private static final boolean READ_SYSTEM_PROPERTIES
+                                    = Boolean.getBoolean(READ_SYSTEM_PROPERTIES_PROPERTY);
 
     protected static final ClassLoader defaultLoader;
     static {
@@ -60,8 +67,10 @@ public abstract class AbstractConfiguration extends CompositeConfiguration
{
 
     protected AbstractConfiguration() {
         super();
-        // add configuration for system properties
-        addConfiguration(new SystemConfiguration());
+        if (READ_SYSTEM_PROPERTIES) {
+            // add configuration for system properties
+            addConfiguration(new SystemConfiguration());
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/8324632b/bookkeeper-server/src/test/java/org/apache/bookkeeper/conf/NoSystemPropertiesConfigurationTest.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/conf/NoSystemPropertiesConfigurationTest.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/conf/NoSystemPropertiesConfigurationTest.java
new file mode 100644
index 0000000..3e34695
--- /dev/null
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/conf/NoSystemPropertiesConfigurationTest.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2016 The Apache Software Foundation.
+ *
+ * Licensed 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.bookkeeper.conf;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test Configuration API
+ *
+ * @author enrico.olivelli
+ * @see SystemPropertiesConfigurationTest
+ */
+public class NoSystemPropertiesConfigurationTest {
+
+    static {  
+        // this property is read when AbstractConfiguration class is loaded.
+        // this test will work as expected only using a new JVM (or classloader) for the
test
+        System.setProperty(ClientConfiguration.THROTTLE, "10");
+    }
+
+    @Test
+    public void testUseSystemProperty() {
+        ClientConfiguration clientConfiguration = new ClientConfiguration();
+        assertEquals(5000, clientConfiguration.getThrottleValue());
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/8324632b/bookkeeper-server/src/test/java/org/apache/bookkeeper/conf/SystemPropertiesConfigurationTest.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/conf/SystemPropertiesConfigurationTest.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/conf/SystemPropertiesConfigurationTest.java
new file mode 100644
index 0000000..10c9575
--- /dev/null
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/conf/SystemPropertiesConfigurationTest.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2016 The Apache Software Foundation.
+ *
+ * Licensed 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.bookkeeper.conf;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test Configuration API
+ *
+ * @author enrico.olivelli
+ * @see  NoSystemPropertiesConfigurationTest
+ */
+public class SystemPropertiesConfigurationTest {
+
+    static {
+        // this property is read when AbstractConfiguration class is loaded.
+        // this test will work as expected only using a new JVM (or classloader) for the
test
+        System.setProperty(AbstractConfiguration.READ_SYSTEM_PROPERTIES_PROPERTY, "true");
+        System.setProperty(ClientConfiguration.THROTTLE, "10");
+    }
+
+    @Test
+    public void testUseSystemProperty() {
+        ClientConfiguration clientConfiguration = new ClientConfiguration();
+        assertEquals(10, clientConfiguration.getThrottleValue());
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/bookkeeper/blob/8324632b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ConfigurationTest.java
----------------------------------------------------------------------
diff --git a/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ConfigurationTest.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ConfigurationTest.java
index ac4e0e0..7784666 100644
--- a/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ConfigurationTest.java
+++ b/bookkeeper-server/src/test/java/org/apache/bookkeeper/test/ConfigurationTest.java
@@ -20,6 +20,7 @@
  */
 package org.apache.bookkeeper.test;
 
+import org.apache.bookkeeper.conf.AbstractConfiguration;
 import org.apache.bookkeeper.conf.ServerConfiguration;
 import org.apache.bookkeeper.conf.ClientConfiguration;
 
@@ -28,6 +29,13 @@ import org.junit.Test;
 import static org.junit.Assert.*;
 
 public class ConfigurationTest {
+
+    static {
+        // this property is read when AbstractConfiguration class is loaded.
+        // this test will work as expected only using a new JVM (or classloader) for the
test
+        System.setProperty(AbstractConfiguration.READ_SYSTEM_PROPERTIES_PROPERTY, "true");
+    }
+
     @Test(timeout=60000)
     public void testConfigurationOverwrite() {
         System.clearProperty("zkServers");


Mime
View raw message