@ -119,7 +119,10 @@ public class StoreChangelogReaderTest {
final int messages = 10 ;
final int messages = 10 ;
setupConsumer ( messages , topicPartition ) ;
setupConsumer ( messages , topicPartition ) ;
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , true , "storeName" ) ) ;
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , true , "storeName" ) ) ;
expect ( active . restoringTaskFor ( topicPartition ) ) . andStubReturn ( task ) ;
replay ( active , task ) ;
changelogReader . restore ( active ) ;
changelogReader . restore ( active ) ;
assertThat ( callback . restored . size ( ) , equalTo ( messages ) ) ;
assertThat ( callback . restored . size ( ) , equalTo ( messages ) ) ;
}
}
@ -136,8 +139,8 @@ public class StoreChangelogReaderTest {
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , true ,
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , true ,
"storeName" ) ) ;
"storeName" ) ) ;
EasyMock . expect ( active . restoringTaskFor ( topicPartition ) ) . andReturn ( task ) ;
EasyMock . expect ( active . restoringTaskFor ( topicPartition ) ) . andStub Return ( task ) ;
EasyMock . replay ( active ) ;
EasyMock . replay ( active , task ) ;
// first restore call "fails" but we should not die with an exception
// first restore call "fails" but we should not die with an exception
assertEquals ( 0 , changelogReader . restore ( active ) . size ( ) ) ;
assertEquals ( 0 , changelogReader . restore ( active ) . size ( ) ) ;
@ -164,7 +167,8 @@ public class StoreChangelogReaderTest {
setupConsumer ( messages , topicPartition ) ;
setupConsumer ( messages , topicPartition ) ;
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , true ,
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , true ,
"storeName" ) ) ;
"storeName" ) ) ;
expect ( active . restoringTaskFor ( topicPartition ) ) . andStubReturn ( task ) ;
replay ( active , task ) ;
changelogReader . restore ( active ) ;
changelogReader . restore ( active ) ;
assertThat ( consumer . assignment ( ) , equalTo ( Collections . < TopicPartition > emptySet ( ) ) ) ;
assertThat ( consumer . assignment ( ) , equalTo ( Collections . < TopicPartition > emptySet ( ) ) ) ;
}
}
@ -175,6 +179,8 @@ public class StoreChangelogReaderTest {
final StateRestorer restorer = new StateRestorer ( topicPartition , restoreListener , null , 3 , true ,
final StateRestorer restorer = new StateRestorer ( topicPartition , restoreListener , null , 3 , true ,
"storeName" ) ;
"storeName" ) ;
changelogReader . register ( restorer ) ;
changelogReader . register ( restorer ) ;
expect ( active . restoringTaskFor ( topicPartition ) ) . andStubReturn ( task ) ;
replay ( active , task ) ;
changelogReader . restore ( active ) ;
changelogReader . restore ( active ) ;
assertThat ( callback . restored . size ( ) , equalTo ( 3 ) ) ;
assertThat ( callback . restored . size ( ) , equalTo ( 3 ) ) ;
assertThat ( restorer . restoredOffset ( ) , equalTo ( 3L ) ) ;
assertThat ( restorer . restoredOffset ( ) , equalTo ( 3L ) ) ;
@ -192,14 +198,14 @@ public class StoreChangelogReaderTest {
setupConsumer ( 5 , one ) ;
setupConsumer ( 5 , one ) ;
setupConsumer ( 3 , two ) ;
setupConsumer ( 3 , two ) ;
changelogReader
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , true , "storeName1" ) ) ;
. register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , true , "storeName1" ) ) ;
changelogReader . register ( new StateRestorer ( one , restoreListener1 , null , Long . MAX_VALUE , true , "storeName2" ) ) ;
changelogReader . register ( new StateRestorer ( one , restoreListener1 , null , Long . MAX_VALUE , true , "storeName2" ) ) ;
changelogReader . register ( new StateRestorer ( two , restoreListener2 , null , Long . MAX_VALUE , true , "storeName3" ) ) ;
changelogReader . register ( new StateRestorer ( two , restoreListener2 , null , Long . MAX_VALUE , true , "storeName3" ) ) ;
expect ( active . restoringTaskFor ( one ) ) . andReturn ( null ) ;
expect ( active . restoringTaskFor ( one ) ) . andStubReturn ( task ) ;
expect ( active . restoringTaskFor ( two ) ) . andReturn ( null ) ;
expect ( active . restoringTaskFor ( two ) ) . andStubReturn ( task ) ;
replay ( active ) ;
expect ( active . restoringTaskFor ( topicPartition ) ) . andStubReturn ( task ) ;
replay ( active , task ) ;
changelogReader . restore ( active ) ;
changelogReader . restore ( active ) ;
assertThat ( callback . restored . size ( ) , equalTo ( 10 ) ) ;
assertThat ( callback . restored . size ( ) , equalTo ( 10 ) ) ;
@ -224,9 +230,13 @@ public class StoreChangelogReaderTest {
changelogReader . register ( new StateRestorer ( one , restoreListener1 , null , Long . MAX_VALUE , true , "storeName2" ) ) ;
changelogReader . register ( new StateRestorer ( one , restoreListener1 , null , Long . MAX_VALUE , true , "storeName2" ) ) ;
changelogReader . register ( new StateRestorer ( two , restoreListener2 , null , Long . MAX_VALUE , true , "storeName3" ) ) ;
changelogReader . register ( new StateRestorer ( two , restoreListener2 , null , Long . MAX_VALUE , true , "storeName3" ) ) ;
expect ( active . restoringTaskFor ( one ) ) . andReturn ( null ) ;
expect ( active . restoringTaskFor ( one ) ) . andReturn ( task ) ;
expect ( active . restoringTaskFor ( two ) ) . andReturn ( null ) ;
expect ( active . restoringTaskFor ( two ) ) . andReturn ( task ) ;
replay ( active ) ;
expect ( active . restoringTaskFor ( topicPartition ) ) . andReturn ( task ) ;
expect ( active . restoringTaskFor ( topicPartition ) ) . andStubReturn ( task ) ;
replay ( active , task ) ;
changelogReader . restore ( active ) ;
changelogReader . restore ( active ) ;
changelogReader . restore ( active ) ;
assertThat ( callback . restored . size ( ) , equalTo ( 10 ) ) ;
assertThat ( callback . restored . size ( ) , equalTo ( 10 ) ) ;
@ -248,6 +258,8 @@ public class StoreChangelogReaderTest {
setupConsumer ( 10 , topicPartition ) ;
setupConsumer ( 10 , topicPartition ) ;
changelogReader
changelogReader
. register ( new StateRestorer ( topicPartition , restoreListener , null , 5 , true , "storeName1" ) ) ;
. register ( new StateRestorer ( topicPartition , restoreListener , null , 5 , true , "storeName1" ) ) ;
expect ( active . restoringTaskFor ( topicPartition ) ) . andStubReturn ( task ) ;
replay ( active , task ) ;
changelogReader . restore ( active ) ;
changelogReader . restore ( active ) ;
assertThat ( callback . restored . size ( ) , equalTo ( 5 ) ) ;
assertThat ( callback . restored . size ( ) , equalTo ( 5 ) ) ;
@ -306,7 +318,10 @@ public class StoreChangelogReaderTest {
public void shouldReturnRestoredOffsetsForPersistentStores ( ) {
public void shouldReturnRestoredOffsetsForPersistentStores ( ) {
setupConsumer ( 10 , topicPartition ) ;
setupConsumer ( 10 , topicPartition ) ;
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , true , "storeName" ) ) ;
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , true , "storeName" ) ) ;
expect ( active . restoringTaskFor ( topicPartition ) ) . andStubReturn ( task ) ;
replay ( active , task ) ;
changelogReader . restore ( active ) ;
changelogReader . restore ( active ) ;
final Map < TopicPartition , Long > restoredOffsets = changelogReader . restoredOffsets ( ) ;
final Map < TopicPartition , Long > restoredOffsets = changelogReader . restoredOffsets ( ) ;
assertThat ( restoredOffsets , equalTo ( Collections . singletonMap ( topicPartition , 10L ) ) ) ;
assertThat ( restoredOffsets , equalTo ( Collections . singletonMap ( topicPartition , 10L ) ) ) ;
}
}
@ -315,6 +330,8 @@ public class StoreChangelogReaderTest {
public void shouldNotReturnRestoredOffsetsForNonPersistentStore ( ) {
public void shouldNotReturnRestoredOffsetsForNonPersistentStore ( ) {
setupConsumer ( 10 , topicPartition ) ;
setupConsumer ( 10 , topicPartition ) ;
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , false , "storeName" ) ) ;
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , false , "storeName" ) ) ;
expect ( active . restoringTaskFor ( topicPartition ) ) . andStubReturn ( task ) ;
replay ( active , task ) ;
changelogReader . restore ( active ) ;
changelogReader . restore ( active ) ;
final Map < TopicPartition , Long > restoredOffsets = changelogReader . restoredOffsets ( ) ;
final Map < TopicPartition , Long > restoredOffsets = changelogReader . restoredOffsets ( ) ;
assertThat ( restoredOffsets , equalTo ( Collections . < TopicPartition , Long > emptyMap ( ) ) ) ;
assertThat ( restoredOffsets , equalTo ( Collections . < TopicPartition , Long > emptyMap ( ) ) ) ;
@ -330,6 +347,8 @@ public class StoreChangelogReaderTest {
consumer . assign ( Collections . singletonList ( topicPartition ) ) ;
consumer . assign ( Collections . singletonList ( topicPartition ) ) ;
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , false ,
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , false ,
"storeName" ) ) ;
"storeName" ) ) ;
expect ( active . restoringTaskFor ( topicPartition ) ) . andStubReturn ( task ) ;
replay ( active , task ) ;
changelogReader . restore ( active ) ;
changelogReader . restore ( active ) ;
assertThat ( callback . restored , CoreMatchers . equalTo ( Utils . mkList ( KeyValue . pair ( bytes , bytes ) , KeyValue . pair ( bytes , bytes ) ) ) ) ;
assertThat ( callback . restored , CoreMatchers . equalTo ( Utils . mkList ( KeyValue . pair ( bytes , bytes ) , KeyValue . pair ( bytes , bytes ) ) ) ) ;
@ -340,6 +359,9 @@ public class StoreChangelogReaderTest {
final Collection < TopicPartition > expected = Collections . singleton ( topicPartition ) ;
final Collection < TopicPartition > expected = Collections . singleton ( topicPartition ) ;
setupConsumer ( 0 , topicPartition ) ;
setupConsumer ( 0 , topicPartition ) ;
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , true , "store" ) ) ;
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , true , "store" ) ) ;
expect ( active . restoringTaskFor ( topicPartition ) ) . andStubReturn ( task ) ;
replay ( active , task ) ;
final Collection < TopicPartition > restored = changelogReader . restore ( active ) ;
final Collection < TopicPartition > restored = changelogReader . restore ( active ) ;
assertThat ( restored , equalTo ( expected ) ) ;
assertThat ( restored , equalTo ( expected ) ) ;
}
}
@ -354,10 +376,9 @@ public class StoreChangelogReaderTest {
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , false , "storeName" ) ) ;
changelogReader . register ( new StateRestorer ( topicPartition , restoreListener , null , Long . MAX_VALUE , false , "storeName" ) ) ;
final TopicPartition postInitialization = new TopicPartition ( "other" , 0 ) ;
final TopicPartition postInitialization = new TopicPartition ( "other" , 0 ) ;
expect ( active . restoringTaskFor ( topicPartition ) ) . andReturn ( null ) ;
expect ( active . restoringTaskFor ( topicPartition ) ) . andStubReturn ( task ) ;
expect ( active . restoringTaskFor ( topicPartition ) ) . andReturn ( null ) ;
expect ( active . restoringTaskFor ( postInitialization ) ) . andStubReturn ( task ) ;
expect ( active . restoringTaskFor ( postInitialization ) ) . andReturn ( null ) ;
replay ( active , task ) ;
replay ( active ) ;
assertTrue ( changelogReader . restore ( active ) . isEmpty ( ) ) ;
assertTrue ( changelogReader . restore ( active ) . isEmpty ( ) ) ;