-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better error message for badly linked events
- Loading branch information
amckenzie
committed
Oct 22, 2019
1 parent
baf02eb
commit f418183
Showing
10 changed files
with
161 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
.../services/eventstore/management/validation/process/EventLinkageErrorMessageGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package uk.gov.justice.services.eventstore.management.validation.process; | ||
|
||
import static java.lang.String.format; | ||
import static uk.gov.justice.services.eventstore.management.validation.process.LinkedEventNumberTable.PUBLISHED_EVENT; | ||
|
||
public class EventLinkageErrorMessageGenerator { | ||
|
||
public String generateErrorMessage( | ||
final int previousEventNumber, | ||
final int eventNumber, | ||
final int lastEventNumber, | ||
final LinkedEventNumberTable linkedEventNumberTable) { | ||
|
||
|
||
final String message; | ||
if (linkedEventNumberTable == PUBLISHED_EVENT) { | ||
message = "Events incorrectly linked in %s table: " + | ||
"Event with event number %d " + | ||
"is linked to previous event number %d " + | ||
"whereas it should be %d"; | ||
|
||
} else { | ||
message = "Events missing from %s table: " + | ||
"Event with event_number %d " + | ||
"has a previous_event_number of %d, " + | ||
"but the event in the previous row in the database " + | ||
"has an event_number of %d"; | ||
} | ||
|
||
return format( | ||
message, | ||
linkedEventNumberTable.getTableName(), | ||
eventNumber, | ||
previousEventNumber, | ||
lastEventNumber); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...gov/justice/services/eventstore/management/validation/process/LinkedEventNumberTable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package uk.gov.justice.services.eventstore.management.validation.process; | ||
|
||
public enum LinkedEventNumberTable { | ||
|
||
PUBLISHED_EVENT("published_event"), | ||
PROCESSED_EVENT("processed_event"); | ||
|
||
private final String tableName; | ||
|
||
LinkedEventNumberTable(final String tableName) { | ||
this.tableName = tableName; | ||
} | ||
|
||
public String getTableName() { | ||
return tableName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...vices/eventstore/management/validation/process/EventLinkageErrorMessageGeneratorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package uk.gov.justice.services.eventstore.management.validation.process; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
import static uk.gov.justice.services.eventstore.management.validation.process.LinkedEventNumberTable.PROCESSED_EVENT; | ||
import static uk.gov.justice.services.eventstore.management.validation.process.LinkedEventNumberTable.PUBLISHED_EVENT; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class EventLinkageErrorMessageGeneratorTest { | ||
|
||
@InjectMocks | ||
private EventLinkageErrorMessageGenerator eventLinkageErrorMessageGenerator; | ||
|
||
@Test | ||
public void shouldGenerateTheCorrectErrorMessageForPublishedEvent() throws Exception { | ||
|
||
final int previousEventNumber = 23; | ||
final int currentEventNumber = 24; | ||
final int lastEvenNumber = 13; | ||
|
||
final String errorMessage = eventLinkageErrorMessageGenerator.generateErrorMessage( | ||
previousEventNumber, | ||
currentEventNumber, | ||
lastEvenNumber, | ||
PUBLISHED_EVENT); | ||
|
||
assertThat(errorMessage, is("Events incorrectly linked in published_event table: " + | ||
"Event with event number 24 is linked to previous event number 23 " + | ||
"whereas it should be 13")); | ||
} | ||
|
||
@Test | ||
public void shouldGenerateTheCorrectErrorMessageForProcessedEvent() throws Exception { | ||
|
||
final int previousEventNumber = 41; | ||
final int currentEventNumber = 42; | ||
final int lastEvenNumber = 23; | ||
|
||
final String errorMessage = eventLinkageErrorMessageGenerator.generateErrorMessage( | ||
previousEventNumber, | ||
currentEventNumber, | ||
lastEvenNumber, | ||
PROCESSED_EVENT); | ||
|
||
assertThat(errorMessage, is("Events missing from processed_event table: " + | ||
"Event with event_number 42 has a previous_event_number of 41, " + | ||
"but the event in the previous row in the database has an event_number of 23")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters