X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Fdmaap%2Fmr%2Fcambria%2Fembed%2FZooKeeperLocal.java;fp=src%2Ftest%2Fjava%2Forg%2Fonap%2Fdmaap%2Fmr%2Fcambria%2Fembed%2FZooKeeperLocal.java;h=94939c73ef0ea7b7e356ae6d742ea7c342182b40;hb=0beea783cef8a84d8bc2655ea678e00d459cc831;hp=97447a87214726a3282f484fb8a2214b08ec5f90;hpb=49b2a82292f8be3b73fe7460573260d47b5c2b98;p=dmaap%2Fmessagerouter%2Fmessageservice.git diff --git a/src/test/java/org/onap/dmaap/mr/cambria/embed/ZooKeeperLocal.java b/src/test/java/org/onap/dmaap/mr/cambria/embed/ZooKeeperLocal.java index 97447a8..94939c7 100644 --- a/src/test/java/org/onap/dmaap/mr/cambria/embed/ZooKeeperLocal.java +++ b/src/test/java/org/onap/dmaap/mr/cambria/embed/ZooKeeperLocal.java @@ -3,6 +3,7 @@ * ONAP Policy Engine * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Modification copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,41 +21,45 @@ package org.onap.dmaap.mr.cambria.embed; +import java.util.Properties; import org.apache.zookeeper.server.ServerConfig; import org.apache.zookeeper.server.ZooKeeperServerMain; -import org.apache.zookeeper.server.admin.AdminServer.AdminServerException; import org.apache.zookeeper.server.quorum.QuorumPeerConfig; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Properties; - public class ZooKeeperLocal { - - ZooKeeperServerMain zooKeeperServer; - - public ZooKeeperLocal(Properties zkProperties) throws FileNotFoundException, IOException{ + + ZooKeeperServerMain testingZooKeeperMain = null; + ServerConfig conf; + Thread t1; + + public ZooKeeperLocal(Properties zkProperties) { QuorumPeerConfig quorumConfiguration = new QuorumPeerConfig(); try { quorumConfiguration.parseProperties(zkProperties); } catch(Exception e) { throw new RuntimeException(e); } - - zooKeeperServer = new ZooKeeperServerMain(); - final ServerConfig configuration = new ServerConfig(); - configuration.readFrom(quorumConfiguration); - - - new Thread() { - public void run() { - try { - zooKeeperServer.runFromConfig(configuration); - } catch (IOException | AdminServerException e) { - System.out.println("ZooKeeper Failed"); - e.printStackTrace(System.err); - } - } - }.start(); + conf = new ServerConfig(); + conf.readFrom(quorumConfiguration); } + + public void run() { + if (testingZooKeeperMain == null){ + t1 = new Thread(() -> { + try { + testingZooKeeperMain = new ZooKeeperServerMain(); + testingZooKeeperMain.runFromConfig(conf); + } catch (Exception e) { + System.out.println("Start of Local ZooKeeper Failed"); + e.printStackTrace(System.err); + } + }); + t1.start(); + }} + + public void stop() { + testingZooKeeperMain.close(); + t1.stop(); + } + }