Search in sources :

Example 1 with UnsubscribeRequest

use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.UnsubscribeRequest in project besu by hyperledger.

the class EthUnsubscribe method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
    try {
        final UnsubscribeRequest unsubscribeRequest = getMapper().mapUnsubscribeRequest(requestContext);
        final boolean unsubscribed = subscriptionManager().unsubscribe(unsubscribeRequest);
        return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), unsubscribed);
    } catch (final InvalidSubscriptionRequestException isEx) {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INVALID_REQUEST);
    } catch (final SubscriptionNotFoundException snfEx) {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.SUBSCRIPTION_NOT_FOUND);
    } catch (final Exception e) {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.INTERNAL_ERROR);
    }
}
Also used : UnsubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.UnsubscribeRequest) SubscriptionNotFoundException(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionNotFoundException) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) InvalidSubscriptionRequestException(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.InvalidSubscriptionRequestException) SubscriptionNotFoundException(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionNotFoundException) InvalidSubscriptionRequestException(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.InvalidSubscriptionRequestException) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

Example 2 with UnsubscribeRequest

use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.UnsubscribeRequest in project besu by hyperledger.

the class EthUnsubscribeTest method responseContainsUnsubscribeStatus.

@Test
public void responseContainsUnsubscribeStatus() {
    final JsonRpcRequestContext request = createJsonRpcRequest();
    final UnsubscribeRequest unsubscribeRequest = new UnsubscribeRequest(1L, CONNECTION_ID);
    when(mapperMock.mapUnsubscribeRequest(eq(request))).thenReturn(unsubscribeRequest);
    when(subscriptionManagerMock.unsubscribe(eq(unsubscribeRequest))).thenReturn(true);
    final JsonRpcSuccessResponse expectedResponse = new JsonRpcSuccessResponse(request.getRequest().getId(), true);
    assertThat(ethUnsubscribe.response(request)).isEqualTo(expectedResponse);
}
Also used : JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) UnsubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.UnsubscribeRequest) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) Test(org.junit.Test)

Example 3 with UnsubscribeRequest

use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.UnsubscribeRequest in project besu by hyperledger.

the class SubscriptionManagerTest method shouldRemoveSubscriptionFromExistingConnection.

@Test
public void shouldRemoveSubscriptionFromExistingConnection() {
    final SubscribeRequest subscribeRequest = subscribeRequest(CONNECTION_ID);
    final Long subscriptionId1 = subscriptionManager.subscribe(subscribeRequest);
    final Long subscriptionId2 = subscriptionManager.subscribe(subscribeRequest);
    assertThat(subscriptionManager.getSubscriptionById(subscriptionId1).getConnectionId()).isEqualTo(CONNECTION_ID);
    assertThat(subscriptionManager.getSubscriptionById(subscriptionId2).getConnectionId()).isEqualTo(CONNECTION_ID);
    final UnsubscribeRequest unsubscribeRequest = new UnsubscribeRequest(subscriptionId1, CONNECTION_ID);
    subscriptionManager.unsubscribe(unsubscribeRequest);
    assertThat(subscriptionManager.getSubscriptionById(subscriptionId1)).isNull();
    assertThat(subscriptionManager.getSubscriptionById(subscriptionId2).getConnectionId()).isEqualTo(CONNECTION_ID);
}
Also used : SubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.SubscribeRequest) PrivateSubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest) UnsubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.UnsubscribeRequest) Test(org.junit.Test)

Example 4 with UnsubscribeRequest

use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.UnsubscribeRequest in project besu by hyperledger.

the class SubscriptionManagerTest method shouldRemoveConnectionWithSingleSubscriptions.

@Test
public void shouldRemoveConnectionWithSingleSubscriptions() {
    final SubscribeRequest subscribeRequest = subscribeRequest(CONNECTION_ID);
    final Long subscriptionId1 = subscriptionManager.subscribe(subscribeRequest);
    assertThat(subscriptionManager.getSubscriptionById(subscriptionId1).getConnectionId()).isEqualTo(CONNECTION_ID);
    final UnsubscribeRequest unsubscribeRequest = new UnsubscribeRequest(subscriptionId1, CONNECTION_ID);
    subscriptionManager.unsubscribe(unsubscribeRequest);
    assertThat(subscriptionManager.getSubscriptionById(subscriptionId1)).isNull();
}
Also used : SubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.SubscribeRequest) PrivateSubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest) UnsubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.UnsubscribeRequest) Test(org.junit.Test)

Example 5 with UnsubscribeRequest

use of org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.UnsubscribeRequest in project besu by hyperledger.

the class SubscriptionManagerTest method unsubscribeExistingSubscriptionShouldDestroySubscription.

@Test
public void unsubscribeExistingSubscriptionShouldDestroySubscription() {
    final SubscribeRequest subscribeRequest = subscribeRequest(CONNECTION_ID);
    final Long subscriptionId = subscriptionManager.subscribe(subscribeRequest);
    assertThat(subscriptionManager.getSubscriptionById(subscriptionId)).isNotNull();
    final UnsubscribeRequest unsubscribeRequest = new UnsubscribeRequest(subscriptionId, CONNECTION_ID);
    final boolean unsubscribed = subscriptionManager.unsubscribe(unsubscribeRequest);
    assertThat(unsubscribed).isTrue();
    assertThat(subscriptionManager.getSubscriptionById(subscriptionId)).isNull();
}
Also used : SubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.SubscribeRequest) PrivateSubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest) UnsubscribeRequest(org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.UnsubscribeRequest) Test(org.junit.Test)

Aggregations

UnsubscribeRequest (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.UnsubscribeRequest)8 Test (org.junit.Test)7 PrivateSubscribeRequest (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.PrivateSubscribeRequest)5 SubscribeRequest (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.SubscribeRequest)5 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)2 JsonRpcSuccessResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)2 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)1 JsonRpcErrorResponse (org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)1 SubscriptionNotFoundException (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.SubscriptionNotFoundException)1 InvalidSubscriptionRequestException (org.hyperledger.besu.ethereum.api.jsonrpc.websocket.subscription.request.InvalidSubscriptionRequestException)1