@Test public void shouldReturnConflictIfCompareAndSetFailsBecauseAValueMismatchExceptionIsThrown() { when(distributedStore.compareAndSet(KEY, casValue)).thenReturn( Futures.<KeyValue>immediateFailedFuture(new ValueMismatchException(KEY, EXPECTED_VALUE, "EXISTING_VALUE"))); assertThatResourceMethodReturnsStatus( client().resource(REQUEST_URI).type(MediaType.APPLICATION_JSON_TYPE).entity(casValue), "PUT", ClientResponse.Status.CONFLICT ); }
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();  }