From b66ebdcc7258dfc0da5de8ec269a75a16ac13297 Mon Sep 17 00:00:00 2001 From: Peter Veentjer Date: Fri, 5 Aug 2011 05:56:15 +0300 Subject: [PATCH 1/5] ticket #1032.. more cleanup --- .../akka/cluster/TransactionLogSpec.scala | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/akka-cluster/src/test/scala/akka/cluster/TransactionLogSpec.scala b/akka-cluster/src/test/scala/akka/cluster/TransactionLogSpec.scala index 71afeff1e9..291e5a995b 100644 --- a/akka-cluster/src/test/scala/akka/cluster/TransactionLogSpec.scala +++ b/akka-cluster/src/test/scala/akka/cluster/TransactionLogSpec.scala @@ -29,14 +29,15 @@ class TransactionLogSpec extends WordSpec with MustMatchers with BeforeAndAfterA private var localBookKeeper: LocalBookKeeper = _ "A synchronous used Transaction Log" should { - "be able to record entries" in { + + "be able to record entries - synchronous" in { val uuid = (new UUID).toString val txlog = TransactionLog.newLogFor(uuid, false, null) val entry = "hello".getBytes("UTF-8") txlog.recordEntry(entry) } - "be able to record and delete entries" in { + "be able to record and delete entries - synchronous" in { val uuid = (new UUID).toString val txlog1 = TransactionLog.newLogFor(uuid, false, null) val entry = "hello".getBytes("UTF-8") @@ -47,7 +48,7 @@ class TransactionLogSpec extends WordSpec with MustMatchers with BeforeAndAfterA intercept[BKNoSuchLedgerExistsException](TransactionLog.logFor(uuid, false, null)) } - "be able to record entries and read entries with 'entriesInRange'" in { + "be able to record entries and read entries with 'entriesInRange' - synchronous" in { val uuid = (new UUID).toString val txlog1 = TransactionLog.newLogFor(uuid, false, null) val entry = "hello".getBytes("UTF-8") @@ -63,7 +64,7 @@ class TransactionLogSpec extends WordSpec with MustMatchers with BeforeAndAfterA txlog2.close } - "be able to record entries and read entries with 'entries'" in { + "be able to record entries and read entries with 'entries' - synchronous" in { val uuid = (new UUID).toString val txlog1 = TransactionLog.newLogFor(uuid, false, null) val entry = "hello".getBytes("UTF-8") @@ -83,7 +84,7 @@ class TransactionLogSpec extends WordSpec with MustMatchers with BeforeAndAfterA txlog2.close } - "be able to record a snapshot" in { + "be able to record a snapshot - synchronous" in { val uuid = (new UUID).toString val txlog1 = TransactionLog.newLogFor(uuid, false, null) val snapshot = "snapshot".getBytes("UTF-8") @@ -91,7 +92,7 @@ class TransactionLogSpec extends WordSpec with MustMatchers with BeforeAndAfterA txlog1.close } - "be able to record and read a snapshot and following entries" in { + "be able to record and read a snapshot and following entries - synchronous" in { val uuid = (new UUID).toString val txlog1 = TransactionLog.newLogFor(uuid, false, null) val snapshot = "snapshot".getBytes("UTF-8") @@ -117,7 +118,7 @@ class TransactionLogSpec extends WordSpec with MustMatchers with BeforeAndAfterA txlog2.close } - "be able to record entries then a snapshot then more entries - and then read from the snapshot and the following entries" in { + "be able to record entries then a snapshot then more entries - and then read from the snapshot and the following entries - synchronous" in { val uuid = (new UUID).toString val txlog1 = TransactionLog.newLogFor(uuid, false, null) @@ -155,7 +156,7 @@ class TransactionLogSpec extends WordSpec with MustMatchers with BeforeAndAfterA txlog.close } - "be able to record and delete entries" in { + "be able to record and delete entries - asynchronous" in { val uuid = (new UUID).toString val txlog1 = TransactionLog.newLogFor(uuid, true, null) Thread.sleep(200) @@ -168,7 +169,7 @@ class TransactionLogSpec extends WordSpec with MustMatchers with BeforeAndAfterA Thread.sleep(200) intercept[BKNoSuchLedgerExistsException](TransactionLog.logFor(uuid, true, null)) } - "be able to record entries and read entries with 'entriesInRange'" in { + "be able to record entries and read entries with 'entriesInRange' - asynchronous" in { val uuid = (new UUID).toString val txlog1 = TransactionLog.newLogFor(uuid, true, null) Thread.sleep(200) @@ -190,7 +191,7 @@ class TransactionLogSpec extends WordSpec with MustMatchers with BeforeAndAfterA txlog2.close } - "be able to record entries and read entries with 'entries'" in { + "be able to record entries and read entries with 'entries' - asynchronous" in { val uuid = (new UUID).toString val txlog1 = TransactionLog.newLogFor(uuid, true, null) Thread.sleep(200) @@ -217,7 +218,7 @@ class TransactionLogSpec extends WordSpec with MustMatchers with BeforeAndAfterA txlog2.close } - "be able to record a snapshot" in { + "be able to record a snapshot - asynchronous" in { val uuid = (new UUID).toString val txlog1 = TransactionLog.newLogFor(uuid, true, null) Thread.sleep(200) @@ -227,7 +228,7 @@ class TransactionLogSpec extends WordSpec with MustMatchers with BeforeAndAfterA txlog1.close } - "be able to record and read a snapshot and following entries" in { + "be able to record and read a snapshot and following entries - asynchronous" in { val uuid = (new UUID).toString val txlog1 = TransactionLog.newLogFor(uuid, true, null) Thread.sleep(200) @@ -263,7 +264,7 @@ class TransactionLogSpec extends WordSpec with MustMatchers with BeforeAndAfterA txlog2.close } - "be able to record entries then a snapshot then more entries - and then read from the snapshot and the following entries" in { + "be able to record entries then a snapshot then more entries - and then read from the snapshot and the following entries - asynchronous" in { val uuid = (new UUID).toString val txlog1 = TransactionLog.newLogFor(uuid, true, null) Thread.sleep(200) From b2bfe9a944f6d91227e41fc8b4e640b94531f68b Mon Sep 17 00:00:00 2001 From: Peter Vlugter Date: Thu, 4 Aug 2011 17:48:49 +1200 Subject: [PATCH 2/5] Some quietening of camel test output --- .../scala/akka/camel/TypedConsumerPublisher.scala | 4 ++-- .../main/scala/akka/camel/CamelContextLifecycle.scala | 6 +++--- akka-camel/src/test/resources/logback.xml | 11 +++++++++++ config/akka.test.conf | 1 + 4 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 akka-camel/src/test/resources/logback.xml diff --git a/akka-camel-typed/src/main/scala/akka/camel/TypedConsumerPublisher.scala b/akka-camel-typed/src/main/scala/akka/camel/TypedConsumerPublisher.scala index e3b99e3535..a51f8ab42f 100644 --- a/akka-camel-typed/src/main/scala/akka/camel/TypedConsumerPublisher.scala +++ b/akka-camel-typed/src/main/scala/akka/camel/TypedConsumerPublisher.scala @@ -57,7 +57,7 @@ private[camel] object TypedConsumerPublisher { */ def handleConsumerMethodRegistered(event: ConsumerMethodRegistered) { CamelContextManager.mandatoryContext.addRoutes(new ConsumerMethodRouteBuilder(event)) - EventHandler notifyListeners EventHandler.Info(this, "published method %s of %s at endpoint %s" format (event.methodName, event.typedActor, event.endpointUri)) + EventHandler.info(this, "published method %s of %s at endpoint %s" format (event.methodName, event.typedActor, event.endpointUri)) } /** @@ -65,7 +65,7 @@ private[camel] object TypedConsumerPublisher { */ def handleConsumerMethodUnregistered(event: ConsumerMethodUnregistered) { CamelContextManager.mandatoryContext.stopRoute(event.methodUuid) - EventHandler notifyListeners EventHandler.Info(this, "unpublished method %s of %s from endpoint %s" format (event.methodName, event.typedActor, event.endpointUri)) + EventHandler.info(this, "unpublished method %s of %s from endpoint %s" format (event.methodName, event.typedActor, event.endpointUri)) } } diff --git a/akka-camel/src/main/scala/akka/camel/CamelContextLifecycle.scala b/akka-camel/src/main/scala/akka/camel/CamelContextLifecycle.scala index 9ff71e0f43..da472da927 100644 --- a/akka-camel/src/main/scala/akka/camel/CamelContextLifecycle.scala +++ b/akka-camel/src/main/scala/akka/camel/CamelContextLifecycle.scala @@ -102,7 +102,7 @@ trait CamelContextLifecycle { c.start t.start _started = true - EventHandler notifyListeners EventHandler.Info(this, "Camel context started") + EventHandler.info(this, "Camel context started") } } @@ -118,7 +118,7 @@ trait CamelContextLifecycle { c.stop _started = false _initialized = false - EventHandler notifyListeners EventHandler.Info(this, "Camel context stopped") + EventHandler.info(this, "Camel context stopped") } } @@ -141,7 +141,7 @@ trait CamelContextLifecycle { this._template = Some(context.createProducerTemplate) _initialized = true - EventHandler notifyListeners EventHandler.Info(this, "Camel context initialized") + EventHandler.info(this, "Camel context initialized") } } diff --git a/akka-camel/src/test/resources/logback.xml b/akka-camel/src/test/resources/logback.xml new file mode 100644 index 0000000000..023f2cd317 --- /dev/null +++ b/akka-camel/src/test/resources/logback.xml @@ -0,0 +1,11 @@ + + + + + [%4p] [%d{ISO8601}] [%t] %c{1}: %m%n + + + + + + diff --git a/config/akka.test.conf b/config/akka.test.conf index 025b5895fe..64583e4e98 100644 --- a/config/akka.test.conf +++ b/config/akka.test.conf @@ -6,4 +6,5 @@ include "akka-reference.conf" akka { event-handlers = ["akka.testkit.TestEventListener"] + event-handler-level = "WARNING" } From d5c0237b2f03abf9bc5bb7daeffa87fa1da7f2b9 Mon Sep 17 00:00:00 2001 From: Peter Vlugter Date: Thu, 4 Aug 2011 18:06:18 +1200 Subject: [PATCH 3/5] Disable parallel execution in global scope For avoiding tests from different projects, like cluster and zookeeper mailbox, to run in parallel --- project/AkkaBuild.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/project/AkkaBuild.scala b/project/AkkaBuild.scala index 84a16ef0cf..bd30d3b4fd 100644 --- a/project/AkkaBuild.scala +++ b/project/AkkaBuild.scala @@ -17,6 +17,7 @@ object AkkaBuild extends Build { id = "akka", base = file("."), settings = parentSettings ++ Unidoc.settings ++ rstdocSettings ++ Seq( + parallelExecution in GlobalScope := false, Unidoc.unidocExclude := Seq(samples.id, tutorials.id), rstdocDirectory <<= baseDirectory / "akka-docs" ), From 562ebd94901d8f04ae5d71becce92f5f99a9c38f Mon Sep 17 00:00:00 2001 From: Peter Vlugter Date: Fri, 5 Aug 2011 15:49:54 +1200 Subject: [PATCH 4/5] Quieten the stm test output --- .../example/UntypedCoordinatedCounter.java | 2 +- .../test/ExpectedFailureException.java | 7 ++++ .../test/UntypedCoordinatedCounter.java | 2 +- .../test/UntypedCoordinatedIncrementTest.java | 17 ++++++++ .../akka/transactor/test/UntypedCounter.java | 6 +-- .../akka/transactor/test/UntypedFailer.java | 2 +- .../test/UntypedTransactorTest.java | 17 ++++++++ .../transactor/CoordinatedIncrementSpec.scala | 38 ++++++++--------- .../scala/transactor/FickleFriendsSpec.scala | 41 ++++++++----------- .../scala/transactor/TransactorSpec.scala | 26 ++++++++---- 10 files changed, 99 insertions(+), 59 deletions(-) create mode 100644 akka-stm/src/test/java/akka/transactor/test/ExpectedFailureException.java diff --git a/akka-stm/src/test/java/akka/transactor/example/UntypedCoordinatedCounter.java b/akka-stm/src/test/java/akka/transactor/example/UntypedCoordinatedCounter.java index 6e78e8ea43..10420b4f9e 100644 --- a/akka-stm/src/test/java/akka/transactor/example/UntypedCoordinatedCounter.java +++ b/akka-stm/src/test/java/akka/transactor/example/UntypedCoordinatedCounter.java @@ -10,7 +10,7 @@ public class UntypedCoordinatedCounter extends UntypedActor { private Ref count = new Ref(0); private void increment() { - System.out.println("incrementing"); + //System.out.println("incrementing"); count.set(count.get() + 1); } diff --git a/akka-stm/src/test/java/akka/transactor/test/ExpectedFailureException.java b/akka-stm/src/test/java/akka/transactor/test/ExpectedFailureException.java new file mode 100644 index 0000000000..a4f1beb647 --- /dev/null +++ b/akka-stm/src/test/java/akka/transactor/test/ExpectedFailureException.java @@ -0,0 +1,7 @@ +package akka.transactor.test; + +public class ExpectedFailureException extends RuntimeException { + public ExpectedFailureException() { + super("Expected failure"); + } +} diff --git a/akka-stm/src/test/java/akka/transactor/test/UntypedCoordinatedCounter.java b/akka-stm/src/test/java/akka/transactor/test/UntypedCoordinatedCounter.java index 99f0cd19fe..abde886454 100644 --- a/akka-stm/src/test/java/akka/transactor/test/UntypedCoordinatedCounter.java +++ b/akka-stm/src/test/java/akka/transactor/test/UntypedCoordinatedCounter.java @@ -26,7 +26,7 @@ public class UntypedCoordinatedCounter extends UntypedActor { } private void increment() { - System.out.println(name + ": incrementing"); + //System.out.println(name + ": incrementing"); count.set(count.get() + 1); } diff --git a/akka-stm/src/test/java/akka/transactor/test/UntypedCoordinatedIncrementTest.java b/akka-stm/src/test/java/akka/transactor/test/UntypedCoordinatedIncrementTest.java index df969c2b27..28d725701d 100644 --- a/akka-stm/src/test/java/akka/transactor/test/UntypedCoordinatedIncrementTest.java +++ b/akka-stm/src/test/java/akka/transactor/test/UntypedCoordinatedIncrementTest.java @@ -10,13 +10,21 @@ import akka.actor.ActorRef; import akka.actor.UntypedActor; import akka.actor.UntypedActorFactory; import akka.dispatch.Future; +import akka.event.EventHandler; +import akka.testkit.EventFilter; +import akka.testkit.ErrorFilter; +import akka.testkit.TestEvent; +import akka.transactor.CoordinatedTransactionException; +import java.util.Arrays; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import scala.Option; +import scala.collection.JavaConverters; +import scala.collection.Seq; public class UntypedCoordinatedIncrementTest { List counters; @@ -63,6 +71,10 @@ public class UntypedCoordinatedIncrementTest { } @Test public void incrementNoCountersWithFailingTransaction() { + EventFilter expectedFailureFilter = (EventFilter) new ErrorFilter(ExpectedFailureException.class); + EventFilter coordinatedFilter = (EventFilter) new ErrorFilter(CoordinatedTransactionException.class); + Seq ignoreExceptions = seq(expectedFailureFilter, coordinatedFilter); + EventHandler.notify(new TestEvent.Mute(ignoreExceptions)); CountDownLatch incrementLatch = new CountDownLatch(numCounters); List actors = new ArrayList(counters); actors.add(failer); @@ -83,6 +95,11 @@ public class UntypedCoordinatedIncrementTest { } } } + EventHandler.notify(new TestEvent.UnMute(ignoreExceptions)); + } + + public Seq seq(A... args) { + return JavaConverters.collectionAsScalaIterableConverter(Arrays.asList(args)).asScala().toSeq(); } } diff --git a/akka-stm/src/test/java/akka/transactor/test/UntypedCounter.java b/akka-stm/src/test/java/akka/transactor/test/UntypedCounter.java index 65923e7f4b..14d6e453f9 100644 --- a/akka-stm/src/test/java/akka/transactor/test/UntypedCounter.java +++ b/akka-stm/src/test/java/akka/transactor/test/UntypedCounter.java @@ -28,7 +28,7 @@ public class UntypedCounter extends UntypedTransactor { } private void increment() { - System.out.println(name + ": incrementing"); + //System.out.println(name + ": incrementing"); count.set(count.get() + 1); } @@ -48,7 +48,7 @@ public class UntypedCounter extends UntypedTransactor { } @Override public void before(Object message) { - System.out.println(name + ": before transaction"); + //System.out.println(name + ": before transaction"); } public void atomically(Object message) { @@ -65,7 +65,7 @@ public class UntypedCounter extends UntypedTransactor { } @Override public void after(Object message) { - System.out.println(name + ": after transaction"); + //System.out.println(name + ": after transaction"); } @Override public boolean normally(Object message) { diff --git a/akka-stm/src/test/java/akka/transactor/test/UntypedFailer.java b/akka-stm/src/test/java/akka/transactor/test/UntypedFailer.java index 898dafa529..5e7328c566 100644 --- a/akka-stm/src/test/java/akka/transactor/test/UntypedFailer.java +++ b/akka-stm/src/test/java/akka/transactor/test/UntypedFailer.java @@ -4,6 +4,6 @@ import akka.transactor.UntypedTransactor; public class UntypedFailer extends UntypedTransactor { public void atomically(Object message) throws Exception { - throw new RuntimeException("Expected failure"); + throw new ExpectedFailureException(); } } diff --git a/akka-stm/src/test/java/akka/transactor/test/UntypedTransactorTest.java b/akka-stm/src/test/java/akka/transactor/test/UntypedTransactorTest.java index fb4cb5c0d5..f8ee344e5b 100644 --- a/akka-stm/src/test/java/akka/transactor/test/UntypedTransactorTest.java +++ b/akka-stm/src/test/java/akka/transactor/test/UntypedTransactorTest.java @@ -9,13 +9,21 @@ import akka.actor.Actors; import akka.actor.UntypedActor; import akka.actor.UntypedActorFactory; import akka.dispatch.Future; +import akka.event.EventHandler; +import akka.testkit.EventFilter; +import akka.testkit.ErrorFilter; +import akka.testkit.TestEvent; +import akka.transactor.CoordinatedTransactionException; +import java.util.Arrays; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import scala.Option; +import scala.collection.JavaConverters; +import scala.collection.Seq; public class UntypedTransactorTest { List counters; @@ -62,6 +70,10 @@ public class UntypedTransactorTest { } @Test public void incrementNoCountersWithFailingTransaction() { + EventFilter expectedFailureFilter = (EventFilter) new ErrorFilter(ExpectedFailureException.class); + EventFilter coordinatedFilter = (EventFilter) new ErrorFilter(CoordinatedTransactionException.class); + Seq ignoreExceptions = seq(expectedFailureFilter, coordinatedFilter); + EventHandler.notify(new TestEvent.Mute(ignoreExceptions)); CountDownLatch incrementLatch = new CountDownLatch(numCounters); List actors = new ArrayList(counters); actors.add(failer); @@ -82,6 +94,11 @@ public class UntypedTransactorTest { } } } + EventHandler.notify(new TestEvent.UnMute(ignoreExceptions)); + } + + public Seq seq(A... args) { + return JavaConverters.collectionAsScalaIterableConverter(Arrays.asList(args)).asScala().toSeq(); } } diff --git a/akka-stm/src/test/scala/transactor/CoordinatedIncrementSpec.scala b/akka-stm/src/test/scala/transactor/CoordinatedIncrementSpec.scala index 1683893b39..d05435b98b 100644 --- a/akka-stm/src/test/scala/transactor/CoordinatedIncrementSpec.scala +++ b/akka-stm/src/test/scala/transactor/CoordinatedIncrementSpec.scala @@ -8,9 +8,8 @@ import akka.transactor.Coordinated import akka.actor.{ Actor, ActorRef } import akka.stm.{ Ref, TransactionFactory } import akka.util.duration._ -import akka.event.EventHandler -import akka.testkit.EventFilter -import akka.testkit.TestEvent._ +import akka.transactor.CoordinatedTransactionException +import akka.testkit._ object CoordinatedIncrement { case class Increment(friends: Seq[ActorRef]) @@ -39,13 +38,15 @@ object CoordinatedIncrement { } } + class ExpectedFailureException extends RuntimeException("Expected failure") + class Failer extends Actor { val txFactory = TransactionFactory(timeout = 3 seconds) def receive = { case coordinated @ Coordinated(Increment(friends)) ⇒ { coordinated.atomic(txFactory) { - throw new RuntimeException("Expected failure") + throw new ExpectedFailureException } } } @@ -55,15 +56,6 @@ object CoordinatedIncrement { class CoordinatedIncrementSpec extends WordSpec with MustMatchers with BeforeAndAfterAll { import CoordinatedIncrement._ - override def beforeAll() { - EventHandler notify Mute(EventFilter[RuntimeException]("Expected failure")) - EventHandler notify Mute(EventFilter[org.multiverse.api.exceptions.DeadTransactionException]()) - } - - override def afterAll() { - EventHandler notify UnMuteAll - } - val numCounters = 5 val timeout = 5 seconds @@ -88,15 +80,19 @@ class CoordinatedIncrementSpec extends WordSpec with MustMatchers with BeforeAnd } "increment no counters with a failing transaction" in { - val (counters, failer) = createActors - val coordinated = Coordinated() - counters(0) ! Coordinated(Increment(counters.tail :+ failer)) - coordinated.await - for (counter ← counters) { - (counter ? GetCount).as[Int].get must be === 0 + filterException[ExpectedFailureException] { + filterException[CoordinatedTransactionException] { + val (counters, failer) = createActors + val coordinated = Coordinated() + counters(0) ! Coordinated(Increment(counters.tail :+ failer)) + coordinated.await + for (counter ← counters) { + (counter ? GetCount).as[Int].get must be === 0 + } + counters foreach (_.stop()) + failer.stop() + } } - counters foreach (_.stop()) - failer.stop() } } } diff --git a/akka-stm/src/test/scala/transactor/FickleFriendsSpec.scala b/akka-stm/src/test/scala/transactor/FickleFriendsSpec.scala index 78821f31c0..1f79afcdf6 100644 --- a/akka-stm/src/test/scala/transactor/FickleFriendsSpec.scala +++ b/akka-stm/src/test/scala/transactor/FickleFriendsSpec.scala @@ -8,9 +8,8 @@ import akka.transactor.Coordinated import akka.actor.{ Actor, ActorRef } import akka.stm._ import akka.util.duration._ -import akka.event.EventHandler -import akka.testkit.EventFilter -import akka.testkit.TestEvent._ +import akka.transactor.CoordinatedTransactionException +import akka.testkit._ import scala.util.Random.{ nextInt ⇒ random } @@ -59,6 +58,8 @@ object FickleFriends { } } + class ExpectedFailureException(message: String) extends RuntimeException(message) + /** * FickleCounter randomly fails at different points with 50% chance of failing overall. */ @@ -72,7 +73,7 @@ object FickleFriends { } def failIf(x: Int, y: Int) = { - if (x == y) throw new RuntimeException("Random fail at position " + x) + if (x == y) throw new ExpectedFailureException("Random fail at position " + x) } def receive = { @@ -98,16 +99,6 @@ object FickleFriends { class FickleFriendsSpec extends WordSpec with MustMatchers with BeforeAndAfterAll { import FickleFriends._ - val ignoreEvents = List(EventFilter(classOf[RuntimeException], message = "Random fail")) - - override def beforeAll() { - ignoreEvents foreach (f ⇒ EventHandler.notify(Mute(f))) - } - - override def afterAll() { - ignoreEvents foreach (f ⇒ EventHandler.notify(UnMute(f))) - } - val numCounters = 2 def createActors = { @@ -119,16 +110,20 @@ class FickleFriendsSpec extends WordSpec with MustMatchers with BeforeAndAfterAl "Coordinated fickle friends" should { "eventually succeed to increment all counters by one" in { - val (counters, coordinator) = createActors - val latch = new CountDownLatch(1) - coordinator ! FriendlyIncrement(counters, latch) - latch.await // this could take a while - (coordinator ? GetCount).as[Int].get must be === 1 - for (counter ← counters) { - (counter ? GetCount).as[Int].get must be === 1 + filterException[ExpectedFailureException] { + filterException[CoordinatedTransactionException] { + val (counters, coordinator) = createActors + val latch = new CountDownLatch(1) + coordinator ! FriendlyIncrement(counters, latch) + latch.await // this could take a while + (coordinator ? GetCount).as[Int].get must be === 1 + for (counter ← counters) { + (counter ? GetCount).as[Int].get must be === 1 + } + counters foreach (_.stop()) + coordinator.stop() + } } - counters foreach (_.stop()) - coordinator.stop() } } } diff --git a/akka-stm/src/test/scala/transactor/TransactorSpec.scala b/akka-stm/src/test/scala/transactor/TransactorSpec.scala index 8cccdf430c..2c72fd1650 100644 --- a/akka-stm/src/test/scala/transactor/TransactorSpec.scala +++ b/akka-stm/src/test/scala/transactor/TransactorSpec.scala @@ -7,6 +7,8 @@ import akka.transactor.Transactor import akka.actor.{ Actor, ActorRef } import akka.stm._ import akka.util.duration._ +import akka.transactor.CoordinatedTransactionException +import akka.testkit._ import java.util.concurrent.CountDownLatch @@ -51,9 +53,11 @@ object TransactorIncrement { } } + class ExpectedFailureException extends RuntimeException("Expected failure") + class Failer extends Transactor { def atomically = { - case _ ⇒ throw new RuntimeException("Expected failure") + case _ ⇒ throw new ExpectedFailureException } } } @@ -99,15 +103,19 @@ class TransactorSpec extends WordSpec with MustMatchers { } "increment no counters with a failing transaction" in { - val (counters, failer) = createTransactors - val failLatch = new CountDownLatch(numCounters + 1) - counters(0) ! Increment(counters.tail :+ failer, failLatch) - failLatch.await(timeout.length, timeout.unit) - for (counter ← counters) { - (counter ? GetCount).as[Int].get must be === 0 + filterException[ExpectedFailureException] { + filterException[CoordinatedTransactionException] { + val (counters, failer) = createTransactors + val failLatch = new CountDownLatch(numCounters + 1) + counters(0) ! Increment(counters.tail :+ failer, failLatch) + failLatch.await(timeout.length, timeout.unit) + for (counter ← counters) { + (counter ? GetCount).as[Int].get must be === 0 + } + counters foreach (_.stop()) + failer.stop() + } } - counters foreach (_.stop()) - failer.stop() } } From 0057acdd8107724e7bf84e46f86d4f0b8fa908f5 Mon Sep 17 00:00:00 2001 From: Peter Vlugter Date: Fri, 5 Aug 2011 18:41:29 +1200 Subject: [PATCH 5/5] Some more quietening of tests --- .../src/test/resources/log4j.properties | 58 +++++++++++++++++++ .../src/test/resources/logback.xml | 11 ++++ .../transactor/CoordinatedIncrementSpec.scala | 29 +++++----- .../scala/transactor/FickleFriendsSpec.scala | 31 +++++----- .../scala/transactor/TransactorSpec.scala | 29 +++++----- .../scala/akka/testkit/TestActorRefSpec.scala | 3 + 6 files changed, 121 insertions(+), 40 deletions(-) create mode 100644 akka-durable-mailboxes/akka-zookeeper-mailbox/src/test/resources/log4j.properties create mode 100644 akka-samples/akka-sample-camel/src/test/resources/logback.xml diff --git a/akka-durable-mailboxes/akka-zookeeper-mailbox/src/test/resources/log4j.properties b/akka-durable-mailboxes/akka-zookeeper-mailbox/src/test/resources/log4j.properties new file mode 100644 index 0000000000..2d07c8e051 --- /dev/null +++ b/akka-durable-mailboxes/akka-zookeeper-mailbox/src/test/resources/log4j.properties @@ -0,0 +1,58 @@ +# Define some default values that can be overridden by system properties +zookeeper.root.logger=INFO, CONSOLE +zookeeper.console.threshold=OFF +zookeeper.log.dir=. +zookeeper.log.file=zookeeper.log +zookeeper.log.threshold=DEBUG +zookeeper.tracelog.dir=. +zookeeper.tracelog.file=zookeeper_trace.log + +# +# ZooKeeper Logging Configuration +# + +# Format is " (, )+ + +# DEFAULT: console appender only +log4j.rootLogger=${zookeeper.root.logger} + +# Example with rolling log file +#log4j.rootLogger=DEBUG, CONSOLE, ROLLINGFILE + +# Example with rolling log file and tracing +#log4j.rootLogger=TRACE, CONSOLE, ROLLINGFILE, TRACEFILE + +# +# Log INFO level and above messages to the console +# +log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender +log4j.appender.CONSOLE.Threshold=${zookeeper.console.threshold} +log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout +log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n + +# +# Add ROLLINGFILE to rootLogger to get log file output +# Log DEBUG level and above messages to a log file +log4j.appender.ROLLINGFILE=org.apache.log4j.RollingFileAppender +log4j.appender.ROLLINGFILE.Threshold=${zookeeper.log.threshold} +log4j.appender.ROLLINGFILE.File=${zookeeper.log.dir}/${zookeeper.log.file} + +# Max log file size of 10MB +log4j.appender.ROLLINGFILE.MaxFileSize=10MB +# uncomment the next line to limit number of backup files +#log4j.appender.ROLLINGFILE.MaxBackupIndex=10 + +log4j.appender.ROLLINGFILE.layout=org.apache.log4j.PatternLayout +log4j.appender.ROLLINGFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n + + +# +# Add TRACEFILE to rootLogger to get log file output +# Log DEBUG level and above messages to a log file +log4j.appender.TRACEFILE=org.apache.log4j.FileAppender +log4j.appender.TRACEFILE.Threshold=TRACE +log4j.appender.TRACEFILE.File=${zookeeper.tracelog.dir}/${zookeeper.tracelog.file} + +log4j.appender.TRACEFILE.layout=org.apache.log4j.PatternLayout +### Notice we are including log4j's NDC here (%x) +log4j.appender.TRACEFILE.layout.ConversionPattern=%d{ISO8601} [myid:%X{myid}] - %-5p [%t:%C{1}@%L][%x] - %m%n diff --git a/akka-samples/akka-sample-camel/src/test/resources/logback.xml b/akka-samples/akka-sample-camel/src/test/resources/logback.xml new file mode 100644 index 0000000000..023f2cd317 --- /dev/null +++ b/akka-samples/akka-sample-camel/src/test/resources/logback.xml @@ -0,0 +1,11 @@ + + + + + [%4p] [%d{ISO8601}] [%t] %c{1}: %m%n + + + + + + diff --git a/akka-stm/src/test/scala/transactor/CoordinatedIncrementSpec.scala b/akka-stm/src/test/scala/transactor/CoordinatedIncrementSpec.scala index d05435b98b..c05f41624f 100644 --- a/akka-stm/src/test/scala/transactor/CoordinatedIncrementSpec.scala +++ b/akka-stm/src/test/scala/transactor/CoordinatedIncrementSpec.scala @@ -5,9 +5,10 @@ import org.scalatest.matchers.MustMatchers import org.scalatest.BeforeAndAfterAll import akka.transactor.Coordinated -import akka.actor.{ Actor, ActorRef } +import akka.actor.{ Actor, ActorRef, ActorTimeoutException } import akka.stm.{ Ref, TransactionFactory } import akka.util.duration._ +import akka.event.EventHandler import akka.transactor.CoordinatedTransactionException import akka.testkit._ @@ -80,19 +81,21 @@ class CoordinatedIncrementSpec extends WordSpec with MustMatchers with BeforeAnd } "increment no counters with a failing transaction" in { - filterException[ExpectedFailureException] { - filterException[CoordinatedTransactionException] { - val (counters, failer) = createActors - val coordinated = Coordinated() - counters(0) ! Coordinated(Increment(counters.tail :+ failer)) - coordinated.await - for (counter ← counters) { - (counter ? GetCount).as[Int].get must be === 0 - } - counters foreach (_.stop()) - failer.stop() - } + val ignoreExceptions = Seq( + EventFilter[ExpectedFailureException], + EventFilter[CoordinatedTransactionException], + EventFilter[ActorTimeoutException]) + EventHandler.notify(TestEvent.Mute(ignoreExceptions)) + val (counters, failer) = createActors + val coordinated = Coordinated() + counters(0) ! Coordinated(Increment(counters.tail :+ failer)) + coordinated.await + for (counter ← counters) { + (counter ? GetCount).as[Int].get must be === 0 } + counters foreach (_.stop()) + failer.stop() + EventHandler.notify(TestEvent.UnMute(ignoreExceptions)) } } } diff --git a/akka-stm/src/test/scala/transactor/FickleFriendsSpec.scala b/akka-stm/src/test/scala/transactor/FickleFriendsSpec.scala index 1f79afcdf6..89f8738c10 100644 --- a/akka-stm/src/test/scala/transactor/FickleFriendsSpec.scala +++ b/akka-stm/src/test/scala/transactor/FickleFriendsSpec.scala @@ -5,9 +5,10 @@ import org.scalatest.matchers.MustMatchers import org.scalatest.BeforeAndAfterAll import akka.transactor.Coordinated -import akka.actor.{ Actor, ActorRef } +import akka.actor.{ Actor, ActorRef, ActorTimeoutException } import akka.stm._ import akka.util.duration._ +import akka.event.EventHandler import akka.transactor.CoordinatedTransactionException import akka.testkit._ @@ -110,20 +111,22 @@ class FickleFriendsSpec extends WordSpec with MustMatchers with BeforeAndAfterAl "Coordinated fickle friends" should { "eventually succeed to increment all counters by one" in { - filterException[ExpectedFailureException] { - filterException[CoordinatedTransactionException] { - val (counters, coordinator) = createActors - val latch = new CountDownLatch(1) - coordinator ! FriendlyIncrement(counters, latch) - latch.await // this could take a while - (coordinator ? GetCount).as[Int].get must be === 1 - for (counter ← counters) { - (counter ? GetCount).as[Int].get must be === 1 - } - counters foreach (_.stop()) - coordinator.stop() - } + val ignoreExceptions = Seq( + EventFilter[ExpectedFailureException], + EventFilter[CoordinatedTransactionException], + EventFilter[ActorTimeoutException]) + EventHandler.notify(TestEvent.Mute(ignoreExceptions)) + val (counters, coordinator) = createActors + val latch = new CountDownLatch(1) + coordinator ! FriendlyIncrement(counters, latch) + latch.await // this could take a while + (coordinator ? GetCount).as[Int].get must be === 1 + for (counter ← counters) { + (counter ? GetCount).as[Int].get must be === 1 } + counters foreach (_.stop()) + coordinator.stop() + EventHandler.notify(TestEvent.UnMute(ignoreExceptions)) } } } diff --git a/akka-stm/src/test/scala/transactor/TransactorSpec.scala b/akka-stm/src/test/scala/transactor/TransactorSpec.scala index 2c72fd1650..86d3588814 100644 --- a/akka-stm/src/test/scala/transactor/TransactorSpec.scala +++ b/akka-stm/src/test/scala/transactor/TransactorSpec.scala @@ -4,9 +4,10 @@ import org.scalatest.WordSpec import org.scalatest.matchers.MustMatchers import akka.transactor.Transactor -import akka.actor.{ Actor, ActorRef } +import akka.actor.{ Actor, ActorRef, ActorTimeoutException } import akka.stm._ import akka.util.duration._ +import akka.event.EventHandler import akka.transactor.CoordinatedTransactionException import akka.testkit._ @@ -103,19 +104,21 @@ class TransactorSpec extends WordSpec with MustMatchers { } "increment no counters with a failing transaction" in { - filterException[ExpectedFailureException] { - filterException[CoordinatedTransactionException] { - val (counters, failer) = createTransactors - val failLatch = new CountDownLatch(numCounters + 1) - counters(0) ! Increment(counters.tail :+ failer, failLatch) - failLatch.await(timeout.length, timeout.unit) - for (counter ← counters) { - (counter ? GetCount).as[Int].get must be === 0 - } - counters foreach (_.stop()) - failer.stop() - } + val ignoreExceptions = Seq( + EventFilter[ExpectedFailureException], + EventFilter[CoordinatedTransactionException], + EventFilter[ActorTimeoutException]) + EventHandler.notify(TestEvent.Mute(ignoreExceptions)) + val (counters, failer) = createTransactors + val failLatch = new CountDownLatch(numCounters + 1) + counters(0) ! Increment(counters.tail :+ failer, failLatch) + failLatch.await(timeout.length, timeout.unit) + for (counter ← counters) { + (counter ? GetCount).as[Int].get must be === 0 } + counters foreach (_.stop()) + failer.stop() + EventHandler.notify(TestEvent.UnMute(ignoreExceptions)) } } diff --git a/akka-testkit/src/test/scala/akka/testkit/TestActorRefSpec.scala b/akka-testkit/src/test/scala/akka/testkit/TestActorRefSpec.scala index 3e8ac34690..0fab0a54b6 100644 --- a/akka-testkit/src/test/scala/akka/testkit/TestActorRefSpec.scala +++ b/akka-testkit/src/test/scala/akka/testkit/TestActorRefSpec.scala @@ -229,6 +229,8 @@ class TestActorRefSpec extends WordSpec with MustMatchers with BeforeAndAfterEac val boss = Actor.actorOf(new Actor { def receive = { case _ ⇒ } }).start() val ref = TestActorRef[WorkerActor].start() + val filter = EventFilter.custom(_ ⇒ true) + EventHandler.notify(TestEvent.Mute(filter)) val log = TestActorRef[Logger] EventHandler.addListener(log) boss link ref @@ -236,6 +238,7 @@ class TestActorRefSpec extends WordSpec with MustMatchers with BeforeAndAfterEac la.count must be(1) la.msg must (include("supervisor") and include("CallingThreadDispatcher")) EventHandler.removeListener(log) + EventHandler.notify(TestEvent.UnMute(filter)) } "proxy apply for the underlying actor" in {