Search in sources :

Example 26 with MissionHealthCheckMatcher

use of com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher in project abort-mission by nagyesta.

the class NotMatcherTest method testMatchesShouldNegateWrappedMatcherWhenCalledWithValidComponent.

@ParameterizedTest
@MethodSource("inputProvider")
void testMatchesShouldNegateWrappedMatcherWhenCalledWithValidComponent(final boolean matches, final String dependency) {
    // given
    final MissionHealthCheckMatcher underTest = MissionHealthCheckMatcherBuilder.builder().not(STRING_MATCHER).build();
    // when
    final boolean actual = underTest.matches(dependency);
    // then
    assertEquals(matches, actual);
}
Also used : MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 27 with MissionHealthCheckMatcher

use of com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher in project abort-mission by nagyesta.

the class OrMatcherTest method testMatchesRequiresOnlyOneOperandToMatchWhenCalled.

@ParameterizedTest
@MethodSource("inputProvider")
void testMatchesRequiresOnlyOneOperandToMatchWhenCalled(final boolean matches, final Collection<String> operands) {
    // given
    final MissionHealthCheckMatcherBuilder builder = (MissionHealthCheckMatcherBuilder) builder();
    for (final String regex : operands) {
        builder.or(builder().classNamePattern(regex).build());
    }
    final MissionHealthCheckMatcher underTest = builder.build();
    // when
    final boolean actual = underTest.matches(this.getClass());
    // then
    assertEquals(matches, actual);
}
Also used : MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 28 with MissionHealthCheckMatcher

use of com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher in project abort-mission by nagyesta.

the class SystemPropertyMatcherTest method testMatchesShouldWorkRegardlessOfTheInput.

@ParameterizedTest
@MethodSource("validInputProvider")
void testMatchesShouldWorkRegardlessOfTheInput(final String envName, final String regex, final Object component, final boolean expected) {
    // given
    final MissionHealthCheckMatcher underTest = MissionHealthCheckMatcherBuilder.builder().envVariable(envName).valuePattern(regex).build();
    assertTrue(underTest instanceof EnvironmentMatcher);
    // when
    final boolean actual = underTest.matches(component);
    // then
    assertEquals(expected, actual);
}
Also used : MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 29 with MissionHealthCheckMatcher

use of com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher in project abort-mission by nagyesta.

the class PercentageBasedMissionHealthCheckEvaluatorTest method testAbortThresholdShouldThrowExceptionWhenCalledWithInvalidValue.

@ParameterizedTest
@ValueSource(ints = { -2, -1, 100, 101 })
void testAbortThresholdShouldThrowExceptionWhenCalledWithInvalidValue(final int input) {
    // given
    final MissionHealthCheckMatcher matcher = mock(MissionHealthCheckMatcher.class);
    // when
    assertThrows(IllegalArgumentException.class, () -> {
        PercentageBasedMissionHealthCheckEvaluator.builder(matcher, new MissionStatisticsCollector(matcher)).abortThreshold(input);
    });
// then exception
}
Also used : MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 30 with MissionHealthCheckMatcher

use of com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher in project abort-mission by nagyesta.

the class PercentageBasedMissionHealthCheckEvaluatorTest method testShouldAbortShouldNotCallInternalMethodWhenDisarmed.

@Test
void testShouldAbortShouldNotCallInternalMethodWhenDisarmed() {
    // given
    final MissionHealthCheckMatcher matcher = mock(MissionHealthCheckMatcher.class);
    final PercentageBasedMissionHealthCheckEvaluator underTest = spy(PercentageBasedMissionHealthCheckEvaluator.builder(matcher, new MissionStatisticsCollector(matcher)).abortThreshold(1).build());
    doReturn(true).when(underTest).isDisarmed(eq(ABORT_MISSION_DISARM_MISSION));
    // when
    underTest.shouldAbort();
    // then
    verify(underTest, never()).shouldAbortInternal();
}
Also used : MissionHealthCheckMatcher(com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MissionHealthCheckMatcher (com.github.nagyesta.abortmission.core.matcher.MissionHealthCheckMatcher)47 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)29 MethodSource (org.junit.jupiter.params.provider.MethodSource)21 Test (org.junit.jupiter.api.Test)15 Registry (java.rmi.registry.Registry)7 StageTimeMeasurement (com.github.nagyesta.abortmission.core.telemetry.StageTimeMeasurement)5 MissionHealthCheckEvaluator (com.github.nagyesta.abortmission.core.healthcheck.MissionHealthCheckEvaluator)4 LaunchStatisticsService (com.github.nagyesta.abortmission.strongback.rmi.service.LaunchStatisticsService)3 RemoteException (java.rmi.RemoteException)3 NullSource (org.junit.jupiter.params.provider.NullSource)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)3 InOrder (org.mockito.InOrder)3 TagDependencyNameExtractor (com.github.nagyesta.abortmission.booster.jupiter.extractor.TagDependencyNameExtractor)2 DependencyNameExtractor (com.github.nagyesta.abortmission.core.extractor.DependencyNameExtractor)2 StringDependencyNameExtractor (com.github.nagyesta.abortmission.core.extractor.impl.StringDependencyNameExtractor)2 StageStatisticsCollectorFactory (com.github.nagyesta.abortmission.core.healthcheck.StageStatisticsCollectorFactory)2 StageStatisticsSnapshot (com.github.nagyesta.abortmission.core.healthcheck.StageStatisticsSnapshot)2 MissionStatisticsCollector (com.github.nagyesta.abortmission.core.healthcheck.impl.MissionStatisticsCollector)2 HashMap (java.util.HashMap)2 Consumer (java.util.function.Consumer)2