public class RESTServerTest {
@Test
public void testBlockingStart() throws IOException, InterruptedException {
CoreConfiguration conf = ConfigurationFactory.getConfiguration("jUnit-RESTServerTest");
MongoConnector dbc = new MongoConnector(conf);
int port = conf.getRestPort();
RESTServer server1 = new RESTServer(conf, new HttpRESTHandler<MongoType>(dbc));
if(!server1.blockingStart()) {
server1 = RESTServer.getNewStartedRESTServer(port, new HttpRESTHandler<MongoType>(dbc));
}
System.out.println("Started server 1 on port "+port);
RESTServer server2 = new RESTServer(conf, new HttpRESTHandler<MongoType>(dbc));
if(server2.blockingStart()) {
System.out.println("We are failing on port "+server2.getPort());
Thread.sleep(1000);
System.out.println("1 alive: "+server1.isAlive());
System.out.println("2 alive: "+server2.isAlive());
System.out.println("1 hasError: "+server1.hasError());
System.out.println("2 hasError: "+server2.hasError());
System.out.println("1 getError: "+server1.getError());
System.out.println("2 getError: "+server2.getError());
System.out.println("1 isExecuting: "+server1.isExecuting());
System.out.println("2 isExecuting: "+server2.isExecuting());
fail("blockingStart() returned true when port should already be taken");
}
server2 = RESTServer.getNewStartedRESTServer(port, new HttpRESTHandler<MongoType>(new MongoConnector(conf)));
System.out.println("Restarted on port "+server2.getPort());
server2 = RESTServer.getNewStartedRESTServer(port, new HttpRESTHandler<MongoType>(new MongoConnector(conf)));
System.out.println("Restarted on port "+server2.getPort());
server1.shutdown();
server2.shutdown();
}