@Test public void testRead() { int readKeyNumber = new Random().nextInt(recordsToInsert); Set<String> fields = new HashSet<>(); fields.add(firstField); fields.add(thirdField); HashMap<String, String> expectedValue = new HashMap<>(); expectedValue.put(firstField, Integer.toString(readKeyNumber)); expectedValue.put(thirdField, Integer.toString(readKeyNumber * readKeyNumber)); HashMap<String, ByteIterator> readValue = new HashMap<>(); assertEquals("Read transaction FAILED.", Status.OK, riakClient.read(bucket, keyPrefix + Integer.toString(readKeyNumber), fields, readValue)); assertEquals("Read test FAILED. Actual read transaction value is NOT MATCHING the expected one.", expectedValue.toString(), readValue.toString()); }
@Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { Location location = new Location(new Namespace(bucketType, table), key); FetchValue fv = new FetchValue.Builder(location).withOption(FetchValue.Option.R, rvalue).build(); FetchValue.Response response; try { response = fetch(fv); if (response.isNotFound()) { if (debug) { System.err.println("Unable to read key " + key + ". Reason: NOT FOUND"); } return Status.NOT_FOUND; } } catch (TimeoutException e) { if (debug) { System.err.println("Unable to read key " + key + ". Reason: TIME OUT"); } return TIME_OUT; } catch (Exception e) { if (debug) { System.err.println("Unable to read key " + key + ". Reason: " + e.toString()); } return Status.ERROR; } HashMap<String, ByteIterator> partialResult = new HashMap<>(); createResultHashMap(fields, response, partialResult); result.putAll(partialResult); return Status.OK; }
RiakKVClient extends DB { @Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { Location location = new Location(new Namespace(bucketType, table), key); FetchValue fv = new FetchValue.Builder(location).withOption(FetchValue.Option.R, rvalue).build(); FetchValue.Response response; try { response = fetch(fv); if (response.isNotFound()) { if (debug) { System.err.println("Unable to read key " + key + ". Reason: NOT FOUND"); } return Status.NOT_FOUND; } } catch (TimeoutException e) { if (debug) { System.err.println("Unable to read key " + key + ". Reason: TIME OUT"); } return TIME_OUT; } catch (Exception e) { if (debug) { System.err.println("Unable to read key " + key + ". Reason: " + e.toString()); } return Status.ERROR; } HashMap<String, ByteIterator> partialResult = new HashMap<>(); createResultHashMap(fields, response, partialResult); result.putAll(partialResult); return Status.OK; } }
RiakKVClient extends DB { @Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { Location location = new Location(new Namespace(bucketType, table), key); FetchValue fv = new FetchValue.Builder(location).withOption(FetchValue.Option.R, rvalue).build(); FetchValue.Response response; try { response = fetch(fv); if (response.isNotFound()) { if (debug) { System.err.println("Unable to read key " + key + ". Reason: NOT FOUND"); } return Status.NOT_FOUND; } } catch (TimeoutException e) { if (debug) { System.err.println("Unable to read key " + key + ". Reason: TIME OUT"); } return TIME_OUT; } catch (Exception e) { if (debug) { System.err.println("Unable to read key " + key + ". Reason: " + e.toString()); } return Status.ERROR; } HashMap<String, ByteIterator> partialResult = new HashMap<>(); createResultHashMap(fields, response, partialResult); result.putAll(partialResult); return Status.OK; }  }
RiakKVClient extends DB { @Override public Status read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { Location location = new Location(new Namespace(bucketType, table), key); FetchValue fv = new FetchValue.Builder(location).withOption(FetchValue.Option.R, rvalue).build(); FetchValue.Response response; try { response = fetch(fv); if (response.isNotFound()) { if (debug) { System.err.println("Unable to read key " + key + ". Reason: NOT FOUND"); } return Status.NOT_FOUND; } } catch (TimeoutException e) { if (debug) { System.err.println("Unable to read key " + key + ". Reason: TIME OUT"); } return TIME_OUT; } catch (Exception e) { if (debug) { System.err.println("Unable to read key " + key + ". Reason: " + e.toString()); } return Status.ERROR; } HashMap<String, ByteIterator> partialResult = new HashMap<>(); createResultHashMap(fields, response, partialResult); result.putAll(partialResult); 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 read(String table, String key, Set<String> fields, Map<String, ByteIterator> result) { Location location = new Location(new Namespace(bucketType, table), key); FetchValue fv = new FetchValue.Builder(location).withOption(FetchValue.Option.R, rvalue).build(); FetchValue.Response response; try { response = fetch(fv); if (response.isNotFound()) { if (debug) { System.err.println("Unable to read key " + key + ". Reason: NOT FOUND"); } return Status.NOT_FOUND; } } catch (TimeoutException e) { if (debug) { System.err.println("Unable to read key " + key + ". Reason: TIME OUT"); } return TIME_OUT; } catch (Exception e) { if (debug) { System.err.println("Unable to read key " + key + ". Reason: " + e.toString()); } return Status.ERROR; } HashMap<String, ByteIterator> partialResult = new HashMap<>(); createResultHashMap(fields, response, partialResult); result.putAll(partialResult); 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();  }