Skip to content

Commit

Permalink
Merge 2b70d89 into 93d5210
Browse files Browse the repository at this point in the history
  • Loading branch information
mapingo committed Oct 14, 2019
2 parents 93d5210 + 2b70d89 commit e7e49b2
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,33 @@
import uk.gov.justice.services.eventstore.management.events.catchup.CatchupProcessingOfEventFailedEvent;
import uk.gov.justice.services.eventstore.management.events.catchup.CatchupRequestedEvent;
import uk.gov.justice.services.eventstore.management.events.catchup.CatchupStartedForSubscriptionEvent;
import uk.gov.justice.services.jmx.logging.MdcLogger;
import uk.gov.justice.services.jmx.logging.MdcLoggerInterceptor;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;
import javax.interceptor.Interceptors;

@Interceptors(MdcLoggerInterceptor.class)
@ApplicationScoped
public class CatchupObserver {

@Inject
private CatchupLifecycle catchupLifecycle;

@Inject
private MdcLogger mdcLogger;

public void onCatchupRequested(@Observes final CatchupRequestedEvent catchupRequestedEvent) {

mdcLogger
.mdcLoggerConsumer()
.accept(() -> catchupLifecycle.handleCatchupRequested(catchupRequestedEvent));
catchupLifecycle.handleCatchupRequested(catchupRequestedEvent);
}

public void onCatchupStartedForSubscription(@Observes final CatchupStartedForSubscriptionEvent catchupStartedForSubscriptionEvent) {

mdcLogger
.mdcLoggerConsumer()
.accept(() -> catchupLifecycle.handleCatchupStartedForSubscription(catchupStartedForSubscriptionEvent));
catchupLifecycle.handleCatchupStartedForSubscription(catchupStartedForSubscriptionEvent);
}

public void onCatchupCompleteForSubscription(@Observes final CatchupCompletedForSubscriptionEvent catchupCompletedForSubscriptionEvent) {

mdcLogger
.mdcLoggerConsumer()
.accept(() -> catchupLifecycle.handleCatchupCompleteForSubscription(catchupCompletedForSubscriptionEvent));
catchupLifecycle.handleCatchupCompleteForSubscription(catchupCompletedForSubscriptionEvent);
}

public void onCatchupProcessingOfEventFailed(@Observes final CatchupProcessingOfEventFailedEvent catchupProcessingOfEventFailedEvent) {
mdcLogger
.mdcLoggerConsumer()
.accept(() -> catchupLifecycle.handleCatchupProcessingOfEventFailed(catchupProcessingOfEventFailedEvent));
catchupLifecycle.handleCatchupProcessingOfEventFailed(catchupProcessingOfEventFailedEvent);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,21 @@
import uk.gov.justice.services.eventstore.management.rebuild.process.RebuildProcessRunner;
import uk.gov.justice.services.jmx.api.command.RebuildCommand;
import uk.gov.justice.services.jmx.command.HandlesSystemCommand;
import uk.gov.justice.services.jmx.logging.MdcLogger;
import uk.gov.justice.services.jmx.logging.MdcLoggerInterceptor;

import java.util.UUID;

import javax.inject.Inject;
import javax.interceptor.Interceptors;

public class RebuildCommandHandler {

@Inject
private RebuildProcessRunner rebuildProcessRunner;

@Inject
private MdcLogger mdcLogger;


@Interceptors(MdcLoggerInterceptor.class)
@HandlesSystemCommand(REBUILD)
public void doRebuild(final RebuildCommand rebuildCommand, final UUID commandId) {

mdcLogger.mdcLoggerConsumer().accept(() -> {
rebuildProcessRunner.runRebuild(commandId, rebuildCommand);
});
rebuildProcessRunner.runRebuild(commandId, rebuildCommand);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,37 @@
import uk.gov.justice.services.jmx.api.command.AddTriggerCommand;
import uk.gov.justice.services.jmx.api.command.RemoveTriggerCommand;
import uk.gov.justice.services.jmx.command.HandlesSystemCommand;
import uk.gov.justice.services.jmx.logging.MdcLogger;
import uk.gov.justice.services.jmx.logging.MdcLoggerInterceptor;

import java.util.UUID;

import javax.inject.Inject;
import javax.interceptor.Interceptors;

import org.slf4j.Logger;

@Interceptors(MdcLoggerInterceptor.class)
public class AddRemoveTriggerCommandHandler {

@Inject
private AddRemoveTriggerProcessRunner addRemoveTriggerProcessRunner;

@Inject
private MdcLogger mdcLogger;

@Inject
private Logger logger;

@HandlesSystemCommand(ADD_TRIGGER)
public void addTriggerToEventLogTable(final AddTriggerCommand addTriggerCommand, final UUID commandId) {

mdcLogger.mdcLoggerConsumer().accept(() -> {
logger.info(format("Received command %s", addTriggerCommand.getName()));

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

addRemoveTriggerProcessRunner.addTriggerToEventLogTable(commandId, addTriggerCommand);
});
addRemoveTriggerProcessRunner.addTriggerToEventLogTable(commandId, addTriggerCommand);
}

@HandlesSystemCommand(REMOVE_TRIGGER)
public void removeTriggerFromEventLogTable(final RemoveTriggerCommand removeTriggerCommand, final UUID commandId) {

mdcLogger.mdcLoggerConsumer().accept(() -> {

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

addRemoveTriggerProcessRunner.removeTriggerFromEventLogTable(commandId, removeTriggerCommand);
});
addRemoveTriggerProcessRunner.removeTriggerFromEventLogTable(commandId, removeTriggerCommand);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import uk.gov.justice.services.eventstore.management.validation.process.CatchupVerificationProcessRunner;
import uk.gov.justice.services.jmx.api.command.VerifyCatchupCommand;
import uk.gov.justice.services.jmx.command.HandlesSystemCommand;
import uk.gov.justice.services.jmx.logging.MdcLogger;
import uk.gov.justice.services.jmx.logging.MdcLoggerInterceptor;

import java.util.UUID;

import javax.inject.Inject;
import javax.interceptor.Interceptors;

import org.slf4j.Logger;

Expand All @@ -19,18 +20,14 @@ public class VerifyCatchupCommandHandler {
@Inject
private CatchupVerificationProcessRunner catchupVerificationProcessRunner;

@Inject
private MdcLogger mdcLogger;

@Inject
private Logger logger;

@Interceptors(MdcLoggerInterceptor.class)
@HandlesSystemCommand(VERIFY_CATCHUP)
public void validateCatchup(final VerifyCatchupCommand verifyCatchupCommand, final UUID commandId) {

mdcLogger.mdcLoggerConsumer().accept(() -> {
logger.info(format("Received %s command", verifyCatchupCommand.getName()));
catchupVerificationProcessRunner.runVerificationProcess(commandId, verifyCatchupCommand);
});
logger.info(format("Received %s command", verifyCatchupCommand.getName()));
catchupVerificationProcessRunner.runVerificationProcess(commandId, verifyCatchupCommand);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import uk.gov.justice.services.eventstore.management.events.catchup.CatchupCompletedForSubscriptionEvent;
import uk.gov.justice.services.eventstore.management.events.catchup.CatchupProcessingOfEventFailedEvent;
import uk.gov.justice.services.eventstore.management.events.catchup.CatchupRequestedEvent;
import uk.gov.justice.services.eventstore.management.events.catchup.CatchupStartedForSubscriptionEvent;
import uk.gov.justice.services.jmx.logging.MdcLogger;

import java.util.function.Consumer;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -24,21 +20,14 @@ public class CatchupObserverTest {
@Mock
private CatchupLifecycle catchupLifecycle;

@Mock
private MdcLogger mdcLogger;

@InjectMocks
private CatchupObserver catchupObserver;

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

@Test
public void shouldHandleCatchupRequested() throws Exception {

final CatchupRequestedEvent catchupRequestedEvent = mock(CatchupRequestedEvent.class);

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

catchupObserver.onCatchupRequested(catchupRequestedEvent);

verify(catchupLifecycle).handleCatchupRequested(catchupRequestedEvent);
Expand All @@ -49,8 +38,6 @@ public void shouldHandleCatchupStartedForSubscription() throws Exception {

final CatchupStartedForSubscriptionEvent catchupStartedForSubscriptionEvent = mock(CatchupStartedForSubscriptionEvent.class);

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

catchupObserver.onCatchupStartedForSubscription(catchupStartedForSubscriptionEvent);

verify(catchupLifecycle).handleCatchupStartedForSubscription(catchupStartedForSubscriptionEvent);
Expand All @@ -61,8 +48,6 @@ public void shouldHandleCatchupCompleteForSubscription() throws Exception {

final CatchupCompletedForSubscriptionEvent catchupCompletedForSubscriptionEvent = mock(CatchupCompletedForSubscriptionEvent.class);

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

catchupObserver.onCatchupCompleteForSubscription(catchupCompletedForSubscriptionEvent);

verify(catchupLifecycle).handleCatchupCompleteForSubscription(catchupCompletedForSubscriptionEvent);
Expand All @@ -73,8 +58,6 @@ public void shouldHandleCatchupProcessingOfEventFailed() throws Exception {

final CatchupProcessingOfEventFailedEvent catchupProcessingOfEventFailedEvent = mock(CatchupProcessingOfEventFailedEvent.class);

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

catchupObserver.onCatchupProcessingOfEventFailed(catchupProcessingOfEventFailedEvent);

verify(catchupLifecycle).handleCatchupProcessingOfEventFailed(catchupProcessingOfEventFailedEvent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

import static java.util.UUID.randomUUID;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import uk.gov.justice.services.eventstore.management.rebuild.process.RebuildProcessRunner;
import uk.gov.justice.services.jmx.api.command.RebuildCommand;
import uk.gov.justice.services.jmx.logging.MdcLogger;

import java.util.UUID;
import java.util.function.Consumer;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -23,22 +20,15 @@ public class RebuildCommandHandlerTest {
@Mock
private RebuildProcessRunner rebuildProcessRunner;

@Mock
private MdcLogger mdcLogger;

@InjectMocks
private RebuildCommandHandler rebuildCommandHandler;

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

@Test
public void shouldFireRebuildEvent() throws Exception {

final UUID commandId = randomUUID();
final RebuildCommand rebuildCommand = new RebuildCommand();

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

rebuildCommandHandler.doRebuild(rebuildCommand, commandId);

verify(rebuildProcessRunner).runRebuild(commandId, rebuildCommand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import static java.util.UUID.randomUUID;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import uk.gov.justice.services.eventstore.management.untrigger.process.AddRemoveTriggerProcessRunner;
import uk.gov.justice.services.jmx.api.command.AddTriggerCommand;
import uk.gov.justice.services.jmx.api.command.RemoveTriggerCommand;
import uk.gov.justice.services.jmx.logging.MdcLogger;

import java.util.UUID;
import java.util.function.Consumer;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -25,25 +22,18 @@ public class AddRemoveTriggerCommandHandlerTest {
@Mock
private AddRemoveTriggerProcessRunner addRemoveTriggerProcessRunner;

@Mock
private MdcLogger mdcLogger;

@Mock
private Logger logger;

@InjectMocks
private AddRemoveTriggerCommandHandler addRemoveTriggerCommandHandler;

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

@Test
public void shouldCallTheAddEventLogTriggerProcess() throws Exception {

final UUID commandId = randomUUID();
final AddTriggerCommand addTriggerCommand = new AddTriggerCommand();

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

addRemoveTriggerCommandHandler.addTriggerToEventLogTable(addTriggerCommand, commandId);

verify(logger).info("Received command ADD_TRIGGER");
Expand All @@ -56,8 +46,6 @@ public void shouldCallTheRemoveEventLogTriggerProcess() throws Exception {
final UUID commandId = randomUUID();
final RemoveTriggerCommand removeTriggerCommand = new RemoveTriggerCommand();

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

addRemoveTriggerCommandHandler.removeTriggerFromEventLogTable(removeTriggerCommand, commandId);

verify(logger).info("Received command REMOVE_TRIGGER");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
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.validation.process.CatchupVerificationProcess;
import uk.gov.justice.services.eventstore.management.validation.process.CatchupVerificationProcessRunner;
import uk.gov.justice.services.jmx.api.command.VerifyCatchupCommand;
import uk.gov.justice.services.jmx.logging.MdcLogger;

import java.util.UUID;
import java.util.function.Consumer;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -25,14 +21,9 @@ public class VerifyCatchupCommandHandlerTest {
@Mock
private CatchupVerificationProcessRunner catchupVerificationProcessRunner;

@Mock
private MdcLogger mdcLogger;

@Mock
private Logger logger;

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

@InjectMocks
private VerifyCatchupCommandHandler verifyCatchupCommandHandler;

Expand All @@ -42,8 +33,6 @@ public void shouldRunTheVerificationProcess() throws Exception {
final UUID commandId = UUID.randomUUID();
final VerifyCatchupCommand verifyCatchupCommand = new VerifyCatchupCommand();

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

verifyCatchupCommandHandler.validateCatchup(verifyCatchupCommand, commandId);

final InOrder inOrder = inOrder(logger, catchupVerificationProcessRunner);
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<cpp.repo.name>event-store</cpp.repo.name>

<framework-api.version>4.1.0</framework-api.version>
<framework.version>6.2.0-M5</framework.version>
<framework.version>6.2.0-M6</framework.version>
<common-bom.version>2.4.0</common-bom.version>
<utilities.version>1.20.1</utilities.version>
<test-utils.version>1.24.3</test-utils.version>
Expand Down

0 comments on commit e7e49b2

Please sign in to comment.