@Test public void shouldReturnNoContentIfCASSucceedsAndDeletesAKey() { SetValue deleteKeySetValue = new SetValue(); deleteKeySetValue.setExpectedValue(EXPECTED_VALUE); deleteKeySetValue.setNewValue(null); when(distributedStore.compareAndSet(KEY, deleteKeySetValue)).thenReturn(Futures.<KeyValue>immediateFuture(null)); ClientResponse response = client().resource(REQUEST_URI).type(MediaType.APPLICATION_JSON_TYPE).put(ClientResponse.class, deleteKeySetValue); assertThat(response.getClientResponseStatus(), equalTo(ClientResponse.Status.NO_CONTENT)); }
private KeyValue compareAndSet(SetValue setValue) throws Exception { LOGGER.info("cas: {}->{} if {}", key, setValue.getNewValue(), setValue.getExpectedValue()); try { ListenableFuture<KeyValue> casFuture = distributedStore.compareAndSet(key, setValue); return casFuture.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 KayVeeException) { throw (KayVeeException) cause; } else { throw e; } } }
KeyResource { private KeyValue compareAndSet(SetValue setValue) throws Exception { LOGGER.info("cas: {}->{} if {}", key, setValue.getNewValue(), setValue.getExpectedValue()); try { ListenableFuture<KeyValue> casFuture = distributedStore.compareAndSet(key, setValue); return casFuture.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 KayVeeException) { throw (KayVeeException) cause; } else { throw e; } } } }
KeyResource { private KeyValue compareAndSet(SetValue setValue) throws Exception { LOGGER.info("cas: {}->{} if {}", key, setValue.getNewValue(), setValue.getExpectedValue()); try { ListenableFuture<KeyValue> casFuture = distributedStore.compareAndSet(key, setValue); return casFuture.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 KayVeeException) { throw (KayVeeException) cause; } else { throw e; } } } KeyResource(String key, Set<ClusterMember> members, DistributedStore distributedStore); }
KeyResource { private KeyValue compareAndSet(SetValue setValue) throws Exception { LOGGER.info("cas: {}->{} if {}", key, setValue.getNewValue(), setValue.getExpectedValue()); try { ListenableFuture<KeyValue> casFuture = distributedStore.compareAndSet(key, setValue); return casFuture.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 KayVeeException) { throw (KayVeeException) 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 compareAndSet(SetValue setValue) throws Exception { LOGGER.info("cas: {}->{} if {}", key, setValue.getNewValue(), setValue.getExpectedValue()); try { ListenableFuture<KeyValue> casFuture = distributedStore.compareAndSet(key, setValue); return casFuture.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 KayVeeException) { throw (KayVeeException) 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();  }