@SuppressWarnings("unchecked")
@Test
public void testNotifyWhenBackendInfoIsStale() {

    final RegisterForShardAvailabilityChanges regMessage =
            shardManagerProbe.expectMsgClass(RegisterForShardAvailabilityChanges.class);
    Registration mockReg = mock(Registration.class);
    shardManagerProbe.reply(new Status.Success(mockReg));
    Consumer<Long> mockCallback = mock(Consumer.class);
    final Registration callbackReg = moduleShardBackendResolver.notifyWhenBackendInfoIsStale(mockCallback);
    regMessage.getCallback().accept(DefaultShardStrategy.DEFAULT_SHARD);
    verify(mockCallback, timeout(5000)).accept(Long.valueOf(0));
    reset(mockCallback);
    callbackReg.close();
    regMessage.getCallback().accept(DefaultShardStrategy.DEFAULT_SHARD);
    Uninterruptibles.sleepUninterruptibly(500, TimeUnit.MILLISECONDS);
    verifyNoMoreInteractions(mockCallback);
}