@Test public void shouldReturnRedirectWithLocationIfSetFailsBecauseNotLeaderExceptionIsThrownWithTheLeaderSetToAValidLeader() { when(distributedStore.set(KEY, setValue)).thenReturn(Futures.<KeyValue>immediateFailedFuture(new NotLeaderException(self, leader))); assertThatValidSetRequestReturnsErrorStatus(ClientResponse.Status.MOVED_PERMANENTLY); }
private KeyValue set(SetValue setValue) throws Exception { LOGGER.info("set: {}->{}", key, setValue.getNewValue()); checkArgument(setValue.getNewValue() != null, "key:%s - null newValue: setValue:%s", key, setValue); try { ListenableFuture<KeyValue> setFuture = distributedStore.set(key, setValue); return setFuture.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 { throw e; } } }
KeyResource { private KeyValue set(SetValue setValue) throws Exception { LOGGER.info("set: {}->{}", key, setValue.getNewValue()); checkArgument(setValue.getNewValue() != null, "key:%s - null newValue: setValue:%s", key, setValue); try { ListenableFuture<KeyValue> setFuture = distributedStore.set(key, setValue); return setFuture.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 { throw e; } } } }
KeyResource { private KeyValue set(SetValue setValue) throws Exception { LOGGER.info("set: {}->{}", key, setValue.getNewValue()); checkArgument(setValue.getNewValue() != null, "key:%s - null newValue: setValue:%s", key, setValue); try { ListenableFuture<KeyValue> setFuture = distributedStore.set(key, setValue); return setFuture.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 { throw e; } } } KeyResource(String key, Set<ClusterMember> members, DistributedStore distributedStore); }
KeyResource { private KeyValue set(SetValue setValue) throws Exception { LOGGER.info("set: {}->{}", key, setValue.getNewValue()); checkArgument(setValue.getNewValue() != null, "key:%s - null newValue: setValue:%s", key, setValue); try { ListenableFuture<KeyValue> setFuture = distributedStore.set(key, setValue); return setFuture.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 { 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 { private KeyValue set(SetValue setValue) throws Exception { LOGGER.info("set: {}->{}", key, setValue.getNewValue()); checkArgument(setValue.getNewValue() != null, "key:%s - null newValue: setValue:%s", key, setValue); try { ListenableFuture<KeyValue> setFuture = distributedStore.set(key, setValue); return setFuture.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 { 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();  }