Integration Testing with Scalatest
Author | Product Version | Reference | Download |
---|---|---|---|
Jason Nerothin | 9.7.2 | i10n-testing-example |
Overview
We describe here a technique for implementing a GigaSpaces integration (i10n) test using a scalatest FunSuite.
Usage
We provide an abstract FunSuite
that is a BeforeAndAfterAllConfigMap
in this gist. Simply implemented, the subclass need only provide a small number of properties and a Spring context file. The superclass uses this information to seed a ConfigMap
, which then configures a nested ProcessingUnitContainerProvider
, which in turn provisions a protected GigaSpace
proxy.
Here's example configuration from a working example that tests against an embedded Space Where GigaSpaces data is stored. It is the logical cache that holds data objects in memory and might also hold them in layered in tiering. Data is hosted from multiple SoRs, consolidated as a unified data model.:
// "defaults" is a protected member, and is
// the only required configuration necessary to
// successfully initialize the FunSuite.
defaults = Map[String, Any](
schemaProperty -> "partitioned-sync2backup"
, numInstancesProperty -> int2Integer(numPartitions)
, numBackupsProperty -> int2Integer(0)
, instanceIdProperty -> int2Integer(1)
, spaceUrlProperty -> s"jini:/*/*/$spaceName" // spaceName is a class member
, spaceModeProperty -> SpaceMode.Remote
, configLocationProperty -> "classpath*:/META-INF/Spring/pu This is the unit of packaging and deployment in the GigaSpaces Data Grid, and is essentially the main GigaSpaces service. The Processing Unit (PU) itself is typically deployed onto the Service Grid. When a Processing Unit is deployed, a Processing Unit instance is the actual runtime entity..xml"
, localViewQueryListProperty -> List[SQLQuery[_]]()
)
The number of backups per partition is zero or one.
In this example, the test code truly is an integration test - designed to run against a running data grid. (Note the reference to pu.xml file, which is available on the test classpath.)
We could as easily have run in-process by using SpaceMode.Embedded
. This makes IDE Integrated Development Environment.
A software application that helps programmers develop software code efficiently. It increases developer productivity by combining capabilities such as software editing, building, testing, and packaging in an easy-to-use application. Example: DBeaver.-driven debugging easier, as it does not incur the workflow overhead of setting up a remote agent or debugger. Here's the code from another working example:
defaults = Map[String, Any](
schemaProperty -> "partitioned-sync2backup"
, numInstancesProperty -> int2Integer(numPartitions)
, numBackupsProperty -> int2Integer(0)
, instanceIdProperty -> int2Integer(1) // count begins at 1
, spaceUrlProperty -> s"/./$spaceName" // spaceName is a class member
, spaceModeProperty -> SpaceMode.Embedded
, configLocationProperty -> "classpath*:/META-INF/Spring/pu.xml"
, localViewQueryListProperty -> List[SQLQuery[_]]()
)
The number of backups per partition is zero or one.
All SpaceModes
supported by data gridare enumerated in the abstract FunSuite class (gisted above). For each mode, corresponding configuration can be provided through the defaults
property.
object SpaceMode extends Enumeration {
type SpaceMode = Value
val Embedded, Remote, LocalCache, LocalView = Value
}
An end-to-end example can be forked from here.
Considerations
- Running multiple partitions from within an i10n test cannot be run with a XAP GigaSpaces eXtreme Application Platform.
Provides a powerful solution for data processing, launching, and running digital services Lite license.
- The working examples presented here uses gradle as a build tool. The code could as easily be used from sbt or the scalatest maven plugin.