Commit fb54a29d by Sarath Subramanian

ATLAS-3168: Fix intermittent UT failure:…

ATLAS-3168: Fix intermittent UT failure: NotificationHookConsumerKafkaTest.initNotificationService()
parent f0b0b951
...@@ -85,7 +85,7 @@ public class NotificationHookConsumerKafkaTest { ...@@ -85,7 +85,7 @@ public class NotificationHookConsumerKafkaTest {
private AtlasMetricsUtil metricsUtil; private AtlasMetricsUtil metricsUtil;
@BeforeTest @BeforeTest
public void setup() throws AtlasException, InterruptedException, AtlasBaseException { public void setup() throws Exception {
MockitoAnnotations.initMocks(this); MockitoAnnotations.initMocks(this);
AtlasType mockType = mock(AtlasType.class); AtlasType mockType = mock(AtlasType.class);
...@@ -95,7 +95,7 @@ public class NotificationHookConsumerKafkaTest { ...@@ -95,7 +95,7 @@ public class NotificationHookConsumerKafkaTest {
when(instanceConverter.toAtlasEntities(anyList())).thenReturn(mockEntity); when(instanceConverter.toAtlasEntities(anyList())).thenReturn(mockEntity);
initNotificationService(); startNotificationServicesWithRetry();
} }
@AfterTest @AfterTest
...@@ -228,6 +228,31 @@ public class NotificationHookConsumerKafkaTest { ...@@ -228,6 +228,31 @@ public class NotificationHookConsumerKafkaTest {
kafkaNotification.send(NotificationInterface.NotificationType.HOOK, message); kafkaNotification.send(NotificationInterface.NotificationType.HOOK, message);
} }
// retry starting notification services every 2 mins for total of 30 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 = 30 * 60 * 1000; // 30 mins
while (true) {
try {
initNotificationService();
break;
} catch (Exception ex) {
cleanUpNotificationService();
if (totalTime >= maxTime) {
throw ex;
}
Thread.sleep(sleepTime);
totalTime = totalTime + sleepTime;
}
}
}
void initNotificationService() throws AtlasException, InterruptedException { void initNotificationService() throws AtlasException, InterruptedException {
Configuration applicationProperties = ApplicationProperties.get(); Configuration applicationProperties = ApplicationProperties.get();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment