changeset 268:e159ff4b557f

tests: MongodTestUtil: throw exception on socket close timeout, add some comments
author Zdenek Zambersky <zzambers@redhat.com>
date Tue, 03 Oct 2017 14:54:00 +0200
parents 2de9f7a29768
children abcc0226b293
files tests/test-utils/src/main/java/com/redhat/thermostat/gateway/tests/utils/MongodTestUtil.java
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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() {