-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
Purger
handling of large window sizes
Large window sizes such as `1000` would trigger an incorrect trimmed window size due to int arithmetic overflow.
- Loading branch information
1 parent
e347410
commit cb77645
Showing
2 changed files
with
44 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package dk.dma.ais.coverage; | ||
|
||
import dk.dma.commons.util.DateTimeUtil; | ||
import org.apache.commons.lang3.time.DateUtils; | ||
import org.joda.time.PeriodType; | ||
import org.junit.Test; | ||
|
||
import java.util.Date; | ||
|
||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class PurgerTest { | ||
|
||
@Test | ||
public void givenLargeWindowSize_whenGetTrimPoint_windowSizeCorrectlyConvertedToHours() { | ||
Purger purger = new Purger(1000, null, 1); | ||
Helper.firstMessage = new Date(); | ||
final int maxWindowSize = 1000; | ||
Helper.latestMessage = DateUtils.addHours(new Date(), 2 * maxWindowSize); | ||
|
||
Date trimPoint = purger.getTrimPoint(); | ||
|
||
assertThat(DateTimeUtil.toInterval(Helper.firstMessage, trimPoint).toPeriod(PeriodType.hours()).getHours(), is(equalTo(maxWindowSize))); | ||
} | ||
} |