use of org.hyperledger.besu.plugin.data.SyncStatus 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.plugin.data.SyncStatus 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.plugin.data.SyncStatus in project besu by hyperledger.
the class SyncingSubscriptionServiceTest method shouldSendNotSyncingResultWhenReceiveNonSyncingStatus.
@Test
public void shouldSendNotSyncingResultWhenReceiveNonSyncingStatus() {
final SyncingSubscription subscription = new SyncingSubscription(9L, "conn", SubscriptionType.SYNCING);
final List<SyncingSubscription> subscriptions = Collections.singletonList(subscription);
final Optional<SyncStatus> syncStatus = Optional.empty();
final JsonRpcResult expectedSyncingResult = new NotSynchronisingResult();
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.plugin.data.SyncStatus in project besu by hyperledger.
the class EthGetBlockByNumberLatestDesyncIntegrationTest method setUpOnce.
@BeforeAll
public static void setUpOnce() throws Exception {
final String genesisJson = Resources.toString(BlockTestUtil.getTestGenesisUrl(), Charsets.UTF_8);
BlockchainImporter importer = new BlockchainImporter(BlockTestUtil.getTestBlockchainUrl(), genesisJson);
MutableBlockchain chain = InMemoryKeyValueStorageProvider.createInMemoryBlockchain(importer.getGenesisBlock());
WorldStateArchive state = InMemoryKeyValueStorageProvider.createInMemoryWorldStateArchive();
importer.getGenesisState().writeStateTo(state.getMutable());
ProtocolContext context = new ProtocolContext(chain, state, null);
for (final Block block : importer.getBlocks()) {
final ProtocolSchedule protocolSchedule = importer.getProtocolSchedule();
final ProtocolSpec protocolSpec = protocolSchedule.getByBlockNumber(block.getHeader().getNumber());
final BlockImporter blockImporter = protocolSpec.getBlockImporter();
blockImporter.importBlock(context, block, HeaderValidationMode.FULL);
}
methodsFactorySynced = new JsonRpcTestMethodsFactory(importer, chain, state, context);
WorldStateArchive unsynced = mock(WorldStateArchive.class);
when(unsynced.isWorldStateAvailable(any(Hash.class), any(Hash.class))).thenReturn(false);
methodsFactoryDesynced = new JsonRpcTestMethodsFactory(importer, chain, unsynced, context);
WorldStateArchive midSync = mock(WorldStateArchive.class);
when(midSync.isWorldStateAvailable(any(Hash.class), any(Hash.class))).thenReturn(true);
Synchronizer synchronizer = mock(Synchronizer.class);
SyncStatus status = mock(SyncStatus.class);
when(status.getCurrentBlock()).thenReturn(// random choice for current sync state.
ARBITRARY_SYNC_BLOCK);
when(synchronizer.getSyncStatus()).thenReturn(Optional.of(status));
methodsFactoryMidDownload = new JsonRpcTestMethodsFactory(importer, chain, midSync, context, synchronizer);
}
use of org.hyperledger.besu.plugin.data.SyncStatus 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);
}
Aggregations