maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bentm...@apache.org
Subject svn commit: r902426 - in /maven/core-integration-testing/trunk: core-it-suite/src/test/java/org/apache/maven/it/ core-it-suite/src/test/resources/mng-4544/ core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven...
Date Sat, 23 Jan 2010 15:45:32 GMT
Author: bentmann
Date: Sat Jan 23 15:45:32 2010
New Revision: 902426

URL: http://svn.apache.org/viewvc?rev=902426&view=rev
Log:
[MNG-4544] Concurrent access to Maven internals involving active component collections is
not thread-safe

o Added IT

Added:
    maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4544ActiveComponentCollectionThreadSafeTest.java
  (with props)
    maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4544/
    maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4544/pom.xml
  (with props)
    maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java
  (with props)
Modified:
    maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java

Modified: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java?rev=902426&r1=902425&r2=902426&view=diff
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
(original)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/IntegrationTestSuite.java
Sat Jan 23 15:45:32 2010
@@ -85,6 +85,7 @@
         // suite.addTestSuite( MavenIT0109ReleaseUpdateTest.class );
         // suite.addTestSuite( MavenIT0108SnapshotUpdateTest.class ); -- MNG-3137
 
+        suite.addTestSuite( MavenITmng4544ActiveComponentCollectionThreadSafeTest.class );
         suite.addTestSuite( MavenITmng4500NoUpdateOfTimestampedSnapshotsTest.class );
         suite.addTestSuite( MavenITmng4498IgnoreBrokenMetadataTest.class );
         suite.addTestSuite( MavenITmng4489MirroringOfExtensionRepoTest.class );

Added: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4544ActiveComponentCollectionThreadSafeTest.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4544ActiveComponentCollectionThreadSafeTest.java?rev=902426&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4544ActiveComponentCollectionThreadSafeTest.java
(added)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4544ActiveComponentCollectionThreadSafeTest.java
Sat Jan 23 15:45:32 2010
@@ -0,0 +1,62 @@
+package org.apache.maven.it;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+
+import java.io.File;
+import java.util.Properties;
+
+/**
+ * This is a test set for <a href="http://jira.codehaus.org/browse/MNG-4544">MNG-4544</a>.
+ * 
+ * @author Benjamin Bentmann
+ */
+public class MavenITmng4544ActiveComponentCollectionThreadSafeTest
+    extends AbstractMavenIntegrationTestCase
+{
+
+    public MavenITmng4544ActiveComponentCollectionThreadSafeTest()
+    {
+        super( "[2.0.3,3.0-alpha-1),[3.0-alpha-7,)" );
+    }
+
+    /**
+     * Test that concurrent access to active component collections is thread-safe.
+     */
+    public void testit()
+        throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/mng-4544"
);
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        verifier.setAutoclean( false );
+        verifier.deleteDirectory( "target" );
+        verifier.executeGoal( "validate" );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        Properties props = verifier.loadProperties( "target/thread.properties" );
+        assertEquals( 0, Integer.parseInt( props.getProperty( "exceptions" ) ) );
+        assertEquals( 2, Integer.parseInt( props.getProperty( "components" ) ) );
+    }
+
+}

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4544ActiveComponentCollectionThreadSafeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng4544ActiveComponentCollectionThreadSafeTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4544/pom.xml
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4544/pom.xml?rev=902426&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4544/pom.xml
(added)
+++ maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4544/pom.xml
Sat Jan 23 15:45:32 2010
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you 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.
+-->
+
+<project>
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.its.mng4544</groupId>
+  <artifactId>test</artifactId>
+  <version>0.1</version>
+
+  <name>Maven Integration Test :: MNG-4544</name>
+  <description>
+    Test that concurrent access to active component collections is thread-safe.
+  </description>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.its.plugins</groupId>
+        <artifactId>maven-it-plugin-active-collection</artifactId>
+        <version>2.1-SNAPSHOT</version>
+        <configuration>
+          <outputFile>target/thread.properties</outputFile>
+        </configuration>
+        <executions>
+          <execution>
+            <id>test</id>
+            <phase>validate</phase>
+            <goals>
+              <goal>check-thread-safety</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4544/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-it-suite/src/test/resources/mng-4544/pom.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java
URL: http://svn.apache.org/viewvc/maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java?rev=902426&view=auto
==============================================================================
--- maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java
(added)
+++ maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java
Sat Jan 23 15:45:32 2010
@@ -0,0 +1,188 @@
+package org.apache.maven.plugin.coreit;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Vector;
+
+/**
+ * Checks the thread-safe retrieval of components from active component collections.
+ * 
+ * @goal check-thread-safety
+ * @phase validate
+ * 
+ * @author Benjamin Bentmann
+ */
+public class CheckThreadSafetyMojo
+    extends AbstractMojo
+{
+
+    /**
+     * Project base directory used for manual path alignment.
+     * 
+     * @parameter default-value="${basedir}"
+     * @readonly
+     */
+    private File basedir;
+
+    /**
+     * The available components, as a map.
+     * 
+     * @component role="org.apache.maven.plugin.coreit.Component"
+     */
+    private Map componentMap;
+
+    /**
+     * The available components, as a list.
+     * 
+     * @component role="org.apache.maven.plugin.coreit.Component"
+     */
+    private List componentList;
+
+    /**
+     * The path to the properties file to create.
+     * 
+     * @parameter expression="${collections.outputFile}"
+     */
+    private File outputFile;
+
+    /**
+     * Runs this mojo.
+     * 
+     * @throws MojoFailureException If the output file could not be created.
+     */
+    public void execute()
+        throws MojoExecutionException
+    {
+        Properties componentProperties = new Properties();
+
+        getLog().info( "[MAVEN-CORE-IT-LOG] Testing concurrent component access" );
+
+        final Map map = componentMap;
+        final List list = componentList;
+        final List go = new Vector();
+        final List exceptions = new Vector();
+
+        Thread[] threads = new Thread[2];
+        for ( int i = 0; i < threads.length; i++ )
+        {
+            // NOTE: The threads need to use different realms to trigger changes of the collections
+            final ClassLoader cl =
+                ( i % 2 ) == 0 ? getClass().getClassLoader() : MojoExecutionException.class.getClassLoader();
+            threads[i] = new Thread()
+            {
+                private final ClassLoader tccl = cl;
+
+                public void run()
+                {
+                    getLog().info( "[MAVEN-CORE-IT-LOG] Thread " + this + " uses " + tccl
);
+                    Thread.currentThread().setContextClassLoader( tccl );
+                    while ( go.isEmpty() )
+                    {
+                        // wait for start
+                    }
+                    for ( int j = 0; j < 10000; j++ )
+                    {
+                        try
+                        {
+                            for ( Iterator it = map.values().iterator(); it.hasNext(); )
+                            {
+                                it.next().toString();
+                            }
+                            for ( Iterator it = list.iterator(); it.hasNext(); )
+                            {
+                                it.next().toString();
+                            }
+                        }
+                        catch ( Exception e )
+                        {
+                            getLog().warn( "[MAVEN-CORE-IT-LOG] Thread " + this + " encountered
concurrency issue", e );
+                            exceptions.add( e );
+                        }
+                    }
+                }
+            };
+            threads[i].start();
+        }
+
+        go.add( null );
+        for ( int i = 0; i < threads.length; i++ )
+        {
+            try
+            {
+                threads[i].join();
+            }
+            catch ( InterruptedException e )
+            {
+                getLog().warn( "[MAVEN-CORE-IT-LOG] Interrupted while joining " + threads[i]
);
+            }
+        }
+
+        componentProperties.setProperty( "components", Integer.toString( componentList.size()
) );
+        componentProperties.setProperty( "exceptions", Integer.toString( exceptions.size()
) );
+
+        if ( !outputFile.isAbsolute() )
+        {
+            outputFile = new File( basedir, outputFile.getPath() );
+        }
+
+        getLog().info( "[MAVEN-CORE-IT-LOG] Creating output file " + outputFile );
+
+        OutputStream out = null;
+        try
+        {
+            outputFile.getParentFile().mkdirs();
+            out = new FileOutputStream( outputFile );
+            componentProperties.store( out, "MAVEN-CORE-IT-LOG" );
+        }
+        catch ( IOException e )
+        {
+            throw new MojoExecutionException( "Output file could not be created: " + outputFile,
e );
+        }
+        finally
+        {
+            if ( out != null )
+            {
+                try
+                {
+                    out.close();
+                }
+                catch ( IOException e )
+                {
+                    // just ignore
+                }
+            }
+        }
+
+        getLog().info( "[MAVEN-CORE-IT-LOG] Created output file " + outputFile );
+    }
+
+}

Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/core-integration-testing/trunk/core-it-support/core-it-plugins/maven-it-plugin-active-collection/src/main/java/org/apache/maven/plugin/coreit/CheckThreadSafetyMojo.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message