You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@metron.apache.org by GitBox <gi...@apache.org> on 2019/02/12 18:36:18 UTC
[GitHub] mmiklavc commented on a change in pull request #1335: METRON-1998:
Only one sensor is flushed by tick tuple
mmiklavc commented on a change in pull request #1335: METRON-1998: Only one sensor is flushed by tick tuple
URL: https://github.com/apache/metron/pull/1335#discussion_r256090130
##########
File path: metron-platform/metron-writer/src/test/java/org/apache/metron/writer/BulkWriterComponentTest.java
##########
@@ -270,4 +273,37 @@ public void flushShouldAckMissingTuples() throws Exception{
verify(collector, times(1)).ack(missingTuple);
verifyNoMoreInteractions(collector);
}
+
+ @Test
+ public void flushTimeoutsShouldFlushAllMessages() throws Exception {
+ Clock clock = mock(Clock.class);
+ BulkMessageWriter<JSONObject> bulkMessageWriter = mock(BulkMessageWriter.class);
+ BulkWriterComponent<JSONObject> bulkWriterComponent = new BulkWriterComponent<>(collector, false, false).withClock(clock);
+
+ BulkWriterResponse response1 = new BulkWriterResponse();
+ response1.addSuccess(tuple1);
+ when(bulkMessageWriter.write("sensor1", configurations, Collections.singletonList(tuple1), Collections.singletonList(message1))).thenReturn(response1);
+ BulkWriterResponse response2 = new BulkWriterResponse();
+ response1.addSuccess(tuple2);
+ when(bulkMessageWriter.write("sensor2", configurations, Collections.singletonList(tuple2), Collections.singletonList(message2))).thenReturn(response2);
+
+ when(clock.currentTimeMillis()).thenReturn(1000L);
+ bulkWriterComponent.write("sensor1", tuple1, message1, bulkMessageWriter, configurations, messageGetStrategy);
+ bulkWriterComponent.write("sensor2", tuple2, message2, bulkMessageWriter, configurations, messageGetStrategy);
+
+ verify(bulkMessageWriter, times(0)).write(any(), any(), any(), any());
+
+ when(clock.currentTimeMillis()).thenReturn(5000L);
+ bulkWriterComponent.flushTimeouts(bulkMessageWriter, configurations, messageGetStrategy);
+
+ verify(bulkMessageWriter, times(0)).write(any(), any(), any(), any());
+
+ when(clock.currentTimeMillis()).thenReturn(7000L);
Review comment:
Can you clarify the clock intervals used and what the actual timeout trigger is? I'm assuming this is probably performing the flush test based on the default flush timeout config. Also, can we have a test for the default and non-default config? e.g.
```
flushTimeoutsShouldFlushAllMessagesAfterDefaultTimeout
flushTimeoutsShouldFlushAllMessagesAfterConfiguredTimeout
```
One other minor suggestion - it might make for a tighter test to remove the intermediate verify statements and add an explicit check around the timeout inflection point, e.g.
```
when(clock.currentTimeMillis()).thenReturn(2000L);
bulkWriterComponent.flushTimeouts(bulkMessageWriter, configurations, messageGetStrategy);
when(clock.currentTimeMillis()).thenReturn(3000L);
bulkWriterComponent.flushTimeouts(bulkMessageWriter, configurations, messageGetStrategy);
when(clock.currentTimeMillis()).thenReturn(4000L);
bulkWriterComponent.flushTimeouts(bulkMessageWriter, configurations, messageGetStrategy);
when(clock.currentTimeMillis()).thenReturn(5000L);
bulkWriterComponent.flushTimeouts(bulkMessageWriter, configurations, messageGetStrategy);
when(clock.currentTimeMillis()).thenReturn(6000L);
bulkWriterComponent.flushTimeouts(bulkMessageWriter, configurations, messageGetStrategy);
when(clock.currentTimeMillis()).thenReturn(6999L);
bulkWriterComponent.flushTimeouts(bulkMessageWriter, configurations, messageGetStrategy);
when(clock.currentTimeMillis()).thenReturn(7000L); // triggers timeout
bulkWriterComponent.flushTimeouts(bulkMessageWriter, configurations, messageGetStrategy);
verify(bulkMessageWriter, times(1)).write("sensor1", configurations, Collections.singletonList(tuple1), Collections.singletonList(message1));
verify(bulkMessageWriter, times(1)).write("sensor2", configurations, Collections.singletonList(tuple2), Collections.singletonList(message2));
when(clock.currentTimeMillis()).thenReturn(7001L); // no trigger
bulkWriterComponent.flushTimeouts(bulkMessageWriter, configurations, messageGetStrategy);
verify(bulkMessageWriter, times(0)).write(any(), any(), any(), any());
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services