Search in sources :

Example 1 with SubscriptionResponse

use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.response.SubscriptionResponse in project besu by hyperledger.

the class SubscriptionManagerSendMessageTest method shouldSendMessageOnTheConnectionIdEventBusAddressForExistingSubscription.

@Test
@Ignore
public void shouldSendMessageOnTheConnectionIdEventBusAddressForExistingSubscription(final TestContext context) {
    final String connectionId = UUID.randomUUID().toString();
    final SubscribeRequest subscribeRequest = new SubscribeRequest(SubscriptionType.SYNCING, null, null, connectionId);
    final JsonRpcResult expectedResult = mock(JsonRpcResult.class);
    final Subscription subscription = new Subscription(1L, connectionId, SubscriptionType.SYNCING, false);
    final SubscriptionResponse expectedResponse = new SubscriptionResponse(subscription, expectedResult);
    final Long subscriptionId = subscriptionManager.subscribe(subscribeRequest);
    final Async async = context.async();
    vertx.eventBus().consumer(connectionId).handler(msg -> {
        context.assertEquals(Json.encode(expectedResponse), msg.body());
        async.complete();
    }).completionHandler(v -> subscriptionManager.sendMessage(subscriptionId, expectedResult));
    async.awaitSuccess(VERTX_AWAIT_TIMEOUT_MILLIS);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) SubscriptionType(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.SubscriptionType) Async(io.vertx.ext.unit.Async) Json(io.vertx.core.json.Json) TestCase.fail(junit.framework.TestCase.fail) Vertx(io.vertx.core.Vertx) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) SubscriptionResponse(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.response.SubscriptionResponse) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) UUID(java.util.UUID) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) SubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.SubscribeRequest) Ignore(org.junit.Ignore) JsonRpcResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.JsonRpcResult) Mockito.mock(org.mockito.Mockito.mock) Before(org.junit.Before) SubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.SubscribeRequest) Async(io.vertx.ext.unit.Async) JsonRpcResult(org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.JsonRpcResult) SubscriptionResponse(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.response.SubscriptionResponse) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with SubscriptionResponse

use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.response.SubscriptionResponse in project besu by hyperledger.

the class SubscriptionManager method sendMessage.

public void sendMessage(final Long subscriptionId, final JsonRpcResult msg) {
    final Subscription subscription = subscriptions.get(subscriptionId);
    if (subscription != null) {
        final SubscriptionResponse response = new SubscriptionResponse(subscription, msg);
        vertx.eventBus().send(subscription.getConnectionId(), Json.encode(response));
    }
}
Also used : SubscriptionResponse(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.response.SubscriptionResponse) PrivateLogsSubscription(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.logs.PrivateLogsSubscription)

Aggregations

SubscriptionResponse (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.response.SubscriptionResponse)2 Vertx (io.vertx.core.Vertx)1 Json (io.vertx.core.json.Json)1 Async (io.vertx.ext.unit.Async)1 TestContext (io.vertx.ext.unit.TestContext)1 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)1 UUID (java.util.UUID)1 TestCase.fail (junit.framework.TestCase.fail)1 JsonRpcResult (org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.JsonRpcResult)1 PrivateLogsSubscription (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.logs.PrivateLogsSubscription)1 SubscribeRequest (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.SubscribeRequest)1 SubscriptionType (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.SubscriptionType)1 NoOpMetricsSystem (org.hyperledger.besu.metrics.noop.NoOpMetricsSystem)1 Before (org.junit.Before)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 Mockito.mock (org.mockito.Mockito.mock)1