diff --git a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/util/TestInitializer.java b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/util/TestInitializer.java index 9d193078ba6dbde746d650e4d69510ebe9f4f53a..3e8afc7f516adab7a260a8ca61d8448e02ab65e5 100644 --- a/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/util/TestInitializer.java +++ b/openbis/sourceTest/java/ch/systemsx/cisd/openbis/generic/server/util/TestInitializer.java @@ -82,6 +82,8 @@ public class TestInitializer private static boolean firstTry = true; + private static Object indexingDatabaseDropper; + private static void init(IndexMode hibernateIndexMode, String scriptFolder) { LogInitializer.init(); @@ -107,33 +109,28 @@ public class TestInitializer } finally { String psql = DumpPreparator.getPSQLExecutable(); - String databaseName = "openbis_" + databaseKind; + final String databaseName = "openbis_" + databaseKind; String sql = "drop database if exists " + databaseName; - List<String> cmd = Arrays.asList(psql, "-U", "postgres", "-c", sql); - for (int i = 0, n = 10; i < n; i++) + final List<String> cmd = Arrays.asList(psql, "-U", "postgres", "-c", sql); + boolean result = ProcessExecutionHelper.runAndLog(cmd, operationLog, operationLog); + if (result == false) { - boolean result = - ProcessExecutionHelper.runAndLog(cmd, operationLog, operationLog); - if (result == false) - { - operationLog.error("Couldn't drop database created for indexing: " - + databaseName); - if (i < n - 1) + operationLog.error("Couldn't drop database created for indexing: " + + databaseName); + indexingDatabaseDropper = new Object() { - operationLog.info("Try it again after some waiting time"); - try - { - Thread.sleep(2000); - } catch (InterruptedException ex) + @Override + protected void finalize() throws Throwable { - // ignored silently + operationLog.info("Try to drop indexing database " + databaseName); + boolean ok = + ProcessExecutionHelper.runAndLog(cmd, operationLog, + operationLog); + operationLog.info("Dropping indexing database " + databaseName + + (ok ? "was" : "wasn't") + " successfull."); + } - } - } else - { - operationLog.info("Database for indexing ropped: " + databaseName); - break; - } + }; } } firstTry = false;