public final class TestSupport extends Object
The test process does the following:
Processor.init()
Processor.process(0, inbox). The inbox always contains one item
from input parameter
optionally calls Processor.complete()
until it returns true or calls it until specified timeout elapses (for streaming sources)
complete()
method returned false and made a progress
optional snapshot+restore test procedure:
saveToSnapshot() is called. If we are not doing restore, this
is the last step.
restoreFromSnapshot()
finishSnapshotRestore() is called
For each call to any processing method the progress is asserted (optional). The processor must do at least one
of these:
true is
considered as making progress
process(). This will test the edge case: the
process() method is called even when the outbox is full to give
the processor a chance to process the inbox. The snapshot bucket will
also have capacity of 1.
cooperativeTimeout(long).
Processor.tryProcess().
TestSupport.verifyProcessor(Processors.map((String s) -> s.toUpperCase()))
.disableCompleteCall() // enabled by default
.disableLogging() // enabled by default
.disableProgressAssertion() // enabled by default
.disableSnapshots() // enabled by default
.cooperativeTimeout(<timeoutInMs>) // default is 1000
.outputChecker(<function>) // default is `Objects::equal`
.input(asList("foo", "bar")) // default is `emptyList()`
.expectOutput(asList("FOO", "BAR"));
| Modifier and Type | Method and Description |
|---|---|
TestSupport |
cooperativeTimeout(long timeout)
If
timeout > 0, the test will fail if any call to processing
method in a cooperative processor exceeds this timeout. |
TestSupport |
disableCompleteCall()
Disables calling
complete() method during the test. |
TestSupport |
disableLogging()
Disables logging of input and output objects.
|
TestSupport |
disableProgressAssertion()
Disables checking of progress of processing methods (see
class javadoc for information on what is "progress"). |
TestSupport |
disableRunUntilCompleted(long timeoutMillis)
If the timeout > 0, the
complete() method is called repeatedly
until the timeout elapses. |
TestSupport |
disableSnapshots()
Disable snapshot save and restore before first item and after each
process() and complete() call. |
static <T> void |
drainOutbox(Queue<T> outboxBucket,
Collection<? super T> target,
boolean logItems)
Move all items from the outbox to the
target list and make the
outbox available to accept more items. |
void |
expectOutput(List<?> expectedOutput)
Sets the expected output and runs the test.
|
TestSupport |
input(List<?> input)
Sets the input objects for processor.
|
TestSupport |
outputChecker(java.util.function.BiPredicate<? super List<?>,? super List<?>> outputChecker)
Predicate to compare expected and actual output.
|
static java.util.function.Supplier<Processor> |
supplierFrom(ProcessorMetaSupplier supplier)
Wraps the provided
ProcessorMetaSupplier with a Supplier<Processor> that returns processors obtained from it. |
static java.util.function.Supplier<Processor> |
supplierFrom(ProcessorSupplier supplier)
Wraps the provided
ProcessorSupplier with a Supplier<Processor> that returns processors obtained from it. |
static TestSupport |
verifyProcessor(Processor processor) |
static TestSupport |
verifyProcessor(ProcessorMetaSupplier supplier) |
static TestSupport |
verifyProcessor(ProcessorSupplier supplier) |
static TestSupport |
verifyProcessor(java.util.function.Supplier<Processor> supplier) |
public static TestSupport verifyProcessor(Processor processor)
processor - a processor instance to test. disableSnapshots()
will be set to false, because can't have new instance after each
restore.public static TestSupport verifyProcessor(@Nonnull java.util.function.Supplier<Processor> supplier)
supplier - a processor supplier create processor instancespublic static TestSupport verifyProcessor(@Nonnull ProcessorSupplier supplier)
supplier - a processor supplier create processor instancespublic static TestSupport verifyProcessor(@Nonnull ProcessorMetaSupplier supplier)
supplier - a processor supplier create processor instancespublic TestSupport input(@Nonnull List<?> input)
Defaults to empty list.
this instance for fluent API.public void expectOutput(@Nonnull List<?> expectedOutput)
AssertionError - If some assertion does not hold.public TestSupport disableProgressAssertion()
class javadoc for information on what is "progress").this instance for fluent API.public TestSupport disableRunUntilCompleted(long timeoutMillis)
complete() method is called repeatedly
until the timeout elapses. After that, the output is compared using
output checker. The complete() method is also not allowed to return true in this
case. This setting is useful for testing of streaming sources.
If the timeout is <= 0 (the default), complete() method is
called until it returns true, after which the output is checked.
Has no effect if complete() call is disabled.
timeoutMillis - how long to wait until outputs matchthis instance for fluent API.public TestSupport disableSnapshots()
process() and complete() call.this instance for fluent API.public TestSupport disableLogging()
this instance for fluent API.public TestSupport disableCompleteCall()
complete() method during the test. Suitable for
testing of streaming processors to make sure that the flushing code in
complete() method is not executed.this instance for fluent API.public TestSupport cooperativeTimeout(long timeout)
timeout > 0, the test will fail if any call to processing
method in a cooperative processor exceeds this timeout. Has no effect
for non-cooperative processors.
Default value is COOPERATIVE_TIME_LIMIT_MS_FAIL ms. Useful to
set to 0 during debugging.
this instance for fluent API.public TestSupport outputChecker(@Nonnull java.util.function.BiPredicate<? super List<?>,? super List<?>> outputChecker)
Defaults to Objects::equals
this instance for fluent API.public static <T> void drainOutbox(Queue<T> outboxBucket, Collection<? super T> target, boolean logItems)
target list and make the
outbox available to accept more items.outboxBucket - the queue from Outbox to draintarget - target listlogItems - whether to log drained items to System.outpublic static java.util.function.Supplier<Processor> supplierFrom(ProcessorSupplier supplier)
ProcessorSupplier with a Supplier<Processor> that returns processors obtained from it.public static java.util.function.Supplier<Processor> supplierFrom(ProcessorMetaSupplier supplier)
ProcessorMetaSupplier with a Supplier<Processor> that returns processors obtained from it.Copyright © 2017 Hazelcast, Inc.. All Rights Reserved.