diff options
Diffstat (limited to 'src/test/java/org/onap/dmaap/mr/cambria/embed/ZooKeeperLocal.java')
-rw-r--r-- | src/test/java/org/onap/dmaap/mr/cambria/embed/ZooKeeperLocal.java | 55 |
1 files changed, 30 insertions, 25 deletions
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(); + } + } |