diff --git hcatalog/server-extensions/src/test/java/org/apache/hive/hcatalog/listener/TestNotificationListener.java hcatalog/server-extensions/src/test/java/org/apache/hive/hcatalog/listener/TestNotificationListener.java index 9e03da4..f242f14 100644 --- hcatalog/server-extensions/src/test/java/org/apache/hive/hcatalog/listener/TestNotificationListener.java +++ hcatalog/server-extensions/src/test/java/org/apache/hive/hcatalog/listener/TestNotificationListener.java @@ -24,6 +24,8 @@ import java.util.List; import java.util.Map; import java.util.Vector; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import javax.jms.Connection; import javax.jms.ConnectionFactory; @@ -65,6 +67,8 @@ public class TestNotificationListener extends HCatBaseTest implements MessageListener { private List actualMessages = new Vector(); + private static final CountDownLatch messageReceivedSignal = new CountDownLatch(8); + private static final int MSG_RECEIVED_TIMEOUT = 30; @Before public void setUp() throws Exception { @@ -132,6 +136,9 @@ public void testAMQListener() throws Exception { driver.run("alter table mytbl add columns (c int comment 'this is an int', d decimal(3,2))"); driver.run("drop table mytbl"); driver.run("drop database mydb"); + + // Wait until either all messages are processed or a maximum time limit is reached. + messageReceivedSignal.await(MSG_RECEIVED_TIMEOUT, TimeUnit.SECONDS); } @Override @@ -243,7 +250,7 @@ public void onMessage(Message msg) { } else { Assert.assertTrue("Unexpected event-type: " + event, false); } - + messageReceivedSignal.countDown(); } catch (JMSException e) { e.printStackTrace(System.err); assert false;