@Override
    public void run() {
      try {
        final MessageSender sender = msm.acquireSender();
        Thread.sleep(rnd.nextInt(THREAD_SLEEP_MILLIS));
        msm.releaseSender(sender);
        counter.decrementAndGet();

      } catch (final Throwable t) {
        threads.put(Thread.currentThread(), t);
      }
    }
  @Test
  public void messageSenderManagerTest() throws Exception {
    final MessageSenderManager msm = new MessageSenderManager();
    msm.setSenderPoolSize(SENDER_COUNT);
    msm.setSenderClass(SENDER_CLASS_NAME);
    msm.init();

    assertTrue(msm.availableSenderCount() == SENDER_COUNT);
    final MessageSender[] senders = new MessageSender[SENDER_COUNT];
    int i = 0;
    final int n = 5;
    for (; i < n; i++) {
      senders[i] = msm.acquireSender();
    }
    assertNotNull(senders[0]);
    assertTrue(msm.availableSenderCount() == (SENDER_COUNT - n));
    for (i = 0; i < n; i++) {
      msm.releaseSender(senders[i]);
    }
    assertTrue(msm.availableSenderCount() == SENDER_COUNT);
    for (i = 0; i < SENDER_COUNT; i++) {
      senders[i] = msm.acquireSender();
    }
    assertTrue(
        senders[0] instanceof DummySender,
        "Sender is an instance of "
            + senders[0].getClass().getName()
            + ". It should be instance of "
            + SENDER_CLASS_NAME);
    assertTrue(msm.availableSenderCount() == 0);
    try {
      msm.acquireSender();
    } catch (final PerfCakeException te) {
      assertTrue(te.getMessage().equals("MessageSender pool is empty."));
    }
    msm.releaseAllSenders();
    assertTrue(msm.availableSenderCount() == SENDER_COUNT);
    msm.close();
  }