private static ConfigurableApplicationContext context;
- private static final String zookeeperHost;
- private static final String kafkaHost;
+ private static String zookeeperHost;
+ private static String kafkaHost;
- static {
+ private static void getHosts() {
@SuppressWarnings("resource")
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ServerMQ.class);
public static void main(String[] args) throws InterruptedException {
+ getHosts();
while (!checkSocket(zookeeperHost)) {
Thread.sleep(1000);
System.out.println("can not connect to zookeeper...");
import org.junit.Test;
import org.springframework.boot.SpringApplication;
+import org.springframework.context.ConfigurableApplicationContext;
/**
* The type Server mq test.
* Test run
*/
@Test
- public void testRun() {
+ public void testRun() throws InterruptedException {
String[] args = new String[0];
- ServerMQ.main(args);
- assertNotNull(getContext());
- SpringApplication.exit(getContext(), () -> 0);
+ ConfigurableApplicationContext context = SpringApplication.run(ServerMQ.class, args);
+ assertNotNull(context);
+ SpringApplication.exit(context, () -> 0);
}
}