Skip to content

Commit

Permalink
Bug Fix Null Pointer on Stop (#3)
Browse files Browse the repository at this point in the history
- S3 Delivery Stream threw a null pointer if was stopped before written
  • Loading branch information
ptimson authored Feb 14, 2017
1 parent 60e7acc commit 647692f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.timson</groupId>
<artifactId>firehose-mock</artifactId>
<version>0.0.2</version>
<version>0.0.3</version>

<name>Firehose Mock</name>
<url>https://github.com/ptimson/firehose-mock</url>
Expand Down
17 changes: 9 additions & 8 deletions src/main/java/io/timson/firehose/stream/S3DeliveryStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ public class S3DeliveryStream implements DeliveryStream {
private final Long bufferIntervalMs;
private final Long bufferFlushSizeBytes;
private final CompressionFormat compressionFormat;

private final TimerTask flushTimerTask = new TimerTask() {
@Override
public void run() {
flush();
}
};
private StringBuilder buffer = new StringBuilder();
private long bufferSize = 0;
private Timer flushTimer;
private TimerTask flushTimerTask;

private S3DeliveryStream(String name,
S3Client s3Client,
Expand All @@ -64,17 +68,14 @@ private String extractBucketName(String s3BucketArn) {
}

private void startFlushTimer() {
flushTimerTask = new TimerTask() {
@Override
public void run() {
flush();
}
};
flushTimer = new Timer();
flushTimer.schedule(flushTimerTask, bufferIntervalMs);
}

private void stopFlushTimer() {
if (flushTimer == null) {
return;
}
flushTimer.cancel();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,9 @@ public void shouldCreateSnappyS3Object_WhenEncryptionTypeIsSnappy() throws Excep
verify(s3Client, only()).createSnappyObject(eq(S3_BUCKET), anyString(), eq(MESSAGE_1));
}

@Test
public void shouldThrowNullPointer_WhenStoppedBeforeMessageWritten() throws Exception {
stream.stop();
}

}

0 comments on commit 647692f

Please sign in to comment.