# HG changeset patch # User Zdenek Zambersky # Date 1507035240 -7200 # Node ID e159ff4b557f2242f9a9929fabfe81c5704b60e1 # Parent 2de9f7a29768c1f6adb69eee35f85f1de826931d tests: MongodTestUtil: throw exception on socket close timeout, add some comments diff -r 2de9f7a29768 -r e159ff4b557f tests/test-utils/src/main/java/com/redhat/thermostat/gateway/tests/utils/MongodTestUtil.java --- a/tests/test-utils/src/main/java/com/redhat/thermostat/gateway/tests/utils/MongodTestUtil.java Wed Sep 27 17:20:28 2017 +0200 +++ b/tests/test-utils/src/main/java/com/redhat/thermostat/gateway/tests/utils/MongodTestUtil.java Tue Oct 03 14:54:00 2017 +0200 @@ -100,6 +100,11 @@ try { mongoClient.getDatabase("admin").runCommand(new Document("shutdown", 1)); } catch (Exception ignored) { + /* + following exception is always thrown: + com.mongodb.MongoSocketReadException: Prematurely reached end of stream + ( probably expected, connection get closed? ) + */ } mongoClient.close(); mongoClient = null; @@ -140,6 +145,7 @@ } private boolean waitForMongodStop() throws IOException, InterruptedException { + // dbexit string is not logged by newer mongodb (>= 3.4 ?) return waitFor("dbexit: rc: 0"); } @@ -179,19 +185,19 @@ return false; } - private boolean waitForSocketToClose(int port) throws InterruptedException { + private void waitForSocketToClose(int port) throws InterruptedException { for (int i = 0; i < WAIT_FOR_MAX_ITERATIONS; ++i) { /* Try to bind socket, if it fails, port is still in use */ try (ServerSocket socket = new ServerSocket()) { SocketAddress address = new InetSocketAddress(port); socket.bind(address, 0); - return true; + return; } catch (IOException e) { /* ignored */ } Thread.sleep(WAIT_FOR_SLEEP_DURATION); } - return false; + throw new RuntimeException("Timeout waiting for mongodb socket to close reached!"); } public boolean isConnectedToDatabase() {