use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.syncing.SyncingSubscription in project besu by hyperledger.
the class EthSubscribeIntegrationTest method shouldAddMultipleConnectionsToMap.
@Test
public void shouldAddMultipleConnectionsToMap(final TestContext context) {
final Async async = context.async(2);
final JsonRpcRequest subscribeRequestBody1 = createEthSubscribeRequestBody(CONNECTION_ID_1);
final JsonRpcRequest subscribeRequestBody2 = createEthSubscribeRequestBody(CONNECTION_ID_2);
final JsonRpcSuccessResponse expectedResponse1 = new JsonRpcSuccessResponse(subscribeRequestBody1.getId(), "0x1");
final JsonRpcSuccessResponse expectedResponse2 = new JsonRpcSuccessResponse(subscribeRequestBody2.getId(), "0x2");
final ServerWebSocket websocketMock1 = mock(ServerWebSocket.class);
when(websocketMock1.textHandlerID()).thenReturn(CONNECTION_ID_1);
when(websocketMock1.writeFrame(argThat(this::isFinalFrame))).then(countDownOnLastFrame(async));
final ServerWebSocket websocketMock2 = mock(ServerWebSocket.class);
when(websocketMock2.textHandlerID()).thenReturn(CONNECTION_ID_2);
when(websocketMock2.writeFrame(argThat(this::isFinalFrame))).then(countDownOnLastFrame(async));
webSocketMessageHandler.handle(websocketMock1, Json.encodeToBuffer(subscribeRequestBody1), Optional.empty());
webSocketMessageHandler.handle(websocketMock2, Json.encodeToBuffer(subscribeRequestBody2), Optional.empty());
async.awaitSuccess(ASYNC_TIMEOUT);
final List<SyncingSubscription> updatedSubscriptions = getSubscriptions();
assertThat(updatedSubscriptions).hasSize(2);
final List<String> connectionIds = updatedSubscriptions.stream().map(Subscription::getConnectionId).collect(Collectors.toList());
assertThat(connectionIds).containsExactlyInAnyOrder(CONNECTION_ID_1, CONNECTION_ID_2);
verify(websocketMock1).writeFrame(argThat(isFrameWithAnyText(Json.encode(expectedResponse1), Json.encode(expectedResponse2))));
verify(websocketMock1).writeFrame(argThat(this::isFinalFrame));
verify(websocketMock2).writeFrame(argThat(isFrameWithAnyText(Json.encode(expectedResponse1), Json.encode(expectedResponse2))));
verify(websocketMock2).writeFrame(argThat(this::isFinalFrame));
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.syncing.SyncingSubscription in project besu by hyperledger.
the class SubscriptionBuilderTest method shouldReturnSubscriptionWhenMappingSyncingSubscription.
@Test
public void shouldReturnSubscriptionWhenMappingSyncingSubscription() {
final Function<Subscription, SyncingSubscription> function = subscriptionBuilder.mapToSubscriptionClass(SyncingSubscription.class);
final Subscription subscription = new SyncingSubscription(1L, CONNECTION_ID, SubscriptionType.SYNCING);
assertThat(function.apply(subscription)).isInstanceOf(SyncingSubscription.class);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.syncing.SyncingSubscription in project besu by hyperledger.
the class SubscriptionBuilderTest method shouldBuildSubscriptionWhenSubscribeRequestTypeIsSyncing.
@Test
public void shouldBuildSubscriptionWhenSubscribeRequestTypeIsSyncing() {
final SubscribeRequest subscribeRequest = new SubscribeRequest(SubscriptionType.SYNCING, null, null, CONNECTION_ID);
final SyncingSubscription expectedSubscription = new SyncingSubscription(1L, CONNECTION_ID, SubscriptionType.SYNCING);
final Subscription builtSubscription = subscriptionBuilder.build(1L, CONNECTION_ID, subscribeRequest);
assertThat(builtSubscription).usingRecursiveComparison().isEqualTo(expectedSubscription);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.syncing.SyncingSubscription in project besu by hyperledger.
the class SubscriptionManagerTest method subscribeShouldCreateSubscription.
@Test
public void subscribeShouldCreateSubscription() {
final SubscribeRequest subscribeRequest = subscribeRequest(CONNECTION_ID);
final Long subscriptionId = subscriptionManager.subscribe(subscribeRequest);
final SyncingSubscription expectedSubscription = new SyncingSubscription(subscriptionId, CONNECTION_ID, subscribeRequest.getSubscriptionType());
final Subscription createdSubscription = subscriptionManager.getSubscriptionById(subscriptionId);
assertThat(subscriptionId).isEqualTo(1L);
assertThat(createdSubscription).isEqualTo(expectedSubscription);
}
use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.syncing.SyncingSubscription in project besu by hyperledger.
the class EthSubscribeIntegrationTest method shouldAddConnectionToMap.
@Test
public void shouldAddConnectionToMap(final TestContext context) {
final Async async = context.async();
final JsonRpcRequest subscribeRequestBody = createEthSubscribeRequestBody(CONNECTION_ID_1);
final JsonRpcSuccessResponse expectedResponse = new JsonRpcSuccessResponse(subscribeRequestBody.getId(), "0x1");
final ServerWebSocket websocketMock = mock(ServerWebSocket.class);
when(websocketMock.textHandlerID()).thenReturn(CONNECTION_ID_1);
when(websocketMock.writeFrame(argThat(this::isFinalFrame))).then(completeOnLastFrame(async, websocketMock));
webSocketMessageHandler.handle(websocketMock, Json.encodeToBuffer(subscribeRequestBody), Optional.empty());
async.awaitSuccess(ASYNC_TIMEOUT);
final List<SyncingSubscription> syncingSubscriptions = getSubscriptions();
assertThat(syncingSubscriptions).hasSize(1);
assertThat(syncingSubscriptions.get(0).getConnectionId()).isEqualTo(CONNECTION_ID_1);
verify(websocketMock).writeFrame(argThat(isFrameWithAnyText(Json.encode(expectedResponse))));
verify(websocketMock).writeFrame(argThat(this::isFinalFrame));
}
Aggregations