Fixing UntypedCoordinatedIncrementTest so it works with computers with less CPUs than 5 :p

This commit is contained in:
Viktor Klang 2011-10-27 14:48:45 +02:00
parent 26f45a599b
commit f8ef63122a
3 changed files with 17 additions and 33 deletions

View file

@ -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)

View file

@ -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());
}
}
}

View file

@ -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<ActorRef> 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<ActorRef>();
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 <A> Seq<A> seq(A... args) {
return JavaConverters.collectionAsScalaIterableConverter(Arrays.asList(args)).asScala().toSeq();
}
@After
public void stop() {
application.stop();
}
}