Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Should use JUnit 4 syntax
  • File name ends with *DistributedTest or *DUnitTest
  • Should use Category annotation DistributedTest
  • Should generally complete in seconds
  • May test interactions between multiple JVMs in a Geode cluster or via networking or via file system
  • Typically uses black-box testing but may include some white-box testing and helps guarantee external quality (feature delivers value to User)
  • A DistributedTest may do any of the following:
    • communicate across the network
    • access the file system
    • require anything special in the environment (such as editing config files or running an external process

Additional notesMost DistributedTests use lambdas to invoke SerializableRunnables or SerializableCallables on additional JVMs. Depending on the exact syntax of the lambda, the test class itself may be serialized, so you need to have the test implement Serializable. Non-serializable fields on the test will need to either be transient or serializable.

If you write an DistributedTest to expose a bug and then confirm its fix, then you should name it with the suffix *RegressionTest. Otherwise you should use the suffix *DistributedTest or *DUnitTest.

...

  • JUnitParams – provides test method parameterization (usually better to use than JUnit 4 Parameterized)
  • System Rules – powerful set of JUnit 4 Rules
    • RestoreSystemProperties
  • Awaitility – useful for awaiting asynchronous conditions

Custom Geode JUnit 4 Rules

...

  • ExecutorServiceRule – provides ExecutorService for concurrent testing
  • ExpectedTimeoutRule – verifies that an API times out and potentially throws TimeoutException
  • JarFileRule – creates a Jar file in an internal TemporaryFolder containing a dynamically generated class
  • RequiresGeodeHome – asserts precondition that GEODE_HOME system property is specified
  • RestoreLocaleRule – restores JVM to original Locale
  • RestoreTCCLRule – restores Thread Context Class Loader
  • RetryRule – retries a test until it passes or exceeds specified number of retries
  • TemporaryFileRule – destroys specified files or directories that aren't created in a TemporaryFolder
  • UseJacksonForJsonPathRule – specifies that JsonPath should use Jackson instead of its default JSON library
  • GfshRule – allows use of Gfsh script string to fork a JVM process in an IntegrationTest

Custom Geode JUnit 4 Rules For DUnit

  • DistributedTestRule – launches the DUnit VMs
  • CacheRule – simple Cache creation and reference for all DUnit VMs
  • ClusterStartupRule – creates Server or Locator in any DUnit VM
  • DistributedDisconnectRule – disconnects all DUnit VMs
  • DistributedRestoreSystemProperties – extends RestoreSystemProperties for all DUnit VMs
  • DistributedUseJacksonForJsonPathRule – extends UseJacksonForJsonPathRule for all DUnit VMs
  • SerializableTestName – extends TestName to be serializable
  • SharedCountersRule – shared counter API for all DUnit VMs
  • SharedErrorCollector – extends ErrorCollector for all DUnit VMs

Custom Geode DUnit API Classes

  • AsyncInvocation – return type from VM#invokeAsync and implements Future
  • Disconnect – disconnect in all or specified VM
  • Host – provides the DUnit VMs
  • VM – provides invocation API for a DUnit VM

Custom Geode DUnit TestCases

  • DistributedTestCase – extend this class for an old-school DUnit test
  • CacheTestCase – adds Cache API to DistributedTestCase

Examples of actual tests

Examples of some good DistributedTests:

...