Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 580A8200B60 for ; Sun, 31 Jul 2016 07:53:37 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 56934160A8B; Sun, 31 Jul 2016 05:53:37 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 73BEC160A8A for ; Sun, 31 Jul 2016 07:53:36 +0200 (CEST) Received: (qmail 655 invoked by uid 500); 31 Jul 2016 05:53:35 -0000 Mailing-List: contact commits-help@bookkeeper.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: bookkeeper-dev@bookkeeper.apache.org Delivered-To: mailing list commits@bookkeeper.apache.org Received: (qmail 646 invoked by uid 99); 31 Jul 2016 05:53:35 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 31 Jul 2016 05:53:35 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 65E47E93E5; Sun, 31 Jul 2016 05:53:35 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sijie@apache.org To: commits@bookkeeper.apache.org Message-Id: <15b2331ea1974dd79ad5efe5a654f5dc@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: bookkeeper git commit: BOOKKEEPER-933: ClientConfiguration always inherits System properties Date: Sun, 31 Jul 2016 05:53:35 +0000 (UTC) archived-at: Sun, 31 Jul 2016 05:53:37 -0000 Repository: bookkeeper Updated Branches: refs/heads/master 1f7e47005 -> 8324632b2 BOOKKEEPER-933: ClientConfiguration always inherits System properties Author: eolivelli Reviewers: Sijie Guo 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 Authored: Sat Jul 30 22:53:28 2016 -0700 Committer: Sijie Guo 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");