]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Clean up also indexes during DB unit test environment initialization 60/3160/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 26 Aug 2019 12:52:50 +0000 (15:52 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 26 Aug 2019 12:52:50 +0000 (15:52 +0300)
gitlab #367

Change-Id: Ia93e2e7169575f97b51ef27130b2579ef4d6fb4e

bundles/org.simantics.db.testing/META-INF/MANIFEST.MF
bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshDatabaseTest.java
bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/AcornTestHandler.java
bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestBase.java

index c80729ad86e094b385e0bbcc010c0e7192ef5c23..960ccf0095f1c8eb88811244a48594bf8e1588f7 100644 (file)
@@ -8,17 +8,18 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Require-Bundle: org.simantics.db.layer0;bundle-version="1.1.0",
  org.simantics.graph.db;bundle-version="1.1.5";visibility:=reexport,
  org.simantics.project;bundle-version="1.0.1";visibility:=reexport,
- org.apache.log4j;bundle-version="1.2.15",
  org.simantics.db.procore;bundle-version="1.1.1",
  org.simantics.db.services;bundle-version="1.1.0",
  org.eclipse.core.runtime;bundle-version="3.6.0",
  org.simantics.workbench;bundle-version="1.1.0",
  org.simantics.db.management;bundle-version="1.1.0",
+ org.simantics.db.indexing;bundle-version="1.1.0",
  org.simantics;bundle-version="1.0.0";visibility:=reexport,
  org.simantics.scl.osgi;bundle-version="1.0.4",
  org.junit;bundle-version="4.12.0",
  org.simantics.db.server,
- org.apache.commons.math3
+ org.apache.commons.math3,
+ org.slf4j.api;bundle-version="1.7.25"
 Export-Package: org.simantics.db.testing.annotation,
  org.simantics.db.testing.base,
  org.simantics.db.testing.cases,
index 963b2d9f5d23af902da80f54221f647c04d9a10e..53ddfb04fc0a1ceaa26c88586bfb684f5427c50a 100644 (file)
@@ -30,15 +30,11 @@ public class FreshDatabaseTest extends TestBase {
 
     @Before
     public void setUp() throws Exception {
-
         TestBase.printStart(this);
         TestSettings testSettings = TestSettings.getInstanceUnsafe();
         configure(testSettings);
-//        state = AcornTests.newSimanticsWorkspace(testSettings, null);
         state = Tests.newSimanticsWorkspace(testSettings, null);
-
         super.setUp();
-
     }
 
     @After
index 5f5da8f2e9d7ac1f746605259d59799d7969ac3a..e7e1722ac6f81aedf60022f60c13f153c7d07a9f 100644 (file)
@@ -1,6 +1,7 @@
 package org.simantics.db.testing.common;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.Properties;
 
 import org.eclipse.core.runtime.Platform;
@@ -10,6 +11,7 @@ import org.simantics.db.Manager;
 import org.simantics.db.ServerI;
 import org.simantics.db.Session;
 import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.indexing.DatabaseIndexing;
 
 /**
  * ProCore specific test handler.
@@ -33,15 +35,27 @@ public class AcornTestHandler {
 
     void initNew() throws DatabaseException {
         Management m = getManagement();
-        if (m.exist())
+        if (m.exist()) {
             m.delete();
+        }
+        deleteIndexes();
         m.create();
     }
 
     void initIfNeccessary() throws DatabaseException {
         Management m = getManagement();
-        if (!m.exist())
+        if (!m.exist()) {
             m.create();
+            deleteIndexes();
+        }
+    }
+
+    private void deleteIndexes() throws DatabaseException {
+        try {
+            DatabaseIndexing.deleteAllIndexes();
+        } catch (IOException e) {
+            throw new DatabaseException("Failed to delete all existing indexes", e);
+        }
     }
 
     public Session getSession() throws DatabaseException {
index 1068fc2f50366ae19a72f8a3029534b86f2c7993..06fc784a29a30b68fa335fec2e25efbb7f9ad5ec 100644 (file)
@@ -27,7 +27,6 @@ import org.simantics.db.Session;
 import org.simantics.db.WriteGraph;
 import org.simantics.db.WriteOnlyGraph;
 import org.simantics.db.common.request.WriteOnlyRequest;
-import org.simantics.db.common.utils.Logger;
 import org.simantics.db.exception.DatabaseException;
 import org.simantics.db.exception.ServiceNotFoundException;
 import org.simantics.db.management.SessionContext;
@@ -38,14 +37,17 @@ import org.simantics.db.service.LifecycleSupport;
 import org.simantics.db.testing.impl.Configuration;
 import org.simantics.layer0.Layer0;
 import org.simantics.utils.FileUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * Base class for Simantics Test Cases. Assumes that ProCore is already running.
+ * Base class for Simantics Test Cases.
+ * Assumes that the Simantics database is already running.
  *
  * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
- *
  */
-abstract public class TestBase /*extends TestCase*/ {
+public abstract class TestBase /*extends TestCase*/ {
+    private static final Logger LOGGER = LoggerFactory.getLogger(TestBase.class);
     public static final boolean DEBUG = Configuration.get().debug;
     public static final String ROOT_LIBRARY_URI = "http:/";
     private NoExitSecurityManager noExitSecurityManager;
@@ -56,7 +58,7 @@ abstract public class TestBase /*extends TestCase*/ {
     static boolean printStart = true;
     public static final ArrayList<String> initialWorkspaceFiles = FileUtils.createFileFilter(Platform.getLocation().toFile(), null);
     public static void printStart(Object t) {
-        if(printStart) System.out.println("Test is " + t.getClass().getName() /*+ "." + t.getName()*/);
+        if(printStart) LOGGER.info("Test is {}", t.getClass().getName());
     }
     protected static void setPrintStart(boolean value) {
         printStart = value;
@@ -270,9 +272,9 @@ abstract public class TestBase /*extends TestCase*/ {
                 try {
                     session.getService(LifecycleSupport.class).close(0, true);
                 } catch (ServiceNotFoundException e) {
-                    Logger.defaultLogError(e);
+                    LOGGER.error("Failed to find LifecycleSupport service", e);
                 } catch (DatabaseException e) {
-                    Logger.defaultLogError(e);
+                    LOGGER.error("Failed to close database", e);
                 }
             }
 //            if (!Thread.currentThread().equals(thread)) {