@Override @After public void after() { // unsubscribe for (Topic topic : topics) { PubSub.getInstance().unsubscribe(topic, testSubscriber); } testSubscriber.count = 0; Assert.assertTrue("Topics should have been removed after unsubscribe()", PubSub.getInstance().getTopics().isEmpty()); }
/** * Submit topic that has no subscribers. * @throws Exception */ @Test public void testPubSubNonSubscribedTopic() throws Exception { // At this point all valid Topic values have been subscribed to // in before() method. // Unsubscribe from one topic and then try publishing to it. PubSub.getInstance().unsubscribe(Topic.HDFS_SYNC_HMS, testSubscriber); Assert.assertEquals("Unexpected number of registered topics", topics.length-1, PubSub.getInstance().getTopics().size()); URL url = new URL(String.format(REQUEST_URL, Topic.HDFS_SYNC_HMS.getName(), "message")); HttpURLConnection conn = null; try { conn = (HttpURLConnection) url.openConnection(); Assert.assertEquals("Unexpected response code", HttpURLConnection.HTTP_BAD_REQUEST, conn.getResponseCode()); } finally { safeClose(conn); } // re-subscribe, not to upset after() method which expects all topics to be subscribed to PubSub.getInstance().subscribe(Topic.HDFS_SYNC_HMS, testSubscriber); }