This is a prerelease version.

View latest

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

Method Static? Origin Description

smallInstanceConfig

yes

HazelcastTestSupport

Returns a compact Config with reduced threads but with Jet and metrics enabled.

smallInstanceConfigWithoutJetAndMetrics

yes

HazelcastTestSupport

Returns a compact Config with Jet and metrics disabled and minimal threads.

shrinkInstanceConfig

yes

HazelcastTestSupport

Applies minimal threads, with Jet and metrics enabled, to a given Config.

regularInstanceConfig

yes

HazelcastTestSupport

Returns a default Config with Jet enabled.

withoutNetworkJoin

yes

HazelcastTestSupport

Modifies a given Config to disable all network join mechanisms (TCP/IP and autodetection).

Threading and concurrency utilities

Method Static? Origin Description

spawn

yes

HazelcastTestSupport

Runs a RunnableEx, Runnable, or Callable in a new thread, returning a Future.

interruptCurrentThread

yes

HazelcastTestSupport

Schedules an interrupt of the current thread after a specified delay.

Sleep and timing helpers

Method Static? Origin Description

sleepMillis

yes

HazelcastTestSupport

Sleeps for the specified number of milliseconds, swallowing interruptions.

sleepSeconds

yes

HazelcastTestSupport

Sleeps for the specified number of seconds.

sleepAtMostSeconds

yes

HazelcastTestSupport

Sleeps up to a target end time, warning if already past.

sleepAndStop

yes

HazelcastTestSupport

Sleeps up to a duration unless an AtomicBoolean flag is set, then sets it.

sleepAtLeastMillis

yes

HazelcastTestSupport

Guarantees sleeping at least the given milliseconds, even across interrupts.

sleepAtLeastSeconds

yes

HazelcastTestSupport

Alias in seconds for sleepAtLeastMillis.

Random data and names

Method Static? Origin Description

generateRandomString

yes

HazelcastTestSupport

Builds a random lowercase ASCII string of given length.

randomString

yes

HazelcastTestSupport

Returns a new unsecure UUID string.

randomMapName

yes

HazelcastTestSupport

Returns a random UUID string as a map name (with optional prefix).

randomName

yes

HazelcastTestSupport

Alias for randomString().

Partition and key generation

Method Static? Origin Description

randomNameOwnedBy

yes

HazelcastTestSupport

Generates a random key whose partition is owned by the local member (with optional prefix).

randomPartitionOwnedBy

yes

HazelcastTestSupport

Picks a random partition that is locally owned by a given instance.

generateKeyOwnedBy / generateKeyNotOwnedBy

yes

HazelcastTestSupport

Generates a key owned (or not) by the local member.

generateKeyForPartition

yes

HazelcastTestSupport

Generates a key mapping to a specific partition ID (with optional prefix).

generateKeysBelongingToSamePartitionsOwnedBy

no

HazelcastTestSupport

Generates multiple keys all belonging to the same owned partition.

Partition table and safe-state

Method Static? Origin Description

warmUpPartitions

yes

HazelcastTestSupport

Forces partition table initialization on instances.

isInstanceInSafeState

yes

HazelcastTestSupport

Checks whether a single instance’s partition state is safe.

isClusterInSafeState

yes

HazelcastTestSupport

Checks whether the entire cluster is in a safe partition state.

isAllInSafeState

yes

HazelcastTestSupport

Verifies that all instances in a collection are safe.

waitInstanceForSafeState / waitClusterForSafeState / waitAllForSafeState

yes

HazelcastTestSupport

Blocks until instance(s) reach safe state, with retry assertions.

assertAllInSafeState

yes

HazelcastTestSupport

Asserts (throws) if any instance is not in safe state.

Cluster assertions

Method Static? Origin Description

assertNoRunningInstances

yes

HazelcastTestSupport

Asserts that no Hazelcast server instances remain.

assertNoRunningClientInstances

yes

HazelcastTestSupport

Asserts that no Hazelcast client instances remain.

assertClusterSize / assertClusterSizeEventually

yes

HazelcastTestSupport

Asserts cluster size immediately or eventually within timeout.

assertMasterAddress / assertMasterAddressEventually

yes

HazelcastTestSupport

Asserts that all instances agree on the master address.

assertClusterState / assertClusterStateEventually

yes

HazelcastTestSupport

Asserts the cluster state immediately or eventually.

General assertions

Method Static? Origin Description

assertContains / assertNotContains / assertContainsAll / assertNotContainsAll

yes

HazelcastTestSupport

Collection- and string-based containment assertions.

assertStartsWith

yes

HazelcastTestSupport

Asserts that one string starts with another (ComparisonFailure on fail).

assertPropertiesEquals

yes

HazelcastTestSupport

Asserts two Properties objects have identical keys and values.

assertInstanceOf

yes

HazelcastTestSupport

Asserts and casts an object to a given class.

assertIterableEquals

yes

HazelcastTestSupport

Asserts an Iterable yields exactly the expected elements in order.

Time-bound assertions

Method Static? Origin Description

assertCompletesEventually

yes

HazelcastTestSupport

Waits for a Future/FutureTask to complete within timeout.

assertSizeEventually / assertEqualsEventually

yes

HazelcastTestSupport

Waits until collections, maps, or values reach expected state.

assertTrueEventually / assertFalseEventually

yes

HazelcastTestSupport

Retries assertions until success or failure within timeout.

assertTrueDelayed

yes

HazelcastTestSupport

Delays for a fixed period, then asserts.

assertTrueAllTheTime / assertTrueFiveSeconds

yes

HazelcastTestSupport

Continuously asserts a predicate over a duration.

assertCountEventually / assertAtomicEventually

yes

HazelcastTestSupport

Waits for latch or atomic to reach an expected value.

Specialized assertions

Method Static? Origin Description

assertUtilityConstructor

yes

HazelcastTestSupport

Verifies a utility class has exactly one private constructor.

assertEnumCoverage

yes

HazelcastTestSupport

Asserts all enum values are handled via valueOf.

assertThrows

yes

HazelcastTestSupport

Asserts that a given runnable throws a specific exception type.

assertBetween / assertGreaterOrEquals

yes

HazelcastTestSupport

Numeric-range assertions.

assertExactlyOneSuccessfulRun

yes

HazelcastTestSupport

Retries a task until exactly one run succeeds or times out.

assertWaitingOperationCountEventually

yes

HazelcastTestSupport

Waits until the parked operation count reaches an expected value.

Connection and membership

Method Static? Origin Description

closeConnectionBetween

yes

HazelcastTestSupport

Simulates network failure by closing connections between two instances.

suspectMember

yes

HazelcastTestSupport

Marks one node as suspected by another, optionally with a reason.

Reflection and cleanup

Method Static? Origin Description

getFieldValue

yes

HazelcastTestSupport

Reflectively retrieves a private field’s value from an object or class.

destroyAllDistributedObjects

yes

HazelcastTestSupport

Iterates over and destroys every DistributedObject on a given instance.

JUnit assumptions

Method Static? Origin Description

assumeThatNoWindowsOS

yes

HazelcastTestSupport

Assumes the test is not running on Windows.

assumeThatLinuxOS

yes

HazelcastTestSupport

Assumes Linux platform.

assumeNoArm64Architecture

yes

HazelcastTestSupport

Assumes non-ARM64 architecture.

File and directory utilities

Method Static? Origin Description

appendToFile

yes

JetTestSupport

Appends one or more lines to an existing file, creating it if needed.

createTempDirectory

yes

JetTestSupport

Creates a temporary directory (deleted on JVM exit) and returns its File.

Jet configuration helpers

Method Static? Origin Description

smallInstanceWithResourceUploadConfig

yes

JetTestSupport

Returns a small default Config with Jet resource-upload enabled.

defaultInstanceConfigWithJetEnabled

yes

JetTestSupport

Returns a default Config with Jet enabled (no thread reduction).

Cluster cleanup and job teardown

Method Static? Origin Description

ditchJob

yes

JetTestSupport

Cancels a job and waits until it is no longer running on any member.

cancelAndJoin

yes

JetTestSupport

Cancels a job and asserts that its join() throws CancellationException.

Pipeline utilities

Method Static? Origin Description

processorFromPipelineSource

yes

JetTestSupport

Extracts the internal ProcessorMetaSupplier from a BatchSource pipeline stage.

awaitSingleRunningJob

yes

JetTestSupport

Waits until exactly one Jet job is in RUNNING state and returns it.

TestHazelcastFactory utilities

Method Static? Origin Description

getCount

no

TestHazelcastInstanceFactory

Returns the configured number of nodes/addresses.

newHazelcastInstance

no

TestHazelcastInstanceFactory

Creates a new server instance using default or mock-network context. Various overloads available.

createAddressOrNull

yes

TestHazelcastInstanceFactory

Attempts to build an Address, returning null on UnknownHostException.

nextAddress()

no

TestHazelcastInstanceFactory

Returns the next pre-allocated or newly minted Address on default port.

nextAddress(int)

no

TestHazelcastInstanceFactory

Returns the next Address starting at a given initial port.

newInstances

no

TestHazelcastInstanceFactory

Creates as many instances as count using default or provided Config. Various overloads available.

newInstancesParallel

no

TestHazelcastInstanceFactory

Creates nodeCount instances in parallel, each with its own address and config.

getAllHazelcastInstances

no

TestHazelcastInstanceFactory

Returns all live instances, mock-network or real.

getKnownAddresses

no

TestHazelcastInstanceFactory

Returns the unmodifiable list of all addresses this factory manages.

terminate(HazelcastInstance)

no

TestHazelcastInstanceFactory

Terminates one instance and removes it from registry if mock-network.

shutdownAll()

no

TestHazelcastInstanceFactory

Shuts down all instances; clears registry or calls Hazelcast.shutdownAll().

terminateAll()

no

TestHazelcastInstanceFactory

Terminates all instances; stops registry or calls HazelcastInstanceFactory.terminateAll().

newHazelcastClient

no

TestHazelcastFactory

Creates a new client in the mock-network setup. Various overloads available.

getHazelcastClientByName(String)

no

TestHazelcastFactory

Retrieves a previously created client proxy by its name.

shutdownAllMembers()

no

TestHazelcastFactory

Shuts down all server members via parent shutdownAll().

shutdownAll()

no

TestHazelcastFactory

Shuts down all clients (mock-network or real) then all members.

terminateAll()

no

TestHazelcastFactory

Terminates all clients then all members.