commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
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 GMT
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);
+        }
+    }
 }



Mime
View raw message