2023-01-08 17:13:31 +08:00
|
|
|
/*
|
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
* license agreements; and to You under the Apache License, version 2.0:
|
|
|
|
|
*
|
|
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
2023-06-22 14:19:26 +01:00
|
|
|
* This file is part of the Apache Pekko project, which was derived from Akka.
|
2023-01-08 17:13:31 +08:00
|
|
|
*/
|
|
|
|
|
|
2018-10-29 17:19:37 +08:00
|
|
|
/*
|
2022-02-04 12:36:44 +01:00
|
|
|
* Copyright (C) 2009-2022 Lightbend Inc. <https://www.lightbend.com>
|
2014-02-21 12:43:30 +01:00
|
|
|
*/
|
|
|
|
|
|
2017-03-16 09:30:00 +01:00
|
|
|
package jdocs.actor.fsm;
|
2013-12-11 14:53:41 +01:00
|
|
|
|
2025-08-25 19:32:35 +08:00
|
|
|
import static jdocs.actor.fsm.Events.Batch;
|
|
|
|
|
import static jdocs.actor.fsm.Events.Flush.Flush;
|
|
|
|
|
import static jdocs.actor.fsm.Events.Queue;
|
|
|
|
|
import static jdocs.actor.fsm.Events.SetTarget;
|
|
|
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
import jdocs.AbstractJavaTest;
|
2022-11-12 10:21:24 +01:00
|
|
|
import org.apache.pekko.actor.ActorRef;
|
|
|
|
|
import org.apache.pekko.actor.ActorSystem;
|
|
|
|
|
import org.apache.pekko.actor.Props;
|
|
|
|
|
import org.apache.pekko.testkit.javadsl.TestKit;
|
2013-12-11 14:53:41 +01:00
|
|
|
import org.junit.AfterClass;
|
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
2014-02-21 12:43:30 +01:00
|
|
|
// #test-code
|
2016-02-11 16:39:25 +01:00
|
|
|
public class BuncherTest extends AbstractJavaTest {
|
2013-12-11 14:53:41 +01:00
|
|
|
|
|
|
|
|
static ActorSystem system;
|
|
|
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
|
public static void setup() {
|
|
|
|
|
system = ActorSystem.create("BuncherTest");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
|
public static void tearDown() {
|
2017-03-17 03:02:47 +08:00
|
|
|
TestKit.shutdownActorSystem(system);
|
2013-12-11 14:53:41 +01:00
|
|
|
system = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
2014-03-13 10:29:06 +01:00
|
|
|
public void testBuncherActorBatchesCorrectly() {
|
2017-03-17 03:02:47 +08:00
|
|
|
new TestKit(system) {
|
2019-01-12 04:00:53 +08:00
|
|
|
{
|
2014-02-21 12:43:30 +01:00
|
|
|
final ActorRef buncher = system.actorOf(Props.create(Buncher.class));
|
2013-12-11 14:53:41 +01:00
|
|
|
final ActorRef probe = getRef();
|
|
|
|
|
|
|
|
|
|
buncher.tell(new SetTarget(probe), probe);
|
|
|
|
|
buncher.tell(new Queue(42), probe);
|
|
|
|
|
buncher.tell(new Queue(43), probe);
|
|
|
|
|
LinkedList<Object> list1 = new LinkedList<>();
|
|
|
|
|
list1.add(42);
|
|
|
|
|
list1.add(43);
|
|
|
|
|
expectMsgEquals(new Batch(list1));
|
|
|
|
|
buncher.tell(new Queue(44), probe);
|
|
|
|
|
buncher.tell(Flush, probe);
|
|
|
|
|
buncher.tell(new Queue(45), probe);
|
|
|
|
|
LinkedList<Object> list2 = new LinkedList<>();
|
|
|
|
|
list2.add(44);
|
|
|
|
|
expectMsgEquals(new Batch(list2));
|
|
|
|
|
LinkedList<Object> list3 = new LinkedList<>();
|
|
|
|
|
list3.add(45);
|
|
|
|
|
expectMsgEquals(new Batch(list3));
|
|
|
|
|
system.stop(buncher);
|
2019-01-12 04:00:53 +08:00
|
|
|
}
|
2013-12-11 14:53:41 +01:00
|
|
|
};
|
|
|
|
|
}
|
2014-02-21 12:43:30 +01:00
|
|
|
|
|
|
|
|
@Test
|
2014-03-13 10:29:06 +01:00
|
|
|
public void testBuncherActorDoesntBatchUninitialized() {
|
2017-03-17 03:02:47 +08:00
|
|
|
new TestKit(system) {
|
2019-01-12 04:00:53 +08:00
|
|
|
{
|
2014-02-21 12:43:30 +01:00
|
|
|
final ActorRef buncher = system.actorOf(Props.create(Buncher.class));
|
|
|
|
|
final ActorRef probe = getRef();
|
|
|
|
|
|
|
|
|
|
buncher.tell(new Queue(42), probe);
|
2018-07-25 09:38:33 +01:00
|
|
|
expectNoMessage();
|
2014-02-21 12:43:30 +01:00
|
|
|
system.stop(buncher);
|
2019-01-12 04:00:53 +08:00
|
|
|
}
|
2014-02-21 12:43:30 +01:00
|
|
|
};
|
|
|
|
|
}
|
2013-12-11 14:53:41 +01:00
|
|
|
}
|
2014-02-21 12:43:30 +01:00
|
|
|
// #test-code
|