Skip to content
Snippets Groups Projects
Commit af02816c authored by felmer's avatar felmer
Browse files

If dropping of database for indexing fails try it in finalize() method.

SVN: 28345
parent 935b559e
No related branches found
No related tags found
No related merge requests found
...@@ -82,6 +82,8 @@ public class TestInitializer ...@@ -82,6 +82,8 @@ public class TestInitializer
private static boolean firstTry = true; private static boolean firstTry = true;
private static Object indexingDatabaseDropper;
private static void init(IndexMode hibernateIndexMode, String scriptFolder) private static void init(IndexMode hibernateIndexMode, String scriptFolder)
{ {
LogInitializer.init(); LogInitializer.init();
...@@ -107,33 +109,28 @@ public class TestInitializer ...@@ -107,33 +109,28 @@ public class TestInitializer
} finally } finally
{ {
String psql = DumpPreparator.getPSQLExecutable(); String psql = DumpPreparator.getPSQLExecutable();
String databaseName = "openbis_" + databaseKind; final String databaseName = "openbis_" + databaseKind;
String sql = "drop database if exists " + databaseName; String sql = "drop database if exists " + databaseName;
List<String> cmd = Arrays.asList(psql, "-U", "postgres", "-c", sql); final List<String> cmd = Arrays.asList(psql, "-U", "postgres", "-c", sql);
for (int i = 0, n = 10; i < n; i++) boolean result = ProcessExecutionHelper.runAndLog(cmd, operationLog, operationLog);
if (result == false)
{ {
boolean result = operationLog.error("Couldn't drop database created for indexing: "
ProcessExecutionHelper.runAndLog(cmd, operationLog, operationLog); + databaseName);
if (result == false) indexingDatabaseDropper = new Object()
{
operationLog.error("Couldn't drop database created for indexing: "
+ databaseName);
if (i < n - 1)
{ {
operationLog.info("Try it again after some waiting time"); @Override
try protected void finalize() throws Throwable
{
Thread.sleep(2000);
} catch (InterruptedException ex)
{ {
// 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; firstTry = false;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment