You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kr...@apache.org on 2010/03/01 22:42:55 UTC

svn commit: r917741 - /maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java

Author: krosenvold
Date: Mon Mar  1 21:42:55 2010
New Revision: 917741

URL: http://svn.apache.org/viewvc?rev=917741&view=rev
Log:
Fixed flaky test by improving focus on supported use-case

Test was failing intermittently

Modified:
    maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java

Modified: maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java
URL: http://svn.apache.org/viewvc/maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java?rev=917741&r1=917740&r2=917741&view=diff
==============================================================================
--- maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java (original)
+++ maven/maven-3/trunk/maven-model-builder/src/test/java/org/apache/maven/model/interpolation/StringSearchModelInterpolatorTest.java Mon Mar  1 21:42:55 2010
@@ -350,43 +350,26 @@
     public void testConcurrentInterpolation() throws Exception {
         final Model model = new Model();
 
-        Properties p = new Properties();
+        final Properties p = new Properties();
         p.setProperty( "key", "value" );
         p.setProperty( "key2", "value2" );
         p.setProperty( "key3", "value3" );
         p.setProperty( "key4", "value4" );
+        p.setProperty( "key5", "value5" );
 
-        List<String[]> values = new ArrayList<String[]>();
-
-        values.add( new String[] { "${key}", "${key2}" } );
-        values.add( new String[] { "${key3}", "${key4}" } );
-        List values2 = new ArrayList();
-        values.add( new String[] { "${key}", "${key2}" } );
-        values.add( new String[] { "${key3}", "${key4}" } );
-        List values3 = new ArrayList();
-        values.add( new String[] { "${key}", "${key2}" } );
-        values.add( new String[] { "${key3}", "${key4}" } );
-
-        // There is an interesting issue here; if I send three identical collections into the three Lists in "obj",
-        // like this:
-        // final ObjectWithMixedProtection obj = new ObjectWithMixedProtection( values, values, values );
-        // I will have concurrency issues on the interpolation of the individual collections, since current
-        // synchronization is per-field and not per-underlying object.
-        // If this turns out to be a realistic use case, we will need to synchronize on the underlying collection
-        // in the interpolate method.
-
-        final ObjectWithMixedProtection obj = new ObjectWithMixedProtection( values, values2, values3 );
         final StringSearchModelInterpolator interpolator = (StringSearchModelInterpolator) createInterpolator();
-        final ModelBuildingRequest config = createModelBuildingRequest(p);
 
 
-        int numItems = 250;
+        int numItems = 100;
         final CountDownLatch countDownLatch = new CountDownLatch(1);
 
         List<Future<SimpleProblemCollector>>  futures = new ArrayList<Future<SimpleProblemCollector>>();
         for (int i = 0; i < numItems; i++){
             Callable<SimpleProblemCollector> future = new Callable<SimpleProblemCollector>() {
                 public SimpleProblemCollector call() throws Exception {
+                    final ObjectWithMixedProtection obj = getValueList();
+                    final ModelBuildingRequest config = createModelBuildingRequest(p);
+
                     countDownLatch.await();
                     final SimpleProblemCollector collector = new SimpleProblemCollector();
                     interpolator.interpolateObject( obj, model, new File( "." ), config, collector);
@@ -399,10 +382,28 @@
         }
         countDownLatch.countDown(); // Start all the threads
         for(Future<SimpleProblemCollector> result : futures){
-            result.get(); // ArrayIndexOutOfBoundsException are typical indication of threading issues
+            SimpleProblemCollector problemCollector = result.get(); // ArrayIndexOutOfBoundsException are typical indication of threading issues
+            assertProblemFree(  problemCollector );
+            
         }
     }
 
+    private ObjectWithMixedProtection getValueList()
+    {
+        List<String[]> values = new ArrayList<String[]>();
+
+        values.add( new String[] { "${key}", "${key2}" } );
+        values.add( new String[] { "${key3}", "${key4}" } );
+        List values2 = new ArrayList();
+        values.add( new String[] { "${key}", "${key2}" } );
+        values.add( new String[] { "${key3}", "${key4}" } );
+        List values3 = new ArrayList();
+        values.add( new String[] { "${key}", "${key2}" } );
+        values.add( new String[] { "${key3}", "${key4}" } );
+
+        return new ObjectWithMixedProtection( values, values2, values3, "${key5}" );
+    }
+
 
     private static final class ObjectWithStringArrayField
     {
@@ -440,12 +441,26 @@
         private List values1;
         protected List values2;
         List values3;
+        private String fooBar;
 
         private ObjectWithMixedProtection(List values1, List values2, List values3) {
             this.values1 = values1;
             this.values2 = values2;
             this.values3 = values3;
         }
+
+        private ObjectWithMixedProtection( List values1, List values2, List values3, String fooBar )
+        {
+            this.values1 = values1;
+            this.values2 = values2;
+            this.values3 = values3;
+            this.fooBar = fooBar;
+        }
+
+        public String getFooBar()
+        {
+            return fooBar;
+        }
     }
     
     public void testFinalFieldsExcludedFromInterpolation()