From f8ef63122af542ffe63d8e9bcb705ef8e7d8b2c2 Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Thu, 27 Oct 2011 14:48:45 +0200 Subject: [PATCH] Fixing UntypedCoordinatedIncrementTest so it works with computers with less CPUs than 5 :p --- .../src/main/scala/akka/AkkaApplication.scala | 3 +- .../test/UntypedCoordinatedCounter.java | 15 +++------ .../test/UntypedCoordinatedIncrementTest.java | 32 +++++++------------ 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/akka-actor/src/main/scala/akka/AkkaApplication.scala b/akka-actor/src/main/scala/akka/AkkaApplication.scala index b2bcccb0b5..28cc0a5668 100644 --- a/akka-actor/src/main/scala/akka/AkkaApplication.scala +++ b/akka-actor/src/main/scala/akka/AkkaApplication.scala @@ -101,8 +101,7 @@ class AkkaApplication(val name: String, val config: Configuration) extends Actor val DispatcherThroughput = getInt("akka.actor.throughput", 5) val DispatcherDefaultShutdown = getLong("akka.actor.dispatcher-shutdown-timeout"). - map(time ⇒ Duration(time, DefaultTimeUnit)). - getOrElse(Duration(1000, TimeUnit.MILLISECONDS)) + map(time ⇒ Duration(time, DefaultTimeUnit)).getOrElse(Duration(1000, TimeUnit.MILLISECONDS)) val MailboxCapacity = getInt("akka.actor.default-dispatcher.mailbox-capacity", -1) val MailboxPushTimeout = Duration(getInt("akka.actor.default-dispatcher.mailbox-push-timeout-time", 10), DefaultTimeUnit) val DispatcherThroughputDeadlineTime = Duration(getInt("akka.actor.throughput-deadline-time", -1), DefaultTimeUnit) 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 2ac3731f06..ecc8a1739d 100644 --- a/akka-stm/src/test/java/akka/transactor/test/UntypedCoordinatedCounter.java +++ b/akka-stm/src/test/java/akka/transactor/test/UntypedCoordinatedCounter.java @@ -45,20 +45,13 @@ public class UntypedCoordinatedCounter extends UntypedActor { coordinated.atomic(new Atomically(txFactory) { public void atomically() { increment(); - StmUtils.scheduleDeferredTask(new Runnable() { - public void run() { latch.countDown(); } - }); - StmUtils.scheduleCompensatingTask(new Runnable() { - public void run() { latch.countDown(); } - }); + StmUtils.scheduleDeferredTask(new Runnable() { public void run() { latch.countDown(); } }); + StmUtils.scheduleCompensatingTask(new Runnable() { public void run() { latch.countDown(); } }); } }); } - } else if (incoming instanceof String) { - String message = (String) incoming; - if (message.equals("GetCount")) { - getSender().tell(count.get()); - } + } else if ("GetCount".equals(incoming)) { + getSender().tell(count.get()); } } } 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 6eeb1546b5..f975c5e429 100644 --- a/akka-stm/src/test/java/akka/transactor/test/UntypedCoordinatedIncrementTest.java +++ b/akka-stm/src/test/java/akka/transactor/test/UntypedCoordinatedIncrementTest.java @@ -1,6 +1,8 @@ package akka.transactor.test; import static org.junit.Assert.*; + +import org.junit.After; import org.junit.Test; import org.junit.Before; @@ -34,11 +36,12 @@ public class UntypedCoordinatedIncrementTest { List counters; ActorRef failer; - int numCounters = 5; + int numCounters = 3; int timeout = 5; int askTimeout = 5000; @Before public void initialise() { + Props p = new Props().withCreator(UntypedFailer.class); counters = new ArrayList(); for (int i = 1; i <= numCounters; i++) { final String name = "counter" + i; @@ -49,7 +52,7 @@ public class UntypedCoordinatedIncrementTest { })); counters.add(counter); } - failer = application.actorOf(new Props().withCreator(UntypedFailer.class)); + failer = application.actorOf(p); } @Test public void incrementAllCountersWithSuccessfulTransaction() { @@ -61,15 +64,7 @@ public class UntypedCoordinatedIncrementTest { } catch (InterruptedException exception) {} for (ActorRef counter : counters) { Future future = counter.ask("GetCount", askTimeout); - future.await(); - if (future.isCompleted()) { - Option resultOption = future.result(); - if (resultOption.isDefined()) { - Object result = resultOption.get(); - int count = (Integer) result; - assertEquals(1, count); - } - } + assertEquals(1, ((Integer)future.get()).intValue()); } } @@ -88,15 +83,7 @@ public class UntypedCoordinatedIncrementTest { } catch (InterruptedException exception) {} for (ActorRef counter : counters) { Future future = counter.ask("GetCount", askTimeout); - future.await(); - if (future.isCompleted()) { - Option resultOption = future.result(); - if (resultOption.isDefined()) { - Object result = resultOption.get(); - int count = (Integer) result; - assertEquals(0, count); - } - } + assertEquals(0, ((Integer)future.get()).intValue()); } application.eventHandler().notify(new TestEvent.UnMute(ignoreExceptions)); } @@ -104,6 +91,11 @@ public class UntypedCoordinatedIncrementTest { public Seq seq(A... args) { return JavaConverters.collectionAsScalaIterableConverter(Arrays.asList(args)).asScala().toSeq(); } + + @After + public void stop() { + application.stop(); + } }