-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.db.procore.cluster;\r
-\r
-import java.io.PrintStream;\r
-\r
-import org.simantics.db.Session;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.impl.ClusterBase;\r
-import org.simantics.db.impl.ClusterI;\r
-import org.simantics.db.impl.ClusterI.CompleteTypeEnum;\r
-import org.simantics.db.impl.ClusterTranslator;\r
-import org.simantics.db.service.ClusterUID;\r
-\r
-import fi.vtt.simantics.procore.internal.SessionImplSocket;\r
-import gnu.trove.map.hash.TIntIntHashMap;\r
-\r
-final public class TestCluster {\r
- private static final boolean DEBUG = false;\r
- private static final int AddedResources = 100; //ClusterTraits.getMaxNumberOfResources();\r
- private static final int AddedStatements = 100; // Must be less than or equal to number of resources.\r
- private static final int ValueCapacity = 5;\r
- private final ClusterBase builtinCluster;\r
- private final ClusterUID BuiltinClusterUID = ClusterUID.Builtin;\r
- private final int BuiltinClusterKey;\r
- private final ClusterBase foreignCluster;\r
- private final ClusterUID ForeignClusterUID = ClusterUID.make(/*ClusterUID.Builtin.first*/0, ClusterUID.Builtin.second+1);\r
- private final ClusterBase objectCluster;\r
- private final ClusterUID ObjectClusterUID = ClusterUID.make(/*ClusterUID.Builtin.first*/0, ClusterUID.Builtin.second+2);\r
- private final ClusterTranslator support;\r
- PrintStream out = System.out;\r
- TestCluster(Session session) {\r
- support = ((SessionImplSocket)session).clusterTranslator;\r
- builtinCluster = support.getClusterByClusterUIDOrMake(BuiltinClusterUID);\r
- BuiltinClusterKey = builtinCluster.getClusterKey();\r
- foreignCluster = support.getClusterByClusterUIDOrMake(ForeignClusterUID);\r
- objectCluster = support.getClusterByClusterUIDOrMake(ObjectClusterUID);\r
- }\r
- private void testReading(ClusterI cluster, int[] resourceKeys, int[] statementKeys, int[] objectKeys, boolean onePredicateOn, int AddedStatements, boolean foreignClusterOn)\r
- throws DatabaseException {\r
- Stopwatch sw = new Stopwatch();\r
- sw.start();\r
- for (int i = 0; i < AddedResources; ++i) {\r
- int resourceKey = resourceKeys[i];\r
- CompleteTypeEnum ct = cluster.getCompleteType(resourceKey, support);\r
- if (ct != CompleteTypeEnum.NotComplete) {\r
- int ck = cluster.getCompleteObjectKey(resourceKey, support);\r
- Assert(0 != ck);\r
- Assert(objectKeys[0] == ck);\r
- }\r
- final TIntIntHashMap predicates = new TIntIntHashMap();\r
- final TIntIntHashMap countMap = new TIntIntHashMap();\r
- countMap.clear();\r
- ClusterI.ObjectProcedure<TIntIntHashMap> readObjects = new ClusterI.ObjectProcedure<TIntIntHashMap>() {\r
- @Override\r
- public boolean execute(final TIntIntHashMap objects, final int object) {\r
- int i = objects.get(object);\r
- objects.put(object, ++i);\r
- return false; // continue looping\r
- }\r
- };\r
- ClusterI.PredicateProcedure<TIntIntHashMap> readPredicates = new ClusterI.PredicateProcedure<TIntIntHashMap>() {\r
- @Override\r
- public boolean execute(TIntIntHashMap set, int predicateKey, int objectIndex) {\r
- set.put(predicateKey, objectIndex);\r
- int i = countMap.get(predicateKey);\r
- countMap.put(predicateKey, ++i);\r
- return false; // continue looping\r
- }\r
- };\r
- cluster.forPredicates(resourceKey, readPredicates, predicates, support);\r
- if (onePredicateOn)\r
- Assert(predicates.size() == 1);\r
- else {\r
- Assert(predicates.size() == AddedStatements);\r
- //Assert(cluster.isComplete(fyi, resourceKey, support));\r
- //Assert(cluster.getCompleteType(fyi, resourceKey, support) == ClusterI.CompleteTypeEnum.InstanceOf);\r
- }\r
- for (int j = 0; j < AddedStatements; ++j) {\r
- int pKey = onePredicateOn ? resourceKey : statementKeys[j];\r
- if (onePredicateOn && foreignClusterOn)\r
- pKey = statementKeys[0];\r
- Assert(predicates.contains(pKey));\r
- Assert(countMap.get(pKey) == 1);\r
- int oIndex = predicates.get(pKey);\r
- if (AddedStatements < 3)\r
- Assert(oIndex == 0);\r
- TIntIntHashMap objects = new TIntIntHashMap();\r
- TIntIntHashMap objects2 = new TIntIntHashMap();\r
- cluster.forObjects(resourceKey, pKey, oIndex, readObjects, objects, support);\r
- cluster.forObjects(resourceKey, pKey, readObjects, objects2, support);\r
- Assert(objects.size() == objects2.size());\r
- if (onePredicateOn) {\r
- Assert(objects.size() == AddedStatements);\r
- for (int k = 0; k < AddedStatements; ++k) {\r
- int oKey = objectKeys[k];\r
- Assert(objects.contains(oKey));\r
- Assert(1 == objects.get(oKey));\r
- Assert(objects2.contains(oKey));\r
- Assert(1 == objects2.get(oKey));\r
- }\r
- } else {\r
- Assert(objects.size() == 1);\r
- int oKey = objectKeys[j];\r
- Assert(objects.contains(oKey));\r
- Assert(1 == objects.get(oKey));\r
- Assert(objects2.contains(oKey));\r
- Assert(1 == objects2.get(oKey));\r
- }\r
- }\r
- if (!cluster.hasValue(resourceKey, support))\r
- throw new RuntimeException("hasValue() failed for resource key=" + resourceKey);\r
- byte[] data = cluster.getValue(resourceKey, support);\r
- Assert(data.length == ValueCapacity);\r
- for (int l = 0; l < ValueCapacity; ++l)\r
- Assert((byte) l == data[l]);\r
- }\r
- sw.stop();\r
- out.println("Elapsed time in millseconds " + sw.elapsedMilli() + " for reading.");\r
- // cluster.check();\r
- // cluster.printDebugInfo(-1, "koss: ", support);\r
- out.println("Used space consumption in bytes: " + cluster.getUsedSpace());\r
-\r
- }\r
- private int getResourceKey(int clusterKey, int resourceIndex)\r
- throws DatabaseException {\r
- return ClusterTraits.createResourceKey(clusterKey, resourceIndex);\r
- }\r
- private boolean clusterTest(boolean onePredicateOn, boolean foreignClusterOn, int AddedStatements)\r
- throws DatabaseException {\r
- String testName = "Cluster ";\r
- out.println("********************************************");\r
- String eo = onePredicateOn ? "on" : "off";\r
- String fco = foreignClusterOn ? "on" : "off";\r
- out.println(testName + " test with one predicate " + eo + ", foreign cluster " + fco);\r
-\r
- Stopwatch sw = new Stopwatch();\r
- sw.start();\r
-\r
- ClusterI cluster = ClusterImpl.make(BuiltinClusterUID, BuiltinClusterKey, support);\r
- if (DEBUG)\r
- System.out.println("cluster key=" + cluster.getClusterKey() + " id=" + cluster.getClusterId() + " uid=" + cluster.getClusterUID());\r
- byte[] value = new byte[ValueCapacity];\r
- for (int i = 0; i < ValueCapacity; ++i)\r
- value[i] = (byte) i;\r
-\r
- Assert(AddedResources <= ClusterTraits.getMaxNumberOfResources());\r
- int[] resourceKeys = new int[AddedResources];\r
- for (int i = 0; i < AddedResources; ++i) {\r
- resourceKeys[i] = cluster.createResource(support);\r
- Assert(ClusterTraits.getResourceIndexFromResourceKey(resourceKeys[i]) == i + 1);\r
- Assert(!cluster.isComplete(resourceKeys[i], support));\r
- }\r
- int[] statementKeys = new int[AddedStatements];\r
- int[] objectKeys = new int[AddedStatements];\r
- for (int i = 0; i < AddedStatements; ++i) {\r
- if (foreignClusterOn) {\r
- Assert(AddedStatements <= ClusterTraits.getMaxNumberOfResources());\r
- statementKeys[i] = getResourceKey(foreignCluster.getClusterKey(), i + 1);\r
- } else {\r
- Assert(AddedStatements <= AddedResources);\r
- statementKeys[i] = getResourceKey(builtinCluster.getClusterKey(), i + 1);\r
- }\r
- objectKeys[i] = getResourceKey(objectCluster.getClusterKey(), i + 1);\r
- }\r
- for (int i = 0; i < AddedResources; ++i) {\r
- final int resourceKey = resourceKeys[i];\r
- for (int j = 0; j < AddedStatements; ++j) {\r
- int sKey = resourceKey;\r
- int pKey = onePredicateOn ? resourceKey : statementKeys[j];\r
- if (onePredicateOn && foreignClusterOn)\r
- pKey = statementKeys[0];\r
- int oKey = objectKeys[j];\r
- cluster = cluster.addRelation(sKey, pKey, oKey, support);\r
- if (null == cluster)\r
- throw new RuntimeException("AddRelation() failed.");\r
- if (null != cluster.addRelation(sKey, pKey, oKey, support))\r
- throw new RuntimeException("AddRelation() failed.");\r
- }\r
- cluster = cluster.setValue(resourceKey, value, value.length, support);\r
- if (!cluster.hasValue(resourceKey, support))\r
- throw new RuntimeException("AddRelation() failed.");\r
- byte[] data = cluster.getValue(resourceKey, support);\r
- Assert(data.length == value.length);\r
- for (int l = 0; l < value.length; ++l)\r
- Assert((byte) l == data[l]);\r
- }\r
-\r
- sw.stop();\r
- out.println("Elapsed time in milliseconds " + sw.elapsedMilli() + " for adding " + AddedResources + " Resources with " + AddedStatements + " statements.");\r
-\r
- testReading(cluster, resourceKeys, statementKeys, objectKeys, onePredicateOn, AddedStatements, foreignClusterOn);\r
-\r
- if (!(cluster instanceof ClusterBig)) {\r
- sw.restart();\r
- ClusterI big = ((ClusterImpl)cluster).toBig(support);\r
- sw.stop();\r
- out.println("Elapsed time in milliseconds " + sw.elapsedMilli() + " for converting to big.");\r
- testReading(big, resourceKeys, statementKeys, objectKeys, onePredicateOn, AddedStatements, foreignClusterOn);\r
- }\r
-\r
- sw.restart();\r
- for (int i = 0; i < AddedResources; ++i) {\r
- int resourceKey = resourceKeys[i];\r
- for (int j = 0; j < AddedStatements; ++j) {\r
- int sKey = resourceKey;\r
- int pKey = onePredicateOn ? resourceKey : statementKeys[j];\r
- if (onePredicateOn && foreignClusterOn)\r
- pKey = statementKeys[0];\r
- int oKey = objectKeys[j];\r
- if (!cluster.removeRelation(sKey, pKey, oKey, support))\r
- throw new RuntimeException("RemoveRelation() failed.");\r
- if (cluster.removeRelation(sKey, pKey, oKey, support))\r
- throw new RuntimeException("RemoveRelation() failed.");\r
- cluster.denyRelation(sKey, pKey, oKey, support);\r
- }\r
- if (!cluster.removeValue(resourceKey, support))\r
- throw new RuntimeException("removeValue() failed.");\r
- if (cluster.removeValue(resourceKey, support))\r
- throw new RuntimeException("removeValue() failed.");\r
- }\r
- sw.stop();\r
- out.println("Elapsed time in millseconds " + sw.elapsedMilli() + " for deleting.");\r
- out.println("Used space consumption in bytes: " + cluster.getUsedSpace());\r
- return false; // ok\r
- }\r
-\r
- private void testBasic()\r
- throws DatabaseException {\r
- final int N = AddedStatements;\r
- support.setStreamOff(true);\r
- try {\r
- for (int i = N; i < N + 1; ++i) {\r
- clusterTest(false, false, i);\r
- clusterTest(false, true, i);\r
- clusterTest(true, false, i);\r
- clusterTest(true, true, i);\r
- }\r
- } finally {\r
- support.setStreamOff(false);\r
- }\r
- }\r
-\r
- private void Assert(boolean condition)\r
- throws DatabaseException {\r
- if (condition)\r
- return;\r
- DatabaseException e = new DatabaseException("Test failed!");\r
- e.printStackTrace(out);\r
- throw e;\r
- }\r
- public static void test(Session session) {\r
- TestCluster tc = new TestCluster(session);\r
- try {\r
- System.out.println("Begin of tests.");\r
- tc.testBasic();\r
- System.out.println("End of tests.");\r
- } catch (Throwable t) {\r
- throw new RuntimeException("Tests failed.", t);\r
- }\r
- }\r
- public static void main(String[] args) {\r
- test(null);\r
- }\r
-}\r
+/*******************************************************************************
+ * 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.procore.cluster;
+
+import java.io.PrintStream;
+
+import org.simantics.db.Session;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.impl.ClusterBase;
+import org.simantics.db.impl.ClusterI;
+import org.simantics.db.impl.ClusterI.CompleteTypeEnum;
+import org.simantics.db.impl.ClusterTranslator;
+import org.simantics.db.service.ClusterUID;
+
+import fi.vtt.simantics.procore.internal.SessionImplSocket;
+import gnu.trove.map.hash.TIntIntHashMap;
+
+final public class TestCluster {
+ private static final boolean DEBUG = false;
+ private static final int AddedResources = 100; //ClusterTraits.getMaxNumberOfResources();
+ private static final int AddedStatements = 100; // Must be less than or equal to number of resources.
+ private static final int ValueCapacity = 5;
+ private final ClusterBase builtinCluster;
+ private final ClusterUID BuiltinClusterUID = ClusterUID.Builtin;
+ private final int BuiltinClusterKey;
+ private final ClusterBase foreignCluster;
+ private final ClusterUID ForeignClusterUID = ClusterUID.make(/*ClusterUID.Builtin.first*/0, ClusterUID.Builtin.second+1);
+ private final ClusterBase objectCluster;
+ private final ClusterUID ObjectClusterUID = ClusterUID.make(/*ClusterUID.Builtin.first*/0, ClusterUID.Builtin.second+2);
+ private final ClusterTranslator support;
+ PrintStream out = System.out;
+ TestCluster(Session session) {
+ support = ((SessionImplSocket)session).clusterTranslator;
+ builtinCluster = support.getClusterByClusterUIDOrMake(BuiltinClusterUID);
+ BuiltinClusterKey = builtinCluster.getClusterKey();
+ foreignCluster = support.getClusterByClusterUIDOrMake(ForeignClusterUID);
+ objectCluster = support.getClusterByClusterUIDOrMake(ObjectClusterUID);
+ }
+ private void testReading(ClusterI cluster, int[] resourceKeys, int[] statementKeys, int[] objectKeys, boolean onePredicateOn, int AddedStatements, boolean foreignClusterOn)
+ throws DatabaseException {
+ Stopwatch sw = new Stopwatch();
+ sw.start();
+ for (int i = 0; i < AddedResources; ++i) {
+ int resourceKey = resourceKeys[i];
+ CompleteTypeEnum ct = cluster.getCompleteType(resourceKey, support);
+ if (ct != CompleteTypeEnum.NotComplete) {
+ int ck = cluster.getCompleteObjectKey(resourceKey, support);
+ Assert(0 != ck);
+ Assert(objectKeys[0] == ck);
+ }
+ final TIntIntHashMap predicates = new TIntIntHashMap();
+ final TIntIntHashMap countMap = new TIntIntHashMap();
+ countMap.clear();
+ ClusterI.ObjectProcedure<TIntIntHashMap> readObjects = new ClusterI.ObjectProcedure<TIntIntHashMap>() {
+ @Override
+ public boolean execute(final TIntIntHashMap objects, final int object) {
+ int i = objects.get(object);
+ objects.put(object, ++i);
+ return false; // continue looping
+ }
+ };
+ ClusterI.PredicateProcedure<TIntIntHashMap> readPredicates = new ClusterI.PredicateProcedure<TIntIntHashMap>() {
+ @Override
+ public boolean execute(TIntIntHashMap set, int predicateKey, int objectIndex) {
+ set.put(predicateKey, objectIndex);
+ int i = countMap.get(predicateKey);
+ countMap.put(predicateKey, ++i);
+ return false; // continue looping
+ }
+ };
+ cluster.forPredicates(resourceKey, readPredicates, predicates, support);
+ if (onePredicateOn)
+ Assert(predicates.size() == 1);
+ else {
+ Assert(predicates.size() == AddedStatements);
+ //Assert(cluster.isComplete(fyi, resourceKey, support));
+ //Assert(cluster.getCompleteType(fyi, resourceKey, support) == ClusterI.CompleteTypeEnum.InstanceOf);
+ }
+ for (int j = 0; j < AddedStatements; ++j) {
+ int pKey = onePredicateOn ? resourceKey : statementKeys[j];
+ if (onePredicateOn && foreignClusterOn)
+ pKey = statementKeys[0];
+ Assert(predicates.contains(pKey));
+ Assert(countMap.get(pKey) == 1);
+ int oIndex = predicates.get(pKey);
+ if (AddedStatements < 3)
+ Assert(oIndex == 0);
+ TIntIntHashMap objects = new TIntIntHashMap();
+ TIntIntHashMap objects2 = new TIntIntHashMap();
+ cluster.forObjects(resourceKey, pKey, oIndex, readObjects, objects, support);
+ cluster.forObjects(resourceKey, pKey, readObjects, objects2, support);
+ Assert(objects.size() == objects2.size());
+ if (onePredicateOn) {
+ Assert(objects.size() == AddedStatements);
+ for (int k = 0; k < AddedStatements; ++k) {
+ int oKey = objectKeys[k];
+ Assert(objects.contains(oKey));
+ Assert(1 == objects.get(oKey));
+ Assert(objects2.contains(oKey));
+ Assert(1 == objects2.get(oKey));
+ }
+ } else {
+ Assert(objects.size() == 1);
+ int oKey = objectKeys[j];
+ Assert(objects.contains(oKey));
+ Assert(1 == objects.get(oKey));
+ Assert(objects2.contains(oKey));
+ Assert(1 == objects2.get(oKey));
+ }
+ }
+ if (!cluster.hasValue(resourceKey, support))
+ throw new RuntimeException("hasValue() failed for resource key=" + resourceKey);
+ byte[] data = cluster.getValue(resourceKey, support);
+ Assert(data.length == ValueCapacity);
+ for (int l = 0; l < ValueCapacity; ++l)
+ Assert((byte) l == data[l]);
+ }
+ sw.stop();
+ out.println("Elapsed time in millseconds " + sw.elapsedMilli() + " for reading.");
+ // cluster.check();
+ // cluster.printDebugInfo(-1, "koss: ", support);
+ out.println("Used space consumption in bytes: " + cluster.getUsedSpace());
+
+ }
+ private int getResourceKey(int clusterKey, int resourceIndex)
+ throws DatabaseException {
+ return ClusterTraits.createResourceKey(clusterKey, resourceIndex);
+ }
+ private boolean clusterTest(boolean onePredicateOn, boolean foreignClusterOn, int AddedStatements)
+ throws DatabaseException {
+ String testName = "Cluster ";
+ out.println("********************************************");
+ String eo = onePredicateOn ? "on" : "off";
+ String fco = foreignClusterOn ? "on" : "off";
+ out.println(testName + " test with one predicate " + eo + ", foreign cluster " + fco);
+
+ Stopwatch sw = new Stopwatch();
+ sw.start();
+
+ ClusterI cluster = ClusterImpl.make(BuiltinClusterUID, BuiltinClusterKey, support);
+ if (DEBUG)
+ System.out.println("cluster key=" + cluster.getClusterKey() + " id=" + cluster.getClusterId() + " uid=" + cluster.getClusterUID());
+ byte[] value = new byte[ValueCapacity];
+ for (int i = 0; i < ValueCapacity; ++i)
+ value[i] = (byte) i;
+
+ Assert(AddedResources <= ClusterTraits.getMaxNumberOfResources());
+ int[] resourceKeys = new int[AddedResources];
+ for (int i = 0; i < AddedResources; ++i) {
+ resourceKeys[i] = cluster.createResource(support);
+ Assert(ClusterTraits.getResourceIndexFromResourceKey(resourceKeys[i]) == i + 1);
+ Assert(!cluster.isComplete(resourceKeys[i], support));
+ }
+ int[] statementKeys = new int[AddedStatements];
+ int[] objectKeys = new int[AddedStatements];
+ for (int i = 0; i < AddedStatements; ++i) {
+ if (foreignClusterOn) {
+ Assert(AddedStatements <= ClusterTraits.getMaxNumberOfResources());
+ statementKeys[i] = getResourceKey(foreignCluster.getClusterKey(), i + 1);
+ } else {
+ Assert(AddedStatements <= AddedResources);
+ statementKeys[i] = getResourceKey(builtinCluster.getClusterKey(), i + 1);
+ }
+ objectKeys[i] = getResourceKey(objectCluster.getClusterKey(), i + 1);
+ }
+ for (int i = 0; i < AddedResources; ++i) {
+ final int resourceKey = resourceKeys[i];
+ for (int j = 0; j < AddedStatements; ++j) {
+ int sKey = resourceKey;
+ int pKey = onePredicateOn ? resourceKey : statementKeys[j];
+ if (onePredicateOn && foreignClusterOn)
+ pKey = statementKeys[0];
+ int oKey = objectKeys[j];
+ cluster = cluster.addRelation(sKey, pKey, oKey, support);
+ if (null == cluster)
+ throw new RuntimeException("AddRelation() failed.");
+ if (null != cluster.addRelation(sKey, pKey, oKey, support))
+ throw new RuntimeException("AddRelation() failed.");
+ }
+ cluster = cluster.setValue(resourceKey, value, value.length, support);
+ if (!cluster.hasValue(resourceKey, support))
+ throw new RuntimeException("AddRelation() failed.");
+ byte[] data = cluster.getValue(resourceKey, support);
+ Assert(data.length == value.length);
+ for (int l = 0; l < value.length; ++l)
+ Assert((byte) l == data[l]);
+ }
+
+ sw.stop();
+ out.println("Elapsed time in milliseconds " + sw.elapsedMilli() + " for adding " + AddedResources + " Resources with " + AddedStatements + " statements.");
+
+ testReading(cluster, resourceKeys, statementKeys, objectKeys, onePredicateOn, AddedStatements, foreignClusterOn);
+
+ if (!(cluster instanceof ClusterBig)) {
+ sw.restart();
+ ClusterI big = ((ClusterImpl)cluster).toBig(support);
+ sw.stop();
+ out.println("Elapsed time in milliseconds " + sw.elapsedMilli() + " for converting to big.");
+ testReading(big, resourceKeys, statementKeys, objectKeys, onePredicateOn, AddedStatements, foreignClusterOn);
+ }
+
+ sw.restart();
+ for (int i = 0; i < AddedResources; ++i) {
+ int resourceKey = resourceKeys[i];
+ for (int j = 0; j < AddedStatements; ++j) {
+ int sKey = resourceKey;
+ int pKey = onePredicateOn ? resourceKey : statementKeys[j];
+ if (onePredicateOn && foreignClusterOn)
+ pKey = statementKeys[0];
+ int oKey = objectKeys[j];
+ if (!cluster.removeRelation(sKey, pKey, oKey, support))
+ throw new RuntimeException("RemoveRelation() failed.");
+ if (cluster.removeRelation(sKey, pKey, oKey, support))
+ throw new RuntimeException("RemoveRelation() failed.");
+ cluster.denyRelation(sKey, pKey, oKey, support);
+ }
+ if (!cluster.removeValue(resourceKey, support))
+ throw new RuntimeException("removeValue() failed.");
+ if (cluster.removeValue(resourceKey, support))
+ throw new RuntimeException("removeValue() failed.");
+ }
+ sw.stop();
+ out.println("Elapsed time in millseconds " + sw.elapsedMilli() + " for deleting.");
+ out.println("Used space consumption in bytes: " + cluster.getUsedSpace());
+ return false; // ok
+ }
+
+ private void testBasic()
+ throws DatabaseException {
+ final int N = AddedStatements;
+ support.setStreamOff(true);
+ try {
+ for (int i = N; i < N + 1; ++i) {
+ clusterTest(false, false, i);
+ clusterTest(false, true, i);
+ clusterTest(true, false, i);
+ clusterTest(true, true, i);
+ }
+ } finally {
+ support.setStreamOff(false);
+ }
+ }
+
+ private void Assert(boolean condition)
+ throws DatabaseException {
+ if (condition)
+ return;
+ DatabaseException e = new DatabaseException("Test failed!");
+ e.printStackTrace(out);
+ throw e;
+ }
+ public static void test(Session session) {
+ TestCluster tc = new TestCluster(session);
+ try {
+ System.out.println("Begin of tests.");
+ tc.testBasic();
+ System.out.println("End of tests.");
+ } catch (Throwable t) {
+ throw new RuntimeException("Tests failed.", t);
+ }
+ }
+ public static void main(String[] args) {
+ test(null);
+ }
+}