Skip to content

Commit

Permalink
Merge pull request #158 from CJSCommonPlatform/run-verify-in-mdc
Browse files Browse the repository at this point in the history
Run verify catchup logging in MDC context
  • Loading branch information
allanmckenzie committed Sep 24, 2019
2 parents d806973 + 5bfd684 commit 4861c3b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ on [Keep a CHANGELOG](http://keepachangelog.com/). This project adheres to
[Semantic Versioning](http://semver.org/).

## [Unreleased]
## [2.0.22] - 2019-09-24
### Changed
- Catchup verification logging now runs in MDC context

## [2.0.21] - 2019-09-23
### Added
- New SystemCommand to verify the results of running catchup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.lang.String.format;
import static uk.gov.justice.services.jmx.api.command.VerifyCatchupCommand.VERIFY_CATCHUP;

import uk.gov.justice.services.eventstore.management.logging.MdcLogger;
import uk.gov.justice.services.eventstore.management.validation.process.CatchupVerificationProcess;
import uk.gov.justice.services.jmx.api.command.VerifyCatchupCommand;
import uk.gov.justice.services.jmx.command.HandlesSystemCommand;
Expand All @@ -16,14 +17,18 @@ public class VerifyCatchupCommandHandler {
@Inject
private CatchupVerificationProcess catchupVerificationProcess;

@Inject
private MdcLogger mdcLogger;

@Inject
private Logger logger;

@HandlesSystemCommand(VERIFY_CATCHUP)
public void validateCatchup(final VerifyCatchupCommand verifyCatchupCommand) {

logger.info(format("Received %s command", verifyCatchupCommand.getName()));

catchupVerificationProcess.runVerification();
mdcLogger.mdcLoggerConsumer().accept(() -> {
logger.info(format("Received %s command", verifyCatchupCommand.getName()));
catchupVerificationProcess.runVerification();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void runVerification() {

errorResults.forEach(verificationResult -> logger.error("ERROR: " + verificationResult.getMessage()));
warningResults.forEach(verificationResult -> logger.warn("WARNING: " + verificationResult.getMessage()));
successfulResults.forEach(verificationResult -> logger.warn("SUCCESS: " + verificationResult.getMessage()));
successfulResults.forEach(verificationResult -> logger.info("SUCCESS: " + verificationResult.getMessage()));
}

private List<VerificationResult> filter(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package uk.gov.justice.services.eventstore.management.validation.commands;

import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.when;

import uk.gov.justice.services.eventstore.management.logging.MdcLogger;
import uk.gov.justice.services.eventstore.management.validation.process.CatchupVerificationProcess;
import uk.gov.justice.services.jmx.api.command.VerifyCatchupCommand;

import java.util.function.Consumer;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
Expand All @@ -19,15 +23,22 @@ public class VerifyCatchupCommandHandlerTest {
@Mock
private CatchupVerificationProcess catchupVerificationProcess;

@Mock
private MdcLogger mdcLogger;

@Mock
private Logger logger;

private Consumer<Runnable> testConsumer = Runnable::run;

@InjectMocks
private VerifyCatchupCommandHandler verifyCatchupCommandHandler;

@Test
public void shouldRunTheVerificationProcess() throws Exception {

when(mdcLogger.mdcLoggerConsumer()).thenReturn(testConsumer);

verifyCatchupCommandHandler.validateCatchup(new VerifyCatchupCommand());

final InOrder inOrder = inOrder(logger, catchupVerificationProcess);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void shouldRunTheVariousVerificationProcessesAndLogTheResults() throws Ex
inOrder.verify(logger).error("ERROR: error 2");
inOrder.verify(logger).warn("WARNING: warning 1");
inOrder.verify(logger).warn("WARNING: warning 2");
inOrder.verify(logger).warn("SUCCESS: success 1");
inOrder.verify(logger).warn("SUCCESS: success 2");
inOrder.verify(logger).info("SUCCESS: success 1");
inOrder.verify(logger).info("SUCCESS: success 2");
}
}

0 comments on commit 4861c3b

Please sign in to comment.