metafacture / metafacture-core

Core package of the Metafacture tool suite for metadata processing.
https://metafacture.org
Apache License 2.0
69 stars 34 forks source link

Provide common test helpers. #407

Open blackwinter opened 2 years ago

blackwinter commented 2 years ago

As mentioned in #386, it would be nice to be able to reuse the stream test pattern (cf. #339) across modules. Currently metamorph and metafacture-mangling make use of it, plus metafacture-yaml once #400 is accepted. There are more candidates that could potentially benefit from it.

I'd like to propose metafacture-test as a new module, with org.metafacture.test.StreamTestHelpers (or maybe org.metafacture.test.helpers.StreamTest) as a starting point. There's always the possibility to extract more test patterns in the future.

It would be a testImplementation dependency for the aforementioned modules.

Would something like this be acceptable? (See also the brief discussion in #386.)

P.S.: While at it, it might make sense to configure test logging (showStandardStreams = true and exceptionFormat = 'full') globally for all subprojects. Unwanted output should be suppressed or otherwise dealt with.

org.metafacture.flowcontrol.ObjectExceptionCatcherTest > shouldCatchException STANDARD_ERROR
    [Test worker] ERROR org.metafacture.flowcontrol.ObjectExceptionCatcher - 'Exception Message' while processing object: data

org.metafacture.flowcontrol.ObjectThreaderTest > shouldSplitAllObjectsToAllThreadedDownStreamReceivers STANDARD_ERROR
    [Test worker] INFO org.metafacture.flowcontrol.ObjectThreader - Adding thread 1
    [Test worker] INFO org.metafacture.flowcontrol.ObjectThreader - Adding thread 2

org.metafacture.json.JsonDecoderTest > testShouldProcessRecordsInArrayRoot STANDARD_ERROR
    SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

org.metafacture.monitoring.StreamLoggerTest > shouldActAsSinkIfNoReceiverIsSet STANDARD_ERROR
    [Test worker] DEBUG org.metafacture.monitoring.StreamLogger - start record 1
    [Test worker] DEBUG org.metafacture.monitoring.StreamLogger - start entity entity
    [Test worker] DEBUG org.metafacture.monitoring.StreamLogger - literal literal=value
    [Test worker] DEBUG org.metafacture.monitoring.StreamLogger - end entity
    [Test worker] DEBUG org.metafacture.monitoring.StreamLogger - end record
    [Test worker] DEBUG org.metafacture.monitoring.StreamLogger - resetStream
    [Test worker] DEBUG org.metafacture.monitoring.StreamLogger - closeStream

org.metafacture.monitoring.StreamLoggerTest > shouldForwardAllReceivedEvents STANDARD_ERROR
    [Test worker] DEBUG org.metafacture.monitoring.StreamLogger - start record 1
    [Test worker] DEBUG org.metafacture.monitoring.StreamLogger - start entity entity
    [Test worker] DEBUG org.metafacture.monitoring.StreamLogger - literal literal=value
    [Test worker] DEBUG org.metafacture.monitoring.StreamLogger - end entity
    [Test worker] DEBUG org.metafacture.monitoring.StreamLogger - end record
    [Test worker] DEBUG org.metafacture.monitoring.StreamLogger - resetStream
    [Test worker] DEBUG org.metafacture.monitoring.StreamLogger - closeStream

org.metafacture.monitoring.ObjectTimerTest > testShouldHandleImmediateCloseStreamWithNoProcessing STANDARD_ERROR
    [Test worker] INFO org.metafacture.monitoring.TimerBase - Executions: 0; Cumulative duration: 0s; Average duration: 0s
    [Test worker] INFO org.metafacture.monitoring.TimerBase - Time to close stream:  14µs 965ns

org.metafacture.monitoring.ObjectTimerTest > testShouldMeasureExecutionTime STANDARD_ERROR
    [Test worker] INFO org.metafacture.monitoring.TimerBase - Execution 1: 150ms 138µs
    [Test worker] INFO org.metafacture.monitoring.TimerBase - Execution 2: 20ms 82µs
    [Test worker] INFO org.metafacture.monitoring.TimerBase - Execution 3: 30ms 130µs
    [Test worker] INFO org.metafacture.monitoring.TimerBase - Execution 4: 202ms 164µs
    [Test worker] INFO org.metafacture.monitoring.TimerBase - Executions: 4; Cumulative duration: 402ms 515µs; Average duration: 100ms 629µs
    [Test worker] INFO org.metafacture.monitoring.TimerBase - Time to close stream:  6µs 170ns

org.metafacture.monitoring.StreamTimerTest > testShouldHandleImmediateCloseStreamWithNoProcessing STANDARD_ERROR
    [Test worker] INFO org.metafacture.monitoring.TimerBase - Executions: 0; Cumulative duration: 0s; Average duration: 0s
    [Test worker] INFO org.metafacture.monitoring.TimerBase - Time to close stream:  1µs 470ns

org.metafacture.monitoring.StreamTimerTest > testShouldMeasureExecutionTime STANDARD_ERROR
    [Test worker] INFO org.metafacture.monitoring.TimerBase - Execution 1: 150ms 242µs
    [Test worker] INFO org.metafacture.monitoring.TimerBase - Execution 2: 20ms 149µs
    [Test worker] INFO org.metafacture.monitoring.TimerBase - Execution 3: 30ms 123µs
    [Test worker] INFO org.metafacture.monitoring.TimerBase - Execution 4: 202ms 170µs
    [Test worker] INFO org.metafacture.monitoring.TimerBase - Executions: 4; Cumulative duration: 402ms 685µs; Average duration: 100ms 671µs
    [Test worker] INFO org.metafacture.monitoring.TimerBase - Time to close stream:  5µs 111ns

org.metafacture.metamorph.test.validators.StreamValidatorTest > shouldFailIfEndRecordEventIsMissing STANDARD_ERROR
    [Test worker] INFO org.metafacture.metamorph.test.validators.StreamValidator - Event Stream: 1{}
blackwinter commented 2 years ago

metafacture-fix could also benefit from this.

blackwinter commented 2 years ago

Maybe also print Morph/Fix script on failure.

dr0i commented 2 years ago

As these scripts can comprise several thousand lines a snippet would be fine.

blackwinter commented 2 years ago

As these scripts can comprise several thousand lines

Not usually in tests, though, right? Those are (almost?) always small scripts with the minimum number of instructions required for the particular test.

blackwinter commented 2 years ago

BTW: This idea was inspired by the Metafix test helper, only limited to test failures so it wouldn't clutter the regular test output.

dr0i commented 2 years ago

Ah, right, sorry, of course - it's about tests ... so just ignore my comment :)

blackwinter commented 2 years ago

configure test logging (showStandardStreams = true and exceptionFormat = 'full') globally for all subprojects.

Already done in #417.