Return-Path: Delivered-To: apmail-maven-commits-archive@www.apache.org Received: (qmail 85651 invoked from network); 23 Jan 2010 15:46:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 23 Jan 2010 15:46:02 -0000 Received: (qmail 56004 invoked by uid 500); 23 Jan 2010 15:46:02 -0000 Delivered-To: apmail-maven-commits-archive@maven.apache.org Received: (qmail 55887 invoked by uid 500); 23 Jan 2010 15:46:01 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 55878 invoked by uid 99); 23 Jan 2010 15:46:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Jan 2010 15:46:01 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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, 23 Jan 2010 15:45:53 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 23D6D238897D; Sat, 23 Jan 2010 15:45:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@maven.apache.org From: bentmann@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100123154533.23D6D238897D@eris.apache.org> 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 MNG-4544. + * + * @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 @@ + + + + + + 4.0.0 + + org.apache.maven.its.mng4544 + test + 0.1 + + Maven Integration Test :: MNG-4544 + + Test that concurrent access to active component collections is thread-safe. + + + + + + org.apache.maven.its.plugins + maven-it-plugin-active-collection + 2.1-SNAPSHOT + + target/thread.properties + + + + test + validate + + check-thread-safety + + + + + + + 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