use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SyncingResult in project besu by hyperledger.
the class EthSyncingTest method shouldReturnExpectedValueWhenSyncStatusIsNotEmpty.
@Test
public void shouldReturnExpectedValueWhenSyncStatusIsNotEmpty() {
final JsonRpcRequestContext request = requestWithParams();
final SyncStatus expectedSyncStatus = new DefaultSyncStatus(0, 1, 2, Optional.empty(), Optional.empty());
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), new SyncingResult(expectedSyncStatus));
final Optional<SyncStatus> optionalSyncStatus = Optional.of(expectedSyncStatus);
when(synchronizer.getSyncStatus()).thenReturn(optionalSyncStatus);
final JsonRpcResponse actualResponse = method.response(request);
assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse);
verify(synchronizer).getSyncStatus();
verifyNoMoreInteractions(synchronizer);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SyncingResult in project besu by hyperledger.
the class SyncingSubscriptionServiceTest method shouldSendSyncStatusWhenReceiveSyncStatus.
@Test
public void shouldSendSyncStatusWhenReceiveSyncStatus() {
final SyncingSubscription subscription = new SyncingSubscription(9L, "conn", SubscriptionType.SYNCING);
final List<SyncingSubscription> subscriptions = Collections.singletonList(subscription);
final Optional<SyncStatus> syncStatus = Optional.of(new DefaultSyncStatus(0L, 1L, 3L, Optional.empty(), Optional.empty()));
final JsonRpcResult expectedSyncingResult = new SyncingResult(syncStatus.get());
doAnswer(invocation -> {
Consumer<List<SyncingSubscription>> consumer = invocation.getArgument(2);
consumer.accept(subscriptions);
return null;
}).when(subscriptionManager).notifySubscribersOnWorkerThread(any(), any(), any());
syncStatusListener.onSyncStatusChanged(syncStatus);
verify(subscriptionManager).sendMessage(ArgumentMatchers.eq(subscription.getSubscriptionId()), eq(expectedSyncingResult));
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SyncingResult in project besu by hyperledger.
the class EthSyncingTest method shouldReturnExpectedValueWhenFastSyncStatusIsNotEmpty.
@Test
public void shouldReturnExpectedValueWhenFastSyncStatusIsNotEmpty() {
final JsonRpcRequestContext request = requestWithParams();
final SyncStatus expectedSyncStatus = new DefaultSyncStatus(0, 1, 2, Optional.of(3L), Optional.of(4L));
final JsonRpcResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), new SyncingResult(expectedSyncStatus));
final Optional<SyncStatus> optionalSyncStatus = Optional.of(expectedSyncStatus);
when(synchronizer.getSyncStatus()).thenReturn(optionalSyncStatus);
final JsonRpcResponse actualResponse = method.response(request);
assertThat(actualResponse).usingRecursiveComparison().isEqualTo(expectedResponse);
verify(synchronizer).getSyncStatus();
verifyNoMoreInteractions(synchronizer);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SyncingResult in project besu by hyperledger.
the class SyncingSubscriptionService method sendSyncingToMatchingSubscriptions.
private void sendSyncingToMatchingSubscriptions(final Optional<SyncStatus> syncStatus) {
subscriptionManager.notifySubscribersOnWorkerThread(SubscriptionType.SYNCING, Subscription.class, syncingSubscriptions -> {
final JsonRpcResult result = syncStatus.isPresent() ? new SyncingResult(syncStatus.get()) : new NotSynchronisingResult();
syncingSubscriptions.forEach(s -> subscriptionManager.sendMessage(s.getSubscriptionId(), result));
});
}
Aggregations