@ -40,6 +40,7 @@ public class SegmentsTest {
@@ -40,6 +40,7 @@ public class SegmentsTest {
private static final int NUM_SEGMENTS = 5 ;
private MockProcessorContext context ;
private Segments segments ;
private long segmentInterval ;
@Before
public void createContext ( ) {
@ -48,7 +49,9 @@ public class SegmentsTest {
@@ -48,7 +49,9 @@ public class SegmentsTest {
Serdes . Long ( ) ,
new NoOpRecordCollector ( ) ,
new ThreadCache ( new LogContext ( "testCache " ) , 0 , new MockStreamsMetrics ( new Metrics ( ) ) ) ) ;
segments = new Segments ( "test" , 4 * 60 * 1000 , NUM_SEGMENTS ) ;
int retentionPeriod = 4 * 60 * 1000 ;
segments = new Segments ( "test" , retentionPeriod , NUM_SEGMENTS ) ;
segmentInterval = Segments . segmentInterval ( retentionPeriod , NUM_SEGMENTS ) ;
}
@After
@ -74,10 +77,10 @@ public class SegmentsTest {
@@ -74,10 +77,10 @@ public class SegmentsTest {
}
@Test
public void shouldGetSegmentNameFromId ( ) {
assertEquals ( "test-19700101000 0" , segments . segmentName ( 0 ) ) ;
assertEquals ( "test-197001010001" , segments . segmentName ( 1 ) ) ;
assertEquals ( "test-197001010002" , segments . segmentName ( 2 ) ) ;
public void shouldGetSegmentNameFromId ( ) throws Exception {
assertEquals ( "test: 0" , segments . segmentName ( 0 ) ) ;
assertEquals ( "test:" + segmentInterval , segments . segmentName ( 1 ) ) ;
assertEquals ( "test:" + 2 * segmentInterval , segments . segmentName ( 2 ) ) ;
}
@Test
@ -85,9 +88,9 @@ public class SegmentsTest {
@@ -85,9 +88,9 @@ public class SegmentsTest {
final Segment segment1 = segments . getOrCreateSegment ( 0 , context ) ;
final Segment segment2 = segments . getOrCreateSegment ( 1 , context ) ;
final Segment segment3 = segments . getOrCreateSegment ( 2 , context ) ;
assertTrue ( new File ( context . stateDir ( ) , "test/test-19700101000 0" ) . isDirectory ( ) ) ;
assertTrue ( new File ( context . stateDir ( ) , "test/test-197001010001" ) . isDirectory ( ) ) ;
assertTrue ( new File ( context . stateDir ( ) , "test/test-197001010002" ) . isDirectory ( ) ) ;
assertTrue ( new File ( context . stateDir ( ) , "test/test: 0" ) . isDirectory ( ) ) ;
assertTrue ( new File ( context . stateDir ( ) , "test/test:" + segmentInterval ) . isDirectory ( ) ) ;
assertTrue ( new File ( context . stateDir ( ) , "test/test:" + 2 * segmentInterval ) . isDirectory ( ) ) ;
assertEquals ( true , segment1 . isOpen ( ) ) ;
assertEquals ( true , segment2 . isOpen ( ) ) ;
assertEquals ( true , segment3 . isOpen ( ) ) ;
@ -97,20 +100,20 @@ public class SegmentsTest {
@@ -97,20 +100,20 @@ public class SegmentsTest {
public void shouldNotCreateSegmentThatIsAlreadyExpired ( ) {
segments . getOrCreateSegment ( 7 , context ) ;
assertNull ( segments . getOrCreateSegment ( 0 , context ) ) ;
assertFalse ( new File ( context . stateDir ( ) , "test/test-19700101000 0" ) . exists ( ) ) ;
assertFalse ( new File ( context . stateDir ( ) , "test/test: 0" ) . exists ( ) ) ;
}
@Test
public void shouldCleanupSegmentsThatHaveExpired ( ) {
final Segment segment1 = segments . getOrCreateSegment ( 0 , context ) ;
final Segment segment2 = segments . getOrCreateSegment ( 0 , context ) ;
final Segment segment2 = segments . getOrCreateSegment ( 1 , context ) ;
final Segment segment3 = segments . getOrCreateSegment ( 7 , context ) ;
assertFalse ( segment1 . isOpen ( ) ) ;
assertFalse ( segment2 . isOpen ( ) ) ;
assertTrue ( segment3 . isOpen ( ) ) ;
assertFalse ( new File ( context . stateDir ( ) , "test/test-19700101000 0" ) . exists ( ) ) ;
assertFalse ( new File ( context . stateDir ( ) , "test/test-197001010001" ) . exists ( ) ) ;
assertTrue ( new File ( context . stateDir ( ) , "test/test-197001010007" ) . exists ( ) ) ;
assertFalse ( new File ( context . stateDir ( ) , "test/test: 0" ) . exists ( ) ) ;
assertFalse ( new File ( context . stateDir ( ) , "test/test:" + segmentInterval ) . exists ( ) ) ;
assertTrue ( new File ( context . stateDir ( ) , "test/test:" + 7 * segmentInterval ) . exists ( ) ) ;
}
@Test