@Test @Ignore public void testFetch() throws Exception { final FetchValue.Response response = mock(FetchValue.Response.class); final Optional<Long> expected = Optional.of(1L); when(client.execute(any(FetchValue.class))).thenReturn(response); final Optional<String> actual = store.fetch(TEST_USER, CURSOR_NAME); verify(client).execute(any(FetchValue.class)); assertThat(actual).isEqualTo(expected); }
public Optional<String> fetch(final String username, final String cursorName) throws NotificationStoreException { Objects.requireNonNull(username, "username == null"); Preconditions.checkArgument(!username.isEmpty(), "username cannot be empty"); Objects.requireNonNull(cursorName, "cursorName == null"); Preconditions.checkArgument(!cursorName.isEmpty(), "cursorName cannot be empty"); final String key = getCursorKey(username, cursorName); final Location location = new Location(NAMESPACE, key); LOGGER.debug("Fetching key (sync): {}", location); final CursorObject cursor; final FetchValue fv = new FetchValue.Builder(location).withTimeout(timeout).build(); try (Timer.Context context = fetchTimer.time()) { final FetchValue.Response response = client.execute(fv); if (response.isNotFound()) { return Optional.empty(); } cursor = response.getValue(CursorObject.class); } catch (UnresolvedConflictException e) { LOGGER.error("Unable to resolve siblings for key: " + location, e); throw new NotificationStoreException(e); } catch (ExecutionException e) { LOGGER.error("Unable to fetch key: " + location, e); throw new NotificationStoreException(e); } catch (InterruptedException e) { LOGGER.warn("Interrupted fetching key: " + location, e); Thread.currentThread().interrupt(); throw new NotificationStoreException(e); } return Optional.ofNullable(cursor).map(c -> c.getValue()); }
CursorStore { public Optional<String> fetch(final String username, final String cursorName) throws NotificationStoreException { Objects.requireNonNull(username, "username == null"); Preconditions.checkArgument(!username.isEmpty(), "username cannot be empty"); Objects.requireNonNull(cursorName, "cursorName == null"); Preconditions.checkArgument(!cursorName.isEmpty(), "cursorName cannot be empty"); final String key = getCursorKey(username, cursorName); final Location location = new Location(NAMESPACE, key); LOGGER.debug("Fetching key (sync): {}", location); final CursorObject cursor; final FetchValue fv = new FetchValue.Builder(location).withTimeout(timeout).build(); try (Timer.Context context = fetchTimer.time()) { final FetchValue.Response response = client.execute(fv); if (response.isNotFound()) { return Optional.empty(); } cursor = response.getValue(CursorObject.class); } catch (UnresolvedConflictException e) { LOGGER.error("Unable to resolve siblings for key: " + location, e); throw new NotificationStoreException(e); } catch (ExecutionException e) { LOGGER.error("Unable to fetch key: " + location, e); throw new NotificationStoreException(e); } catch (InterruptedException e) { LOGGER.warn("Interrupted fetching key: " + location, e); Thread.currentThread().interrupt(); throw new NotificationStoreException(e); } return Optional.ofNullable(cursor).map(c -> c.getValue()); } }
CursorStore { public Optional<String> fetch(final String username, final String cursorName) throws NotificationStoreException { Objects.requireNonNull(username, "username == null"); Preconditions.checkArgument(!username.isEmpty(), "username cannot be empty"); Objects.requireNonNull(cursorName, "cursorName == null"); Preconditions.checkArgument(!cursorName.isEmpty(), "cursorName cannot be empty"); final String key = getCursorKey(username, cursorName); final Location location = new Location(NAMESPACE, key); LOGGER.debug("Fetching key (sync): {}", location); final CursorObject cursor; final FetchValue fv = new FetchValue.Builder(location).withTimeout(timeout).build(); try (Timer.Context context = fetchTimer.time()) { final FetchValue.Response response = client.execute(fv); if (response.isNotFound()) { return Optional.empty(); } cursor = response.getValue(CursorObject.class); } catch (UnresolvedConflictException e) { LOGGER.error("Unable to resolve siblings for key: " + location, e); throw new NotificationStoreException(e); } catch (ExecutionException e) { LOGGER.error("Unable to fetch key: " + location, e); throw new NotificationStoreException(e); } catch (InterruptedException e) { LOGGER.warn("Interrupted fetching key: " + location, e); Thread.currentThread().interrupt(); throw new NotificationStoreException(e); } return Optional.ofNullable(cursor).map(c -> c.getValue()); } CursorStore(
      final RiakClient client, final Duration timeout, final Duration requestTimeout); }
CursorStore { public Optional<String> fetch(final String username, final String cursorName) throws NotificationStoreException { Objects.requireNonNull(username, "username == null"); Preconditions.checkArgument(!username.isEmpty(), "username cannot be empty"); Objects.requireNonNull(cursorName, "cursorName == null"); Preconditions.checkArgument(!cursorName.isEmpty(), "cursorName cannot be empty"); final String key = getCursorKey(username, cursorName); final Location location = new Location(NAMESPACE, key); LOGGER.debug("Fetching key (sync): {}", location); final CursorObject cursor; final FetchValue fv = new FetchValue.Builder(location).withTimeout(timeout).build(); try (Timer.Context context = fetchTimer.time()) { final FetchValue.Response response = client.execute(fv); if (response.isNotFound()) { return Optional.empty(); } cursor = response.getValue(CursorObject.class); } catch (UnresolvedConflictException e) { LOGGER.error("Unable to resolve siblings for key: " + location, e); throw new NotificationStoreException(e); } catch (ExecutionException e) { LOGGER.error("Unable to fetch key: " + location, e); throw new NotificationStoreException(e); } catch (InterruptedException e) { LOGGER.warn("Interrupted fetching key: " + location, e); Thread.currentThread().interrupt(); throw new NotificationStoreException(e); } return Optional.ofNullable(cursor).map(c -> c.getValue()); } CursorStore(
      final RiakClient client, final Duration timeout, final Duration requestTimeout); void initialize(); Optional<String> fetch(final String username, final String cursorName); void store(final String username, final String cursorName, final String value); void delete(final String username, final String cursorName); String getCursorKey(final String username, final String cursorName); }
CursorStore { public Optional<String> fetch(final String username, final String cursorName) throws NotificationStoreException { Objects.requireNonNull(username, "username == null"); Preconditions.checkArgument(!username.isEmpty(), "username cannot be empty"); Objects.requireNonNull(cursorName, "cursorName == null"); Preconditions.checkArgument(!cursorName.isEmpty(), "cursorName cannot be empty"); final String key = getCursorKey(username, cursorName); final Location location = new Location(NAMESPACE, key); LOGGER.debug("Fetching key (sync): {}", location); final CursorObject cursor; final FetchValue fv = new FetchValue.Builder(location).withTimeout(timeout).build(); try (Timer.Context context = fetchTimer.time()) { final FetchValue.Response response = client.execute(fv); if (response.isNotFound()) { return Optional.empty(); } cursor = response.getValue(CursorObject.class); } catch (UnresolvedConflictException e) { LOGGER.error("Unable to resolve siblings for key: " + location, e); throw new NotificationStoreException(e); } catch (ExecutionException e) { LOGGER.error("Unable to fetch key: " + location, e); throw new NotificationStoreException(e); } catch (InterruptedException e) { LOGGER.warn("Interrupted fetching key: " + location, e); Thread.currentThread().interrupt(); throw new NotificationStoreException(e); } return Optional.ofNullable(cursor).map(c -> c.getValue()); } CursorStore(
      final RiakClient client, final Duration timeout, final Duration requestTimeout); void initialize(); Optional<String> fetch(final String username, final String cursorName); void store(final String username, final String cursorName, final String value); void delete(final String username, final String cursorName); String getCursorKey(final String username, final String cursorName);  }