Versions Compared

Key

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

...

  • Awaitility -- await for some state to change
  • CountDownLatch -- coordinate between VMs and/or threads
  • Mockito Spy and Verify
    • Verify with timeout can be used instead of Awaitility
    • Wrap anything with spy or use it to implement a callback such as CacheListener
    • Verify is used to validate number of invocations with optional timeout
  • All timeouts should use GeodeAwaitility.getTimeout()
  • Possible exceptions to the rule
    • Busy waiting in loops (Awaitility is usually a better option than custom looping)
    • Slow receiver/listener type testing (there’s probably a better way to do it)

Examples: SleepDistributedTest, MultiThreadedIntegrationTest

It’s not polite to eat all the exceptions...

...

  • Use ExecutorServiceRule or DistributedExcutorServiceRule
    • Provides debugging support for hangs
    • Cleans up threads on tear down
    • Test task code should be interruptible
  • Use Future or CompletableFuture for submitted runnable/callable
  • Always invoke get() on any Future or CompletableFuture

Examples: AsyncErrorHandlingTest, ExecutorSyncHangIntegrationTest, ExecutorLockHangIntegrationTest, ExecutorErrorHandlingDistributedTest

Handling exceptions in callbacks

  • Avoid catching exception and setting some test state to check later
  • Use ErrorCollector in unit and integration tests
  • Use SharedErrorCollector in distributed tests

Examples: AsyncErrorHandlingIntegrationTest, AsyncErrorHandlingDistributedTest

AsyncInvocation usage

  • Timeout now gets a remote stack trace to use as the cause and dumps stack traces for that JVM’s threads
  • Always use await() or get()
    • Both check and throw any remote exceptions
    • Both use GeodeAwaitility Timeout and will throw TimeoutException if it’s exceeded
  • Use await() for Void types and get() when expecting a non-null value

Examples: AsyncInvocationDistributedTest, AsyncInvocationHangDistributedTest

Know your DUnit Rules

...