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