@Test
public void shouldDecrementShardWithExcessUsage() throws IOException {

  // init counter
  assertEquals(0, shardedCounter.getCounter(COUNTER_ID1));
  updateShard(COUNTER_ID1, 0, 1);
  updateShard(COUNTER_ID1, 1, 1);
  updateLimitInStorage(COUNTER_ID1, 1);
  // Invalidate snapshot to force pull changes from Datastore emulator
  shardedCounter.inMemSnapshot.invalidate(COUNTER_ID1);
  // assert cache is updated with the new value
  assertEquals(2L, shardedCounter.getCounter(COUNTER_ID1));
  //decrement counter by 1
  updateCounterInTransaction(COUNTER_ID1, -1L);
  // assert that the only shard in excess was chosen to be decremented
  assertEquals(1L, datastore.get(getKey(COUNTER_ID1, 0))
      .getLong(PROPERTY_SHARD_VALUE));
  assertEquals(0L, datastore.get(getKey(COUNTER_ID1, 1))
      .getLong(PROPERTY_SHARD_VALUE));
  // assert cache is updated with the new value
  shardedCounter.inMemSnapshot.invalidate(COUNTER_ID1);
  assertEquals(1L, shardedCounter.getCounter(COUNTER_ID1));
}