PubSub.getInstance().subscribe(PubSub.Topic.HDFS_SYNC_HMS, this);
@Override @Before public void before() throws Exception { // Subscribe to all defined topics. // After each successfull HTTP-GET, testSubscriber.onMessage() // will be called and "topic" and "message" fields will be // set according to HTTP-GET parameters. testSubscriber.count = 0; for (Topic topic : topics) { PubSub.getInstance().subscribe(topic, testSubscriber); } Assert.assertEquals("Unexpected number of registered topics", topics.length, PubSub.getInstance().getTopics().size()); }
/** * 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); }