@Before
  public void setup() throws Exception {
    UnitTestConnectionService.add(
        CLUSTER_URI,
        new UnitTestConnectionService.PassthroughServerBuilder()
            .resource("defaultResource", 8, MemoryUnit.MB)
            .build());

    Connection connection = new UnitTestConnectionService().connect(CLUSTER_URI, new Properties());
    EhcacheClientEntityFactory entityFactory = new EhcacheClientEntityFactory(connection);

    ServerSideConfiguration serverConfig =
        new ServerSideConfiguration(
            "defaultResource", Collections.<String, ServerSideConfiguration.Pool>emptyMap());
    entityFactory.create("TestCacheManager", serverConfig);

    EhcacheClientEntity clientEntity = entityFactory.retrieve("TestCacheManager", serverConfig);
    ClusteredResourcePool resourcePool = ClusteredResourcePoolBuilder.fixed(4, MemoryUnit.MB);
    ServerStoreConfiguration serverStoreConfiguration =
        new ServerStoreConfiguration(
            resourcePool.getPoolAllocation(),
            Long.class.getName(),
            String.class.getName(),
            Long.class.getName(),
            String.class.getName(),
            LongSerializer.class.getName(),
            StringSerializer.class.getName(),
            null);
    clientEntity.createCache(CACHE_IDENTIFIER, serverStoreConfiguration);
    ServerStoreMessageFactory factory = new ServerStoreMessageFactory(CACHE_IDENTIFIER);
    ServerStoreProxy serverStoreProxy = new NoInvalidationServerStoreProxy(factory, clientEntity);

    TestTimeSource testTimeSource = new TestTimeSource();

    OperationsCodec<Long, String> codec =
        new OperationsCodec<Long, String>(new LongSerializer(), new StringSerializer());
    ChainResolver<Long, String> resolver =
        new ChainResolver<Long, String>(codec, Expirations.noExpiration());
    store = new ClusteredStore<Long, String>(codec, resolver, serverStoreProxy, testTimeSource);
  }
  public EventualServerStoreProxy(
      final ServerStoreMessageFactory messageFactory, final EhcacheClientEntity entity) {
    this.delegate = new NoInvalidationServerStoreProxy(messageFactory, entity);
    entity.addResponseListener(
        EhcacheEntityResponse.ServerInvalidateHash.class,
        new EhcacheClientEntity.ResponseListener<EhcacheEntityResponse.ServerInvalidateHash>() {
          @Override
          public void onResponse(EhcacheEntityResponse.ServerInvalidateHash response) {
            if (response.getCacheId().equals(messageFactory.getCacheId())) {
              long key = response.getKey();
              LOGGER.debug(
                  "CLIENT: on cache {}, server requesting hash {} to be invalidated",
                  messageFactory.getCacheId(),
                  key);
              for (InvalidationListener listener : invalidationListeners) {
                listener.onInvalidateHash(key);
              }
            } else {
              LOGGER.debug(
                  "CLIENT: on cache {}, ignoring invalidation on unrelated cache : {}",
                  messageFactory.getCacheId(),
                  response.getCacheId());
            }
          }
        });
    entity.addResponseListener(
        EhcacheEntityResponse.ClientInvalidateHash.class,
        new EhcacheClientEntity.ResponseListener<EhcacheEntityResponse.ClientInvalidateHash>() {
          @Override
          public void onResponse(EhcacheEntityResponse.ClientInvalidateHash response) {
            final String cacheId = response.getCacheId();
            final long key = response.getKey();
            final int invalidationId = response.getInvalidationId();

            if (cacheId.equals(messageFactory.getCacheId())) {
              LOGGER.debug(
                  "CLIENT: doing work to invalidate hash {} from cache {} (ID {})",
                  key,
                  cacheId,
                  invalidationId);
              for (InvalidationListener listener : invalidationListeners) {
                listener.onInvalidateHash(key);
              }
            } else {
              LOGGER.debug(
                  "CLIENT: on cache {}, ignoring invalidation on unrelated cache : {}",
                  messageFactory.getCacheId(),
                  response.getCacheId());
            }
          }
        });
    entity.addResponseListener(
        EhcacheEntityResponse.ClientInvalidateAll.class,
        new EhcacheClientEntity.ResponseListener<EhcacheEntityResponse.ClientInvalidateAll>() {
          @Override
          public void onResponse(EhcacheEntityResponse.ClientInvalidateAll response) {
            final String cacheId = response.getCacheId();
            final int invalidationId = response.getInvalidationId();

            if (cacheId.equals(messageFactory.getCacheId())) {
              LOGGER.debug(
                  "CLIENT: doing work to invalidate all from cache {} (ID {})",
                  cacheId,
                  invalidationId);
              for (InvalidationListener listener : invalidationListeners) {
                listener.onInvalidateAll();
              }
            } else {
              LOGGER.debug(
                  "CLIENT: on cache {}, ignoring invalidation on unrelated cache : {}",
                  messageFactory.getCacheId(),
                  response.getCacheId());
            }
          }
        });
  }