You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Simone Tripodi <si...@apache.org> on 2012/03/05 07:59:19 UTC

Re: svn commit: r1296883 - in /commons/sandbox/graph/trunk: ./ src/test/java/org/apache/commons/graph/model/ src/test/java/org/apache/commons/graph/utils/

NICE!
-Simo

http://people.apache.org/~simonetripodi/
http://simonetripodi.livejournal.com/
http://twitter.com/simonetripodi
http://www.99soft.org/



On Sun, Mar 4, 2012 at 10:33 PM,  <ma...@apache.org> wrote:
> Author: marcosperanza
> Date: Sun Mar  4 21:33:54 2012
> New Revision: 1296883
>
> URL: http://svn.apache.org/viewvc?rev=1296883&view=rev
> Log:
> Removed unneeded GroboUtil dependency
>
> Added:
>    commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/utils/MultiThreadedTestRunner.java   (with props)
>    commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/utils/TestRunner.java   (with props)
> Modified:
>    commons/sandbox/graph/trunk/pom.xml
>    commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/model/BaseMutableGraphTestCase.java
>
> Modified: commons/sandbox/graph/trunk/pom.xml
> URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/pom.xml?rev=1296883&r1=1296882&r2=1296883&view=diff
> ==============================================================================
> --- commons/sandbox/graph/trunk/pom.xml (original)
> +++ commons/sandbox/graph/trunk/pom.xml Sun Mar  4 21:33:54 2012
> @@ -113,28 +113,15 @@
>     <commons.componentid>graph</commons.componentid>
>     <commons.jira.componentid>12314503</commons.jira.componentid>
>   </properties>
> -
> -  <repositories>
> -    <repository>
> -        <id>opensymphony-releases</id>
> -        <name>Opensymphony Releases</name>
> -        <url>https://oss.sonatype.org/content/repositories/opensymphony-releases</url>
> -    </repository>
> -  </repositories>
> -
> +
>   <dependencies>
>     <dependency>
> -        <groupId>junit</groupId>
> -        <artifactId>junit</artifactId>
> -        <version>4.10</version>
> -        <scope>test</scope>
> -    </dependency>
> -    <dependency>
> -        <groupId>net.sourceforge.groboutils</groupId>
> -        <artifactId>groboutils-core</artifactId>
> -        <version>5</version>
> +      <groupId>junit</groupId>
> +      <artifactId>junit</artifactId>
> +      <version>4.10</version>
> +      <scope>test</scope>
>     </dependency>
> -</dependencies>
> +  </dependencies>
>
>   <build>
>     <resources>
>
> Modified: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/model/BaseMutableGraphTestCase.java
> URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/model/BaseMutableGraphTestCase.java?rev=1296883&r1=1296882&r2=1296883&view=diff
> ==============================================================================
> --- commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/model/BaseMutableGraphTestCase.java (original)
> +++ commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/model/BaseMutableGraphTestCase.java Sun Mar  4 21:33:54 2012
> @@ -30,12 +30,11 @@ import static org.junit.Assert.fail;
>  import java.util.ArrayList;
>  import java.util.List;
>
> -import net.sourceforge.groboutils.junit.v1.MultiThreadedTestRunner;
> -import net.sourceforge.groboutils.junit.v1.TestRunnable;
> -
>  import org.apache.commons.graph.CommonsGraph;
>  import org.apache.commons.graph.GraphException;
>  import org.apache.commons.graph.MutableGraph;
> +import org.apache.commons.graph.utils.MultiThreadedTestRunner;
> +import org.apache.commons.graph.utils.TestRunner;
>  import org.junit.Test;
>
>  /**
> @@ -292,14 +291,13 @@ public class BaseMutableGraphTestCase
>
>         BaseLabeledEdge e = g.getEdge( source, target );
>         g.removeEdge( e );
> -
> +
>         BaseLabeledEdge edge = g.getEdge( source, target );
> -        assertNull( edge  );
> +        assertNull( edge );
>     }
> -
> +
>     /**
> -     * Test method for
> -     * {@link org.apache.commons.graph.model.BaseMutableGraph#removeEdge(org.apache.commons.graph.Edge)}
> +     * Test method for {@link org.apache.commons.graph.model.BaseMutableGraph#removeEdge(org.apache.commons.graph.Edge)}
>      */
>     @Test
>     public final void testUndirectedGraphRemoveEdge()
> @@ -320,10 +318,9 @@ public class BaseMutableGraphTestCase
>
>         assertNull( edge );
>     }
> -
> +
>     /**
> -     * Test method for
> -     * {@link org.apache.commons.graph.model.BaseMutableGraph#removeEdge(org.apache.commons.graph.Edge)}
> +     * Test method for {@link org.apache.commons.graph.model.BaseMutableGraph#removeEdge(org.apache.commons.graph.Edge)}
>      */
>     @Test( expected = GraphException.class )
>     public final void testUndirectedGraphRemoveEdgeNotExists()
> @@ -346,10 +343,9 @@ public class BaseMutableGraphTestCase
>         g.removeEdge( e );
>
>     }
> -
> +
>     /**
> -     * Test method for
> -     * {@link org.apache.commons.graph.model.BaseMutableGraph#removeEdge(org.apache.commons.graph.Edge)}
> +     * Test method for {@link org.apache.commons.graph.model.BaseMutableGraph#removeEdge(org.apache.commons.graph.Edge)}
>      */
>     @Test( expected = GraphException.class )
>     public final void testDirectedGraphRemoveEdgeNotExists()
> @@ -372,27 +368,26 @@ public class BaseMutableGraphTestCase
>         g.removeEdge( e );
>
>     }
> -
> +
>     /**
> -     * Test Graph model ina  multi-thread enviroment.
> +     * Test Graph model ina multi-thread enviroment.
>      */
>     @Test
> -    public final void testMultiTh()
> +    public final void testMultiThreadUndirectGraph()
>         throws Throwable
>     {
>         final MutableGraph<BaseLabeledVertex, BaseLabeledEdge> g =
>             (MutableGraph<BaseLabeledVertex, BaseLabeledEdge>) CommonsGraph.synchronize( (MutableGraph<BaseLabeledVertex, BaseLabeledEdge>) new UndirectedMutableGraph<BaseLabeledVertex, BaseLabeledEdge>() );
>
> -        TestRunnable tr1, tr2, tr3;
> +        TestRunner tr1, tr2, tr3;
>         tr1 = new GraphInsert( g, 0, 10 );
>         tr2 = new GraphInsert( g, 10, 20 );
>         tr3 = new GraphInsert( g, 20, 30 );
>
> -        TestRunnable[] trs = { tr1, tr2, tr3 };
> +        TestRunner[] trs = { tr1, tr2, tr3 };
>         MultiThreadedTestRunner mttr = new MultiThreadedTestRunner( trs );
>
> -        // kickstarts the MTTR & fires off threads
> -        mttr.runTestRunnables();
> +        mttr.runRunnables();
>
>         assertEquals( 30, g.getOrder() );
>
> @@ -410,16 +405,14 @@ public class BaseMutableGraphTestCase
>         final MutableGraph<BaseLabeledVertex, BaseLabeledEdge> g =
>             (MutableGraph<BaseLabeledVertex, BaseLabeledEdge>) CommonsGraph.synchronize( (MutableGraph<BaseLabeledVertex, BaseLabeledEdge>) new DirectedMutableGraph<BaseLabeledVertex, BaseLabeledEdge>() );
>
> -        TestRunnable tr1, tr2, tr3;
> +        TestRunner tr1, tr2, tr3;
>         tr1 = new GraphInsert( g, 0, 10 );
>         tr2 = new GraphInsert( g, 10, 20 );
>         tr3 = new GraphInsert( g, 20, 30 );
>
> -        TestRunnable[] trs = { tr1, tr2, tr3 };
> +        TestRunner[] trs = { tr1, tr2, tr3 };
>         MultiThreadedTestRunner mttr = new MultiThreadedTestRunner( trs );
> -
> -        // kickstarts the MTTR & fires off threads
> -        mttr.runTestRunnables();
> +        mttr.runRunnables();
>
>         assertEquals( 30, g.getOrder() );
>
> @@ -427,8 +420,9 @@ public class BaseMutableGraphTestCase
>         assertEquals( ( 30 * ( 30 - 1 ) ), g.getSize() );
>     }
>
> +    // Utility class.
>     private class GraphInsert
> -        extends TestRunnable
> +        extends TestRunner
>     {
>
>         private MutableGraph<BaseLabeledVertex, BaseLabeledEdge> g;
> @@ -444,8 +438,8 @@ public class BaseMutableGraphTestCase
>             this.end = end;
>         }
>
> +        @Override
>         public void runTest()
> -            throws Throwable
>         {
>
>             // building a complete Graph
> @@ -478,5 +472,4 @@ public class BaseMutableGraphTestCase
>             }
>         }
>     }
> -
>  }
>
> Added: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/utils/MultiThreadedTestRunner.java
> URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/utils/MultiThreadedTestRunner.java?rev=1296883&view=auto
> ==============================================================================
> --- commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/utils/MultiThreadedTestRunner.java (added)
> +++ commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/utils/MultiThreadedTestRunner.java Sun Mar  4 21:33:54 2012
> @@ -0,0 +1,72 @@
> +package org.apache.commons.graph.utils;
> +
> +import java.util.ArrayList;
> +import java.util.List;
> +
> +/*
> + * 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.
> + */
> +
> +/**
> + * Simple utility class.
> + * It is used for executing multi-thread test case.
> + */
> +public class MultiThreadedTestRunner
> +{
> +    final private List<Thread> th;
> +    long maxWait = 60L * 60L * 1000;
> +    final private List<Throwable> exeptions;
> +
> +
> +    public MultiThreadedTestRunner( TestRunner[] runnables )
> +    {
> +        th = new ArrayList<Thread>();
> +        exeptions = new ArrayList<Throwable>();
> +        for ( int i = 0; i < runnables.length; i++ )
> +        {
> +            runnables[i].setTestRunner( this );
> +            th.add( new Thread( runnables[i] ) );
> +        }
> +    }
> +
> +    public void runRunnables() throws Throwable
> +    {
> +        for ( Thread t : th )
> +        {
> +            t.start();
> +        }
> +
> +        for ( Thread t : th )
> +        {
> +            t.join( maxWait );
> +        }
> +
> +        if ( this.exeptions.size() > 0 )
> +        {
> +            throw this.exeptions.get( 0 );
> +        }
> +    }
> +
> +    /**
> +     * @param e
> +     */
> +    public void addException( Throwable e )
> +    {
> +        exeptions.add( e );
> +    }
> +}
>
> Propchange: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/utils/MultiThreadedTestRunner.java
> ------------------------------------------------------------------------------
>    svn:eol-style = native
>
> Propchange: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/utils/MultiThreadedTestRunner.java
> ------------------------------------------------------------------------------
>    svn:keywords = Date Author Id Revision HeadURL
>
> Propchange: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/utils/MultiThreadedTestRunner.java
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
> Added: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/utils/TestRunner.java
> URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/utils/TestRunner.java?rev=1296883&view=auto
> ==============================================================================
> --- commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/utils/TestRunner.java (added)
> +++ commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/utils/TestRunner.java Sun Mar  4 21:33:54 2012
> @@ -0,0 +1,49 @@
> +package org.apache.commons.graph.utils;
> +
> +/*
> + * 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.
> + */
> +
> +/**
> + * Abstract class. It's a generic multi-thread test case
> + *
> + */
> +abstract public class TestRunner
> +    implements Runnable
> +{
> +    private MultiThreadedTestRunner runner;
> +
> +    abstract public void runTest();
> +
> +    public void setTestRunner( MultiThreadedTestRunner runner )
> +    {
> +        this.runner = runner;
> +    }
> +
> +    public void run()
> +    {
> +        try
> +        {
> +            runTest();
> +        }
> +        catch ( Throwable e )
> +        {
> +            runner.addException( e );
> +        }
> +    }
> +}
>
> Propchange: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/utils/TestRunner.java
> ------------------------------------------------------------------------------
>    svn:eol-style = native
>
> Propchange: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/utils/TestRunner.java
> ------------------------------------------------------------------------------
>    svn:keywords = Date Author Id Revision HeadURL
>
> Propchange: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/utils/TestRunner.java
> ------------------------------------------------------------------------------
>    svn:mime-type = text/plain
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org