Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3DF40F465 for ; Sat, 1 Jun 2013 19:59:51 +0000 (UTC) Received: (qmail 44251 invoked by uid 500); 1 Jun 2013 19:59:50 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 44174 invoked by uid 500); 1 Jun 2013 19:59:50 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 44139 invoked by uid 99); 1 Jun 2013 19:59:50 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Jun 2013 19:59:50 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 01 Jun 2013 19:59:49 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 8BB542388AA6; Sat, 1 Jun 2013 19:59:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1488582 - /commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java Date: Sat, 01 Jun 2013 19:59:29 -0000 To: commits@commons.apache.org From: oheger@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130601195929.8BB542388AA6@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: oheger Date: Sat Jun 1 19:59:29 2013 New Revision: 1488582 URL: http://svn.apache.org/r1488582 Log: Added a test case for concurrent access to CombinedConfiguration without a Synchronizer. Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java?rev=1488582&r1=1488581&r2=1488582&view=diff ============================================================================== --- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java (original) +++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/combined/TestCombinedConfigurationBuilder.java Sat Jun 1 19:59:29 2013 @@ -23,6 +23,7 @@ import static org.junit.Assert.assertNot import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; @@ -34,6 +35,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.CountDownLatch; import org.apache.commons.configuration.BaseHierarchicalConfiguration; import org.apache.commons.configuration.CombinedConfiguration; @@ -1250,6 +1252,33 @@ public class TestCombinedConfigurationBu } /** + * Tests whether a newly created instance can be read concurrently without a + * special synchronizer. + */ + @Test + public void testConcurrentReadAccessWithoutSynchronizer() + throws ConfigurationException + { + builder.configure(new FileBasedBuilderParametersImpl() + .setFile(TEST_FILE)); + CombinedConfiguration config = builder.getConfiguration(); + final int threadCount = 32; + CountDownLatch startLatch = new CountDownLatch(1); + ReadThread[] threads = new ReadThread[threadCount]; + for (int i = 0; i < threadCount; i++) + { + threads[i] = new ReadThread(config, startLatch); + threads[i].start(); + } + + startLatch.countDown(); + for (ReadThread t : threads) + { + t.verify(); + } + } + + /** * A test builder provider implementation for testing whether providers can * be defined in the definition file. */ @@ -1423,4 +1452,56 @@ public class TestCombinedConfigurationBu return builders; } } + + /** + * A thread class for testing concurrent read access to a newly created + * configuration. + */ + private static class ReadThread extends Thread + { + /** The configuration to access. */ + private final CombinedConfiguration config; + + /** The start latch. */ + private final CountDownLatch startLatch; + + /** The value read from the configuration. */ + private Boolean value; + + public ReadThread(CombinedConfiguration cc, CountDownLatch latch) + { + config = cc; + startLatch = latch; + } + + @Override + public void run() + { + try + { + startLatch.await(); + value = config.getBoolean("configuration.loaded"); + } + catch (InterruptedException iex) + { + // ignore + } + } + + /** + * Verifies that the correct value was read. + */ + public void verify() + { + try + { + join(); + } + catch (InterruptedException iex) + { + fail("Waiting was interrupted: " + iex); + } + assertEquals("Wrong value read", Boolean.TRUE, value); + } + } }