@Test
public void shouldFailToUpdateResourceCountersOnDequeueDueToCapacity() throws Exception {

  givenState(INSTANCE, State.QUEUED);
  doThrow(new CounterCapacityException("foo"))
      .when(transaction).updateCounter(shardedCounter, "resource1", 1);
  final Set<Resource> resources = ImmutableSet.of(Resource.create("resource1", 1));
  final List<String> resourceIds = resources.stream().map(Resource::id).sorted().collect(toList());
  final Event dequeueEvent = Event.dequeue(INSTANCE, ImmutableSet.copyOf(resourceIds));
  final Event infoEvent = Event.info(INSTANCE,
      Message.info(String.format("Resource limit reached for: %s", resourceIds)));
  final PersistentStateManager spied = spy(stateManager);
  doNothing().when(spied).receiveIgnoreClosed(eq(infoEvent), anyLong());
  try {
    spied.receive(dequeueEvent);
    fail();
  } catch (Exception e) {
    // expected exception
  }
  verify(spied).receiveIgnoreClosed(eq(infoEvent), anyLong());
}