From 2314ba77cd57f53b6f6d0a39ddaee9958d819fc8 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Mon, 26 Aug 2019 15:52:50 +0300 Subject: [PATCH] Clean up also indexes during DB unit test environment initialization gitlab #367 Change-Id: Ia93e2e7169575f97b51ef27130b2579ef4d6fb4e --- .../META-INF/MANIFEST.MF | 5 +++-- .../db/testing/cases/FreshDatabaseTest.java | 4 ---- .../db/testing/common/AcornTestHandler.java | 18 ++++++++++++++++-- .../simantics/db/testing/common/TestBase.java | 16 +++++++++------- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/bundles/org.simantics.db.testing/META-INF/MANIFEST.MF b/bundles/org.simantics.db.testing/META-INF/MANIFEST.MF index c80729ad8..960ccf009 100644 --- a/bundles/org.simantics.db.testing/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.db.testing/META-INF/MANIFEST.MF @@ -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, diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshDatabaseTest.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshDatabaseTest.java index 963b2d9f5..53ddfb04f 100644 --- a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshDatabaseTest.java +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/cases/FreshDatabaseTest.java @@ -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 diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/AcornTestHandler.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/AcornTestHandler.java index 5f5da8f2e..e7e1722ac 100644 --- a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/AcornTestHandler.java +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/AcornTestHandler.java @@ -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 { diff --git a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestBase.java b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestBase.java index 1068fc2f5..06fc784a2 100644 --- a/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestBase.java +++ b/bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/TestBase.java @@ -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 - * */ -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 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)) { -- 2.47.1