コード例 #1
0
 @Test
 public void shouldGetNullElement() {
   final String key = "doesn't exitst";
   StoredElement element = instance.get(key);
   assertNotNull(element);
   assertTrue(element instanceof StoredElement);
   assertTrue(element.elementIsNull());
 }
コード例 #2
0
    @Test
    public void shouldGetExistingElement() {
      final String key = "my element";
      byte[] value = {1, 2, 3};

      instance.put(key, value);

      StoredElement element = instance.get(key);
      assertNotNull(element);
      assertTrue(element instanceof StoredElement);
      assertFalse(element.elementIsNull());
    }
コード例 #3
0
  public void onCacheGet(CacheRequest cacheGet, FilterDirector director) {
    final StoredElement element =
        hashRingDatastore.get(
            cacheGet.getCacheKey(),
            encodingProvider.decode(cacheGet.getCacheKey()),
            cacheGet.getRequestedRemoteBehavior());

    if (!element.elementIsNull()) {
      try {
        director.getResponseOutputStream().write(element.elementBytes());

        director.setResponseStatus(HttpStatusCode.OK);
        director.setFilterAction(FilterAction.RETURN);
      } catch (IOException ioe) {
        LOG.error(ioe.getMessage(), ioe);

        director.setResponseStatus(HttpStatusCode.INTERNAL_SERVER_ERROR);
        director.setFilterAction(FilterAction.RETURN);
      }
    } else {
      director.setResponseStatus(HttpStatusCode.NOT_FOUND);
      director.setFilterAction(FilterAction.RETURN);
    }
  }