Skip to content

Commit

Permalink
#46 test beauty in EventBatcherTest
Browse files Browse the repository at this point in the history
  • Loading branch information
BGehrels committed Feb 6, 2019
1 parent 8c443cb commit 62ecec1
Showing 1 changed file with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public void shouldNotPublishEmptyBatches() {

@Test
public void shouldPublishNonFilledBatchOnFinish() throws JsonProcessingException {
EventLog eventLogEntry = new EventLog(1, "type", "body", "flow", now(), now(), "me", now());
NakadiEvent nakadiEvent = new NakadiEvent();
EventLog eventLogEntry = eventLogEntry(1, "type");
NakadiEvent nakadiEvent = nakadiEvent("1");

when(objectMapper.writeValueAsBytes(any())).thenReturn(new byte[500]);

Expand All @@ -47,10 +47,10 @@ public void shouldPublishNonFilledBatchOnFinish() throws JsonProcessingException

@Test
public void shouldPublishNonFilledBatchOnEventTypeChange() throws JsonProcessingException {
EventLog eventLogEntry1 = new EventLog(1, "type1", "body", "flow", now(), now(), "me", now());
EventLog eventLogEntry2 = new EventLog(1, "type2", "body", "flow", now(), now(), "me", now());
NakadiEvent nakadiEvent1 = new NakadiEvent();
NakadiEvent nakadiEvent2 = new NakadiEvent();
EventLog eventLogEntry1 = eventLogEntry(1, "type1");
EventLog eventLogEntry2 = eventLogEntry(2, "type2");
NakadiEvent nakadiEvent1 = nakadiEvent("1");
NakadiEvent nakadiEvent2 = nakadiEvent("2");

when(objectMapper.writeValueAsBytes(any())).thenReturn(new byte[500]);

Expand All @@ -61,12 +61,12 @@ public void shouldPublishNonFilledBatchOnEventTypeChange() throws JsonProcessing

@Test
public void shouldPublishFilledBatchOnSubmissionOfNewEvent() throws JsonProcessingException {
EventLog eventLogEntry1 = new EventLog(1, "type1", "body", "flow", now(), now(), "me", now());
EventLog eventLogEntry2 = new EventLog(2, "type1", "body", "flow", now(), now(), "me", now());
EventLog eventLogEntry3 = new EventLog(3, "type1", "body", "flow", now(), now(), "me", now());
NakadiEvent nakadiEvent1 = new NakadiEvent();
NakadiEvent nakadiEvent2 = new NakadiEvent();
NakadiEvent nakadiEvent3 = new NakadiEvent();
EventLog eventLogEntry1 = eventLogEntry(1, "type1");
EventLog eventLogEntry2 = eventLogEntry(2, "type1");
EventLog eventLogEntry3 = eventLogEntry(3, "type1");
NakadiEvent nakadiEvent1 = nakadiEvent("1");
NakadiEvent nakadiEvent2 = nakadiEvent("2");
NakadiEvent nakadiEvent3 = nakadiEvent("3");

when(objectMapper.writeValueAsBytes(any())).thenReturn(new byte[15000000]);

Expand All @@ -86,10 +86,10 @@ public void shouldPublishFilledBatchOnSubmissionOfNewEvent() throws JsonProcessi

@Test
public void shouldTryPublishEventsIndividuallyWhenTheyExceedBatchThresholdThe() throws JsonProcessingException {
EventLog eventLogEntry1 = new EventLog(1, "type1", "body", "flow", now(), now(), "me", now());
EventLog eventLogEntry2 = new EventLog(2, "type1", "body", "flow", now(), now(), "me", now());
NakadiEvent nakadiEvent1 = new NakadiEvent();
NakadiEvent nakadiEvent2 = new NakadiEvent();
EventLog eventLogEntry1 = eventLogEntry(1, "type1");
EventLog eventLogEntry2 = eventLogEntry(2, "type1");
NakadiEvent nakadiEvent1 = nakadiEvent("1");
NakadiEvent nakadiEvent2 = nakadiEvent("2");

when(objectMapper.writeValueAsBytes(any()))
.thenReturn(new byte[45000000])
Expand All @@ -105,10 +105,10 @@ public void shouldTryPublishEventsIndividuallyWhenTheyExceedBatchThresholdThe()

@Test
public void willGracefullySkipNonSerializableEvents() throws JsonProcessingException {
EventLog eventLogEntry1 = new EventLog(1, "type1", "body", "flow", now(), now(), "me", now());
EventLog eventLogEntry2 = new EventLog(2, "type1", "body", "flow", now(), now(), "me", now());
NakadiEvent nakadiEvent1 = new NakadiEvent();
NakadiEvent nakadiEvent2 = new NakadiEvent();
EventLog eventLogEntry1 = eventLogEntry(1, "type1");
EventLog eventLogEntry2 = eventLogEntry(2, "type1");
NakadiEvent nakadiEvent1 = nakadiEvent("1");
NakadiEvent nakadiEvent2 = nakadiEvent("2");

when(objectMapper.writeValueAsBytes(any()))
.thenThrow(new IllegalStateException())
Expand All @@ -123,4 +123,16 @@ public void willGracefullySkipNonSerializableEvents() throws JsonProcessingExcep

verify(publisher).accept(eq(singletonList(new BatchItem(eventLogEntry2, nakadiEvent2))));
}

private EventLog eventLogEntry(int i, String type1) {
return new EventLog(i, type1, "body", "flow", now(), now(), "me", now());
}

private NakadiEvent nakadiEvent(String eid) {
NakadiMetadata metadata = new NakadiMetadata();
metadata.setEid(eid);
NakadiEvent nakadiEvent = new NakadiEvent();
nakadiEvent.setMetadata(metadata);
return nakadiEvent;
}
}

0 comments on commit 62ecec1

Please sign in to comment.