@Test public void testUpdate() { int updateKeyNumber = new Random().nextInt(recordsToInsert); HashMap<String, ByteIterator> readValueBeforeUpdate = new HashMap<>(); riakClient.read(bucket, keyPrefix + Integer.toString(updateKeyNumber), null, readValueBeforeUpdate); HashMap<String, String> updateValue = new HashMap<>(); updateValue.put(firstField, "UPDATED"); updateValue.put(secondField, "UPDATED"); updateValue.put(thirdField, "UPDATED"); assertEquals("Update transaction FAILED.", Status.OK, riakClient.update(bucket, keyPrefix + Integer.toString(updateKeyNumber), StringByteIterator .getByteIteratorMap(updateValue))); HashMap<String, ByteIterator> readValueAfterUpdate = new HashMap<>(); assertEquals("Update test FAILED. Unable to read key value.", Status.OK, riakClient.read(bucket, keyPrefix + Integer.toString(updateKeyNumber), null, readValueAfterUpdate)); assertEquals("Update transaction NOT EXECUTED PROPERLY. Values DID NOT CHANGE.", updateValue.toString(), readValueAfterUpdate.toString()); assertEquals("Update test FAILED. Unable to restore previous key value.", Status.OK, riakClient.update(bucket, keyPrefix + Integer.toString(updateKeyNumber), readValueBeforeUpdate)); }
@Override public Status update(String table, String key, Map<String, ByteIterator> values) { if (!strongConsistency) { return insert(table, key, values); } Location location = new Location(new Namespace(bucketType, table), key); UpdateValue update = new UpdateValue.Builder(location) .withUpdate(new UpdateEntity(new RiakObject().setValue(BinaryValue.create(serializeTable(values))))) .build(); RiakFuture<UpdateValue.Response, Location> future = riakClient.executeAsync(update); try { future.get(transactionTimeLimit, TimeUnit.SECONDS).wasUpdated(); } catch (TimeoutException e) { if (debug) { System.err.println("Unable to update key " + key + ". Reason: TIME OUT"); } return TIME_OUT; } catch (Exception e) { if (debug) { System.err.println("Unable to update key " + key + ". Reason: " + e.toString()); } return Status.ERROR; } return Status.OK; }
RiakKVClient extends DB { @Override public Status update(String table, String key, Map<String, ByteIterator> values) { if (!strongConsistency) { return insert(table, key, values); } Location location = new Location(new Namespace(bucketType, table), key); UpdateValue update = new UpdateValue.Builder(location) .withUpdate(new UpdateEntity(new RiakObject().setValue(BinaryValue.create(serializeTable(values))))) .build(); RiakFuture<UpdateValue.Response, Location> future = riakClient.executeAsync(update); try { future.get(transactionTimeLimit, TimeUnit.SECONDS).wasUpdated(); } catch (TimeoutException e) { if (debug) { System.err.println("Unable to update key " + key + ". Reason: TIME OUT"); } return TIME_OUT; } catch (Exception e) { if (debug) { System.err.println("Unable to update key " + key + ". Reason: " + e.toString()); } return Status.ERROR; } return Status.OK; } }
RiakKVClient extends DB { @Override public Status update(String table, String key, Map<String, ByteIterator> values) { if (!strongConsistency) { return insert(table, key, values); } Location location = new Location(new Namespace(bucketType, table), key); UpdateValue update = new UpdateValue.Builder(location) .withUpdate(new UpdateEntity(new RiakObject().setValue(BinaryValue.create(serializeTable(values))))) .build(); RiakFuture<UpdateValue.Response, Location> future = riakClient.executeAsync(update); try { future.get(transactionTimeLimit, TimeUnit.SECONDS).wasUpdated(); } catch (TimeoutException e) { if (debug) { System.err.println("Unable to update key " + key + ". Reason: TIME OUT"); } return TIME_OUT; } catch (Exception e) { if (debug) { System.err.println("Unable to update key " + key + ". Reason: " + e.toString()); } return Status.ERROR; } return Status.OK; }  }
RiakKVClient extends DB { @Override public Status update(String table, String key, Map<String, ByteIterator> values) { if (!strongConsistency) { return insert(table, key, values); } Location location = new Location(new Namespace(bucketType, table), key); UpdateValue update = new UpdateValue.Builder(location) .withUpdate(new UpdateEntity(new RiakObject().setValue(BinaryValue.create(serializeTable(values))))) .build(); RiakFuture<UpdateValue.Response, Location> future = riakClient.executeAsync(update); try { future.get(transactionTimeLimit, TimeUnit.SECONDS).wasUpdated(); } catch (TimeoutException e) { if (debug) { System.err.println("Unable to update key " + key + ". Reason: TIME OUT"); } return TIME_OUT; } catch (Exception e) { if (debug) { System.err.println("Unable to update key " + key + ". Reason: " + e.toString()); } return Status.ERROR; } return Status.OK; }  void init(); @Override Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result); @Override Status scan(String table, String startkey, int recordcount, Set<String> fields,
                     Vector<HashMap<String, ByteIterator>> result); @Override Status insert(String table, String key, Map<String, ByteIterator> values); @Override Status update(String table, String key, Map<String, ByteIterator> values); @Override Status delete(String table, String key); void cleanup(); }
RiakKVClient extends DB { @Override public Status update(String table, String key, Map<String, ByteIterator> values) { if (!strongConsistency) { return insert(table, key, values); } Location location = new Location(new Namespace(bucketType, table), key); UpdateValue update = new UpdateValue.Builder(location) .withUpdate(new UpdateEntity(new RiakObject().setValue(BinaryValue.create(serializeTable(values))))) .build(); RiakFuture<UpdateValue.Response, Location> future = riakClient.executeAsync(update); try { future.get(transactionTimeLimit, TimeUnit.SECONDS).wasUpdated(); } catch (TimeoutException e) { if (debug) { System.err.println("Unable to update key " + key + ". Reason: TIME OUT"); } return TIME_OUT; } catch (Exception e) { if (debug) { System.err.println("Unable to update key " + key + ". Reason: " + e.toString()); } return Status.ERROR; } return Status.OK; }  void init(); @Override Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result); @Override Status scan(String table, String startkey, int recordcount, Set<String> fields,
                     Vector<HashMap<String, ByteIterator>> result); @Override Status insert(String table, String key, Map<String, ByteIterator> values); @Override Status update(String table, String key, Map<String, ByteIterator> values); @Override Status delete(String table, String key); void cleanup();  }