directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fel...@apache.org
Subject svn commit: r952543 - in /directory/buildtools/trunk/junit-addons: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/directory/ src/main/java/org/apache/directory/junit/ src/main/java/org/apache/dire...
Date Tue, 08 Jun 2010 05:55:19 GMT
Author: felixk
Date: Tue Jun  8 05:55:19 2010
New Revision: 952543

URL: http://svn.apache.org/viewvc?rev=952543&view=rev
Log:
JUnit addon to run tests and suites concurrent, see also http://junit.org/node/589

Added:
    directory/buildtools/trunk/junit-addons/
    directory/buildtools/trunk/junit-addons/pom.xml   (with props)
    directory/buildtools/trunk/junit-addons/src/
    directory/buildtools/trunk/junit-addons/src/main/
    directory/buildtools/trunk/junit-addons/src/main/java/
    directory/buildtools/trunk/junit-addons/src/main/java/org/
    directory/buildtools/trunk/junit-addons/src/main/java/org/apache/
    directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/
    directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/
    directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/
    directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/Concurrent.java
  (with props)
    directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/ConcurrentJunitRunner.java
  (with props)
    directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/ConcurrentSuite.java
  (with props)

Added: directory/buildtools/trunk/junit-addons/pom.xml
URL: http://svn.apache.org/viewvc/directory/buildtools/trunk/junit-addons/pom.xml?rev=952543&view=auto
==============================================================================
--- directory/buildtools/trunk/junit-addons/pom.xml (added)
+++ directory/buildtools/trunk/junit-addons/pom.xml Tue Jun  8 05:55:19 2010
@@ -0,0 +1,61 @@
+<?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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.directory.project</groupId>
+    <artifactId>project</artifactId>
+    <version>17</version>
+  </parent>
+  <groupId>org.apache.directory.junit</groupId>
+  <artifactId>junit-addons</artifactId>
+  <version>0.1-SNAPSHOT</version>
+  <name>junit-addons</name>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>4.8.1</version>
+    </dependency>
+  </dependencies>
+
+  <distributionManagement>
+    <site>
+      <id>apache.directory.buildtools.junit-addons</id>
+      <url>${distMgmtSiteUrl}</url>
+    </site>
+  </distributionManagement>
+
+  <issueManagement>
+    <system>JIRA</system>
+    <url>http://issues.apache.org/jira/browse/DIR</url>
+  </issueManagement>
+
+  <scm>
+    <connection>scm:svn:http://svn.apache.org/repos/asf/directory/buildtools/trunk/junit-addons</connection>
+    <developerConnection>scm:svn:https://svn.apache.org/repos/asf/directory/buildtools/trunk/junit-addons</developerConnection>
+    <url>http://svn.apache.org/viewvc/directory/buildtools/trunk/junit-addons</url>
+  </scm>
+</project>

Propchange: directory/buildtools/trunk/junit-addons/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/Concurrent.java
URL: http://svn.apache.org/viewvc/directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/Concurrent.java?rev=952543&view=auto
==============================================================================
--- directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/Concurrent.java
(added)
+++ directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/Concurrent.java
Tue Jun  8 05:55:19 2010
@@ -0,0 +1,38 @@
+/*
+ *  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. 
+ *  
+ */
+package org.apache.directory.junit.tools;
+
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+/**
+ * @author Mathieu Carbou (mathieu.carbou@gmail.com)
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(
+    { ElementType.TYPE })
+public @interface Concurrent
+{
+    int threads() default 5;
+}
\ No newline at end of file

Propchange: directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/Concurrent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/ConcurrentJunitRunner.java
URL: http://svn.apache.org/viewvc/directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/ConcurrentJunitRunner.java?rev=952543&view=auto
==============================================================================
--- directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/ConcurrentJunitRunner.java
(added)
+++ directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/ConcurrentJunitRunner.java
Tue Jun  8 05:55:19 2010
@@ -0,0 +1,103 @@
+/*
+ *  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. 
+ *  
+ */
+package org.apache.directory.junit.tools;
+
+
+import java.util.LinkedList;
+import java.util.Queue;
+import java.util.concurrent.CompletionService;
+import java.util.concurrent.ExecutorCompletionService;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.RunnerScheduler;
+
+
+/**
+ * @author Mathieu Carbou (mathieu.carbou@gmail.com)
+ */
+public class ConcurrentJunitRunner extends BlockJUnit4ClassRunner
+{
+    public ConcurrentJunitRunner( final Class<?> klass ) throws InitializationError
+    {
+        super( klass );
+        setScheduler( new RunnerScheduler()
+        {
+            ExecutorService executorService = Executors.newFixedThreadPool( klass
+                .isAnnotationPresent( Concurrent.class ) ? klass.getAnnotation( Concurrent.class
).threads() : 5,
+                new NamedThreadFactory( klass.getSimpleName() ) );
+            CompletionService<Void> completionService = new ExecutorCompletionService<Void>(
executorService );
+            Queue<Future<Void>> tasks = new LinkedList<Future<Void>>();
+
+
+            @Override
+            public void schedule( Runnable childStatement )
+            {
+                tasks.offer( completionService.submit( childStatement, null ) );
+            }
+
+
+            @Override
+            public void finished()
+            {
+                try
+                {
+                    while ( !tasks.isEmpty() )
+                        tasks.remove( completionService.take() );
+                }
+                catch ( InterruptedException e )
+                {
+                    Thread.currentThread().interrupt();
+                }
+                finally
+                {
+                    while ( !tasks.isEmpty() )
+                        tasks.poll().cancel( true );
+                    executorService.shutdownNow();
+                }
+            }
+        } );
+    }
+
+    static final class NamedThreadFactory implements ThreadFactory
+    {
+        static final AtomicInteger poolNumber = new AtomicInteger( 1 );
+        final AtomicInteger threadNumber = new AtomicInteger( 1 );
+        final ThreadGroup group;
+
+
+        NamedThreadFactory( String poolName )
+        {
+            group = new ThreadGroup( poolName + "-" + poolNumber.getAndIncrement() );
+        }
+
+
+        @Override
+        public Thread newThread( Runnable r )
+        {
+            return new Thread( group, r, group.getName() + "-thread-" + threadNumber.getAndIncrement(),
0 );
+        }
+    }
+}

Propchange: directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/ConcurrentJunitRunner.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/ConcurrentSuite.java
URL: http://svn.apache.org/viewvc/directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/ConcurrentSuite.java?rev=952543&view=auto
==============================================================================
--- directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/ConcurrentSuite.java
(added)
+++ directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/ConcurrentSuite.java
Tue Jun  8 05:55:19 2010
@@ -0,0 +1,66 @@
+/*
+ *  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. 
+ *  
+ */
+package org.apache.directory.junit.tools;
+
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.internal.builders.AllDefaultPossibilitiesBuilder;
+import org.junit.runner.Runner;
+import org.junit.runners.Suite;
+import org.junit.runners.model.InitializationError;
+import org.junit.runners.model.RunnerBuilder;
+
+
+/**
+ * @author Mathieu Carbou (mathieu.carbou@gmail.com)
+ */
+public final class ConcurrentSuite extends Suite
+{
+    public ConcurrentSuite( Class<?> klass ) throws InitializationError
+    {
+        super( klass, new AllDefaultPossibilitiesBuilder( true )
+        {
+            @Override
+            public Runner runnerForClass( Class<?> testClass ) throws Throwable
+            {
+                List<RunnerBuilder> builders = Arrays.asList( new RunnerBuilder()
+                {
+                    @Override
+                    public Runner runnerForClass( Class<?> testClass ) throws Throwable
+                    {
+                        Concurrent annotation = testClass.getAnnotation( Concurrent.class
);
+                        if ( annotation != null )
+                            return new ConcurrentJunitRunner( testClass );
+                        return null;
+                    }
+                }, ignoredBuilder(), annotatedBuilder(), suiteMethodBuilder(), junit3Builder(),
junit4Builder() );
+                for ( RunnerBuilder each : builders )
+                {
+                    Runner runner = each.safeRunnerForClass( testClass );
+                    if ( runner != null )
+                        return runner;
+                }
+                return null;
+            }
+        } );
+    }
+}

Propchange: directory/buildtools/trunk/junit-addons/src/main/java/org/apache/directory/junit/tools/ConcurrentSuite.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message