@ -149,6 +149,29 @@ public class NewBlockHeadersSubscriptionServiceTest {
verify ( blockchainQueries , times ( 1 ) ) . blockByHash ( any ( ) ) ;
}
@Test
public void shouldOnlyCreateResponsesOnce ( ) {
final NewBlockHeadersSubscription subscription1 = createSubscription ( true ) ;
final NewBlockHeadersSubscription subscription2 = createSubscription ( false ) ;
final NewBlockHeadersSubscription subscription3 = createSubscription ( true ) ;
final NewBlockHeadersSubscription subscription4 = createSubscription ( false ) ;
mockSubscriptionManagerNotifyMethod ( subscription1 , subscription2 , subscription3 , subscription4 ) ;
simulateAddingBlockOnCanonicalChain ( ) ;
verify ( subscriptionManager , times ( 4 ) )
. sendMessage ( subscriptionIdCaptor . capture ( ) , responseCaptor . capture ( ) ) ;
assertThat ( subscriptionIdCaptor . getAllValues ( ) )
. containsExactly (
subscription1 . getSubscriptionId ( ) ,
subscription2 . getSubscriptionId ( ) ,
subscription3 . getSubscriptionId ( ) ,
subscription4 . getSubscriptionId ( ) ) ;
verify ( blockchainQueries , times ( 1 ) ) . blockByHashWithTxHashes ( any ( ) ) ;
verify ( blockchainQueries , times ( 1 ) ) . blockByHash ( any ( ) ) ;
}
private BlockResult expectedBlockWithTransactions ( final List < Hash > objects ) {
final BlockWithMetadata < Hash , Hash > testBlockWithMetadata =
new BlockWithMetadata < > ( blockHeader , objects , Collections . emptyList ( ) , UInt256 . ONE , 1 ) ;
@ -159,11 +182,12 @@ public class NewBlockHeadersSubscriptionServiceTest {
return expectedNewBlock ;
}
private void mockSubscriptionManagerNotifyMethod ( final NewBlockHeadersSubscription subscription ) {
private void mockSubscriptionManagerNotifyMethod (
final NewBlockHeadersSubscription . . . subscriptions ) {
doAnswer (
invocation - > {
Consumer < List < NewBlockHeadersSubscription > > consumer = invocation . getArgument ( 2 ) ;
consumer . accept ( Collections . singletonList ( subscription ) ) ;
consumer . accept ( List . of ( subscriptions ) ) ;
return null ;
} )
. when ( subscriptionManager )