Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run verify catchup logging in MDC context #158

Merged
merged 1 commit into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}