]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Fixing problems in the database unit testing environment with Acorn 90/1690/3
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 13:46:47 +0000 (16:46 +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

Change-Id: I92fdce70a1e436cc13af3cf0738a7e227fddd682

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 9725ffe8da2df0aabb169b301b955642781205dd..2f04d7eda1af9f9976fdb182b1cab3e89b89cd01 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 {
@@ -469,7 +471,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
@@ -490,7 +492,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);
                }
                
@@ -604,7 +606,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 {
@@ -671,7 +673,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);
@@ -707,5 +709,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 c5480d86ec6c636233b5e5b21d8d5e688f319966..a65d19b5b7c82770d6ce58b07b9831dcbdb51b21 100644 (file)
@@ -13,47 +13,32 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.StandardOpenOption;
 import java.nio.file.attribute.FileAttribute;
-import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Map;
 import java.util.Set;
 
 import org.simantics.databoard.file.RuntimeIOException;
 
 public class FileIO {
-       
-    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 07fe18e61201cc16fd4e62bd62b808d8d6b5041d..20abf68db0e6853ac882b5df5c22dbf638ef6eb7 100644 (file)
@@ -61,6 +61,7 @@ public class GraphClientImpl2 implements Database.Session {
        private Path dbFolder;
        private final Database database;
        private ServiceLocator locator;
+       private FileCache fileCache;
        private MainProgram mainProgram;
 
        static class ClientThreadFactory implements ThreadFactory {
@@ -85,7 +86,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 a19a8540b48d3faafcf002541a622032046396a8..076bea89ecb04239d0198d7e2c05444d8423b981 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;
@@ -17,14 +18,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 f20b384569d2c9893e7a3999756cd3308409ab2b..bfd8bd6aa7d59615be580518d95bba89986a92d3 100644 (file)
@@ -32,7 +32,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);
@@ -40,7 +40,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 57d6f6a04b5d387c2c0b31ca2fd6cafab845dd4c..29d211374e901f516e94d35e5324c422df2dfa97 100644 (file)
@@ -34,14 +34,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 116464727c55cceb44500b740880c9912d1ca373..12250d6a4e80af39208655289f9517a38b9c0bb9 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;
@@ -14,14 +15,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 508c951067dedc3df895d938b3a0e84f9dda771c..1fc945cc2e3900df412d48b37ee513a7ab735159 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;
@@ -17,6 +18,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;
@@ -37,8 +39,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;
@@ -49,8 +52,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);
        }
 
        /*
@@ -96,7 +99,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) {
@@ -189,7 +192,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 {
     }
+
 }