Search in sources :

Example 1 with SyncingResult

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);
}
Also used : JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) SyncingResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SyncingResult) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) DefaultSyncStatus(org.hyperledger.besu.ethereum.core.DefaultSyncStatus) SyncStatus(org.hyperledger.besu.plugin.data.SyncStatus) DefaultSyncStatus(org.hyperledger.besu.ethereum.core.DefaultSyncStatus) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Test(org.junit.Test)

Example 2 with SyncingResult

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));
}
Also used : SyncingResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SyncingResult) DefaultSyncStatus(org.hyperledger.besu.ethereum.core.DefaultSyncStatus) SyncStatus(org.hyperledger.besu.plugin.data.SyncStatus) DefaultSyncStatus(org.hyperledger.besu.ethereum.core.DefaultSyncStatus) JsonRpcResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.JsonRpcResult) List(java.util.List) Test(org.junit.Test)

Example 3 with SyncingResult

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);
}
Also used : JsonRpcResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse) SyncingResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SyncingResult) JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) DefaultSyncStatus(org.hyperledger.besu.ethereum.core.DefaultSyncStatus) SyncStatus(org.hyperledger.besu.plugin.data.SyncStatus) DefaultSyncStatus(org.hyperledger.besu.ethereum.core.DefaultSyncStatus) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Test(org.junit.Test)

Example 4 with SyncingResult

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));
    });
}
Also used : SyncingResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SyncingResult) JsonRpcResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.JsonRpcResult)

Aggregations

SyncingResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.SyncingResult)4 DefaultSyncStatus (org.hyperledger.besu.ethereum.core.DefaultSyncStatus)3 SyncStatus (org.hyperledger.besu.plugin.data.SyncStatus)3 Test (org.junit.Test)3 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)2 JsonRpcResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcResponse)2 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)2 JsonRpcResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.JsonRpcResult)2 List (java.util.List)1