PSF-LoginServer/src/test/scala/objects/DeploymentTest.scala

269 lines
10 KiB
Scala
Raw Normal View History

// Copyright (c) 2017 PSForever
package objects
import akka.actor.{Actor, ActorRef, ActorSystem, Props}
import akka.testkit.TestProbe
Facility Turrets (#223) * object class, actor class, and definitions for base turrets; untested * wired base turrets into existence, with hoop jumping; created interface for objects with mounted weapons (vehicles and turrets); working example phalanx_sgl_hevgatcan in Anguta, Ceryshen * re-wiring manned turrets so that the turreted weapon itself never changes externally but merely identifies different and changes internally; workflow for upgrading wall turrets in place (30s); clarifications and documentation for HackMessage and UseItemMessage; getting rid of orphaned packages from previous location of services * added a simple task that reverts upgraded manned turrets to their None state after a certain amount of time has passed; it works but need improvement * turret weapon upgrades now last for a duration of 30 minutes before reverting; created a service support actor base actor that underlies all current support actors; nano-dispenser now properly loads 1 unit of upgrade canister, rather than 100 units; all canister types have appropriate 2x3 inventory size * forgot to hurry; moved over the Services tests from main/test folder into the common/test folder and needed to change the location of ActorTest to accommodate it; test and documentation for MannedTurret; codecov ignore update * wired facility turrets in Anguta, Ceryshen; Akna tower, Ceryshen; and S.Villa tower, home3 (Anguta tower is a watchtower); attempted workaround for Travis CI issues with receiveN; re-introduced RemoveActorTest, at least the first test; expanded how ZoneActor performs tests on MannedTurret setup * getting rid of useless commented-out code; making common operations for mounting and dismounting * removed outdated comment; added ResourceSilo tests; added extra test for Zone
2018-07-14 21:25:44 -04:00
import base.ActorTest
import net.psforever.objects.serverobject.PlanetSideServerObject
import net.psforever.objects.{GlobalDefinitions, Vehicle}
import net.psforever.objects.serverobject.deploy.{Deployment, DeploymentBehavior}
import net.psforever.objects.zones.{Zone, ZoneMap}
import net.psforever.types.{DriveState, PlanetSideEmpire, PlanetSideGUID, Vector3}
import org.specs2.mutable.Specification
import net.psforever.services.vehicle.{VehicleAction, VehicleServiceMessage}
import scala.concurrent.duration.Duration
class DeploymentTest extends Specification {
"Deployment" should {
"construct" in {
val obj = new DeploymentTest.DeploymentObject()
obj.DeploymentState mustEqual DriveState.Mobile
obj.DeployTime mustEqual 0
obj.UndeployTime mustEqual 0
}
"change deployment state" in {
val obj = new DeploymentTest.DeploymentObject()
obj.DeploymentState mustEqual DriveState.Mobile
obj.DeploymentState = DriveState.Deployed
obj.DeploymentState mustEqual DriveState.Deployed
obj.DeploymentState = DriveState.Deploying
obj.DeploymentState mustEqual DriveState.Deploying
obj.DeploymentState = DriveState.Undeploying
obj.DeploymentState mustEqual DriveState.Undeploying
obj.DeploymentState = DriveState.State7
obj.DeploymentState mustEqual DriveState.State7
}
"have custom deployment time by object" in {
val ams = Vehicle(GlobalDefinitions.ams)
Persistence #1 featuring quill (#508) * Add .scalafmt.conf * Adopt quill for database access * Removed postgresql-async * Refactored all instances of database access * Creating duplicate characters of the same account is no longer possible * Rewrote large parts of LoginSessionActor * Implement migrations * Move overrides into subdirectory * Make usernames case insensitive * Use LOWER(?) comparison instead of storing lowercased username * import scala.util.{Success, Failure} * Add config and joda-time dependencies * Add sbt-scalafmt * Use defaultWithAlign scalafmt preset * Format all * Add scalafix * Remove unused imports * Don't lowercase username when inserting * Update readme * Listen on worldserver.Hostname address * Remove database test on startup It could fail when the global thread pool is busy loading zone maps. Migrations run on the main thread and also serve the purpose of verifying the database configuration so it's fine to remove the test altogether. * Refactor chat message handlers, zones What started as a small change to how zones are stored turned into a pretty big effort of refactoring the chat message handler. The !hack command was removed, the /capturebase commandwas added. * Expose db ports in docker-compose.yml * Silence property override log * Rework configuration * Unify configuration using the typesafe.config library * Add configuration option for public address * Configuration is now loaded from application.conf rather than worldserver.ini * Refactor PsLogin and remove unnecessary logging * Move pslogin into net.psforever.pslogin namespace * Fix coverage
2020-07-14 05:54:05 +02:00
(ams.DeployTime == 0) mustEqual false //not default
(ams.UndeployTime == 0) mustEqual false //not default
}
}
}
class DeploymentBehavior1Test extends ActorTest {
"Deployment" should {
"construct" in {
val obj = DeploymentTest.SetUpAgent
assert(obj.Actor != ActorRef.noSender)
assert(obj.DeploymentState == DriveState.Mobile)
}
}
}
class DeploymentBehavior2Test extends ActorTest {
"Deployment" should {
"change following a deployment cycle using TryDeploymentChange" in {
val obj = DeploymentTest.SetUpAgent
val probe = new TestProbe(system)
val eventsProbe = new TestProbe(system)
obj.Zone.VehicleEvents = eventsProbe.ref
assert(obj.DeploymentState == DriveState.Mobile)
//to Deploying
obj.Actor.tell(Deployment.TryDeploymentChange(DriveState.Deploying), probe.ref)
val reply1a = probe.receiveOne(Duration.create(500, "ms"))
assert(reply1a match {
case Deployment.CanDeploy(_, DriveState.Deploying) => true
case _ => false
})
val reply1b = eventsProbe.receiveOne(Duration.create(500, "ms"))
assert(reply1b match {
case VehicleServiceMessage(
"test",
VehicleAction.DeployRequest(_, PlanetSideGUID(1), DriveState.Deploying, 0, false, Vector3.Zero)
) =>
true
case _ => false
})
//to Deployed
val reply2 = eventsProbe.receiveOne(Duration.create(500, "ms"))
assert(reply2 match {
case VehicleServiceMessage(
"test",
VehicleAction.DeployRequest(_, PlanetSideGUID(1), DriveState.Deployed, 0, false, Vector3.Zero)
) =>
true
case _ => false
})
assert(obj.DeploymentState == DriveState.Deployed)
//to Undeploying
obj.Actor.tell(Deployment.TryDeploymentChange(DriveState.Undeploying), probe.ref)
val reply3a = probe.receiveOne(Duration.create(500, "ms"))
assert(reply3a match {
case Deployment.CanUndeploy(_, DriveState.Undeploying) => true
case _ => false
})
val reply3b = eventsProbe.receiveOne(Duration.create(500, "ms"))
assert(reply3b match {
case VehicleServiceMessage(
"test",
VehicleAction.DeployRequest(_, PlanetSideGUID(1), DriveState.Undeploying, 0, false, Vector3.Zero)
) =>
true
case _ => false
})
//to Mobile
val reply4 = eventsProbe.receiveOne(Duration.create(500, "ms"))
assert(reply4 match {
case VehicleServiceMessage(
"test",
VehicleAction.DeployRequest(_, PlanetSideGUID(1), DriveState.Mobile, 0, false, Vector3.Zero)
) =>
true
case _ => false
})
assert(obj.DeploymentState == DriveState.Mobile)
}
}
}
class DeploymentBehavior3Test extends ActorTest {
"Deployment" should {
"change following a deployment cycle using TryDeploy and TryUndeploy" in {
val obj = DeploymentTest.SetUpAgent
val probe = new TestProbe(system)
val eventsProbe = new TestProbe(system)
obj.Zone.VehicleEvents = eventsProbe.ref
assert(obj.DeploymentState == DriveState.Mobile)
//to Deploying
obj.Actor.tell(Deployment.TryDeploy(DriveState.Deploying), probe.ref)
val reply1a = probe.receiveOne(Duration.create(500, "ms"))
assert(reply1a match {
case Deployment.CanDeploy(_, DriveState.Deploying) => true
case _ => false
})
val reply1b = eventsProbe.receiveOne(Duration.create(500, "ms"))
assert(reply1b match {
case VehicleServiceMessage(
"test",
VehicleAction.DeployRequest(_, PlanetSideGUID(1), DriveState.Deploying, 0, false, Vector3.Zero)
) =>
true
case _ => false
})
//to Deployed
val reply2 = eventsProbe.receiveOne(Duration.create(500, "ms"))
assert(reply2 match {
case VehicleServiceMessage(
"test",
VehicleAction.DeployRequest(_, PlanetSideGUID(1), DriveState.Deployed, 0, false, Vector3.Zero)
) =>
true
case _ => false
})
assert(obj.DeploymentState == DriveState.Deployed)
//to Undeploying
obj.Actor.tell(Deployment.TryUndeploy(DriveState.Undeploying), probe.ref)
val reply3a = probe.receiveOne(Duration.create(500, "ms"))
assert(reply3a match {
case Deployment.CanUndeploy(_, DriveState.Undeploying) => true
case _ => false
})
val reply3b = eventsProbe.receiveOne(Duration.create(500, "ms"))
assert(reply3b match {
case VehicleServiceMessage(
"test",
VehicleAction.DeployRequest(_, PlanetSideGUID(1), DriveState.Undeploying, 0, false, Vector3.Zero)
) =>
true
case _ => false
})
//to Mobile
val reply4 = eventsProbe.receiveOne(Duration.create(500, "ms"))
assert(reply4 match {
case VehicleServiceMessage(
"test",
VehicleAction.DeployRequest(_, PlanetSideGUID(1), DriveState.Mobile, 0, false, Vector3.Zero)
) =>
true
case _ => false
})
assert(obj.DeploymentState == DriveState.Mobile)
}
}
}
class DeploymentBehavior4Test extends ActorTest {
"Deployment" should {
"not deploy to an out of order state" in {
val obj = DeploymentTest.SetUpAgent
assert(obj.DeploymentState == DriveState.Mobile)
obj.Actor ! Deployment.TryDeploymentChange(DriveState.Deployed)
val reply1 = receiveOne(Duration.create(100, "ms"))
assert(reply1.isInstanceOf[Deployment.CanNotChangeDeployment])
assert(reply1.asInstanceOf[Deployment.CanNotChangeDeployment].obj == obj)
assert(reply1.asInstanceOf[Deployment.CanNotChangeDeployment].to_state == DriveState.Deployed)
assert(obj.DeploymentState == DriveState.Mobile)
obj.Actor ! Deployment.TryDeploy(DriveState.Deployed)
val reply2 = receiveOne(Duration.create(100, "ms"))
assert(reply2.isInstanceOf[Deployment.CanNotChangeDeployment])
assert(reply2.asInstanceOf[Deployment.CanNotChangeDeployment].obj == obj)
assert(reply2.asInstanceOf[Deployment.CanNotChangeDeployment].to_state == DriveState.Deployed)
assert(obj.DeploymentState == DriveState.Mobile)
}
}
}
class DeploymentBehavior5Test extends ActorTest {
"Deployment" should {
"not deploy to an undeploy state" in {
val obj = DeploymentTest.SetUpAgent
assert(obj.DeploymentState == DriveState.Mobile)
obj.Actor ! Deployment.TryDeploymentChange(DriveState.Deploying)
receiveOne(Duration.create(100, "ms")) //consume
obj.Actor ! Deployment.TryDeploymentChange(DriveState.Deployed)
receiveOne(Duration.create(100, "ms")) //consume
assert(obj.DeploymentState == DriveState.Deployed)
obj.Actor ! Deployment.TryDeploy(DriveState.Undeploying)
val reply = receiveOne(Duration.create(100, "ms"))
assert(reply.isInstanceOf[Deployment.CanNotChangeDeployment])
assert(reply.asInstanceOf[Deployment.CanNotChangeDeployment].obj == obj)
assert(reply.asInstanceOf[Deployment.CanNotChangeDeployment].to_state == DriveState.Undeploying)
assert(obj.DeploymentState == DriveState.Deployed)
}
}
}
class DeploymentBehavior6Test extends ActorTest {
"Deployment" should {
"not undeploy to a deploy state" in {
val obj = DeploymentTest.SetUpAgent
assert(obj.DeploymentState == DriveState.Mobile)
obj.Actor ! Deployment.TryUndeploy(DriveState.Deploying)
val reply = receiveOne(Duration.create(100, "ms"))
assert(reply.isInstanceOf[Deployment.CanNotChangeDeployment])
assert(reply.asInstanceOf[Deployment.CanNotChangeDeployment].obj == obj)
assert(reply.asInstanceOf[Deployment.CanNotChangeDeployment].to_state == DriveState.Deploying)
assert(obj.DeploymentState == DriveState.Mobile)
}
}
}
object DeploymentTest {
class DeploymentObject extends PlanetSideServerObject with Deployment {
Persistence #1 featuring quill (#508) * Add .scalafmt.conf * Adopt quill for database access * Removed postgresql-async * Refactored all instances of database access * Creating duplicate characters of the same account is no longer possible * Rewrote large parts of LoginSessionActor * Implement migrations * Move overrides into subdirectory * Make usernames case insensitive * Use LOWER(?) comparison instead of storing lowercased username * import scala.util.{Success, Failure} * Add config and joda-time dependencies * Add sbt-scalafmt * Use defaultWithAlign scalafmt preset * Format all * Add scalafix * Remove unused imports * Don't lowercase username when inserting * Update readme * Listen on worldserver.Hostname address * Remove database test on startup It could fail when the global thread pool is busy loading zone maps. Migrations run on the main thread and also serve the purpose of verifying the database configuration so it's fine to remove the test altogether. * Refactor chat message handlers, zones What started as a small change to how zones are stored turned into a pretty big effort of refactoring the chat message handler. The !hack command was removed, the /capturebase commandwas added. * Expose db ports in docker-compose.yml * Silence property override log * Rework configuration * Unify configuration using the typesafe.config library * Add configuration option for public address * Configuration is now loaded from application.conf rather than worldserver.ini * Refactor PsLogin and remove unnecessary logging * Move pslogin into net.psforever.pslogin namespace * Fix coverage
2020-07-14 05:54:05 +02:00
def Faction: PlanetSideEmpire.Value = PlanetSideEmpire.NEUTRAL
def Definition = null
}
Persistence #1 featuring quill (#508) * Add .scalafmt.conf * Adopt quill for database access * Removed postgresql-async * Refactored all instances of database access * Creating duplicate characters of the same account is no longer possible * Rewrote large parts of LoginSessionActor * Implement migrations * Move overrides into subdirectory * Make usernames case insensitive * Use LOWER(?) comparison instead of storing lowercased username * import scala.util.{Success, Failure} * Add config and joda-time dependencies * Add sbt-scalafmt * Use defaultWithAlign scalafmt preset * Format all * Add scalafix * Remove unused imports * Don't lowercase username when inserting * Update readme * Listen on worldserver.Hostname address * Remove database test on startup It could fail when the global thread pool is busy loading zone maps. Migrations run on the main thread and also serve the purpose of verifying the database configuration so it's fine to remove the test altogether. * Refactor chat message handlers, zones What started as a small change to how zones are stored turned into a pretty big effort of refactoring the chat message handler. The !hack command was removed, the /capturebase commandwas added. * Expose db ports in docker-compose.yml * Silence property override log * Rework configuration * Unify configuration using the typesafe.config library * Add configuration option for public address * Configuration is now loaded from application.conf rather than worldserver.ini * Refactor PsLogin and remove unnecessary logging * Move pslogin into net.psforever.pslogin namespace * Fix coverage
2020-07-14 05:54:05 +02:00
private class DeploymentControl(obj: Deployment.DeploymentObject) extends Actor with DeploymentBehavior {
override def DeploymentObject = obj
Persistence #1 featuring quill (#508) * Add .scalafmt.conf * Adopt quill for database access * Removed postgresql-async * Refactored all instances of database access * Creating duplicate characters of the same account is no longer possible * Rewrote large parts of LoginSessionActor * Implement migrations * Move overrides into subdirectory * Make usernames case insensitive * Use LOWER(?) comparison instead of storing lowercased username * import scala.util.{Success, Failure} * Add config and joda-time dependencies * Add sbt-scalafmt * Use defaultWithAlign scalafmt preset * Format all * Add scalafix * Remove unused imports * Don't lowercase username when inserting * Update readme * Listen on worldserver.Hostname address * Remove database test on startup It could fail when the global thread pool is busy loading zone maps. Migrations run on the main thread and also serve the purpose of verifying the database configuration so it's fine to remove the test altogether. * Refactor chat message handlers, zones What started as a small change to how zones are stored turned into a pretty big effort of refactoring the chat message handler. The !hack command was removed, the /capturebase commandwas added. * Expose db ports in docker-compose.yml * Silence property override log * Rework configuration * Unify configuration using the typesafe.config library * Add configuration option for public address * Configuration is now loaded from application.conf rather than worldserver.ini * Refactor PsLogin and remove unnecessary logging * Move pslogin into net.psforever.pslogin namespace * Fix coverage
2020-07-14 05:54:05 +02:00
def receive = deployBehavior.orElse { case _ => }
}
Persistence #1 featuring quill (#508) * Add .scalafmt.conf * Adopt quill for database access * Removed postgresql-async * Refactored all instances of database access * Creating duplicate characters of the same account is no longer possible * Rewrote large parts of LoginSessionActor * Implement migrations * Move overrides into subdirectory * Make usernames case insensitive * Use LOWER(?) comparison instead of storing lowercased username * import scala.util.{Success, Failure} * Add config and joda-time dependencies * Add sbt-scalafmt * Use defaultWithAlign scalafmt preset * Format all * Add scalafix * Remove unused imports * Don't lowercase username when inserting * Update readme * Listen on worldserver.Hostname address * Remove database test on startup It could fail when the global thread pool is busy loading zone maps. Migrations run on the main thread and also serve the purpose of verifying the database configuration so it's fine to remove the test altogether. * Refactor chat message handlers, zones What started as a small change to how zones are stored turned into a pretty big effort of refactoring the chat message handler. The !hack command was removed, the /capturebase commandwas added. * Expose db ports in docker-compose.yml * Silence property override log * Rework configuration * Unify configuration using the typesafe.config library * Add configuration option for public address * Configuration is now loaded from application.conf rather than worldserver.ini * Refactor PsLogin and remove unnecessary logging * Move pslogin into net.psforever.pslogin namespace * Fix coverage
2020-07-14 05:54:05 +02:00
def SetUpAgent(implicit system: ActorSystem) = {
val obj = new DeploymentObject()
obj.GUID = PlanetSideGUID(1)
obj.Zone = Zone("test", new ZoneMap("test"), 1)
obj.Actor = system.actorOf(Props(classOf[DeploymentControl], obj), "test")
obj
}
}