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);
}
}
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);
}
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);
}
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();
}
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();
}
Aggregations