ATLAS-3168: Fix intermittent UT failure: KafkaNotificationTest.initNotificationService()
(cherry picked from commit ed288a759c556c704c824eb921c81b563a32f3e9)
diff --git a/notification/src/test/java/org/apache/atlas/kafka/KafkaNotificationTest.java b/notification/src/test/java/org/apache/atlas/kafka/KafkaNotificationTest.java
index 63114bf..9b3535e 100644
--- a/notification/src/test/java/org/apache/atlas/kafka/KafkaNotificationTest.java
+++ b/notification/src/test/java/org/apache/atlas/kafka/KafkaNotificationTest.java
@@ -40,7 +40,7 @@
@BeforeClass
public void setup() throws Exception {
- initNotificationService();
+ startNotificationServicesWithRetry();
}
@AfterClass
@@ -77,6 +77,31 @@
consumer.close();
}
+ // retry starting notification services every 2 mins for total of 20 mins
+ // running parallel tests will keep the notification service ports occupied, hence retry
+ void startNotificationServicesWithRetry() throws Exception {
+ long totalTime = 0;
+ long sleepTime = 2 * 60 * 1000; // 2 mins
+ long maxTime = 20 * 60 * 1000; // 20 mins
+
+ while (true) {
+ try {
+ initNotificationService();
+ break;
+ } catch (Exception ex) {
+ cleanUpNotificationService();
+
+ if (totalTime >= maxTime) {
+ throw ex;
+ }
+
+ Thread.sleep(sleepTime);
+
+ totalTime = totalTime + sleepTime;
+ }
+ }
+ }
+
void initNotificationService() throws Exception {
Configuration applicationProperties = ApplicationProperties.get();