Skip to content

Commit

Permalink
[PAN-2529] subscribing to sync events should receive false when in sy…
Browse files Browse the repository at this point in the history
  • Loading branch information
Errorific authored and notlesh committed May 4, 2019
1 parent 8a84992 commit 8690418
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public long getHighestBlock() {
return highestBlock;
}

public boolean inSync() {
return currentBlock == highestBlock;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ private void sendSyncingToMatchingSubscriptions(final SyncStatus syncStatus) {
final List<Subscription> syncingSubscriptions =
subscriptionManager.subscriptionsOfType(SubscriptionType.SYNCING, Subscription.class);

syncingSubscriptions.forEach(
s -> subscriptionManager.sendMessage(s.getId(), new SyncingResult(syncStatus)));
if (syncStatus.inSync()) {
syncingSubscriptions.forEach(
s -> subscriptionManager.sendMessage(s.getId(), new NotSynchronisingResult()));
} else {
syncingSubscriptions.forEach(
s -> subscriptionManager.sendMessage(s.getId(), new SyncingResult(syncStatus)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,24 @@ public void shouldSendSyncStatusWhenReceiveSyncStatus() {
final SyncingSubscription subscription = new SyncingSubscription(9L, SubscriptionType.SYNCING);
when(subscriptionManager.subscriptionsOfType(any(), any()))
.thenReturn(Lists.newArrayList(subscription));
final SyncStatus syncStatus = new SyncStatus(0L, 1L, 1L);
final SyncStatus syncStatus = new SyncStatus(0L, 1L, 3L);
final SyncingResult expectedSyncingResult = new SyncingResult(syncStatus);

syncStatusListener.onSyncStatus(syncStatus);

verify(subscriptionManager).sendMessage(eq(subscription.getId()), eq(expectedSyncingResult));
}

@Test
public void shouldSendNotSyncingStatusWhenReceiveSyncStatusAtHead() {
final SyncingSubscription subscription = new SyncingSubscription(9L, SubscriptionType.SYNCING);
when(subscriptionManager.subscriptionsOfType(any(), any()))
.thenReturn(Lists.newArrayList(subscription));
final SyncStatus syncStatus = new SyncStatus(0L, 1L, 1L);

syncStatusListener.onSyncStatus(syncStatus);

verify(subscriptionManager)
.sendMessage(eq(subscription.getId()), any(NotSynchronisingResult.class));
}
}

0 comments on commit 8690418

Please sign in to comment.