mirror of
https://github.com/2revoemag/PSF-BotServer.git
synced 2026-04-26 06:15:21 +00:00
moving ActorTest-style tests from common to pslogin (#300)
This commit is contained in:
parent
1b26396bb3
commit
e4d607533f
7 changed files with 343 additions and 331 deletions
|
|
@ -1,67 +0,0 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
|
||||
import akka.actor.{ActorRef, ActorSystem, MDCContextAware}
|
||||
import akka.testkit.{ImplicitSender, TestKit, TestProbe}
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import net.psforever.packet.{ControlPacket, GamePacket}
|
||||
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}
|
||||
import org.specs2.specification.Scope
|
||||
|
||||
abstract class ActorTest(sys : ActorSystem = ActorSystem("system", ConfigFactory.parseMap(ActorTest.LoggingConfig)))
|
||||
extends TestKit(sys) with Scope with ImplicitSender with WordSpecLike with Matchers with BeforeAndAfterAll {
|
||||
override def afterAll {
|
||||
TestKit.shutdownActorSystem(system)
|
||||
}
|
||||
}
|
||||
|
||||
object ActorTest {
|
||||
import scala.collection.JavaConverters._
|
||||
private val LoggingConfig = Map(
|
||||
"akka.loggers" -> List("akka.testkit.TestEventListener").asJava,
|
||||
"akka.loglevel" -> "OFF",
|
||||
"akka.stdout-loglevel" -> "OFF",
|
||||
"akka.log-dead-letters" -> "OFF"
|
||||
).asJava
|
||||
|
||||
final case class MDCGamePacket(packet : GamePacket)
|
||||
|
||||
final case class MDCControlPacket(packet : ControlPacket)
|
||||
|
||||
class MDCTestProbe(probe : TestProbe) extends MDCContextAware {
|
||||
/*
|
||||
The way this test mediator works needs to be explained.
|
||||
|
||||
MDCContextAware objects initialize themselves in a chain of ActorRefs defined in the HelloFriend message.
|
||||
As the iterator is consumed, it produces a right-neighbor (r-neighbor) that is much further along the chain.
|
||||
The HelloFriend is passed to that r-neighbor and that is how subsequent neighbors are initialized and chained.
|
||||
|
||||
MDCContextAware objects consume and produce internal messages called MdcMsg that wrap around the payload.
|
||||
Normally inaccessible from the outside, the payload is unwrapped within the standard receive PartialFunction.
|
||||
By interacting with a TestProbe constructor param, information that would be concealed by MdcMsg can be polled.
|
||||
|
||||
The l-neighbor of the MDCContextAware is the system of the base.ActorTest TestKit.
|
||||
The r-neighbor of the MDCContextAware is this MDCTestProbe and, indirectly, the TestProbe that was interjected.
|
||||
Pass l-input into the MDCContextAware itself.
|
||||
The r-output is a normal message that can be polled on that TestProbe.
|
||||
Pass r-input into this MDCTestProbe directly.
|
||||
The l-output is an MdcMsg that can be treated just as r-output, sending it to this Actor and polling the TestProbe.
|
||||
*/
|
||||
private var left : ActorRef = ActorRef.noSender
|
||||
|
||||
def receive : Receive = {
|
||||
case msg @ HelloFriend(_, _) =>
|
||||
left = sender()
|
||||
probe.ref ! msg
|
||||
|
||||
case MDCGamePacket(msg) =>
|
||||
left ! msg
|
||||
|
||||
case MDCControlPacket(msg) =>
|
||||
left ! msg
|
||||
|
||||
case msg =>
|
||||
left ! msg
|
||||
probe.ref ! msg
|
||||
}
|
||||
}
|
||||
}
|
||||
46
pslogin/src/test/scala/MDCTestProbe.scala
Normal file
46
pslogin/src/test/scala/MDCTestProbe.scala
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright (c) 2019 PSForever
|
||||
import akka.actor.{ActorRef, MDCContextAware}
|
||||
import akka.testkit.TestProbe
|
||||
import net.psforever.packet.{ControlPacket, GamePacket}
|
||||
|
||||
final case class MDCGamePacket(packet : GamePacket)
|
||||
|
||||
final case class MDCControlPacket(packet : ControlPacket)
|
||||
|
||||
class MDCTestProbe(probe : TestProbe) extends MDCContextAware {
|
||||
/*
|
||||
The way this test mediator works needs to be explained.
|
||||
|
||||
MDCContextAware objects initialize themselves in a chain of ActorRefs defined in the HelloFriend message.
|
||||
As the iterator is consumed, it produces a right-neighbor (r-neighbor) that is much further along the chain.
|
||||
The HelloFriend is passed to that r-neighbor and that is how subsequent neighbors are initialized and chained.
|
||||
|
||||
MDCContextAware objects consume and produce internal messages called MdcMsg that wrap around the payload.
|
||||
Normally inaccessible from the outside, the payload is unwrapped within the standard receive PartialFunction.
|
||||
By interacting with a TestProbe constructor param, information that would be concealed by MdcMsg can be polled.
|
||||
|
||||
The l-neighbor of the MDCContextAware is the system of the base.actor.base.ActorTest TestKit.
|
||||
The r-neighbor of the MDCContextAware is this MDCTestProbe and, indirectly, the TestProbe that was interjected.
|
||||
Pass l-input into the MDCContextAware itself.
|
||||
The r-output is a normal message that can be polled on that TestProbe.
|
||||
Pass r-input into this MDCTestProbe directly.
|
||||
The l-output is an MdcMsg that can be treated just as r-output, sending it to this Actor and polling the TestProbe.
|
||||
*/
|
||||
private var left : ActorRef = ActorRef.noSender
|
||||
|
||||
def receive : Receive = {
|
||||
case msg @ HelloFriend(_, _) =>
|
||||
left = sender()
|
||||
probe.ref ! msg
|
||||
|
||||
case MDCGamePacket(msg) =>
|
||||
left ! msg
|
||||
|
||||
case MDCControlPacket(msg) =>
|
||||
left ! msg
|
||||
|
||||
case msg =>
|
||||
left ! msg
|
||||
probe.ref ! msg
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
|
||||
import actor.base.ActorTest
|
||||
import akka.actor.{ActorRef, Props}
|
||||
import akka.testkit.TestProbe
|
||||
import net.psforever.packet.control.{ControlSync, MultiPacketBundle, SlottedMetaPacket}
|
||||
|
|
@ -36,7 +36,7 @@ class PacketCodingActor3Test extends ActorTest {
|
|||
"PacketCodingActor" should {
|
||||
"initialize (an r-neighbor)" in {
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
val iter = List(probe2).iterator
|
||||
val msg = HelloFriend(135, iter)
|
||||
|
|
@ -56,12 +56,12 @@ class PacketCodingActor4Test extends ActorTest {
|
|||
"PacketCodingActor" should {
|
||||
"translate r-originating game packet into l-facing hexadecimal data" in {
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
||||
val msg = ActorTest.MDCGamePacket(PacketCoding.CreateGamePacket(0, string_obj))
|
||||
val msg = MDCGamePacket(PacketCoding.CreateGamePacket(0, string_obj))
|
||||
probe2 ! msg
|
||||
val reply1 = receiveOne(300 milli) //we get a MdcMsg message back
|
||||
probe2 ! reply1 //by feeding the MdcMsg into the actor, we get normal output on the probe
|
||||
|
|
@ -77,7 +77,7 @@ class PacketCodingActor5Test extends ActorTest {
|
|||
"PacketCodingActor" should {
|
||||
"translate l-originating hexadecimal data into r-facing game packet" in {
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
|
@ -100,7 +100,7 @@ class PacketCodingActor6Test extends ActorTest {
|
|||
"PacketCodingActor" should {
|
||||
"permit l-originating game packet to pass through as an r-facing game packet" in {
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
|
@ -119,12 +119,12 @@ class PacketCodingActor7Test extends ActorTest {
|
|||
"PacketCodingActor" should {
|
||||
"translate r-originating control packet into l-facing hexadecimal data" in {
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
||||
val msg = ActorTest.MDCControlPacket(PacketCoding.CreateControlPacket(string_obj))
|
||||
val msg = MDCControlPacket(PacketCoding.CreateControlPacket(string_obj))
|
||||
probe2 ! msg
|
||||
val reply1 = receiveOne(300 milli) //we get a MdcMsg message back
|
||||
probe2 ! reply1 //by feeding the MdcMsg into the actor, we get normal output on the probe
|
||||
|
|
@ -140,7 +140,7 @@ class PacketCodingActor8Test extends ActorTest {
|
|||
"PacketCodingActor" should {
|
||||
"translate l-originating hexadecimal data into r-facing control packet" in {
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
|
@ -163,7 +163,7 @@ class PacketCodingActor9Test extends ActorTest {
|
|||
"PacketCodingActor" should {
|
||||
"permit l-originating control packet to pass through as an r-facing control packet" in {
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
|
@ -179,7 +179,7 @@ class PacketCodingActorATest extends ActorTest {
|
|||
"PacketCodingActor" should {
|
||||
"permit l-originating unhandled message to pass through as an r-facing unhandled message" in {
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
|
@ -194,7 +194,7 @@ class PacketCodingActorBTest extends ActorTest {
|
|||
"PacketCodingActor" should {
|
||||
"permit r-originating unhandled message to pass through as an l-facing unhandled message" in {
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
|
@ -213,7 +213,7 @@ class PacketCodingActorCTest extends ActorTest {
|
|||
"PacketCodingActor" should {
|
||||
"should split r-originating hexadecimal data if it is larger than the MTU limit" in {
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
|
@ -353,12 +353,12 @@ class PacketCodingActorDTest extends ActorTest {
|
|||
"PacketCodingActor" should {
|
||||
"should split r-originating game packet if it is larger than the MTU limit" in {
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
||||
val msg = ActorTest.MDCGamePacket(PacketCoding.CreateGamePacket(0, string_obj))
|
||||
val msg = MDCGamePacket(PacketCoding.CreateGamePacket(0, string_obj))
|
||||
probe2 ! msg
|
||||
receiveN(4)
|
||||
}
|
||||
|
|
@ -373,7 +373,7 @@ class PacketCodingActorETest extends ActorTest {
|
|||
val string_obj2 = GamePacket(GamePacketOpcode.PlayerStateMessageUpstream, 0, PlayerStateMessageUpstream(PlanetSideGUID(1256),Vector3(3077.0469f,4734.258f,56.390625f),Some(Vector3(5.5f,1.1875f,0.0f)),36.5625f,-2.8125f,0.0f,867,0,false,false,false,false,168,0))
|
||||
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
|
@ -394,7 +394,7 @@ class PacketCodingActorFTest extends ActorTest {
|
|||
val string_obj = GamePacket(GamePacketOpcode.GenericObjectStateMsg, 0, GenericObjectStateMsg(PlanetSideGUID(242), 16))
|
||||
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
|
@ -415,7 +415,7 @@ class PacketCodingActorGTest extends ActorTest {
|
|||
val string_obj = GamePacket(GamePacketOpcode.GenericObjectStateMsg, 0, GenericObjectStateMsg(PlanetSideGUID(242), 16))
|
||||
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
|
@ -437,7 +437,7 @@ class PacketCodingActorHTest extends ActorTest {
|
|||
val string_obj2 = GamePacket(GamePacketOpcode.ObjectDeleteMessage, 0, ObjectDeleteMessage(PlanetSideGUID(1105), 2))
|
||||
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
|
@ -491,7 +491,7 @@ class PacketCodingActorITest extends ActorTest {
|
|||
"PacketCodingActor" should {
|
||||
"bundle an r-originating packet into an l-facing SlottedMetaPacket byte stream data (SlottedMetaPacket)" in {
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
|
@ -525,7 +525,7 @@ class PacketCodingActorJTest extends ActorTest {
|
|||
val string_hex = hex"00090000001904194f044004195104400419530440"
|
||||
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
|
@ -653,7 +653,7 @@ class PacketCodingActorKTest extends ActorTest {
|
|||
val pkt = MultiPacketBundle(list)
|
||||
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
|
@ -804,7 +804,7 @@ class PacketCodingActorLTest extends ActorTest {
|
|||
"PacketCodingActor" should {
|
||||
"split, rather than bundle, r-originating packets into a number of MTU-acceptable l-facing byte streams" in {
|
||||
val probe1 = TestProbe()
|
||||
val probe2 = system.actorOf(Props(classOf[ActorTest.MDCTestProbe], probe1), "mdc-probe")
|
||||
val probe2 = system.actorOf(Props(classOf[MDCTestProbe], probe1), "mdc-probe")
|
||||
val pca : ActorRef = system.actorOf(Props[PacketCodingActor], "pca")
|
||||
pca ! HelloFriend(135, List(probe2).iterator)
|
||||
probe1.receiveOne(100 milli) //consume
|
||||
|
|
|
|||
27
pslogin/src/test/scala/actor/base/ActorTest.scala
Normal file
27
pslogin/src/test/scala/actor/base/ActorTest.scala
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package actor.base
|
||||
|
||||
// Copyright (c) 2017 PSForever
|
||||
|
||||
import akka.actor.{ActorRef, ActorSystem, MDCContextAware}
|
||||
import akka.testkit.{ImplicitSender, TestKit, TestProbe}
|
||||
import com.typesafe.config.ConfigFactory
|
||||
import net.psforever.packet.{ControlPacket, GamePacket}
|
||||
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpecLike}
|
||||
import org.specs2.specification.Scope
|
||||
|
||||
abstract class ActorTest(sys : ActorSystem = ActorSystem("system", ConfigFactory.parseMap(ActorTest.LoggingConfig)))
|
||||
extends TestKit(sys) with Scope with ImplicitSender with WordSpecLike with Matchers with BeforeAndAfterAll {
|
||||
override def afterAll {
|
||||
TestKit.shutdownActorSystem(system)
|
||||
}
|
||||
}
|
||||
|
||||
object ActorTest {
|
||||
import scala.collection.JavaConverters._
|
||||
private val LoggingConfig = Map(
|
||||
"akka.loggers" -> List("akka.testkit.TestEventListener").asJava,
|
||||
"akka.loglevel" -> "OFF",
|
||||
"akka.stdout-loglevel" -> "OFF",
|
||||
"akka.log-dead-letters" -> "OFF"
|
||||
).asJava
|
||||
}
|
||||
242
pslogin/src/test/scala/actor/objects/VehicleSpawnPadTest.scala
Normal file
242
pslogin/src/test/scala/actor/objects/VehicleSpawnPadTest.scala
Normal file
|
|
@ -0,0 +1,242 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package actor.objects
|
||||
|
||||
import akka.actor.{ActorRef, ActorSystem, Props}
|
||||
import akka.testkit.TestProbe
|
||||
import actor.base.ActorTest
|
||||
import net.psforever.objects.serverobject.pad.{VehicleSpawnControl, VehicleSpawnPad}
|
||||
import net.psforever.objects.serverobject.structures.StructureType
|
||||
import net.psforever.objects.{Avatar, GlobalDefinitions, Player, Vehicle}
|
||||
import net.psforever.objects.zones.Zone
|
||||
import net.psforever.packet.game.PlanetSideGUID
|
||||
import net.psforever.types._
|
||||
import services.vehicle.{VehicleAction, VehicleServiceMessage}
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
class VehicleSpawnControl1Test extends ActorTest {
|
||||
"VehicleSpawnControl" should {
|
||||
"construct" in {
|
||||
val obj = VehicleSpawnPad(GlobalDefinitions.mb_pad_creation)
|
||||
obj.Actor = system.actorOf(Props(classOf[VehicleSpawnControl], obj), "mb_pad_creation")
|
||||
assert(obj.Actor != ActorRef.noSender)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class VehicleSpawnControl2Test extends ActorTest {
|
||||
"VehicleSpawnControl" should {
|
||||
"complete a vehicle order" in {
|
||||
val (vehicle, player, pad, zone) = VehicleSpawnPadControlTest.SetUpAgents(PlanetSideEmpire.TR)
|
||||
val probe = new TestProbe(system, "zone-events")
|
||||
|
||||
zone.VehicleEvents = probe.ref //zone events
|
||||
pad.Actor ! VehicleSpawnPad.VehicleOrder(player, vehicle) //order
|
||||
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.ConcealPlayer])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.LoadVehicle])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.AttachToRails])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.StartPlayerSeatedInVehicle])
|
||||
vehicle.Seats(0).Occupant = player
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.PlayerSeatedInVehicle])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.DetachFromRails])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.ServerVehicleOverrideStart])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.ServerVehicleOverrideEnd])
|
||||
//if we move the vehicle away from the pad, we should receive a ResetSpawnPad message
|
||||
//that means that the first order has cleared and the spawn pad is now waiting for additional orders
|
||||
vehicle.Position = Vector3(12,0,0)
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.ResetSpawnPad])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class VehicleSpawnControl3Test extends ActorTest {
|
||||
"VehicleSpawnControl" should {
|
||||
"block the second vehicle order until the first is completed" in {
|
||||
val (vehicle, player, pad, zone) = VehicleSpawnPadControlTest.SetUpAgents(PlanetSideEmpire.TR)
|
||||
//we can recycle the vehicle and the player for each order
|
||||
val probe = new TestProbe(system, "zone-events")
|
||||
val player2 = Player(Avatar("test2", player.Faction, CharacterGender.Male, 0, CharacterVoice.Mute))
|
||||
player2.GUID = PlanetSideGUID(11)
|
||||
player2.Continent = zone.Id
|
||||
player2.Spawn
|
||||
|
||||
zone.VehicleEvents = probe.ref //zone events
|
||||
pad.Actor ! VehicleSpawnPad.VehicleOrder(player, vehicle) //first order
|
||||
pad.Actor ! VehicleSpawnPad.VehicleOrder(player2, vehicle) //second order (vehicle shared)
|
||||
|
||||
assert(probe.receiveOne(1 seconds) match {
|
||||
case VehicleSpawnPad.PeriodicReminder(_, VehicleSpawnPad.Reminders.Queue, _) => true
|
||||
case _ => false
|
||||
})
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.ConcealPlayer])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.LoadVehicle])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.AttachToRails])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.StartPlayerSeatedInVehicle])
|
||||
vehicle.Seats(0).Occupant = player
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.PlayerSeatedInVehicle])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.DetachFromRails])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.ServerVehicleOverrideStart])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.ServerVehicleOverrideEnd])
|
||||
assert(probe.receiveOne(1 minute) match {
|
||||
case VehicleSpawnPad.PeriodicReminder(_, VehicleSpawnPad.Reminders.Blocked, _) => true
|
||||
case _ => false
|
||||
})
|
||||
assert(probe.receiveOne(1 minute) match {
|
||||
case VehicleSpawnPad.PeriodicReminder(_, VehicleSpawnPad.Reminders.Blocked, _) => true
|
||||
case _ => false
|
||||
})
|
||||
|
||||
//if we move the vehicle away from the pad, we should receive a second ConcealPlayer message
|
||||
//that means that the first order has cleared and the spawn pad is now working on the second order successfully
|
||||
player.VehicleSeated = None //since shared between orders, as necessary
|
||||
vehicle.Seats(0).Occupant = None
|
||||
vehicle.Position = Vector3(12,0,0)
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.ResetSpawnPad])
|
||||
probe.expectMsgClass(3 seconds, classOf[VehicleSpawnPad.ConcealPlayer])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class VehicleSpawnControl4Test extends ActorTest {
|
||||
"VehicleSpawnControl" should {
|
||||
"clean up the vehicle if the driver-to-be is on the wrong continent" in {
|
||||
val (vehicle, player, pad, zone) = VehicleSpawnPadControlTest.SetUpAgents(PlanetSideEmpire.TR)
|
||||
val probe = new TestProbe(system, "zone-events")
|
||||
zone.VehicleEvents = probe.ref
|
||||
player.Continent = "problem" //problem
|
||||
|
||||
pad.Actor ! VehicleSpawnPad.VehicleOrder(player, vehicle) //order
|
||||
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.DisposeVehicle])
|
||||
probe.expectNoMsg(5 seconds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class VehicleSpawnControl5Test extends ActorTest() {
|
||||
"VehicleSpawnControl" should {
|
||||
"abandon a destroyed vehicle on the spawn pad (blocking)" in {
|
||||
val (vehicle, player, pad, zone) = VehicleSpawnPadControlTest.SetUpAgents(PlanetSideEmpire.TR)
|
||||
|
||||
val probe = new TestProbe(system, "zone-events")
|
||||
zone.VehicleEvents = probe.ref
|
||||
pad.Actor ! VehicleSpawnPad.VehicleOrder(player, vehicle) //order
|
||||
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.ConcealPlayer])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.LoadVehicle])
|
||||
vehicle.Health = 0 //problem
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.AttachToRails])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.DetachFromRails])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.RevealPlayer])
|
||||
assert(probe.receiveOne(1 minute) match {
|
||||
case VehicleServiceMessage(_, VehicleAction.LoadVehicle(_,_,_,_,_)) => true
|
||||
case _ => false
|
||||
})
|
||||
assert(probe.receiveOne(1 minute) match {
|
||||
case VehicleSpawnPad.PeriodicReminder(_, VehicleSpawnPad.Reminders.Blocked, _) => true
|
||||
case _ => false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class VehicleSpawnControl6Test extends ActorTest() {
|
||||
"VehicleSpawnControl" should {
|
||||
"abandon a vehicle on the spawn pad if driver is unfit to drive (blocking)" in {
|
||||
val (vehicle, player, pad, zone) = VehicleSpawnPadControlTest.SetUpAgents(PlanetSideEmpire.TR)
|
||||
|
||||
val probe = new TestProbe(system, "zone-events")
|
||||
zone.VehicleEvents = probe.ref
|
||||
pad.Actor ! VehicleSpawnPad.VehicleOrder(player, vehicle) //order
|
||||
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.ConcealPlayer])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.LoadVehicle])
|
||||
player.Die
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.AttachToRails])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.DetachFromRails])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.RevealPlayer])
|
||||
assert(probe.receiveOne(1 minute) match {
|
||||
case VehicleServiceMessage(_, VehicleAction.LoadVehicle(_,_,_,_,_)) => true
|
||||
case _ => false
|
||||
})
|
||||
assert(probe.receiveOne(1 minute) match {
|
||||
case VehicleSpawnPad.PeriodicReminder(_, VehicleSpawnPad.Reminders.Blocked, _) => true
|
||||
case _ => false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class VehicleSpawnControl7Test extends ActorTest {
|
||||
"VehicleSpawnControl" should {
|
||||
"abandon a vehicle on the spawn pad if driver is unfit to drive (blocking)" in {
|
||||
val (vehicle, player, pad, zone) = VehicleSpawnPadControlTest.SetUpAgents(PlanetSideEmpire.TR)
|
||||
val probe = new TestProbe(system, "zone-events")
|
||||
player.ExoSuit = ExoSuitType.MAX
|
||||
|
||||
zone.VehicleEvents = probe.ref //zone events
|
||||
pad.Actor ! VehicleSpawnPad.VehicleOrder(player, vehicle) //order
|
||||
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.ConcealPlayer])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.LoadVehicle])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.AttachToRails])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.StartPlayerSeatedInVehicle])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.DetachFromRails])
|
||||
probe.expectMsgClass(1 minute, classOf[VehicleSpawnPad.RevealPlayer])
|
||||
assert(probe.receiveOne(1 minute) match {
|
||||
case VehicleServiceMessage(_, VehicleAction.LoadVehicle(_,_,_,_,_)) => true
|
||||
case _ => false
|
||||
})
|
||||
assert(probe.receiveOne(1 minute) match {
|
||||
case VehicleSpawnPad.PeriodicReminder(_, VehicleSpawnPad.Reminders.Blocked, _) => true
|
||||
case _ => false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object VehicleSpawnPadControlTest {
|
||||
import net.psforever.objects.zones.ZoneMap
|
||||
private val map = new ZoneMap("test-map")
|
||||
|
||||
def SetUpAgents(faction : PlanetSideEmpire.Value)(implicit system : ActorSystem) : (Vehicle, Player, VehicleSpawnPad, Zone) = {
|
||||
import net.psforever.objects.guid.NumberPoolHub
|
||||
import net.psforever.objects.guid.source.LimitedNumberSource
|
||||
import net.psforever.objects.serverobject.structures.Building
|
||||
import net.psforever.objects.vehicles.VehicleControl
|
||||
import net.psforever.objects.zones.ZoneActor
|
||||
import net.psforever.objects.Tool
|
||||
import net.psforever.types.CharacterGender
|
||||
|
||||
val vehicle = Vehicle(GlobalDefinitions.two_man_assault_buggy)
|
||||
val weapon = vehicle.WeaponControlledFromSeat(1).get.asInstanceOf[Tool]
|
||||
val zone = new Zone("test-zone", map, 0) {
|
||||
override def SetupNumberPools() = {
|
||||
val guid : NumberPoolHub = new NumberPoolHub(LimitedNumberSource(5))
|
||||
guid.AddPool("test-pool", (0 to 2).toList)
|
||||
//do not do this under normal conditions
|
||||
guid.register(vehicle, "test-pool")
|
||||
guid.register(weapon, "test-pool")
|
||||
guid.register(weapon.AmmoSlot.Box, "test-pool")
|
||||
GUID(guid)
|
||||
}
|
||||
}
|
||||
zone.Actor = system.actorOf(Props(classOf[ZoneActor], zone), s"test-zone-${System.nanoTime()}")
|
||||
zone.Actor ! Zone.Init()
|
||||
vehicle.Actor = system.actorOf(Props(classOf[VehicleControl], vehicle), s"vehicle-control-${System.nanoTime()}")
|
||||
|
||||
val pad = VehicleSpawnPad(GlobalDefinitions.mb_pad_creation)
|
||||
pad.Actor = system.actorOf(Props(classOf[VehicleSpawnControl], pad), s"test-pad-${System.nanoTime()}")
|
||||
pad.Owner = new Building("Building", building_guid = 0, map_id = 0, zone, StructureType.Building, GlobalDefinitions.building)
|
||||
pad.Owner.Faction = faction
|
||||
val player = Player(Avatar("test", faction, CharacterGender.Male, 0, CharacterVoice.Mute))
|
||||
player.GUID = PlanetSideGUID(10)
|
||||
player.Continent = zone.Id
|
||||
player.Spawn
|
||||
//note: pad and vehicle are both at Vector3(1,0,0) so they count as blocking
|
||||
pad.Position = Vector3(1,0,0)
|
||||
vehicle.Position = Vector3(1,0,0)
|
||||
(vehicle, player, pad, zone)
|
||||
}
|
||||
}
|
||||
598
pslogin/src/test/scala/actor/service/AvatarServiceTest.scala
Normal file
598
pslogin/src/test/scala/actor/service/AvatarServiceTest.scala
Normal file
|
|
@ -0,0 +1,598 @@
|
|||
// Copyright (c) 2017 PSForever
|
||||
package actor.service
|
||||
|
||||
import akka.actor.Props
|
||||
import akka.routing.RandomPool
|
||||
import actor.base.ActorTest
|
||||
import net.psforever.objects._
|
||||
import net.psforever.objects.guid.{GUIDTask, TaskResolver}
|
||||
import net.psforever.objects.zones.{Zone, ZoneActor, ZoneMap}
|
||||
import net.psforever.packet.game.objectcreate.{DroppedItemData, ObjectClass, ObjectCreateMessageParent, PlacementData}
|
||||
import net.psforever.packet.game.{ObjectCreateMessage, PlanetSideGUID, PlayerStateMessageUpstream}
|
||||
import net.psforever.types._
|
||||
import services.{RemoverActor, Service, ServiceManager}
|
||||
import services.avatar._
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
class AvatarService1Test extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"construct" in {
|
||||
ServiceManager.boot(system)
|
||||
system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
assert(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarService2Test extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"subscribe" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
assert(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarService3Test extends ActorTest {
|
||||
"AvatarService" should {
|
||||
ServiceManager.boot(system)
|
||||
"subscribe to a specific channel" in {
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! Service.Leave()
|
||||
assert(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarService4Test extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"subscribe" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! Service.LeaveAll()
|
||||
assert(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarService5Test extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass an unhandled message" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! "hello"
|
||||
expectNoMsg()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ArmorChangedTest extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass ArmorChanged" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.ArmorChanged(PlanetSideGUID(10), ExoSuitType.Reinforced, 0))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.ArmorChanged(ExoSuitType.Reinforced, 0)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ConcealPlayerTest extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass ConcealPlayer" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.ConcealPlayer(PlanetSideGUID(10)))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.ConcealPlayer()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class EquipmentInHandTest extends ActorTest {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), "release-test-service")
|
||||
val toolDef = GlobalDefinitions.beamer
|
||||
val tool = Tool(toolDef)
|
||||
tool.GUID = PlanetSideGUID(40)
|
||||
tool.AmmoSlots.head.Box.GUID = PlanetSideGUID(41)
|
||||
val pkt = ObjectCreateMessage(
|
||||
toolDef.ObjectId,
|
||||
tool.GUID,
|
||||
ObjectCreateMessageParent(PlanetSideGUID(11), 2),
|
||||
toolDef.Packet.ConstructorData(tool).get
|
||||
)
|
||||
|
||||
"AvatarService" should {
|
||||
"pass EquipmentInHand" in {
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.EquipmentInHand(PlanetSideGUID(10), PlanetSideGUID(11), 2, tool))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.EquipmentInHand(pkt)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DeployItemTest extends ActorTest {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), "deploy-item-test-service")
|
||||
val objDef = GlobalDefinitions.motionalarmsensor
|
||||
val obj = new SensorDeployable(objDef)
|
||||
obj.Position = Vector3(1,2,3)
|
||||
obj.Orientation = Vector3(4,5,6)
|
||||
obj.GUID = PlanetSideGUID(40)
|
||||
val pkt = ObjectCreateMessage(
|
||||
objDef.ObjectId,
|
||||
obj.GUID,
|
||||
objDef.Packet.ConstructorData(obj).get
|
||||
)
|
||||
|
||||
"AvatarService" should {
|
||||
"pass DeployItem" in {
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.DeployItem(PlanetSideGUID(10), obj))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.DropItem(pkt)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DroptItemTest extends ActorTest {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), "release-test-service")
|
||||
val toolDef = GlobalDefinitions.beamer
|
||||
val tool = Tool(toolDef)
|
||||
tool.Position = Vector3(1,2,3)
|
||||
tool.Orientation = Vector3(4,5,6)
|
||||
tool.GUID = PlanetSideGUID(40)
|
||||
tool.AmmoSlots.head.Box.GUID = PlanetSideGUID(41)
|
||||
val pkt = ObjectCreateMessage(
|
||||
toolDef.ObjectId,
|
||||
tool.GUID,
|
||||
DroppedItemData(
|
||||
PlacementData(tool.Position, tool.Orientation),
|
||||
toolDef.Packet.ConstructorData(tool).get
|
||||
)
|
||||
)
|
||||
|
||||
"AvatarService" should {
|
||||
"pass DropItem" in {
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.DropItem(PlanetSideGUID(10), tool, Zone.Nowhere))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.DropItem(pkt)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class LoadPlayerTest extends ActorTest {
|
||||
val obj = Player(Avatar("TestCharacter1", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
|
||||
obj.GUID = PlanetSideGUID(10)
|
||||
obj.Slot(5).Equipment.get.GUID = PlanetSideGUID(11)
|
||||
val c1data = obj.Definition.Packet.DetailedConstructorData(obj).get
|
||||
val pkt1 = ObjectCreateMessage(ObjectClass.avatar, PlanetSideGUID(10), c1data)
|
||||
val parent = ObjectCreateMessageParent(PlanetSideGUID(12), 0)
|
||||
obj.VehicleSeated = PlanetSideGUID(12)
|
||||
val c2data = obj.Definition.Packet.DetailedConstructorData(obj).get
|
||||
val pkt2 = ObjectCreateMessage(ObjectClass.avatar, PlanetSideGUID(10), parent, c2data)
|
||||
|
||||
"AvatarService" should {
|
||||
"pass LoadPlayer" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
//no parent data
|
||||
service ! AvatarServiceMessage("test", AvatarAction.LoadPlayer(
|
||||
PlanetSideGUID(20), ObjectClass.avatar, PlanetSideGUID(10), c1data, None)
|
||||
)
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(20), AvatarResponse.LoadPlayer(pkt1)))
|
||||
//parent data
|
||||
service ! AvatarServiceMessage("test", AvatarAction.LoadPlayer(
|
||||
PlanetSideGUID(20), ObjectClass.avatar, PlanetSideGUID(10), c2data, Some(parent))
|
||||
)
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(20), AvatarResponse.LoadPlayer(pkt2)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ObjectDeleteTest extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass ObjectDelete" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.ObjectDelete(PlanetSideGUID(10), PlanetSideGUID(11)))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.ObjectDelete(PlanetSideGUID(11), 0)))
|
||||
|
||||
service ! AvatarServiceMessage("test", AvatarAction.ObjectDelete(PlanetSideGUID(10), PlanetSideGUID(11), 55))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.ObjectDelete(PlanetSideGUID(11), 55)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ObjectHeldTest extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass ObjectHeld" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.ObjectHeld(PlanetSideGUID(10), 1))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.ObjectHeld(1)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PutDownFDUTest extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass PutDownFDU" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.PutDownFDU(PlanetSideGUID(10)))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.PutDownFDU(PlanetSideGUID(10))))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PlanetsideAttributeTest extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass PlanetsideAttribute" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.PlanetsideAttribute(PlanetSideGUID(10), 5, 1200L))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.PlanetsideAttribute(5, 1200L)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PlayerStateTest extends ActorTest {
|
||||
val msg = PlayerStateMessageUpstream(PlanetSideGUID(75), Vector3(3694.1094f, 2735.4531f, 90.84375f), Some(Vector3(4.375f, 2.59375f, 0.0f)), 61.875f, 351.5625f, 0.0f, 136, 0, false, false, false, false, 112, 0)
|
||||
|
||||
"AvatarService" should {
|
||||
"pass PlayerState" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.PlayerState(PlanetSideGUID(10), Vector3(3694.1094f, 2735.4531f, 90.84375f), Some(Vector3(4.375f, 2.59375f, 0.0f)), 61.875f, 351.5625f, 0.0f, 136, false, false, false, false, false, false))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.PlayerState(Vector3(3694.1094f, 2735.4531f, 90.84375f), Some(Vector3(4.375f, 2.59375f, 0.0f)), 61.875f, 351.5625f, 0.0f, 136, false, false, false, false, false, false)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PickupItemATest extends ActorTest {
|
||||
val obj = Player(Avatar("TestCharacter", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
|
||||
obj.GUID = PlanetSideGUID(10)
|
||||
obj.Slot(5).Equipment.get.GUID = PlanetSideGUID(11)
|
||||
|
||||
val toolDef = GlobalDefinitions.beamer
|
||||
val tool = Tool(toolDef)
|
||||
tool.GUID = PlanetSideGUID(40)
|
||||
tool.AmmoSlots.head.Box.GUID = PlanetSideGUID(41)
|
||||
val pkt = ObjectCreateMessage(
|
||||
toolDef.ObjectId,
|
||||
tool.GUID,
|
||||
ObjectCreateMessageParent(PlanetSideGUID(10), 0),
|
||||
toolDef.Packet.ConstructorData(tool).get
|
||||
)
|
||||
|
||||
"pass PickUpItem as EquipmentInHand (visible pistol slot)" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.PickupItem(PlanetSideGUID(10), Zone.Nowhere, obj, 0, tool))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.EquipmentInHand(pkt)))
|
||||
}
|
||||
}
|
||||
|
||||
class PickupItemBTest extends ActorTest {
|
||||
val obj = Player(Avatar("TestCharacter", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
|
||||
val tool = Tool(GlobalDefinitions.beamer)
|
||||
tool.GUID = PlanetSideGUID(40)
|
||||
|
||||
"pass PickUpItem as ObjectDelete (not visible inventory space)" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.PickupItem(PlanetSideGUID(10), Zone.Nowhere, obj, 6, tool))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.ObjectDelete(tool.GUID, 0)))
|
||||
}
|
||||
}
|
||||
|
||||
class ReloadTest extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass Reload" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.Reload(PlanetSideGUID(10), PlanetSideGUID(40)))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.Reload(PlanetSideGUID(40))))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ChangeAmmoTest extends ActorTest {
|
||||
val ammoDef = GlobalDefinitions.energy_cell
|
||||
val ammoBox = AmmoBox(ammoDef)
|
||||
|
||||
"AvatarService" should {
|
||||
"pass ChangeAmmo" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.ChangeAmmo(PlanetSideGUID(10), PlanetSideGUID(40), 0, PlanetSideGUID(40), ammoDef.ObjectId, PlanetSideGUID(41), ammoDef.Packet.ConstructorData(ammoBox).get))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.ChangeAmmo(PlanetSideGUID(40), 0, PlanetSideGUID(40), ammoDef.ObjectId, PlanetSideGUID(41), ammoDef.Packet.ConstructorData(ammoBox).get)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ChangeFireModeTest extends ActorTest {
|
||||
val ammoDef = GlobalDefinitions.energy_cell
|
||||
val ammoBox = AmmoBox(ammoDef)
|
||||
|
||||
"AvatarService" should {
|
||||
"pass ChangeFireMode" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.ChangeFireMode(PlanetSideGUID(10), PlanetSideGUID(40), 0))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.ChangeFireMode(PlanetSideGUID(40), 0)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ChangeFireStateStartTest extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass ChangeFireState_Start" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.ChangeFireState_Start(PlanetSideGUID(10), PlanetSideGUID(40)))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.ChangeFireState_Start(PlanetSideGUID(40))))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ChangeFireStateStopTest extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass ChangeFireState_Stop" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.ChangeFireState_Stop(PlanetSideGUID(10), PlanetSideGUID(40)))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.ChangeFireState_Stop(PlanetSideGUID(40))))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DamageTest extends ActorTest {
|
||||
val test_func_ref : (Any)=>Unit = {
|
||||
def test_func(o : Any) : Unit = { }
|
||||
test_func
|
||||
}
|
||||
val player = Player(Avatar("TestCharacter", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
|
||||
|
||||
"AvatarService" should {
|
||||
"pass Damage" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.Damage(PlanetSideGUID(10), player, test_func_ref))
|
||||
val msg = receiveOne(1 seconds)
|
||||
assert(msg.isInstanceOf[AvatarServiceResponse])
|
||||
assert(msg.asInstanceOf[AvatarServiceResponse].toChannel == "/test/Avatar")
|
||||
assert(msg.asInstanceOf[AvatarServiceResponse].avatar_guid == PlanetSideGUID(10))
|
||||
assert(msg.asInstanceOf[AvatarServiceResponse].replyMessage
|
||||
.isInstanceOf[AvatarResponse.DamageResolution])
|
||||
assert(msg.asInstanceOf[AvatarServiceResponse].replyMessage
|
||||
.asInstanceOf[AvatarResponse.DamageResolution].target == player)
|
||||
assert(msg.asInstanceOf[AvatarServiceResponse].replyMessage
|
||||
.asInstanceOf[AvatarResponse.DamageResolution].resolution_function == test_func_ref)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class WeaponDryFireTest extends ActorTest {
|
||||
"AvatarService" should {
|
||||
"pass WeaponDryFire" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.WeaponDryFire(PlanetSideGUID(10), PlanetSideGUID(40)))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.WeaponDryFire(PlanetSideGUID(40))))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarStowEquipmentTest extends ActorTest {
|
||||
val tool = Tool(GlobalDefinitions.beamer)
|
||||
|
||||
"AvatarService" should {
|
||||
"pass StowEquipment" in {
|
||||
ServiceManager.boot(system)
|
||||
val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName)
|
||||
service ! Service.Join("test")
|
||||
service ! AvatarServiceMessage("test", AvatarAction.StowEquipment(PlanetSideGUID(10), PlanetSideGUID(11), 2, tool))
|
||||
expectMsg(AvatarServiceResponse("/test/Avatar", PlanetSideGUID(10), AvatarResponse.StowEquipment(PlanetSideGUID(11), 2, tool)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Preparation for these three Release tests is involved.
|
||||
The ServiceManager must not only be set up correctly, but must be given a TaskResolver.
|
||||
The AvatarService is started and that starts CorpseRemovalActor, an essential part of this test.
|
||||
The CorpseRemovalActor needs that TaskResolver created by the ServiceManager;
|
||||
but, another independent TaskResolver will be needed for manual parts of the test.
|
||||
(The ServiceManager's TaskResolver can be "borrowed" but that requires writing code to intercept it.)
|
||||
The Zone needs to be set up and initialized properly with a ZoneActor.
|
||||
The ZoneActor builds the GUID Actor and the ZonePopulationActor.
|
||||
|
||||
ALL of these Actors will talk to each other.
|
||||
The lines of communication can short circuit if the next Actor does not have the correct information.
|
||||
Putting Actor startup in the main class, outside of the body of the test, helps.
|
||||
Frequent pauses to allow everything to sort their messages also helps.
|
||||
Even with all this work, the tests have a high chance of failure just due to being asynchronous.
|
||||
*/
|
||||
class AvatarReleaseTest extends ActorTest {
|
||||
ServiceManager.boot(system) ! ServiceManager.Register(RandomPool(1).props(Props[TaskResolver]), "taskResolver")
|
||||
val zone = new Zone("test", new ZoneMap("test-map"), 0) { override def SetupNumberPools() = { AddPool("dynamic", 1 to 10) } }
|
||||
val service = system.actorOf(Props(classOf[AvatarService], zone), "release-test-service")
|
||||
val taskResolver = system.actorOf(Props[TaskResolver], "release-test-resolver")
|
||||
zone.Actor = system.actorOf(Props(classOf[ZoneActor], zone), "release-test-zone")
|
||||
zone.Actor ! Zone.Init()
|
||||
val obj = Player(Avatar("TestCharacter", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
|
||||
obj.Continent = "test"
|
||||
obj.Release
|
||||
|
||||
"AvatarService" should {
|
||||
"pass Release" in {
|
||||
expectNoMsg(100 milliseconds) //spacer
|
||||
|
||||
service ! Service.Join("test")
|
||||
taskResolver ! GUIDTask.RegisterObjectTask(obj)(zone.GUID)
|
||||
assert(zone.Corpses.isEmpty)
|
||||
zone.Population ! Zone.Corpse.Add(obj)
|
||||
expectNoMsg(200 milliseconds) //spacer
|
||||
|
||||
assert(zone.Corpses.size == 1)
|
||||
assert(obj.HasGUID)
|
||||
val guid = obj.GUID
|
||||
service ! AvatarServiceMessage("test", AvatarAction.Release(obj, zone, Some(1 second))) //alive for one second
|
||||
|
||||
val reply1 = receiveOne(200 milliseconds)
|
||||
assert(reply1.isInstanceOf[AvatarServiceResponse])
|
||||
val reply1msg = reply1.asInstanceOf[AvatarServiceResponse]
|
||||
assert(reply1msg.toChannel == "/test/Avatar")
|
||||
assert(reply1msg.avatar_guid == guid)
|
||||
assert(reply1msg.replyMessage.isInstanceOf[AvatarResponse.Release])
|
||||
assert(reply1msg.replyMessage.asInstanceOf[AvatarResponse.Release].player == obj)
|
||||
|
||||
val reply2 = receiveOne(2 seconds)
|
||||
assert(reply2.isInstanceOf[AvatarServiceResponse])
|
||||
val reply2msg = reply2.asInstanceOf[AvatarServiceResponse]
|
||||
assert(reply2msg.toChannel.equals("/test/Avatar"))
|
||||
assert(reply2msg.avatar_guid == Service.defaultPlayerGUID)
|
||||
assert(reply2msg.replyMessage.isInstanceOf[AvatarResponse.ObjectDelete])
|
||||
assert(reply2msg.replyMessage.asInstanceOf[AvatarResponse.ObjectDelete].item_guid == guid)
|
||||
|
||||
expectNoMsg(1 seconds)
|
||||
assert(zone.Corpses.isEmpty)
|
||||
assert(!obj.HasGUID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarReleaseEarly1Test extends ActorTest {
|
||||
ServiceManager.boot(system) ! ServiceManager.Register(RandomPool(1).props(Props[TaskResolver]), "taskResolver")
|
||||
val zone = new Zone("test", new ZoneMap("test-map"), 0) { override def SetupNumberPools() = { AddPool("dynamic", 1 to 10) } }
|
||||
val service = system.actorOf(Props(classOf[AvatarService], zone), "release-test-service")
|
||||
val taskResolver = system.actorOf(Props[TaskResolver], "release-test-resolver")
|
||||
zone.Actor = system.actorOf(Props(classOf[ZoneActor], zone), "release-test-zone")
|
||||
zone.Actor ! Zone.Init()
|
||||
val obj = Player(Avatar("TestCharacter1", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
|
||||
obj.Continent = "test"
|
||||
obj.Release
|
||||
|
||||
"AvatarService" should {
|
||||
"pass Release" in {
|
||||
expectNoMsg(100 milliseconds) //spacer
|
||||
|
||||
service ! Service.Join("test")
|
||||
taskResolver ! GUIDTask.RegisterObjectTask(obj)(zone.GUID)
|
||||
assert(zone.Corpses.isEmpty)
|
||||
zone.Population ! Zone.Corpse.Add(obj)
|
||||
expectNoMsg(200 milliseconds) //spacer
|
||||
|
||||
assert(zone.Corpses.size == 1)
|
||||
assert(obj.HasGUID)
|
||||
val guid = obj.GUID
|
||||
service ! AvatarServiceMessage("test", AvatarAction.Release(obj, zone)) //3+ minutes!
|
||||
|
||||
val reply1 = receiveOne(200 milliseconds)
|
||||
assert(reply1.isInstanceOf[AvatarServiceResponse])
|
||||
val reply1msg = reply1.asInstanceOf[AvatarServiceResponse]
|
||||
assert(reply1msg.toChannel == "/test/Avatar")
|
||||
assert(reply1msg.avatar_guid == guid)
|
||||
assert(reply1msg.replyMessage.isInstanceOf[AvatarResponse.Release])
|
||||
assert(reply1msg.replyMessage.asInstanceOf[AvatarResponse.Release].player == obj)
|
||||
|
||||
service ! AvatarServiceMessage.Corpse(RemoverActor.HurrySpecific(List(obj), zone)) //IMPORTANT: ONE ENTRY
|
||||
val reply2 = receiveOne(200 milliseconds)
|
||||
assert(reply2.isInstanceOf[AvatarServiceResponse])
|
||||
val reply2msg = reply2.asInstanceOf[AvatarServiceResponse]
|
||||
assert(reply2msg.toChannel.equals("/test/Avatar"))
|
||||
assert(reply2msg.avatar_guid == Service.defaultPlayerGUID)
|
||||
assert(reply2msg.replyMessage.isInstanceOf[AvatarResponse.ObjectDelete])
|
||||
assert(reply2msg.replyMessage.asInstanceOf[AvatarResponse.ObjectDelete].item_guid == guid)
|
||||
|
||||
expectNoMsg(1 seconds)
|
||||
assert(zone.Corpses.isEmpty)
|
||||
assert(!obj.HasGUID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class AvatarReleaseEarly2Test extends ActorTest {
|
||||
ServiceManager.boot(system) ! ServiceManager.Register(RandomPool(1).props(Props[TaskResolver]), "taskResolver")
|
||||
val zone = new Zone("test", new ZoneMap("test-map"), 0) { override def SetupNumberPools() = { AddPool("dynamic", 1 to 10) } }
|
||||
val service = system.actorOf(Props(classOf[AvatarService], zone), "release-test-service")
|
||||
val taskResolver = system.actorOf(Props[TaskResolver], "release-test-resolver")
|
||||
zone.Actor = system.actorOf(Props(classOf[ZoneActor], zone), "release-test-zone")
|
||||
zone.Actor ! Zone.Init()
|
||||
val objAlt = Player(Avatar("TestCharacter2", PlanetSideEmpire.NC, CharacterGender.Male, 1, CharacterVoice.Voice1)) //necessary clutter
|
||||
val obj = Player(Avatar("TestCharacter1", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1))
|
||||
obj.Continent = "test"
|
||||
obj.Release
|
||||
|
||||
"AvatarService" should {
|
||||
"pass Release" in {
|
||||
expectNoMsg(100 milliseconds) //spacer
|
||||
|
||||
service ! Service.Join("test")
|
||||
taskResolver ! GUIDTask.RegisterObjectTask(obj)(zone.GUID)
|
||||
assert(zone.Corpses.isEmpty)
|
||||
zone.Population ! Zone.Corpse.Add(obj)
|
||||
expectNoMsg(200 milliseconds) //spacer
|
||||
|
||||
assert(zone.Corpses.size == 1)
|
||||
assert(obj.HasGUID)
|
||||
val guid = obj.GUID
|
||||
service ! AvatarServiceMessage("test", AvatarAction.Release(obj, zone)) //3+ minutes!
|
||||
|
||||
val reply1 = receiveOne(200 milliseconds)
|
||||
assert(reply1.isInstanceOf[AvatarServiceResponse])
|
||||
val reply1msg = reply1.asInstanceOf[AvatarServiceResponse]
|
||||
assert(reply1msg.toChannel == "/test/Avatar")
|
||||
assert(reply1msg.avatar_guid == guid)
|
||||
assert(reply1msg.replyMessage.isInstanceOf[AvatarResponse.Release])
|
||||
assert(reply1msg.replyMessage.asInstanceOf[AvatarResponse.Release].player == obj)
|
||||
|
||||
service ! AvatarServiceMessage.Corpse(RemoverActor.HurrySpecific(List(objAlt, obj), zone)) //IMPORTANT: TWO ENTRIES
|
||||
val reply2 = receiveOne(100 milliseconds)
|
||||
assert(reply2.isInstanceOf[AvatarServiceResponse])
|
||||
val reply2msg = reply2.asInstanceOf[AvatarServiceResponse]
|
||||
assert(reply2msg.toChannel.equals("/test/Avatar"))
|
||||
assert(reply2msg.avatar_guid == Service.defaultPlayerGUID)
|
||||
assert(reply2msg.replyMessage.isInstanceOf[AvatarResponse.ObjectDelete])
|
||||
assert(reply2msg.replyMessage.asInstanceOf[AvatarResponse.ObjectDelete].item_guid == guid)
|
||||
|
||||
expectNoMsg(1 seconds)
|
||||
assert(zone.Corpses.isEmpty)
|
||||
assert(!obj.HasGUID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object AvatarServiceTest {
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
private val number = new AtomicInteger(1)
|
||||
|
||||
def TestName : String = {
|
||||
s"service${number.getAndIncrement()}"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue