mirror of
https://github.com/psforever/PSF-LoginServer.git
synced 2026-07-09 13:34:40 +00:00
sorted out some tests for the event systems
This commit is contained in:
parent
14da36dabe
commit
f05a0ab96a
20 changed files with 111 additions and 132 deletions
|
|
@ -12,7 +12,6 @@ import net.psforever.objects.avatar.ModePermissions
|
|||
import net.psforever.objects.avatar.scoring.{Assist, Death, EquipmentStat, KDAStat, Kill, Life, ScoreCard, SupportActivity}
|
||||
import net.psforever.objects.sourcing.{TurretSource, VehicleSource}
|
||||
import net.psforever.packet.game.ImplantAction
|
||||
import net.psforever.services.avatar.AvatarServiceResponse
|
||||
import net.psforever.types.{ChatMessageType, StatisticalCategory, StatisticalElement}
|
||||
import net.psforever.zones.Zones
|
||||
import org.joda.time.{LocalDateTime, Seconds}
|
||||
|
|
@ -3490,6 +3489,7 @@ class AvatarActor(
|
|||
value: Int
|
||||
): Unit = {
|
||||
import akka.actor.typed.scaladsl.adapter.TypedActorRefOps
|
||||
import net.psforever.services.avatar.AvatarServiceResponse
|
||||
sessionActor.toClassic ! AvatarServiceResponse("", guid, AvatarAction.AvatarImplant(action, index, value))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1624,10 +1624,9 @@ object Zone {
|
|||
if (zone.id.startsWith("tzsh")) {
|
||||
zone.npcPopulation = context.actorOf(Props(classOf[ShootingRangeTargetSpawnerActor], zone), s"$id-npcs")
|
||||
}
|
||||
|
||||
zone.avatarEvents = context.actorOf(Props(classOf[AvatarService], zone), s"$id-avatar-events")
|
||||
zone.localEvents = context.actorOf(Props(classOf[LocalService], zone), s"$id-local-events")
|
||||
zone.vehicleEvents = context.actorOf(Props(classOf[VehicleService]), s"$id-vehicle-events")
|
||||
zone.avatarEvents = context.actorOf(AvatarService(), s"$id-avatar-events")
|
||||
zone.localEvents = context.actorOf(LocalService(zone), s"$id-local-events")
|
||||
zone.vehicleEvents = context.actorOf(VehicleService(), s"$id-vehicle-events")
|
||||
|
||||
zone.timeOfDayOrigin = System.currentTimeMillis()
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,12 @@ case object LitterRemovalSupport
|
|||
|
||||
case object AvatarStamp extends EventSystemStamp
|
||||
|
||||
class AvatarService
|
||||
extends GenericEventServiceWithCacheAndSupport(
|
||||
stamp = AvatarStamp,
|
||||
eventSupportServices = List(CorpseRemovalSupport, LitterRemovalSupport)
|
||||
)
|
||||
object AvatarService {
|
||||
def apply(): Props = {
|
||||
Props(
|
||||
classOf[GenericEventServiceWithCacheAndSupport],
|
||||
AvatarStamp,
|
||||
List(CorpseRemovalSupport, LitterRemovalSupport)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ trait EventSystemStamp {
|
|||
* and, dispatches the response to all subscribers associated with the channel provided in the message.
|
||||
* @param stamp distinct tag associated with an event system
|
||||
*/
|
||||
abstract class GenericEventService(stamp: EventSystemStamp)
|
||||
class GenericEventService(stamp: EventSystemStamp)
|
||||
extends Actor {
|
||||
protected lazy val log: Logger = org.log4s.getLogger(getClass.getSimpleName)
|
||||
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ private case object FlushCachedMessages extends GenericMessageEnvelope {
|
|||
def filter: PlanetSideGUID = Service.defaultPlayerGUID
|
||||
}
|
||||
|
||||
abstract class GenericEventServiceWithCacheAndSupport
|
||||
class GenericEventServiceWithCacheAndSupport
|
||||
(
|
||||
stamp: EventSystemStamp,
|
||||
eventSupportServices: List[EventServiceSupport]
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ trait GenericSupportEnvelopeOnly
|
|||
* @param stamp distinct tag associated with an event system
|
||||
* @param eventSupportServices list of support actors to initialize
|
||||
*/
|
||||
abstract class GenericEventServiceWithSupport
|
||||
class GenericEventServiceWithSupport
|
||||
(
|
||||
stamp: EventSystemStamp,
|
||||
eventSupportServices: List[EventServiceSupport]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) 2017-2026 PSForever
|
||||
package net.psforever.services.galaxy
|
||||
|
||||
import akka.actor.Props
|
||||
import net.psforever.services.base.{EventSystemStamp, GenericEventService}
|
||||
|
||||
case object GalaxyStamp extends EventSystemStamp {
|
||||
|
|
@ -13,5 +14,8 @@ case object GalaxyStamp extends EventSystemStamp {
|
|||
}
|
||||
}
|
||||
|
||||
class GalaxyService
|
||||
extends GenericEventService(stamp = GalaxyStamp)
|
||||
object GalaxyService {
|
||||
def apply(): Props = {
|
||||
Props(classOf[GenericEventService], GalaxyStamp)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,8 +41,12 @@ case class CaptureFlagSupport(zone: Zone)
|
|||
|
||||
case object LocalStamp extends EventSystemStamp
|
||||
|
||||
class LocalService(zone: Zone)
|
||||
extends GenericEventServiceWithSupport(
|
||||
stamp = LocalStamp,
|
||||
eventSupportServices = List(DoorCloserSupport, HackClearSupport, HackCaptureSupport, CaptureFlagSupport(zone))
|
||||
)
|
||||
object LocalService {
|
||||
def apply(zone: Zone): Props = {
|
||||
Props(
|
||||
classOf[GenericEventServiceWithSupport],
|
||||
LocalStamp,
|
||||
List(DoorCloserSupport, HackClearSupport, HackCaptureSupport, CaptureFlagSupport(zone))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,8 +15,12 @@ case object TurretUpgradeSupport
|
|||
|
||||
case object VehicleStamp extends EventSystemStamp
|
||||
|
||||
class VehicleService
|
||||
extends GenericEventServiceWithCacheAndSupport(
|
||||
stamp = VehicleStamp,
|
||||
eventSupportServices = List(TurretUpgradeSupport)
|
||||
)
|
||||
object VehicleService {
|
||||
def apply(): Props = {
|
||||
Props(
|
||||
classOf[GenericEventServiceWithCacheAndSupport],
|
||||
VehicleStamp,
|
||||
List(TurretUpgradeSupport)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,9 @@ class DamageCalculationsTests extends Specification {
|
|||
val projectile = Projectile(proj, wep, wep_fmode, player, Vector3(2, 2, 0), Vector3.Zero)
|
||||
val target = Vehicle(GlobalDefinitions.fury)
|
||||
target.Position = Vector3(10, 0, 0)
|
||||
player.GUID = PlanetSideGUID(1)
|
||||
projectile.GUID = PlanetSideGUID(2)
|
||||
target.GUID = PlanetSideGUID(3)
|
||||
val resprojectile = DamageInteraction(
|
||||
SourceEntry(target),
|
||||
ProjectileReason(
|
||||
|
|
@ -271,6 +274,7 @@ class DamageCalculationsTests extends Specification {
|
|||
)
|
||||
val minDamageBase = charge_weapon.Projectile.Charging.get.min.Damage0
|
||||
val chargeBaseDamage = charge_weapon.Projectile.Damage0
|
||||
charge_projectile.GUID = PlanetSideGUID(1)
|
||||
|
||||
"charge (none)" in {
|
||||
val cprojectile = charge_projectile.quality(ProjectileQuality.Modified(0))
|
||||
|
|
@ -329,6 +333,7 @@ class DamageCalculationsTests extends Specification {
|
|||
Vector3(2, 2, 0),
|
||||
Vector3.Zero
|
||||
)
|
||||
flak_projectile.GUID = PlanetSideGUID(1)
|
||||
|
||||
"flak hit (resolution is splash, no degrade)" in {
|
||||
val resfprojectile = DamageInteraction(
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import scala.concurrent.duration._
|
|||
class OrbitalShuttlePadControlTest extends FreedContextActorTest {
|
||||
import akka.actor.typed.scaladsl.adapter._
|
||||
val services: ActorRef = ServiceManager.boot(system)
|
||||
services ! ServiceManager.Register(Props[GalaxyService](), "galaxy")
|
||||
services ! ServiceManager.Register(GalaxyService(), "galaxy")
|
||||
services ! ServiceManager.Register(Props[HartService](), "hart")
|
||||
expectNoMessage(1000 milliseconds)
|
||||
var buildingMap = new TrieMap[Int, Building]()
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ class ResourceSiloControlStartupMessageSomeTest extends ActorTest {
|
|||
|
||||
class ResourceSiloControlUseTest extends FreedContextActorTest {
|
||||
import akka.actor.typed.scaladsl.adapter._
|
||||
ServiceManager.boot(system) ! ServiceManager.Register(Props[GalaxyService](), "galaxy")
|
||||
ServiceManager.boot(system) ! ServiceManager.Register(GalaxyService(), "galaxy")
|
||||
expectNoMessage(1000 milliseconds)
|
||||
var buildingMap = new TrieMap[Int, Building]()
|
||||
val guid = new NumberPoolHub(new MaxNumberSource(max = 10))
|
||||
|
|
|
|||
|
|
@ -429,9 +429,4 @@ object ProximityTest {
|
|||
val avatarId = new AtomicInteger(0)
|
||||
|
||||
class SampleTerminal extends Terminal(GlobalDefinitions.dropship_vehicle_terminal) with ProximityUnit
|
||||
|
||||
class ProbedLocalService(probe: TestProbe, zone: Zone) extends LocalService(zone) {
|
||||
self.tell(Service.Join("test"), probe.ref)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class EnvelopeTest extends Specification {
|
|||
"construct (quick)" in {
|
||||
val input = GenericResponseEnvelope(TestStamp, "test", TestFilter, TestMessage(5))
|
||||
input match {
|
||||
case reply @ GenericResponseEnvelope("test", TestFilter, TestMessage(5)) =>
|
||||
case reply @ GenericResponseEnvelope("/test/out", TestFilter, TestMessage(5)) =>
|
||||
reply.stamp mustEqual TestStamp
|
||||
case _ =>
|
||||
ko
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import net.psforever.services.Service
|
|||
import net.psforever.services.base.message.EventMessage
|
||||
import net.psforever.services.base.{CachedEnvelope, CachedGenericEventEnvelope, EventServiceSupport, GenericEventServiceWithCacheAndSupport, GenericSupportEnvelope}
|
||||
import net.psforever.types.PlanetSideGUID
|
||||
import service.base.EventServiceSupportTest.TestSupportService
|
||||
|
||||
import scala.concurrent.duration._
|
||||
|
||||
|
|
@ -29,7 +28,7 @@ object EventServiceCacheSupportTest {
|
|||
|
||||
def SpawnTestSystem(eventSupportServices: List[EventServiceSupport])(implicit system: ActorSystem, self: ActorRef): ActorRef = {
|
||||
val name = self.getClass.getSimpleName.replace("EventServiceCacheSupportTest", "")
|
||||
system.actorOf(Props(classOf[TestSupportService], eventSupportServices), name = s"EventServiceCacheSupportTest.$name")
|
||||
system.actorOf(Props(classOf[TestCacheService], eventSupportServices), name = s"EventServiceCacheSupportTest.$name")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -135,9 +134,9 @@ class EventServiceCacheSupportTestMultipleCachedSameMessages extends ActorTest {
|
|||
val secondMessage = CachedEnvelope(PlanetSideGUID(1), "test", TestMessage(2))
|
||||
val thirdMessage = CachedEnvelope(PlanetSideGUID(1), "test", TestMessage(3)) //this one!
|
||||
events ! firstMessage
|
||||
mainProbe.expectNoMessage(50 milliseconds)
|
||||
events ! secondMessage
|
||||
events ! thirdMessage
|
||||
mainProbe.expectNoMessage(50 milliseconds)
|
||||
val reply = mainProbe.receiveOne(125 milliseconds)
|
||||
reply match {
|
||||
case badmsg if badmsg == firstMessage =>
|
||||
|
|
@ -148,6 +147,7 @@ class EventServiceCacheSupportTestMultipleCachedSameMessages extends ActorTest {
|
|||
case badmsg =>
|
||||
assert(false, s"(7) expected delivery of test envelope, but received $badmsg instead")
|
||||
}
|
||||
mainProbe.expectNoMessage(150 milliseconds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class EventServiceTestNotSubscribed extends ActorTest {
|
|||
events ! MessageEnvelope("test", Service.defaultPlayerGUID, TestMessage(5))
|
||||
val reply = probe.receiveOne(100 milliseconds)
|
||||
reply match {
|
||||
case GenericResponseEnvelope("/test", _, TestMessage(5)) => ()
|
||||
case GenericResponseEnvelope("/test/out", _, TestMessage(5)) => ()
|
||||
case _ => assert(false, "(2) message expected but not received")
|
||||
}
|
||||
missedProbe.expectNoMessage(100 milliseconds)
|
||||
|
|
@ -127,11 +127,11 @@ class EventServiceTestLeave extends ActorTest {
|
|||
events ! MessageEnvelope("anotherTest", Service.defaultPlayerGUID, TestMessage(5))
|
||||
val reply1 = probe.receiveN(2, 100 milliseconds)
|
||||
reply1.head match {
|
||||
case GenericResponseEnvelope("/test", _, _) => ()
|
||||
case GenericResponseEnvelope("/test/out", _, _) => ()
|
||||
case _ => assert(false, "(3) message expected but not received")
|
||||
}
|
||||
reply1(1) match {
|
||||
case GenericResponseEnvelope("/anotherTest", _, _) => ()
|
||||
case GenericResponseEnvelope("/anotherTest/out", _, _) => ()
|
||||
case _ => assert(false, "(4) message expected but not received")
|
||||
}
|
||||
|
||||
|
|
@ -140,7 +140,7 @@ class EventServiceTestLeave extends ActorTest {
|
|||
events ! MessageEnvelope("anotherTest", Service.defaultPlayerGUID, TestMessage(6))
|
||||
val reply2 = probe.receiveOne(100 milliseconds)
|
||||
reply2 match {
|
||||
case GenericResponseEnvelope("/test", _, TestMessage(5)) => ()
|
||||
case GenericResponseEnvelope("/test/out", _, TestMessage(5)) => ()
|
||||
case _ => assert(false, "(5) message expected but not received")
|
||||
}
|
||||
probe.expectNoMessage(250 milliseconds)
|
||||
|
|
@ -148,7 +148,7 @@ class EventServiceTestLeave extends ActorTest {
|
|||
}
|
||||
}
|
||||
|
||||
class EventServiceTestLeaveAll1 extends ActorTest {
|
||||
class EventServiceTestLeaveAll extends ActorTest {
|
||||
import EventServiceTestBase._
|
||||
"GenericEventSystem" should {
|
||||
"leave all channels (1)" in {
|
||||
|
|
@ -161,40 +161,11 @@ class EventServiceTestLeaveAll1 extends ActorTest {
|
|||
events ! MessageEnvelope("anotherTest", Service.defaultPlayerGUID, TestMessage(6))
|
||||
val reply = probe.receiveN(2,100 milliseconds)
|
||||
reply.head match {
|
||||
case GenericResponseEnvelope("/test", _, TestMessage(5)) => ()
|
||||
case GenericResponseEnvelope("/test/out", _, TestMessage(5)) => ()
|
||||
case _ => assert(false, "(6) message expected but not received")
|
||||
}
|
||||
reply(1) match {
|
||||
case GenericResponseEnvelope("/anotherTest", _, TestMessage(6)) => ()
|
||||
case _ => assert(false, "(7) message expected but not received")
|
||||
}
|
||||
|
||||
events.tell(Service.LeaveAll, probe.ref)
|
||||
events ! MessageEnvelope("test", Service.defaultPlayerGUID, TestMessage(5))
|
||||
events ! MessageEnvelope("anotherTest", Service.defaultPlayerGUID, TestMessage(6))
|
||||
probe.expectNoMessage(250 milliseconds)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class EventServiceTestLeaveAll2 extends ActorTest {
|
||||
import EventServiceTestBase._
|
||||
"GenericEventSystem" should {
|
||||
"leave all channels" in {
|
||||
val probe = TestProbe("testProbe")
|
||||
val events = EventServiceTest.SpawnTestSystem()
|
||||
events.tell(Service.Join("test"), probe.ref)
|
||||
events.tell(Service.Join("anotherTest"), probe.ref)
|
||||
|
||||
events ! MessageEnvelope("test", Service.defaultPlayerGUID, TestMessage(5))
|
||||
events ! MessageEnvelope("anotherTest", Service.defaultPlayerGUID, TestMessage(6))
|
||||
val reply = probe.receiveN(2,100 milliseconds)
|
||||
reply.head match {
|
||||
case GenericResponseEnvelope("/test", _, TestMessage(5)) => ()
|
||||
case _ => assert(false, "(6) message expected but not received")
|
||||
}
|
||||
reply(1) match {
|
||||
case GenericResponseEnvelope("/anotherTest", _, TestMessage(6)) => ()
|
||||
case GenericResponseEnvelope("/anotherTest/out", _, TestMessage(6)) => ()
|
||||
case _ => assert(false, "(7) message expected but not received")
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue