+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.tests.client;
+
+import org.junit.Test;
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.Read;
+import org.simantics.db.testing.base.ExistingDatabaseTest;
+import org.simantics.db.testing.common.TestBase;
+import org.simantics.layer0.Layer0;
+public class JournalTest extends ExistingDatabaseTest {
+ private static final int N = 10;
+ private static boolean WRITE = false;
+
+ @Test
+ public void testJournal() throws DatabaseException{
+ write();
+ validate();
+ }
+ private void write()
+ throws DatabaseException {
+ if (!WRITE)
+ return;
+ for (int i=0; i<N; ++i)
+ writeData();
+ }
+ private void writeData()
+ throws DatabaseException {
+ getSession().syncRequest(new WriteRequest() {
+ @Override
+ public void perform(WriteGraph g) throws DatabaseException {
+ Layer0 b = Layer0.getInstance(g);
+ Resource root = g.getRootLibrary();
+ Resource r = g.newResource();
+ g.claim(root, b.ConsistsOf, null, r);
+ }
+ });
+ }
+ private void validate()
+ throws DatabaseException {
+ for (int i=0; i<N; ++i)
+ validateData();
+ }
+ private void validateData()
+ throws DatabaseException {
+ getSession().syncRequest(new Read<Resource>() {
+ @Override
+ public Resource perform(ReadGraph g) throws DatabaseException {
+ Layer0 l0 = Layer0.getInstance(g);
+ Resource root = g.getResource(TestBase.ROOT_LIBRARY_URI);
+ for (Resource r : g.getObjects(root, l0.ConsistsOf))
+ if (DEBUG)
+ System.out.println("Resource " + r);
+ return null;
+ }
+
+ });
+ }
+}
\ No newline at end of file