]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixing problems in the database unit testing environment with Acorn 93/1693/1
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 5 Apr 2018 06:47:03 +0000 (09:47 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 5 Apr 2018 17:26:22 +0000 (20:26 +0300)
* Removed static map from org.simantics.acorn.FileIO.
  Moved the map into a session service as org.simantics.acorn.FileCache
* Changed org.simantics.db.testing.common.Tests utilities to use Acorn
  instead of ProCore (AcornTestHandler). Did not introduce abstraction
  for this for now.

refs #7855

Conflicts:
bundles/org.simantics.acorn/src/org/simantics/acorn/FileIO.java

Change-Id: Iec42395cc71b30a4c376a44778b358e3807e6ec9
(cherry picked from commit 03fac449ec81e88669169d671bb386eb93ac060d)

15 files changed:
bundles/org.simantics.acorn/src/org/simantics/acorn/ClusterManager.java
bundles/org.simantics.acorn/src/org/simantics/acorn/FileCache.java [new file with mode: 0644]
bundles/org.simantics.acorn/src/org/simantics/acorn/FileIO.java
bundles/org.simantics.acorn/src/org/simantics/acorn/GraphClientImpl2.java
bundles/org.simantics.acorn/src/org/simantics/acorn/internal/AcornDatabase.java
bundles/org.simantics.acorn/src/org/simantics/acorn/lru/ChangeSetInfo.java
bundles/org.simantics.acorn/src/org/simantics/acorn/lru/ClusterInfo.java
bundles/org.simantics.acorn/src/org/simantics/acorn/lru/ClusterStreamChunk.java
bundles/org.simantics.acorn/src/org/simantics/acorn/lru/FileInfo.java
bundles/org.simantics.acorn/src/org/simantics/acorn/lru/LRUObject.java
bundles/org.simantics.acorn/src/org/simantics/db/javacore/HeadState.java
bundles/org.simantics.db.procore/src/fi/vtt/simantics/procore/internal/SessionImplDb.java
bundles/org.simantics.db.testing/.settings/org.eclipse.jdt.core.prefs
bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/AcornTests.java
bundles/org.simantics.db.testing/src/org/simantics/db/testing/common/Tests.java

index a2cb2fa864c0cb6b0155a87442cd147e8e527eb6..cb9ac578e1aade416162beffde3ad27b2051d4f9 100644 (file)
@@ -47,8 +47,9 @@ public class ClusterManager {
        private ArrayList<String> currentChanges = new ArrayList<String>();
 
        public final Path dbFolder;
-       public Path lastSessionDirectory;
-       public Path workingDirectory;
+       private FileCache fileCache;
+       Path lastSessionDirectory;
+       Path workingDirectory;
 
        public LRU<String, ClusterStreamChunk> streamLRU;
        public LRU<Long, ChangeSetInfo> csLRU;
@@ -67,8 +68,9 @@ public class ClusterManager {
         * 
         */
 
-       public ClusterManager(Path dbFolder) {
+       public ClusterManager(Path dbFolder, FileCache fileCache) {
                this.dbFolder = dbFolder;
+               this.fileCache = fileCache;
        }
 
        public ArrayList<String> getChanges(long changeSetId) throws AcornAccessVerificationException, IllegalAcornStateException {
@@ -467,7 +469,7 @@ public class ClusterManager {
                        Path readDir = dbFolder.resolve(parts[1]);
                        int offset = Integer.parseInt(parts[2]);
                        int length = Integer.parseInt(parts[3]);
-                       FileInfo info = new FileInfo(fileLRU, readDir, parts[0], offset, length);
+                       FileInfo info = new FileInfo(fileLRU, fileCache, readDir, parts[0], offset, length);
                        fileLRU.map(info);
                }
                // Update chunks
@@ -488,7 +490,7 @@ public class ClusterManager {
                        Long revisionId = Long.parseLong(parts[0]);
                        int offset = Integer.parseInt(parts[2]);
                        int length = Integer.parseInt(parts[3]);
-                       ChangeSetInfo info = new ChangeSetInfo(csLRU, readDir, revisionId, offset, length);
+                       ChangeSetInfo info = new ChangeSetInfo(csLRU, fileCache, readDir, revisionId, offset, length);
                        csLRU.map(info);
                }
                
@@ -602,7 +604,7 @@ public class ClusterManager {
                try {
                        ArrayList<String> csids = new ArrayList<String>(currentChanges);
                        currentChanges = new ArrayList<String>();
-                       new ChangeSetInfo(csLRU, changeSetId, data, csids);
+                       new ChangeSetInfo(csLRU, fileCache, changeSetId, data, csids);
                } catch (Throwable t) {
                        throw new IllegalAcornStateException(t);
                } finally {
@@ -669,7 +671,7 @@ public class ClusterManager {
                        try {
                                info = fileLRU.get(key);
                                if (info == null) {
-                                       info = new FileInfo(fileLRU, key, (int) (offset + size));
+                                       info = new FileInfo(fileLRU, fileCache, key, (int) (offset + size));
                                }
                        } catch (Throwable t) {
                                throw new IllegalAcornStateException(t);
@@ -705,5 +707,9 @@ public class ClusterManager {
     public long getTailChangeSetId() {
        return state.tailChangeSetId;
     }
-    
+
+    public FileCache getFileCache() {
+        return fileCache;
+    }
+
 }
diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/FileCache.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/FileCache.java
new file mode 100644 (file)
index 0000000..b0f9d37
--- /dev/null
@@ -0,0 +1,28 @@
+package org.simantics.acorn;
+
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.simantics.db.Disposable;
+
+/**
+ * @author Tuukka Lehtonen
+ * @since 1.32.0
+ */
+public class FileCache implements Disposable {
+
+       private Map<Path, FileIO> map = new HashMap<>();
+
+       public FileIO get(Path path) {
+               synchronized (map) {
+                       return map.computeIfAbsent(path, FileIO::new);
+               }
+       }
+
+       @Override
+       public void dispose() {
+               map = new HashMap<>();
+       }
+
+}
index 8f3009afab3f82b84c23156775efd901a925c1ae..305094f8315ac443ed75933219111e1deda8eb04 100644 (file)
@@ -25,38 +25,26 @@ import org.slf4j.LoggerFactory;
 public class FileIO {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(FileIO.class);
-    private static final FileAttribute<?>[] NO_ATTRIBUTES = new FileAttribute[0];
-    
+
+    private static final FileAttribute<?>[] NO_ATTRIBUTES = {};
+
     private static final Set<OpenOption> CREATE_OPTIONS = new HashSet<>(2);
     private static final Set<OpenOption> APPEND_OPTIONS = new HashSet<>(1);
-    
+
     static {
         CREATE_OPTIONS.add(StandardOpenOption.WRITE);
         CREATE_OPTIONS.add(StandardOpenOption.CREATE);
-        
+
         APPEND_OPTIONS.add(StandardOpenOption.APPEND);
     }
-    
+
        private Path path;
        private int writePosition = 0;
 
-       private FileIO(Path path) {
+       public FileIO(Path path) {
                this.path = path;
        }
-       
-       private static Map<Path, FileIO> map = new HashMap<Path, FileIO>();
-       
-       public static FileIO get(Path path) {
-               synchronized(map) {
-                       FileIO existing = map.get(path);
-                       if(existing == null) {
-                               existing = new FileIO(path);
-                               map.put(path, existing);
-                       }
-                       return existing;
-               }
-       }
-       
+
        //private static final boolean TRACE_SWAP = false;
        private static final boolean TRACE_PERF = false;
 
index 7a57053bcf6aa9f1af09548424bfe00c59456751..2ffdc715ff2546db5e03e67e102858a2317b87ef 100644 (file)
@@ -68,6 +68,7 @@ public class GraphClientImpl2 implements Database.Session {
        private Path dbFolder;
        private final Database database;
        private ServiceLocator locator;
+       private FileCache fileCache;
        private MainProgram mainProgram;
 
        private static class ClientThreadFactory implements ThreadFactory {
@@ -92,7 +93,10 @@ public class GraphClientImpl2 implements Database.Session {
            this.database = database;
            this.dbFolder = dbFolder;
            this.locator = locator;
-           this.clusters = new ClusterManager(dbFolder);
+           this.fileCache = new FileCache();
+           // This disposes the cache when the session is shut down 
+           locator.registerService(FileCache.class, fileCache);
+           this.clusters = new ClusterManager(dbFolder, fileCache);
            load();
            ClusterSetsSupport cssi = locator.getService(ClusterSetsSupport.class);
            cssi.setReadDirectory(clusters.lastSessionDirectory);
index a423fbdbe23b815871688fb17cb2c6fb165550f7..8109df6cd25fd8a4ca2f4a9cdacd405ff6b60b7c 100644 (file)
@@ -13,6 +13,7 @@ import java.nio.file.SimpleFileVisitor;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.EnumSet;
 import java.util.Properties;
+import java.util.stream.Stream;
 
 import org.simantics.acorn.GraphClientImpl2;
 import org.simantics.db.Database;
@@ -23,6 +24,8 @@ import org.simantics.db.server.ProCoreException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import fi.vtt.simantics.procore.internal.StaticSessionProperties;
+
 /**
  * @author Tuukka Lehtonen
  */
@@ -112,6 +115,15 @@ public class AcornDatabase implements Database {
     @Override
     public void deleteFiles() throws ProCoreException {
         deleteTree(folder);
+        File vgPath = StaticSessionProperties.virtualGraphStoragePath;
+        if (vgPath != null) {
+            try (Stream<Path> vgs = Files.list(vgPath.toPath())) {
+                for (Path p : vgs.toArray(Path[]::new))
+                    deleteTree(p);
+            } catch (IOException e) {
+                throw new ProCoreException(e);
+            }
+        }
     }
 
     @Override
@@ -147,6 +159,8 @@ public class AcornDatabase implements Database {
             raLockFile = null;
             Files.deleteIfExists(lockFile);
             isRunning = false;
+            safeLoggingClose(currentClient, currentClient.getDbFolder());
+            currentClient = null;
         } catch (IOException e) {
             LOGGER.error("Failed to start database at " + folder.toAbsolutePath(), e);
         }
@@ -224,39 +238,37 @@ public class AcornDatabase implements Database {
         throw new UnsupportedOperationException();
     }
 
-    private static void deleteTree(Path path) throws ProCoreException {
-        if (!Files.exists(path))
-            return;
-
-        class Visitor extends SimpleFileVisitor<Path> {
-            @Override
-            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+    static class Visitor extends SimpleFileVisitor<Path> {
+        @Override
+        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+            try {
+                Files.delete(file);
+            } catch (IOException ioe) {
+                LOGGER.error("Failed to delete file {}", file, ioe);
+                throw ioe;
+            }
+            return FileVisitResult.CONTINUE;
+        }
+        @Override
+        public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
+            if (e == null) {
                 try {
-                    Files.delete(file);
+                    Files.delete(dir);
                 } catch (IOException ioe) {
-                    ioe.printStackTrace();
+                    LOGGER.error("Failed to delete directory {}", dir, ioe);
                     throw ioe;
                 }
                 return FileVisitResult.CONTINUE;
             }
-            @Override
-            public FileVisitResult postVisitDirectory(Path dir, IOException e) throws IOException {
-                if (e == null) {
-                    try {
-                        Files.delete(dir);
-                    } catch (IOException ioe) {
-                        ioe.printStackTrace();
-                        throw ioe;
-                    }
-                    return FileVisitResult.CONTINUE;
-                }
-                throw e;
-            }
+            throw e;
         }
+    }
+
+    private static void deleteTree(Path path) throws ProCoreException {
+        if (!Files.exists(path))
+            return;
         try {
-            Visitor v = new Visitor();
-            EnumSet<FileVisitOption> opts = EnumSet.noneOf(FileVisitOption.class);
-            Files.walkFileTree(path, opts, Integer.MAX_VALUE, v);
+            Files.walkFileTree(path, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, new Visitor());
         } catch (IOException e) {
             throw new ProCoreException("Could not delete " + path, e);
         }
@@ -272,7 +284,17 @@ public class AcornDatabase implements Database {
             return;
         try (AutoCloseable c = closeable) {
         } catch (Exception e) {
-            LOGGER.error("Failed to close " + closeable.getClass() + " of " + file.toAbsolutePath());
+            LOGGER.error("Failed to close " + closeable.getClass() + " of " + file.toAbsolutePath(), e);
+        }
+    }
+
+    private static void safeLoggingClose(Database.Session session, Path file) {
+        if (session == null)
+            return;
+        try {
+            session.close();
+        } catch (Exception e) {
+            LOGGER.error("Failed to close " + session.getClass() + " of " + file.toAbsolutePath(), e);
         }
     }
 
index e1915d32b771aba4e7e1f5109f6be07d83d6b948..235b26418be7f610a3d79d6e1760f176d331ccaa 100644 (file)
@@ -4,6 +4,7 @@ import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Arrays;
 
+import org.simantics.acorn.FileCache;
 import org.simantics.acorn.exception.AcornAccessVerificationException;
 import org.simantics.acorn.exception.IllegalAcornStateException;
 import org.simantics.db.service.Bytes;
@@ -20,14 +21,14 @@ public class ChangeSetInfo extends LRUObject<Long, ChangeSetInfo> {
        private ArrayList<String> clusterChangeSetIds;
        
        // Stub
-       public ChangeSetInfo(LRU<Long, ChangeSetInfo> LRU, Path readDir, Long revision, int offset, int length) throws AcornAccessVerificationException {
-               super(LRU, revision, readDir, "clusterStream", offset, length, false, false);
+       public ChangeSetInfo(LRU<Long, ChangeSetInfo> LRU, FileCache fileCache, Path readDir, Long revision, int offset, int length) throws AcornAccessVerificationException {
+               super(LRU, fileCache, revision, readDir, "clusterStream", offset, length, false, false);
                LRU.map(this);
        }
        
        // New
-       public ChangeSetInfo(LRU<Long, ChangeSetInfo> LRU, Long revision, byte[] bytes, ArrayList<String> clusterChangeSetIds) throws AcornAccessVerificationException {
-               super(LRU, revision, LRU.getDirectory(), "clusterStream", true, true);
+       public ChangeSetInfo(LRU<Long, ChangeSetInfo> LRU, FileCache fileCache, Long revision, byte[] bytes, ArrayList<String> clusterChangeSetIds) throws AcornAccessVerificationException {
+               super(LRU, fileCache, revision, LRU.getDirectory(), "clusterStream", true, true);
                this.metadataBytes = bytes;
                this.metadataBytes = bytes;
                this.clusterChangeSetIds = clusterChangeSetIds;
index 54689394d2e894e30ea0139fbed4aa78dfff237c..f058a559d9ca54960d061b2493a9bbf600d91953 100644 (file)
@@ -35,7 +35,7 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
        
        // Stub
        public ClusterInfo(ClusterManager manager, LRU<ClusterUID, ClusterInfo> LRU, Path readDirectory, ClusterUID uid, int offset, int length) throws AcornAccessVerificationException {
-               super(LRU, uid, readDirectory, uid.toString() + ".cluster", offset, length, false, false);
+               super(LRU, manager.getFileCache(), uid, readDirectory, uid.toString() + ".cluster", offset, length, false, false);
                this.manager = manager;
                this.cluster = null;
                LRU.map(this);
@@ -43,7 +43,7 @@ public class ClusterInfo extends LRUObject<ClusterUID, ClusterInfo> implements P
        
        // New
        public ClusterInfo(ClusterManager manager, LRU<ClusterUID, ClusterInfo> LRU, ClusterImpl cluster) throws AcornAccessVerificationException, IllegalAcornStateException {
-               super(LRU, cluster.getClusterUID(), LRU.getDirectory(), cluster.getClusterUID().toString() + ".cluster", true, true);
+               super(LRU, manager.getFileCache(), cluster.getClusterUID(), LRU.getDirectory(), cluster.getClusterUID().toString() + ".cluster", true, true);
                this.manager = manager;
                this.cluster = cluster;
                LRU.insert(this, accessTime);
index 767746eb005864c2046a5e1b50237a1e03006030..3fa5e327f918b039c0ddb0dc9adea85b1a3999ff 100644 (file)
@@ -36,14 +36,14 @@ public class ClusterStreamChunk extends LRUObject<String, ClusterStreamChunk> im
        
        // Stub
        public ClusterStreamChunk(ClusterManager manager, LRU<String, ClusterStreamChunk> LRU, Path readDir, String id, int offset, int length) throws AcornAccessVerificationException {
-               super(LRU, id, readDir, "clusterStream", offset, length, false, false);
+               super(LRU, manager.getFileCache(), id, readDir, "clusterStream", offset, length, false, false);
                this.manager = manager;
                LRU.map(this);
        }
        
        // Creation
        public ClusterStreamChunk(ClusterManager manager, LRU<String, ClusterStreamChunk> LRU, String id) throws AcornAccessVerificationException {
-               super(LRU, id, LRU.getDirectory(), "clusterStream", true, true);
+               super(LRU, manager.getFileCache(), id, LRU.getDirectory(), "clusterStream", true, true);
                this.manager = manager;
                LRU.insert(this, accessTime);
        }
index 0e1367f9954ee2f2aad677f7d89bd0b86fda620b..d65d3dc86451c48cf5b2acdf5e464d2de77b5dcf 100644 (file)
@@ -2,6 +2,7 @@ package org.simantics.acorn.lru;
 
 import java.nio.file.Path;
 
+import org.simantics.acorn.FileCache;
 import org.simantics.acorn.exception.AcornAccessVerificationException;
 import org.simantics.acorn.exception.IllegalAcornStateException;
 import org.simantics.db.Database.Session.ResourceSegment;
@@ -17,14 +18,14 @@ public class FileInfo extends LRUObject<String, FileInfo> {
        private TByteArrayList bytes;
        
        // Stub
-       public FileInfo(LRU<String, FileInfo> LRU, Path readDir, String id, int offset, int length) throws AcornAccessVerificationException {
-               super(LRU, id, readDir, id.toString() + ".extFile", offset, length, false, false);
+       public FileInfo(LRU<String, FileInfo> LRU, FileCache fileCache, Path readDir, String id, int offset, int length) throws AcornAccessVerificationException {
+               super(LRU, fileCache, id, readDir, id.toString() + ".extFile", offset, length, false, false);
                LRU.map(this);
        }
        
        // New
-       public FileInfo(LRU<String, FileInfo> LRU, String id, int size) throws AcornAccessVerificationException {
-               super(LRU, id, LRU.getDirectory(), id.toString() + ".extFile", true, true);
+       public FileInfo(LRU<String, FileInfo> LRU, FileCache fileCache, String id, int size) throws AcornAccessVerificationException {
+               super(LRU, fileCache, id, LRU.getDirectory(), id.toString() + ".extFile", true, true);
                this.bytes = new TByteArrayList(size);
                LRU.insert(this, accessTime);
        }
index a84a281089c289de2dbad32cd5dce6db359453ea..5230723b70b5bd25fc6b5e3a6ac5412c071615a1 100644 (file)
@@ -5,6 +5,7 @@ import java.nio.file.Path;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.TimeUnit;
 
+import org.simantics.acorn.FileCache;
 import org.simantics.acorn.FileIO;
 import org.simantics.acorn.Persistable;
 import org.simantics.acorn.exception.AcornAccessVerificationException;
@@ -19,6 +20,7 @@ public abstract class LRUObject<MapKey, MapValue extends LRUObject<MapKey, MapVa
        
        // Final stuff
        final protected LRU<MapKey, MapValue> LRU;
+       final protected FileCache fileCache;
        final private Semaphore mutex = new Semaphore(1);
        final private MapKey key;
        final private String fileName;
@@ -39,8 +41,9 @@ public abstract class LRUObject<MapKey, MapValue extends LRUObject<MapKey, MapVa
        private Thread mutexOwner;
 
        // for loading
-       public LRUObject(LRU<MapKey, MapValue> LRU, MapKey key, Path readDirectory, String fileName, int offset, int length, boolean dirty, boolean resident) {
+       public LRUObject(LRU<MapKey, MapValue> LRU, FileCache fileCache, MapKey key, Path readDirectory, String fileName, int offset, int length, boolean dirty, boolean resident) {
                this.LRU = LRU;
+               this.fileCache = fileCache;
                this.key = key;
                this.fileName = fileName;
                this.offset = offset;
@@ -51,8 +54,8 @@ public abstract class LRUObject<MapKey, MapValue extends LRUObject<MapKey, MapVa
        }
 
        // for creating
-       public LRUObject(LRU<MapKey, MapValue> LRU, MapKey key, Path readDirectory, String fileName, boolean dirty, boolean resident) {
-               this(LRU, key, readDirectory, fileName, -1, -1, dirty, resident);
+       public LRUObject(LRU<MapKey, MapValue> LRU, FileCache fileCache, MapKey key, Path readDirectory, String fileName, boolean dirty, boolean resident) {
+               this(LRU, fileCache, key, readDirectory, fileName, -1, -1, dirty, resident);
        }
 
        /*
@@ -98,7 +101,7 @@ public abstract class LRUObject<MapKey, MapValue extends LRUObject<MapKey, MapVa
             Pair<byte[], Integer> pair = toBytes();
             byte[] data = pair.first;
             int length = pair.second;
-            FileIO fio = FileIO.get(bytes);
+            FileIO fio = fileCache.get(bytes);
             int offset = fio.saveBytes(data, length, overwrite());
             setPosition(offset, length);
         } catch (AcornAccessVerificationException | IllegalAcornStateException e) {
@@ -191,7 +194,7 @@ public abstract class LRUObject<MapKey, MapValue extends LRUObject<MapKey, MapVa
                if(VERIFY) verifyAccess();
                Path dir = getDirectory();
                Path f = dir.resolve(getFileName());
-               FileIO fio = FileIO.get(f);
+               FileIO fio = fileCache.get(f);
                return fio.readBytes(getOffset(), getLength());
        }
        
index 0fb29333b50d527e781cfbe5285c9411ec646ea8..23ec57863762931fd759fe9953061c7fe888b5a3 100644 (file)
@@ -13,6 +13,10 @@ import java.util.Arrays;
 
 import org.simantics.acorn.exception.InvalidHeadStateException;
 
+/**
+ * @deprecated exists only for backwards compatibility 
+ */
+@Deprecated
 public class HeadState implements Serializable {
 
     private static final long serialVersionUID = -4135031566499790077L;
index d60c0573ad83882ea21fe547ea18041e5a719b84..92c5e9dda255a93b19ffeb21954a2c4153c7c674 100644 (file)
@@ -123,8 +123,9 @@ final public class SessionImplDb extends SessionImplSocket {
 
         String databaseId = serverInfo.getDatabaseId();
         String serverId = serverInfo.getServerId();
-        virtualGraphServerSupport.connect(databaseId + "." + serverId);
-        clusterSetsSupport.connect(databaseId + "." + serverId);
+        String id = databaseId + "." + serverId;
+        virtualGraphServerSupport.connect(id);
+        clusterSetsSupport.connect(id);
 
     }
 
index f42de363afaae68bbd968318f1d331877f5514fc..0c68a61dca867ceb49e79d2402935261ec3e3809 100644 (file)
@@ -1,7 +1,7 @@
 eclipse.preferences.version=1
 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
-org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
 org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.7
+org.eclipse.jdt.core.compiler.source=1.8
index e72ea3280d35d1bf3ea2a24e5121ebca8e85d2ad..8d8ffb5a88ef7891f5abe2776f3e822ac58dd4ef 100644 (file)
@@ -17,14 +17,12 @@ import org.simantics.databoard.binding.Binding;
 import org.simantics.databoard.binding.error.BindingConstructionException;
 import org.simantics.db.Session;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.util.RuntimeEnvironmentRequest;
 import org.simantics.db.management.ISessionContextProvider;
 import org.simantics.db.management.ISessionContextProviderSource;
 import org.simantics.db.management.SessionContext;
 import org.simantics.db.management.SessionContextProvider;
 import org.simantics.db.management.SingleSessionContextProviderSource;
 import org.simantics.db.service.LifecycleSupport;
-import org.simantics.db.service.VirtualGraphSupport;
 import org.simantics.db.testing.impl.Configuration;
 import org.simantics.graph.db.TransferableGraphs;
 import org.simantics.graph.representation.TransferableGraph1;
@@ -41,7 +39,7 @@ public class AcornTests {
 
     public static void freshDatabase() throws Exception {
         DatabaseState state = freshWorkspace(Configuration.get().coreDir, null);
-        AcornTests.shutdown(state);
+        shutdown(state);
     }
 
     public static DatabaseState existingDatabase() throws Exception {
@@ -60,8 +58,7 @@ public class AcornTests {
         AcornTestHandler testHandler = AcornTests.getTestHandler(testSettings, address);
         testHandler.initNew();
         initSimanticsStuff();
-        SessionContext sessionContext = SimanticsPlatform.INSTANCE.startUp("acorn", null, RecoveryPolicy.FixError,
-                OntologyRecoveryPolicy.Merge, true, new DefaultChoiceUserAgent());
+        SessionContext sessionContext = SimanticsPlatform.INSTANCE.startUp("acorn", null, RecoveryPolicy.FixError, OntologyRecoveryPolicy.Merge, true, new DefaultChoiceUserAgent());
         return new DatabaseState(address, sessionContext);
     }
 
@@ -78,12 +75,6 @@ public class AcornTests {
         SCLOsgi.SOURCE_REPOSITORY = null;
         SCLOsgi.MODULE_REPOSITORY = null;
         SCLOsgi.TEST_REPOSITORY = null;
-        
-//        VirtualGraphSupport vsupport;
-//        if (state != null) {
-//            vsupport = state.getSession().getService(VirtualGraphSupport.class);
-//            vsupport.discard();
-//        }
 
         if (Platform.isRunning()) {
             SimanticsPlatform.INSTANCE.shutdown(null);
@@ -147,7 +138,7 @@ public class AcornTests {
             session = null;
         } catch (Exception e) {
             session = null;
-            throw new DatabaseException("Sessuion did not close cleanly.");
+            throw new DatabaseException("Session did not close cleanly.");
         }
     }
 
index 311360cdcb97b6638eb516b8566ba3c1e78ae8ad..2848aabe1f2279faea903839dce4501c2a5ffdea 100644 (file)
@@ -21,7 +21,6 @@ import org.simantics.db.Resource;
 import org.simantics.db.Session;
 import org.simantics.db.Statement;
 import org.simantics.db.exception.DatabaseException;
-import org.simantics.db.layer0.util.RuntimeEnvironmentRequest;
 import org.simantics.db.management.ISessionContextProvider;
 import org.simantics.db.management.ISessionContextProviderSource;
 import org.simantics.db.management.SessionContext;
@@ -34,7 +33,9 @@ import org.simantics.graph.representation.TransferableGraph1;
 import org.simantics.scl.osgi.SCLOsgi;
 
 public class Tests {
-    private static TestHandler testHandler;
+
+    private static AcornTestHandler testHandler;
+
     public static boolean contains(Collection<Statement> stms, Resource predicate, Resource object) {
         for(Statement stm : stms) {
             if(stm.getPredicate().equals(predicate) && stm.getObject().equals(object)) return true;
@@ -48,17 +49,21 @@ public class Tests {
         }
         return false;
     }
+
     public static DatabaseState freshWorkspace(String CORE_DIR, ArrayList<String> fileFilter) throws Exception {
         SimanticsPlatform.INSTANCE.resetWorkspace(null, fileFilter);
         return newSimanticsWorkspace(null, CORE_DIR);
     }
+
     public static void freshDatabase() throws Exception {
         DatabaseState state = freshWorkspace(Configuration.get().coreDir, null);
-        Tests.shutdown(state);
+        shutdown(state);
     }
+
     public static DatabaseState existingDatabase() throws Exception {
         return oldSimanticsWorkspace(null, Configuration.get().coreDir);
     }
+
     private static void initSimanticsStuff() {
         // Set session context provider.
         final ISessionContextProvider provider = new SessionContextProvider(null);
@@ -66,76 +71,28 @@ public class Tests {
         Simantics.setSessionContextProviderSource(source);
         org.simantics.db.layer0.internal.SimanticsInternal.setSessionContextProviderSource(source);
     }
+
     public static DatabaseState newSimanticsWorkspace(TestSettings testSettings, String address) throws Exception {
-        TestHandler testHandler = Tests.getTestHandler(testSettings, address);
+        AcornTestHandler testHandler = getTestHandler(testSettings, address);
         testHandler.initNew();
         initSimanticsStuff();
         SessionContext sessionContext = SimanticsPlatform.INSTANCE.startUp(Simantics.getDefaultDatabaseDriver(), null, RecoveryPolicy.FixError, OntologyRecoveryPolicy.Merge, true, new DefaultChoiceUserAgent());
-       return new DatabaseState(address, sessionContext);
+        return new DatabaseState(address, sessionContext);
     }
+
     public static DatabaseState oldSimanticsWorkspace(TestSettings testSettings, String address) throws Exception {
-        Tests.getTestHandler(testSettings, address);
+        getTestHandler(testSettings, address);
         initSimanticsStuff();
         SessionContext sessionContext = SimanticsPlatform.INSTANCE.startUp(Simantics.getDefaultDatabaseDriver(), null, RecoveryPolicy.FixError, OntologyRecoveryPolicy.Merge, false, null);
         return new DatabaseState(address, sessionContext);
     }
-//        for (String ontology : testSettings.getOntologies()) {
-//            initOntology(session, ontology);
-//        }
-//        String[] adapters = testSettings.getAdapters();
-//        if(adapters != null) {
-//            File[] files = new File[adapters.length];
-//            for(int i=0;i<adapters.length;i++)
-//                files[i] = new File(testSettings.getWorkspace(), adapters[i]);
-//            System.err.println("Loading adapters: " + Arrays.toString(files));
-//            AdapterRegistry2.getInstance().initialize(testSettings.getClass().getClassLoader(), null, files);
-//            new AdaptionServiceInitializer().initialize(session);
-//        }
-//        return new DatabaseState(testHandler.getServer(), SessionContext.create(session, false));
-//    }
-//    @SuppressWarnings("deprecation")
-//    private static DatabaseState initPlatform(TestHandler testHandler, boolean fresh) throws Exception {
-//            // Starts database server.
-//            SimanticsPlatform.INSTANCE.startUpExisting(null, RecoveryPolicy.ThrowError, true);
-//            return new DatabaseState(SimanticsPlatform.INSTANCE.server, SimanticsPlatform.INSTANCE.sessionContext);
-//        }
-//    }
-//    private static DatabaseState initDatabase(TestHandler testHandler, boolean fresh) throws DatabaseException {
-//        TestSettings settings = TestSettings.getInstance();
-//        if (fresh)
-//            testHandler.initNew();
-//        else
-//            testHandler.initOld();
-//        Session session = testHandler.getSession();
-//        if (fresh) {
-//            for(String ontology : settings.getOntologies()) {
-//                initOntology(session, ontology);
-//            }
-//        }
-//        String[] adapters = settings.getAdapters();
-//        if(adapters != null) {
-//            File[] files = new File[adapters.length];
-//            for(int i=0;i<adapters.length;i++)
-//                files[i] = new File(settings.getWorkspace(), adapters[i]);
-//            System.err.println("Loading adapters: " + Arrays.toString(files));
-//            AdapterRegistry2.getInstance().initialize(settings.getClass().getClassLoader(), null, files);
-//            new AdaptionServiceInitializer().initialize(session);
-//        }
-//        return new DatabaseState(testHandler.getServer(), SessionContext.create(session, false));
-//    }
-//    private static DatabaseState initDatabaseDep(TestHandler testHandler, boolean fresh) throws Exception {
-//        if (Platform.isRunning())
-//            return initPlatform(testHandler, fresh);
-//        else
-//            return initDatabase(testHandler, fresh);
-//    }
     public static void shutdown(DatabaseState state) throws Exception {
         if (SCLOsgi.MODULE_REPOSITORY != null)
             SCLOsgi.MODULE_REPOSITORY.flush();
         SCLOsgi.SOURCE_REPOSITORY = null;
         SCLOsgi.MODULE_REPOSITORY = null;
         SCLOsgi.TEST_REPOSITORY = null;
-        
+
         if (Platform.isRunning()) {
             SimanticsPlatform.INSTANCE.shutdown(null);
             return;
@@ -151,8 +108,7 @@ public class Tests {
         }
     }
 
-    public static void initOntology(Session session, String relative)
-    throws DatabaseException {
+    public static void initOntology(Session session, String relative) throws DatabaseException {
         // Open transferable graph file for layer0.
         Binding binding;
         try {
@@ -183,14 +139,17 @@ public class Tests {
 //    public static TestHandler newTestHandler(TestSettings testSettings, String dbFolderName) throws DatabaseException {
 //        return new TestHandler(testSettings, dbFolderName);
 //    }
-    public static TestHandler getTestHandler() throws DatabaseException {
+
+    public static AcornTestHandler getTestHandler() throws DatabaseException {
         return getTestHandler(null, null);
     }
-    public static TestHandler getTestHandler(TestSettings testSettings, String address) throws DatabaseException {
+
+    public static AcornTestHandler getTestHandler(TestSettings testSettings, String address) throws DatabaseException {
         if (null == testHandler)
-            testHandler = new TestHandler(testSettings, address);
+            testHandler = new AcornTestHandler(testSettings, address);
         return testHandler;
     }
+
     public static void closeSession(Session session) throws DatabaseException {
         try {
             LifecycleSupport support = session.getService(LifecycleSupport.class);
@@ -198,10 +157,11 @@ public class Tests {
             session = null;
         } catch (Exception e) {
             session = null;
-            throw new DatabaseException("Sessuion did not close cleanly.");
+            throw new DatabaseException("Session did not close cleanly.");
         }
     }
-    public static void killCore() throws DatabaseException {
 
+    public static void killCore() throws DatabaseException {
     }
+
 }