@Test
  public void testUnsubscribeTopic() throws Exception {
    // Subscribe a topic and publish a message for the topic
    helixNotifier.subscribe(refTopics.get(0), listeners.get(0));
    latch0.set(new CountDownLatch(1));
    helixNotifier.publish(refTopics.get(0), refMessages.get(0));
    awaitLatchOrTimeout(latch0.get(), LATCH_TIMEOUT_MS);
    assertEquals("Received topic is different from expected", refTopics.get(0), receivedTopicsByListener0.get(0));
    assertEquals("Received message is different from expected", refMessages.get(0), receivedMessagesByListener0.get(0));

    // unsubscribe the listener
    helixNotifier.unsubscribe(refTopics.get(0), listeners.get(0));
    latch0.set(new CountDownLatch(1));
    helixNotifier.publish(refTopics.get(0), refMessages.get(0));
    try {
      awaitLatchOrTimeout(latch0.get(), 1);
      fail("should have thrown");
    } catch (TimeoutException e) {
      // expected, since the TopicListener would not be called, and the latch would not be counted down.
    }

    // unsubscribe the listener again should be silent
    helixNotifier.unsubscribe(refTopics.get(0), listeners.get(0));
  }
Tests unsubscribing a topic. This test is meaningful when using {@link MockHelixPropertyStore}, where
a single thread guarantees to know if {@link TopicListener#onMessage(String, Object)} has been
called or not.
@throws Exception Any unexpected exception.
ambry-commons/src/test/java/com/github/ambry/commons/HelixNotifierTest.java