diff options
-rw-r--r-- | rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java | 19 | ||||
-rw-r--r-- | rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java | 2 |
2 files changed, 13 insertions, 8 deletions
diff --git a/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java b/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java index 812ee48..3995e4c 100644 --- a/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java +++ b/rulemgt/src/main/java/org/onap/holmes/rulemgt/Initializer.java @@ -30,6 +30,7 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; import java.util.HashSet; import java.util.Set; +import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import static org.onap.holmes.common.utils.CommonUtils.getEnv; @@ -38,7 +39,7 @@ import static org.onap.holmes.common.utils.CommonUtils.isIpAddress; @Service public class Initializer { private static final Logger logger = LoggerFactory.getLogger(Initializer.class); - private static boolean readyForMsbReg = false; + private volatile static boolean readyForMsbReg = false; private MsbRegister msbRegister; @Inject @@ -48,17 +49,19 @@ public class Initializer { @PostConstruct private void init() { - waitUntilReady(); - try { - msbRegister.register2Msb(createMicroServiceInfo()); - } catch (CorrelationException e) { - logger.error(e.getMessage(), e); - } + Executors.newSingleThreadExecutor().execute(() -> { + waitUntilReady(); + try { + msbRegister.register2Msb(createMicroServiceInfo()); + } catch (CorrelationException e) { + logger.error(e.getMessage(), e); + } + }); } private void waitUntilReady() { int count = 1; - while(!readyForMsbReg) { + while (!readyForMsbReg) { if (count > 20) { break; } diff --git a/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java b/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java index f658d35..8e4a6fe 100644 --- a/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java +++ b/rulemgt/src/test/java/org/onap/holmes/rulemgt/InitializerTest.java @@ -51,6 +51,8 @@ public class InitializerTest { WhiteboxImpl.invokeMethod(initializer, "init"); + TimeUnit.SECONDS.sleep(6); + PowerMock.verifyAll(); } |