Skip to main content
Version: 6.0-SNAPSHOT

Helper methods

The following tables document the helper methods available in Hazelcast. Member methods are available only when the test class inherits the respective support class, hence only in JUnit 4. Static methods can also be used in other frameworks.

Configuration helpers​

MethodStatic?OriginDescription
smallInstanceConfigyesHazelcastTestSupportReturns a compact Config with reduced threads but with Jet and metrics enabled.
smallInstanceConfigWithoutJetAndMetricsyesHazelcastTestSupportReturns a compact Config with Jet and metrics disabled and minimal threads.
shrinkInstanceConfigyesHazelcastTestSupportApplies minimal threads, with Jet and metrics enabled, to a given Config.
regularInstanceConfigyesHazelcastTestSupportReturns a default Config with Jet enabled.
withoutNetworkJoinyesHazelcastTestSupportModifies a given Config to disable all network join mechanisms (TCP/IP and autodetection).

Threading and concurrency utilities​

MethodStatic?OriginDescription
spawnyesHazelcastTestSupportRuns a RunnableEx, Runnable, or Callable in a new thread, returning a Future.
interruptCurrentThreadyesHazelcastTestSupportSchedules an interrupt of the current thread after a specified delay.

Sleep and timing helpers​

MethodStatic?OriginDescription
sleepMillisyesHazelcastTestSupportSleeps for the specified number of milliseconds, swallowing interruptions.
sleepSecondsyesHazelcastTestSupportSleeps for the specified number of seconds.
sleepAtMostSecondsyesHazelcastTestSupportSleeps up to a target end time, warning if already past.
sleepAndStopyesHazelcastTestSupportSleeps up to a duration unless an AtomicBoolean flag is set, then sets it.
sleepAtLeastMillisyesHazelcastTestSupportGuarantees sleeping at least the given milliseconds, even across interrupts.
sleepAtLeastSecondsyesHazelcastTestSupportAlias in seconds for sleepAtLeastMillis.

Random data and names​

MethodStatic?OriginDescription
generateRandomStringyesHazelcastTestSupportBuilds a random lowercase ASCII string of given length.
randomStringyesHazelcastTestSupportReturns a new unsecure UUID string.
randomMapNameyesHazelcastTestSupportReturns a random UUID string as a map name (with optional prefix).
randomNameyesHazelcastTestSupportAlias for randomString().

Partition and key generation​

MethodStatic?OriginDescription
randomNameOwnedByyesHazelcastTestSupportGenerates a random key whose partition is owned by the local member (with optional prefix).
randomPartitionOwnedByyesHazelcastTestSupportPicks a random partition that is locally owned by a given instance.
generateKeyOwnedBy / generateKeyNotOwnedByyesHazelcastTestSupportGenerates a key owned (or not) by the local member.
generateKeyForPartitionyesHazelcastTestSupportGenerates a key mapping to a specific partition ID (with optional prefix).
generateKeysBelongingToSamePartitionsOwnedBynoHazelcastTestSupportGenerates multiple keys all belonging to the same owned partition.

Partition table and safe-state​

MethodStatic?OriginDescription
warmUpPartitionsyesHazelcastTestSupportForces partition table initialization on instances.
isInstanceInSafeStateyesHazelcastTestSupportChecks whether a single instance's partition state is safe.
isClusterInSafeStateyesHazelcastTestSupportChecks whether the entire cluster is in a safe partition state.
isAllInSafeStateyesHazelcastTestSupportVerifies that all instances in a collection are safe.
waitInstanceForSafeState / waitClusterForSafeState / waitAllForSafeStateyesHazelcastTestSupportBlocks until instance(s) reach safe state, with retry assertions.
assertAllInSafeStateyesHazelcastTestSupportAsserts (throws) if any instance is not in safe state.

Cluster assertions​

MethodStatic?OriginDescription
assertNoRunningInstancesyesHazelcastTestSupportAsserts that no Hazelcast server instances remain.
assertNoRunningClientInstancesyesHazelcastTestSupportAsserts that no Hazelcast client instances remain.
assertClusterSize / assertClusterSizeEventuallyyesHazelcastTestSupportAsserts cluster size immediately or eventually within timeout.
assertMasterAddress / assertMasterAddressEventuallyyesHazelcastTestSupportAsserts that all instances agree on the master address.
assertClusterState / assertClusterStateEventuallyyesHazelcastTestSupportAsserts the cluster state immediately or eventually.

General assertions​

MethodStatic?OriginDescription
assertContains / assertNotContains / assertContainsAll / assertNotContainsAllyesHazelcastTestSupportCollection- and string-based containment assertions.
assertStartsWithyesHazelcastTestSupportAsserts that one string starts with another (ComparisonFailure on fail).
assertPropertiesEqualsyesHazelcastTestSupportAsserts two Properties objects have identical keys and values.
assertInstanceOfyesHazelcastTestSupportAsserts and casts an object to a given class.
assertIterableEqualsyesHazelcastTestSupportAsserts an Iterable yields exactly the expected elements in order.

Time-bound assertions​

MethodStatic?OriginDescription
assertCompletesEventuallyyesHazelcastTestSupportWaits for a Future/FutureTask to complete within timeout.
assertSizeEventually / assertEqualsEventuallyyesHazelcastTestSupportWaits until collections, maps, or values reach expected state.
assertTrueEventually / assertFalseEventuallyyesHazelcastTestSupportRetries assertions until success or failure within timeout.
assertTrueDelayedyesHazelcastTestSupportDelays for a fixed period, then asserts.
assertTrueAllTheTime / assertTrueFiveSecondsyesHazelcastTestSupportContinuously asserts a predicate over a duration.
assertCountEventually / assertAtomicEventuallyyesHazelcastTestSupportWaits for latch or atomic to reach an expected value.

Specialized assertions​

MethodStatic?OriginDescription
assertUtilityConstructoryesHazelcastTestSupportVerifies a utility class has exactly one private constructor.
assertEnumCoverageyesHazelcastTestSupportAsserts all enum values are handled via valueOf.
assertThrowsyesHazelcastTestSupportAsserts that a given runnable throws a specific exception type.
assertBetween / assertGreaterOrEqualsyesHazelcastTestSupportNumeric-range assertions.
assertExactlyOneSuccessfulRunyesHazelcastTestSupportRetries a task until exactly one run succeeds or times out.
assertWaitingOperationCountEventuallyyesHazelcastTestSupportWaits until the parked operation count reaches an expected value.

Connection and membership​

MethodStatic?OriginDescription
closeConnectionBetweenyesHazelcastTestSupportSimulates network failure by closing connections between two instances.
suspectMemberyesHazelcastTestSupportMarks one node as suspected by another, optionally with a reason.

Reflection and cleanup​

MethodStatic?OriginDescription
getFieldValueyesHazelcastTestSupportReflectively retrieves a private field's value from an object or class.
destroyAllDistributedObjectsyesHazelcastTestSupportIterates over and destroys every DistributedObject on a given instance.

JUnit assumptions​

MethodStatic?OriginDescription
assumeThatNoWindowsOSyesHazelcastTestSupportAssumes the test is not running on Windows.
assumeThatLinuxOSyesHazelcastTestSupportAssumes Linux platform.
assumeNoArm64ArchitectureyesHazelcastTestSupportAssumes non-ARM64 architecture.

File and directory utilities​

MethodStatic?OriginDescription
appendToFileyesJetTestSupportAppends one or more lines to an existing file, creating it if needed.
createTempDirectoryyesJetTestSupportCreates a temporary directory (deleted on JVM exit) and returns its File.

Jet configuration helpers​

MethodStatic?OriginDescription
smallInstanceWithResourceUploadConfigyesJetTestSupportReturns a small default Config with Jet resource-upload enabled.
defaultInstanceConfigWithJetEnabledyesJetTestSupportReturns a default Config with Jet enabled (no thread reduction).

Cluster cleanup and job teardown​

MethodStatic?OriginDescription
ditchJobyesJetTestSupportCancels a job and waits until it is no longer running on any member.
cancelAndJoinyesJetTestSupportCancels a job and asserts that its join() throws CancellationException.

Pipeline utilities​

MethodStatic?OriginDescription
processorFromPipelineSourceyesJetTestSupportExtracts the internal ProcessorMetaSupplier from a BatchSource pipeline stage.
awaitSingleRunningJobyesJetTestSupportWaits until exactly one Jet job is in RUNNING state and returns it.

TestHazelcastFactory utilities​

MethodStatic?OriginDescription
getCountnoTestHazelcastInstanceFactoryReturns the configured number of nodes/addresses.
newHazelcastInstancenoTestHazelcastInstanceFactoryCreates a new server instance using default or mock-network context. Various overloads available.
createAddressOrNullyesTestHazelcastInstanceFactoryAttempts to build an Address, returning null on UnknownHostException.
nextAddress()noTestHazelcastInstanceFactoryReturns the next pre-allocated or newly minted Address on default port.
nextAddress(int)noTestHazelcastInstanceFactoryReturns the next Address starting at a given initial port.
newInstancesnoTestHazelcastInstanceFactoryCreates as many instances as count using default or provided Config. Various overloads available.
newInstancesParallelnoTestHazelcastInstanceFactoryCreates nodeCount instances in parallel, each with its own address and config.
getAllHazelcastInstancesnoTestHazelcastInstanceFactoryReturns all live instances, mock-network or real.
getKnownAddressesnoTestHazelcastInstanceFactoryReturns the unmodifiable list of all addresses this factory manages.
terminate(HazelcastInstance)noTestHazelcastInstanceFactoryTerminates one instance and removes it from registry if mock-network.
shutdownAll()noTestHazelcastInstanceFactoryShuts down all instances; clears registry or calls Hazelcast.shutdownAll().
terminateAll()noTestHazelcastInstanceFactoryTerminates all instances; stops registry or calls HazelcastInstanceFactory.terminateAll().
newHazelcastClientnoTestHazelcastFactoryCreates a new client in the mock-network setup. Various overloads available.
getHazelcastClientByName(String)noTestHazelcastFactoryRetrieves a previously created client proxy by its name.
shutdownAllMembers()noTestHazelcastFactoryShuts down all server members via parent shutdownAll().
shutdownAll()noTestHazelcastFactoryShuts down all clients (mock-network or real) then all members.
terminateAll()noTestHazelcastFactoryTerminates all clients then all members.