@Test public void shouldReturnInternalServerErrorWithNoLocationIfGetFailsBecauseNotLeaderExceptionIsThrownWithTheLeaderSetToAnInvalidLeader() { when(distributedStore.get(KEY)).thenReturn(Futures.<KeyValue>immediateFailedFuture(new NotLeaderException(self, "UNKNOWN_LEADER"))); assertThatValidGetRequestReturnsErrorStatus(ClientResponse.Status.INTERNAL_SERVER_ERROR); }
@GET @Produces(MediaType.APPLICATION_JSON) public KeyValue get() throws Exception { LOGGER.info("get: {}", key); try { ListenableFuture<KeyValue> getFuture = distributedStore.get(key); return getFuture.get(ResourceConstants.COMMAND_TIMEOUT, ResourceConstants.COMMAND_TIMEOUT_TIME_UNIT); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof NotLeaderException) { throw createCannotSubmitCommandException((NotLeaderException) cause); } else if (cause instanceof KeyNotFoundException) { throw (KeyNotFoundException) cause; } else { throw e; } } }
KeyResource { @GET @Produces(MediaType.APPLICATION_JSON) public KeyValue get() throws Exception { LOGGER.info("get: {}", key); try { ListenableFuture<KeyValue> getFuture = distributedStore.get(key); return getFuture.get(ResourceConstants.COMMAND_TIMEOUT, ResourceConstants.COMMAND_TIMEOUT_TIME_UNIT); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof NotLeaderException) { throw createCannotSubmitCommandException((NotLeaderException) cause); } else if (cause instanceof KeyNotFoundException) { throw (KeyNotFoundException) cause; } else { throw e; } } } }
KeyResource { @GET @Produces(MediaType.APPLICATION_JSON) public KeyValue get() throws Exception { LOGGER.info("get: {}", key); try { ListenableFuture<KeyValue> getFuture = distributedStore.get(key); return getFuture.get(ResourceConstants.COMMAND_TIMEOUT, ResourceConstants.COMMAND_TIMEOUT_TIME_UNIT); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof NotLeaderException) { throw createCannotSubmitCommandException((NotLeaderException) cause); } else if (cause instanceof KeyNotFoundException) { throw (KeyNotFoundException) cause; } else { throw e; } } } KeyResource(String key, Set<ClusterMember> members, DistributedStore distributedStore); }
KeyResource { @GET @Produces(MediaType.APPLICATION_JSON) public KeyValue get() throws Exception { LOGGER.info("get: {}", key); try { ListenableFuture<KeyValue> getFuture = distributedStore.get(key); return getFuture.get(ResourceConstants.COMMAND_TIMEOUT, ResourceConstants.COMMAND_TIMEOUT_TIME_UNIT); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof NotLeaderException) { throw createCannotSubmitCommandException((NotLeaderException) cause); } else if (cause instanceof KeyNotFoundException) { throw (KeyNotFoundException) cause; } else { throw e; } } } KeyResource(String key, Set<ClusterMember> members, DistributedStore distributedStore); @GET @Produces(MediaType.APPLICATION_JSON) KeyValue get(); @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Nullable KeyValue update(SetValue setValue); @DELETE void delete(); }
KeyResource { @GET @Produces(MediaType.APPLICATION_JSON) public KeyValue get() throws Exception { LOGGER.info("get: {}", key); try { ListenableFuture<KeyValue> getFuture = distributedStore.get(key); return getFuture.get(ResourceConstants.COMMAND_TIMEOUT, ResourceConstants.COMMAND_TIMEOUT_TIME_UNIT); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof NotLeaderException) { throw createCannotSubmitCommandException((NotLeaderException) cause); } else if (cause instanceof KeyNotFoundException) { throw (KeyNotFoundException) cause; } else { throw e; } } } KeyResource(String key, Set<ClusterMember> members, DistributedStore distributedStore); @GET @Produces(MediaType.APPLICATION_JSON) KeyValue get(); @PUT @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @Nullable KeyValue update(SetValue setValue); @DELETE void delete();  }