@Test public void shouldReturnUnavailableWhenStoreNotAvailable() throws Exception { final GetStateFork handler = new GetStateFork(chainDataProvider, jsonProvider); when(chainDataProvider.isStoreAvailable()).thenReturn(false); handler.handle(context); verifyStatusCode(SC_NOT_FOUND); }
@OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get state fork", tags = {TAG_V1_BEACON, TAG_VALIDATOR_REQUIRED}, description = "Request beacon node to provide all validators that are scheduled to propose a block in the given epoch.", pathParams = { @OpenApiParam(name = PARAM_STATE_ID, description = PARAM_STATE_ID_DESCRIPTION), }, responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = GetStateForkResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST), @OpenApiResponse(status = RES_NOT_FOUND), @OpenApiResponse(status = RES_INTERNAL_ERROR), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = SERVICE_UNAVAILABLE) }) @Override public void handle(@NotNull final Context ctx) throws Exception { final Map<String, String> pathParams = ctx.pathParamMap(); try { final Optional<UInt64> maybeSlot = chainDataProvider.stateParameterToSlot(pathParams.get(PARAM_STATE_ID)); if (maybeSlot.isEmpty()) { ctx.status(SC_NOT_FOUND); return; } SafeFuture<Optional<Fork>> future = chainDataProvider.getForkAtSlot(maybeSlot.get()); handleOptionalResult(ctx, future, this::handleResult, SC_NOT_FOUND); } catch (ChainDataUnavailableException ex) { LOG.trace(ex); ctx.status(SC_SERVICE_UNAVAILABLE); } catch (IllegalArgumentException ex) { LOG.trace(ex); ctx.status(SC_BAD_REQUEST); ctx.result(jsonProvider.objectToJSON(new BadRequest(ex.getMessage()))); } }
GetStateFork extends AbstractHandler implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get state fork", tags = {TAG_V1_BEACON, TAG_VALIDATOR_REQUIRED}, description = "Request beacon node to provide all validators that are scheduled to propose a block in the given epoch.", pathParams = { @OpenApiParam(name = PARAM_STATE_ID, description = PARAM_STATE_ID_DESCRIPTION), }, responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = GetStateForkResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST), @OpenApiResponse(status = RES_NOT_FOUND), @OpenApiResponse(status = RES_INTERNAL_ERROR), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = SERVICE_UNAVAILABLE) }) @Override public void handle(@NotNull final Context ctx) throws Exception { final Map<String, String> pathParams = ctx.pathParamMap(); try { final Optional<UInt64> maybeSlot = chainDataProvider.stateParameterToSlot(pathParams.get(PARAM_STATE_ID)); if (maybeSlot.isEmpty()) { ctx.status(SC_NOT_FOUND); return; } SafeFuture<Optional<Fork>> future = chainDataProvider.getForkAtSlot(maybeSlot.get()); handleOptionalResult(ctx, future, this::handleResult, SC_NOT_FOUND); } catch (ChainDataUnavailableException ex) { LOG.trace(ex); ctx.status(SC_SERVICE_UNAVAILABLE); } catch (IllegalArgumentException ex) { LOG.trace(ex); ctx.status(SC_BAD_REQUEST); ctx.result(jsonProvider.objectToJSON(new BadRequest(ex.getMessage()))); } } }
GetStateFork extends AbstractHandler implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get state fork", tags = {TAG_V1_BEACON, TAG_VALIDATOR_REQUIRED}, description = "Request beacon node to provide all validators that are scheduled to propose a block in the given epoch.", pathParams = { @OpenApiParam(name = PARAM_STATE_ID, description = PARAM_STATE_ID_DESCRIPTION), }, responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = GetStateForkResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST), @OpenApiResponse(status = RES_NOT_FOUND), @OpenApiResponse(status = RES_INTERNAL_ERROR), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = SERVICE_UNAVAILABLE) }) @Override public void handle(@NotNull final Context ctx) throws Exception { final Map<String, String> pathParams = ctx.pathParamMap(); try { final Optional<UInt64> maybeSlot = chainDataProvider.stateParameterToSlot(pathParams.get(PARAM_STATE_ID)); if (maybeSlot.isEmpty()) { ctx.status(SC_NOT_FOUND); return; } SafeFuture<Optional<Fork>> future = chainDataProvider.getForkAtSlot(maybeSlot.get()); handleOptionalResult(ctx, future, this::handleResult, SC_NOT_FOUND); } catch (ChainDataUnavailableException ex) { LOG.trace(ex); ctx.status(SC_SERVICE_UNAVAILABLE); } catch (IllegalArgumentException ex) { LOG.trace(ex); ctx.status(SC_BAD_REQUEST); ctx.result(jsonProvider.objectToJSON(new BadRequest(ex.getMessage()))); } } GetStateFork(final DataProvider dataProvider, final JsonProvider jsonProvider);   GetStateFork(final ChainDataProvider chainDataProvider, final JsonProvider jsonProvider); }
GetStateFork extends AbstractHandler implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get state fork", tags = {TAG_V1_BEACON, TAG_VALIDATOR_REQUIRED}, description = "Request beacon node to provide all validators that are scheduled to propose a block in the given epoch.", pathParams = { @OpenApiParam(name = PARAM_STATE_ID, description = PARAM_STATE_ID_DESCRIPTION), }, responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = GetStateForkResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST), @OpenApiResponse(status = RES_NOT_FOUND), @OpenApiResponse(status = RES_INTERNAL_ERROR), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = SERVICE_UNAVAILABLE) }) @Override public void handle(@NotNull final Context ctx) throws Exception { final Map<String, String> pathParams = ctx.pathParamMap(); try { final Optional<UInt64> maybeSlot = chainDataProvider.stateParameterToSlot(pathParams.get(PARAM_STATE_ID)); if (maybeSlot.isEmpty()) { ctx.status(SC_NOT_FOUND); return; } SafeFuture<Optional<Fork>> future = chainDataProvider.getForkAtSlot(maybeSlot.get()); handleOptionalResult(ctx, future, this::handleResult, SC_NOT_FOUND); } catch (ChainDataUnavailableException ex) { LOG.trace(ex); ctx.status(SC_SERVICE_UNAVAILABLE); } catch (IllegalArgumentException ex) { LOG.trace(ex); ctx.status(SC_BAD_REQUEST); ctx.result(jsonProvider.objectToJSON(new BadRequest(ex.getMessage()))); } } GetStateFork(final DataProvider dataProvider, final JsonProvider jsonProvider);   GetStateFork(final ChainDataProvider chainDataProvider, final JsonProvider jsonProvider); @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get state fork", tags = {TAG_V1_BEACON, TAG_VALIDATOR_REQUIRED}, description = "Request beacon node to provide all validators that are scheduled to propose a block in the given epoch.", pathParams = { @OpenApiParam(name = PARAM_STATE_ID, description = PARAM_STATE_ID_DESCRIPTION), }, responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = GetStateForkResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST), @OpenApiResponse(status = RES_NOT_FOUND), @OpenApiResponse(status = RES_INTERNAL_ERROR), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = SERVICE_UNAVAILABLE) }) @Override void handle(@NotNull final Context ctx); }
GetStateFork extends AbstractHandler implements Handler { @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get state fork", tags = {TAG_V1_BEACON, TAG_VALIDATOR_REQUIRED}, description = "Request beacon node to provide all validators that are scheduled to propose a block in the given epoch.", pathParams = { @OpenApiParam(name = PARAM_STATE_ID, description = PARAM_STATE_ID_DESCRIPTION), }, responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = GetStateForkResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST), @OpenApiResponse(status = RES_NOT_FOUND), @OpenApiResponse(status = RES_INTERNAL_ERROR), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = SERVICE_UNAVAILABLE) }) @Override public void handle(@NotNull final Context ctx) throws Exception { final Map<String, String> pathParams = ctx.pathParamMap(); try { final Optional<UInt64> maybeSlot = chainDataProvider.stateParameterToSlot(pathParams.get(PARAM_STATE_ID)); if (maybeSlot.isEmpty()) { ctx.status(SC_NOT_FOUND); return; } SafeFuture<Optional<Fork>> future = chainDataProvider.getForkAtSlot(maybeSlot.get()); handleOptionalResult(ctx, future, this::handleResult, SC_NOT_FOUND); } catch (ChainDataUnavailableException ex) { LOG.trace(ex); ctx.status(SC_SERVICE_UNAVAILABLE); } catch (IllegalArgumentException ex) { LOG.trace(ex); ctx.status(SC_BAD_REQUEST); ctx.result(jsonProvider.objectToJSON(new BadRequest(ex.getMessage()))); } } GetStateFork(final DataProvider dataProvider, final JsonProvider jsonProvider);   GetStateFork(final ChainDataProvider chainDataProvider, final JsonProvider jsonProvider); @OpenApi( path = ROUTE, method = HttpMethod.GET, summary = "Get state fork", tags = {TAG_V1_BEACON, TAG_VALIDATOR_REQUIRED}, description = "Request beacon node to provide all validators that are scheduled to propose a block in the given epoch.", pathParams = { @OpenApiParam(name = PARAM_STATE_ID, description = PARAM_STATE_ID_DESCRIPTION), }, responses = { @OpenApiResponse( status = RES_OK, content = @OpenApiContent(from = GetStateForkResponse.class)), @OpenApiResponse(status = RES_BAD_REQUEST), @OpenApiResponse(status = RES_NOT_FOUND), @OpenApiResponse(status = RES_INTERNAL_ERROR), @OpenApiResponse(status = RES_SERVICE_UNAVAILABLE, description = SERVICE_UNAVAILABLE) }) @Override void handle(@NotNull final Context ctx); static final String ROUTE; }