]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertMemoryConsumption.java
Added missing org.simantics.modeling.tests plug-ins.
[simantics/platform.git] / bundles / org.simantics.modeling.tests / src / org / simantics / modeling / tests / commands / AssertMemoryConsumption.java
diff --git a/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertMemoryConsumption.java b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertMemoryConsumption.java
new file mode 100644 (file)
index 0000000..07f3091
--- /dev/null
@@ -0,0 +1,31 @@
+package org.simantics.modeling.tests.commands;
+
+import junit.framework.Assert;
+
+import org.simantics.db.testing.common.WriteCommand;
+import org.simantics.modeling.tests.cases.ModelingCommandSequenceTest;
+
+public class AssertMemoryConsumption extends WriteCommand<ModelingCommandSequenceTest> {
+
+       private int expected;
+       
+       public AssertMemoryConsumption(int expected) {
+               this.expected = expected;
+       }
+
+       @Override
+       public void run(ModelingCommandSequenceTest environment) throws Exception {
+               Assert.assertTrue(getUsedMemory() < expected);
+       }
+       
+       private long getUsedMemory() {
+               
+       System.gc();
+       System.gc();
+       System.gc();
+       Runtime runtime = Runtime.getRuntime();
+       return runtime.totalMemory() - runtime.freeMemory();
+               
+       }
+
+}
\ No newline at end of file