You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@etch.apache.org by sc...@apache.org on 2008/12/01 21:00:38 UTC
svn commit: r722208 - in /incubator/etch/trunk:
binding-csharp/runtime/src/test/csharp/Etch/Support/TestFreePool.cs
binding-csharp/runtime/src/test/csharp/EtchTestProj.csproj
binding-java/runtime/src/test/java/etch/bindings/java/support/TestFreePool.java
Author: sccomer
Date: Mon Dec 1 12:00:37 2008
New Revision: 722208
URL: http://svn.apache.org/viewvc?rev=722208&view=rev
Log:
implemented unit tests for FreePool in both csharp and java bindings.
Added:
incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/Etch/Support/TestFreePool.cs (with props)
Modified:
incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/EtchTestProj.csproj
incubator/etch/trunk/binding-java/runtime/src/test/java/etch/bindings/java/support/TestFreePool.java
Added: incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/Etch/Support/TestFreePool.cs
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/Etch/Support/TestFreePool.cs?rev=722208&view=auto
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/Etch/Support/TestFreePool.cs (added)
+++ incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/Etch/Support/TestFreePool.cs Mon Dec 1 12:00:37 2008
@@ -0,0 +1,294 @@
+// $Id$
+//
+// Copyright 2007-2008 Cisco Systems Inc.
+//
+// Licensed 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.
+
+using System;
+using System.Threading;
+using NUnit.Framework;
+
+namespace Etch.Support
+{
+ [TestFixture]
+ public class TestFreePool
+ {
+ [Test]
+ public void close1()
+ {
+ FreePool p = new FreePool(2);
+ p.Close();
+ }
+
+ [Test]
+ [ExpectedException(typeof(Exception))]
+ public void close2()
+ {
+ // free pool thread count exceeded or pool closed
+ FreePool p = new FreePool(2);
+ p.Close();
+
+ MyPoolRunnable r = new MyPoolRunnable(0, false);
+ p.Run(r.run, r.exception);
+ }
+
+ [Test]
+ public void close3()
+ {
+ FreePool p = new FreePool(2);
+ p.Close();
+ p.Close();
+ }
+
+ [Test]
+ [ExpectedException(typeof(Exception))]
+ public void join1()
+ {
+ // free pool thread count exceeded or pool closed
+ FreePool p = new FreePool(2);
+ p.Join();
+
+ MyPoolRunnable r = new MyPoolRunnable(0, false);
+ p.Run(r.run, r.exception);
+ }
+
+ [Test]
+ public void join2()
+ {
+ FreePool p = new FreePool(2);
+
+ MyPoolRunnable r = new MyPoolRunnable(0, false);
+ Assert.IsFalse(r.done);
+ Assert.IsNull(r.ex);
+ p.Run(r.run, r.exception);
+ Thread.Sleep(30);
+ Assert.IsTrue(r.done);
+ Assert.IsNull(r.ex);
+ p.Join();
+ }
+
+ [Test]
+ public void join3()
+ {
+ FreePool p = new FreePool(2);
+
+ MyPoolRunnable r = new MyPoolRunnable(30, false);
+ Assert.IsFalse(r.done);
+ Assert.IsNull(r.ex);
+ p.Run(r.run, r.exception);
+ Assert.IsFalse(r.done);
+ Assert.IsNull(r.ex);
+ p.Join();
+ Assert.IsTrue(r.done);
+ Assert.IsNull(r.ex);
+ }
+
+ [Test]
+ public void run1()
+ {
+ FreePool p = new FreePool(2);
+
+ MyPoolRunnable r = new MyPoolRunnable(0, false);
+ Assert.IsFalse(r.done);
+ Assert.IsNull(r.ex);
+
+ p.Run(r.run, r.exception);
+
+ Thread.Sleep(30);
+ Assert.IsTrue(r.done);
+ Assert.IsNull(r.ex);
+ }
+
+ [Test]
+ public void run2()
+ {
+ FreePool p = new FreePool(2);
+ for (int i = 0; i < 100; i++)
+ {
+ MyPoolRunnable r = new MyPoolRunnable(0, false);
+ Assert.IsFalse(r.done);
+ Assert.IsNull(r.ex);
+
+ p.Run(r.run, r.exception);
+
+ Thread.Sleep(30);
+ Assert.IsTrue(r.done);
+ Assert.IsNull(r.ex);
+ }
+ }
+
+ [Test]
+ public void run3()
+ {
+ FreePool p = new FreePool(2);
+
+ MyPoolRunnable r = new MyPoolRunnable(0, true);
+ Assert.IsFalse(r.done);
+ Assert.IsNull(r.ex);
+
+ p.Run(r.run, r.exception);
+
+ Thread.Sleep(30);
+ Assert.IsFalse(r.done);
+ Assert.IsNotNull(r.ex);
+ }
+
+ [Test]
+ public void run4()
+ {
+ FreePool p = new FreePool(2);
+
+ MyPoolRunnable r = new MyPoolRunnable(30, false);
+ Assert.IsFalse(r.done);
+ Assert.IsNull(r.ex);
+
+ p.Run(r.run, r.exception);
+
+ Thread.Sleep(15);
+ Assert.IsFalse(r.done);
+ Assert.IsNull(r.ex);
+
+ Thread.Sleep(45);
+ Assert.IsTrue(r.done);
+ Assert.IsNull(r.ex);
+ }
+
+ [Test]
+ public void run5()
+ {
+ FreePool p = new FreePool(2);
+
+ MyPoolRunnable r1 = new MyPoolRunnable(30, false);
+ Assert.IsFalse(r1.done);
+ Assert.IsNull(r1.ex);
+
+ MyPoolRunnable r2 = new MyPoolRunnable(30, false);
+ Assert.IsFalse(r2.done);
+ Assert.IsNull(r2.ex);
+
+ p.Run(r1.run, r1.exception);
+ p.Run(r2.run, r2.exception);
+
+ Thread.Sleep(15);
+ Assert.IsFalse(r1.done);
+ Assert.IsNull(r1.ex);
+
+ Assert.IsFalse(r2.done);
+ Assert.IsNull(r2.ex);
+
+ Thread.Sleep(45);
+ Assert.IsTrue(r1.done);
+ Assert.IsNull(r1.ex);
+
+ Assert.IsTrue(r2.done);
+ Assert.IsNull(r2.ex);
+ }
+
+ [Test]
+ [ExpectedException(typeof(Exception))]
+ public void run6()
+ {
+ // free pool thread count exceeded
+ FreePool p = new FreePool(2);
+
+ MyPoolRunnable r1 = new MyPoolRunnable(30, false);
+ Assert.IsFalse(r1.done);
+ Assert.IsNull(r1.ex);
+
+ MyPoolRunnable r2 = new MyPoolRunnable(30, false);
+ Assert.IsFalse(r2.done);
+ Assert.IsNull(r2.ex);
+
+ MyPoolRunnable r3 = new MyPoolRunnable(30, false);
+ Assert.IsFalse(r3.done);
+ Assert.IsNull(r3.ex);
+
+ p.Run(r1.run, r1.exception);
+ p.Run(r2.run, r2.exception);
+ p.Run(r3.run, r3.exception);
+ }
+
+ [Test]
+ public void run7()
+ {
+ FreePool p = new FreePool(2);
+
+ MyPoolRunnable r1 = new MyPoolRunnable(30, false);
+ Assert.IsFalse(r1.done);
+ Assert.IsNull(r1.ex);
+
+ MyPoolRunnable r2 = new MyPoolRunnable(30, false);
+ Assert.IsFalse(r2.done);
+ Assert.IsNull(r2.ex);
+
+ MyPoolRunnable r3 = new MyPoolRunnable(30, false);
+ Assert.IsFalse(r3.done);
+ Assert.IsNull(r3.ex);
+
+ p.Run(r1.run, r1.exception);
+ p.Run(r2.run, r2.exception);
+ try { p.Run(r3.run, r3.exception); } catch (Exception) { }
+
+ Thread.Sleep(15);
+ Assert.IsFalse(r1.done);
+ Assert.IsNull(r1.ex);
+
+ Assert.IsFalse(r2.done);
+ Assert.IsNull(r2.ex);
+
+ Assert.IsFalse(r3.done);
+ Assert.IsNull(r3.ex);
+
+ Thread.Sleep(45);
+ Assert.IsTrue(r1.done);
+ Assert.IsNull(r1.ex);
+
+ Assert.IsTrue(r2.done);
+ Assert.IsNull(r2.ex);
+
+ Assert.IsFalse(r3.done);
+ Assert.IsNull(r3.ex);
+ }
+ }
+
+ class MyPoolRunnable
+ {
+ public MyPoolRunnable( int delay, bool excp )
+ {
+ this.delay = delay;
+ this.excp = excp;
+ }
+
+ private readonly int delay;
+
+ private readonly bool excp;
+
+ public bool done;
+
+ public Exception ex;
+
+ public void run()
+ {
+ if (delay > 0)
+ Thread.Sleep(delay);
+ if (excp)
+ throw new Exception();
+ done = true;
+ }
+
+ public void exception( Exception e )
+ {
+ ex = e;
+ }
+ }
+}
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/Etch/Support/TestFreePool.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/Etch/Support/TestFreePool.cs
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/EtchTestProj.csproj
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/EtchTestProj.csproj?rev=722208&r1=722207&r2=722208&view=diff
==============================================================================
--- incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/EtchTestProj.csproj (original)
+++ incubator/etch/trunk/binding-csharp/runtime/src/test/csharp/EtchTestProj.csproj Mon Dec 1 12:00:37 2008
@@ -33,6 +33,8 @@
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
+ <Reference Include="System.Data" />
+ <Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Etch\Msg\TestComboValidator.cs" />
@@ -45,6 +47,7 @@
<Compile Include="Etch\Msg\TestTypeMap.cs" />
<Compile Include="Etch\Msg\TestXType.cs" />
<Compile Include="Etch\Support\TestDefaultValueFactory.cs" />
+ <Compile Include="Etch\Support\TestFreePool.cs" />
<Compile Include="Etch\Support\TestRemoteBase.cs" />
<Compile Include="Etch\Support\TestStubBase.cs" />
<Compile Include="Etch\Support\TestTodoManager.cs" />
Modified: incubator/etch/trunk/binding-java/runtime/src/test/java/etch/bindings/java/support/TestFreePool.java
URL: http://svn.apache.org/viewvc/incubator/etch/trunk/binding-java/runtime/src/test/java/etch/bindings/java/support/TestFreePool.java?rev=722208&r1=722207&r2=722208&view=diff
==============================================================================
--- incubator/etch/trunk/binding-java/runtime/src/test/java/etch/bindings/java/support/TestFreePool.java (original)
+++ incubator/etch/trunk/binding-java/runtime/src/test/java/etch/bindings/java/support/TestFreePool.java Mon Dec 1 12:00:37 2008
@@ -17,8 +17,10 @@
package etch.bindings.java.support;
-import org.junit.Ignore;
import org.junit.Test;
+import static org.junit.Assert.*;
+
+import etch.bindings.java.support.Pool.PoolRunnable;
/**
* Test of FreePool
@@ -27,9 +29,279 @@
{
/** @throws Exception */
@Test
- @Ignore
- public void nothing() throws Exception
+ public void close1() throws Exception
+ {
+ FreePool p = new FreePool( 2 );
+ p.close();
+ }
+
+ /** @throws Exception */
+ @Test( expected = IllegalStateException.class )
+ public void close2() throws Exception
+ {
+ // free pool thread count exceeded or pool closed
+ FreePool p = new FreePool( 2 );
+ p.close();
+
+ MyPoolRunnable r = new MyPoolRunnable( 0, false );
+ p.run( r );
+ }
+
+ /** @throws Exception */
+ @Test
+ public void close3() throws Exception
+ {
+ FreePool p = new FreePool( 2 );
+ p.close();
+ p.close();
+ }
+
+ /** @throws Exception */
+ @Test( expected = IllegalStateException.class )
+ public void join1() throws Exception
+ {
+ // free pool thread count exceeded or pool closed
+ FreePool p = new FreePool( 2 );
+ p.join();
+
+ MyPoolRunnable r = new MyPoolRunnable( 0, false );
+ p.run( r );
+ }
+
+ /** @throws Exception */
+ @Test
+ public void join2() throws Exception
+ {
+ FreePool p = new FreePool( 2 );
+
+ MyPoolRunnable r = new MyPoolRunnable( 0, false );
+ assertFalse( r.done );
+ assertNull( r.ex );
+ p.run( r );
+ Thread.sleep( 30 );
+ assertTrue( r.done );
+ assertNull( r.ex );
+ p.join();
+ }
+
+ /** @throws Exception */
+ @Test
+ public void join3() throws Exception
+ {
+ FreePool p = new FreePool( 2 );
+
+ MyPoolRunnable r = new MyPoolRunnable( 30, false );
+ assertFalse( r.done );
+ assertNull( r.ex );
+ p.run( r );
+ assertFalse( r.done );
+ assertNull( r.ex );
+ p.join();
+ assertTrue( r.done );
+ assertNull( r.ex );
+ }
+
+ /** @throws Exception */
+ @Test
+ public void run1() throws Exception
+ {
+ FreePool p = new FreePool( 2 );
+
+ MyPoolRunnable r = new MyPoolRunnable( 0, false );
+ assertFalse( r.done );
+ assertNull( r.ex );
+
+ p.run( r );
+
+ Thread.sleep( 30 );
+ assertTrue( r.done );
+ assertNull( r.ex );
+ }
+
+ /** @throws Exception */
+ @Test
+ public void run2() throws Exception
+ {
+ FreePool p = new FreePool( 2 );
+ for (int i = 0; i < 100; i++)
+ {
+ MyPoolRunnable r = new MyPoolRunnable( 0, false );
+ assertFalse( r.done );
+ assertNull( r.ex );
+
+ p.run( r );
+
+ Thread.sleep( 30 );
+ assertTrue( r.done );
+ assertNull( r.ex );
+ }
+ }
+
+ /** @throws Exception */
+ @Test
+ public void run3() throws Exception
+ {
+ FreePool p = new FreePool( 2 );
+
+ MyPoolRunnable r = new MyPoolRunnable( 0, true );
+ assertFalse( r.done );
+ assertNull( r.ex );
+
+ p.run( r );
+
+ Thread.sleep( 30 );
+ assertFalse( r.done );
+ assertNotNull( r.ex );
+ }
+
+ /** @throws Exception */
+ @Test
+ public void run4() throws Exception
+ {
+ FreePool p = new FreePool( 2 );
+
+ MyPoolRunnable r = new MyPoolRunnable( 30, false );
+ assertFalse( r.done );
+ assertNull( r.ex );
+
+ p.run( r );
+
+ Thread.sleep( 15 );
+ assertFalse( r.done );
+ assertNull( r.ex );
+
+ Thread.sleep( 45 );
+ assertTrue( r.done );
+ assertNull( r.ex );
+ }
+
+ /** @throws Exception */
+ @Test
+ public void run5() throws Exception
+ {
+ FreePool p = new FreePool( 2 );
+
+ MyPoolRunnable r1 = new MyPoolRunnable( 30, false );
+ assertFalse( r1.done );
+ assertNull( r1.ex );
+
+ MyPoolRunnable r2 = new MyPoolRunnable( 30, false );
+ assertFalse( r2.done );
+ assertNull( r2.ex );
+
+ p.run( r1 );
+ p.run( r2 );
+
+ Thread.sleep( 15 );
+ assertFalse( r1.done );
+ assertNull( r1.ex );
+
+ assertFalse( r2.done );
+ assertNull( r2.ex );
+
+ Thread.sleep( 45 );
+ assertTrue( r1.done );
+ assertNull( r1.ex );
+
+ assertTrue( r2.done );
+ assertNull( r2.ex );
+ }
+
+ /** @throws Exception */
+ @Test( expected = IllegalStateException.class )
+ public void run6() throws Exception
+ {
+ // free pool thread count exceeded
+ FreePool p = new FreePool( 2 );
+
+ MyPoolRunnable r1 = new MyPoolRunnable( 30, false );
+ assertFalse( r1.done );
+ assertNull( r1.ex );
+
+ MyPoolRunnable r2 = new MyPoolRunnable( 30, false );
+ assertFalse( r2.done );
+ assertNull( r2.ex );
+
+ MyPoolRunnable r3 = new MyPoolRunnable( 30, false );
+ assertFalse( r3.done );
+ assertNull( r3.ex );
+
+ p.run( r1 );
+ p.run( r2 );
+ p.run( r3 );
+ }
+
+ /** @throws Exception */
+ @Test
+ public void run7() throws Exception
{
- // TODO write some unit tests for FreePool.
+ FreePool p = new FreePool( 2 );
+
+ MyPoolRunnable r1 = new MyPoolRunnable( 30, false );
+ assertFalse( r1.done );
+ assertNull( r1.ex );
+
+ MyPoolRunnable r2 = new MyPoolRunnable( 30, false );
+ assertFalse( r2.done );
+ assertNull( r2.ex );
+
+ MyPoolRunnable r3 = new MyPoolRunnable( 30, false );
+ assertFalse( r3.done );
+ assertNull( r3.ex );
+
+ p.run( r1 );
+ p.run( r2 );
+ try { p.run( r3 ); } catch ( IllegalStateException e ) {}
+
+ Thread.sleep( 15 );
+ assertFalse( r1.done );
+ assertNull( r1.ex );
+
+ assertFalse( r2.done );
+ assertNull( r2.ex );
+
+ assertFalse( r3.done );
+ assertNull( r3.ex );
+
+ Thread.sleep( 45 );
+ assertTrue( r1.done );
+ assertNull( r1.ex );
+
+ assertTrue( r2.done );
+ assertNull( r2.ex );
+
+ assertFalse( r3.done );
+ assertNull( r3.ex );
+ }
+
+ private final class MyPoolRunnable implements PoolRunnable
+ {
+ public MyPoolRunnable( int delay, boolean excp )
+ {
+ this.delay = delay;
+ this.excp = excp;
+ }
+
+ private final int delay;
+
+ private final boolean excp;
+
+ public boolean done;
+
+ public Exception ex;
+
+ public void run() throws Exception
+ {
+ if (delay > 0)
+ Thread.sleep( delay );
+ if (excp)
+ throw new RuntimeException();
+ done = true;
+ }
+
+ public void exception( Exception e )
+ {
+ ex = e;
+ }
}
}