X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.modeling.tests%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Ftests%2Fcommands%2FAssertMemoryConsumption.java;fp=bundles%2Forg.simantics.modeling.tests%2Fsrc%2Forg%2Fsimantics%2Fmodeling%2Ftests%2Fcommands%2FAssertMemoryConsumption.java;h=07f3091dd85d603897d95301d9510b7ab1846a48;hp=0000000000000000000000000000000000000000;hb=ca6fcd858a0b82eb1b5a8f12c4d5df30e84393e0;hpb=67fd62f9c742337ec80eef658192db198a0efaac 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 index 000000000..07f3091dd --- /dev/null +++ b/bundles/org.simantics.modeling.tests/src/org/simantics/modeling/tests/commands/AssertMemoryConsumption.java @@ -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 { + + 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