Fix brokerStarter test 34/141834/2 master
authoradheli.tavares <adheli.tavares@est.tech>
Thu, 14 Aug 2025 14:15:58 +0000 (15:15 +0100)
committerAdheli Tavares <adheli.tavares@est.tech>
Fri, 15 Aug 2025 09:46:26 +0000 (09:46 +0000)
Issue-ID: POLICY-5445
Change-Id: Ie95904359ce611ee1e24b03ea7ec7ba67f9e0019
Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
participant/participant-intermediary/src/main/java/org/onap/policy/clamp/acm/participant/intermediary/handler/BrokerStarter.java
participant/participant-intermediary/src/test/java/org/onap/policy/clamp/acm/participant/intermediary/handler/BrokerStarterTest.java

index 808460e..49a8a9f 100644 (file)
@@ -45,6 +45,7 @@ public class BrokerStarter<T> {
     private final ParticipantParameters parameters;
     private final List<Publisher> publishers;
     private final List<Listener<T>> listeners;
+    private int retryCount = -1;
 
     /**
      * Constructor.
@@ -70,6 +71,9 @@ public class BrokerStarter<T> {
     }
 
     protected TopicHealthCheck createTopicHealthCheck(TopicParameters topic) {
+        if (topic.getTopicCommInfrastructure().equals(Topic.CommInfrastructure.NOOP.name())) {
+            retryCount = 0;
+        }
         return new TopicHealthCheckFactory().getTopicHealthCheck(topic);
     }
 
@@ -88,14 +92,11 @@ public class BrokerStarter<T> {
 
     private void runTopicHealthCheck() {
         var fetchTimeout = getFetchTimeout();
-        var retries = 10; // TODO - make this configurable with max number of retries or timeout
         while (!topicHealthCheck.healthCheck(getTopics())) {
             LOGGER.debug(" Broker not up yet!");
             try {
                 Thread.sleep(fetchTimeout);
-                retries--;
-                if (retries == 0) {
-                    LOGGER.error("Broker not up after {} retries", retries);
+                if (retryCount == 0) {
                     break;
                 }
             } catch (InterruptedException e) {
index 093ae9e..7a2daf6 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2025 Nordix Foundation.
+ *  Copyright (C) 2025 OpenInfra Foundation Europe. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -26,10 +26,13 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import java.util.List;
+import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.onap.policy.clamp.acm.participant.intermediary.comm.ParticipantStatusReqListener;
 import org.onap.policy.clamp.acm.participant.intermediary.main.parameters.CommonTestData;
 import org.onap.policy.common.message.bus.event.Topic;
+import org.onap.policy.common.message.bus.event.TopicEndpoint;
+import org.onap.policy.common.message.bus.event.TopicEndpointManager;
 import org.onap.policy.common.message.bus.healthcheck.TopicHealthCheck;
 import org.onap.policy.common.parameters.topic.TopicParameters;
 import org.springframework.context.event.ContextClosedEvent;
@@ -37,6 +40,12 @@ import org.springframework.context.event.ContextRefreshedEvent;
 
 class BrokerStarterTest {
 
+    @BeforeEach
+    void setUp() {
+        TopicEndpoint endpointManager = TopicEndpointManager.getManager();
+        endpointManager.start();
+    }
+
     @Test
     void testWithClampAdminTopicsNull() {
         var parameters = CommonTestData.getParticipantParameters();