diff options
author | Eike Stepper | 2007-07-30 08:38:28 +0000 |
---|---|---|
committer | Eike Stepper | 2007-07-30 08:38:28 +0000 |
commit | 7a3b45aae976f1ee63905a44e00f06b6ba54cb6d (patch) | |
tree | 1054e6ac8bf480ea8d621d273d51c4fdf3659012 /plugins/org.eclipse.net4j.tests | |
parent | f9a96e3a8877d5e353c7d0be1ff3cd4117d450fd (diff) | |
download | cdo-7a3b45aae976f1ee63905a44e00f06b6ba54cb6d.tar.gz cdo-7a3b45aae976f1ee63905a44e00f06b6ba54cb6d.tar.xz cdo-7a3b45aae976f1ee63905a44e00f06b6ba54cb6d.zip |
*** empty log message ***
Diffstat (limited to 'plugins/org.eclipse.net4j.tests')
-rw-r--r-- | plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractOMTest.java | 30 | ||||
-rw-r--r-- | plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/MonitorTest.java | 121 |
2 files changed, 143 insertions, 8 deletions
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractOMTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractOMTest.java index a5af3b8dd8..c7eb2e4363 100644 --- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractOMTest.java +++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractOMTest.java @@ -58,6 +58,20 @@ public abstract class AbstractOMTest extends TestCase System.out.println(); } + @Override + protected void runTest() throws Throwable + { + try + { + super.runTest(); + } + catch (Throwable t) + { + t.printStackTrace(System.out); + throw t; + } + } + protected void enableConsole() { if (!consoleEnabled) @@ -82,20 +96,20 @@ public abstract class AbstractOMTest extends TestCase } } - protected static void msg(String m) + protected void doSetUp() throws Exception { - if (consoleEnabled) - { - System.out.println(); - System.out.println("--> " + m); - } } - protected void doSetUp() throws Exception + protected void doTearDown() throws Exception { } - protected void doTearDown() throws Exception + protected static void msg(String m) { + if (consoleEnabled) + { + System.out.println(); + System.out.println("--> " + m); + } } }
\ No newline at end of file diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/MonitorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/MonitorTest.java new file mode 100644 index 0000000000..8d3ea99a59 --- /dev/null +++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/MonitorTest.java @@ -0,0 +1,121 @@ +/*************************************************************************** + * Copyright (c) 2004-2007 Eike Stepper, Germany. + * 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: + * Eike Stepper - initial API and implementation + **************************************************************************/ +package org.eclipse.net4j.tests; + +import org.eclipse.net4j.util.om.monitor.IllegalMonitorNestingException; +import org.eclipse.net4j.util.om.monitor.MonitorAlreadyBegunException; +import org.eclipse.net4j.util.om.monitor.MonitorUtil; +import org.eclipse.net4j.util.om.monitor.OMMonitor; +import org.eclipse.net4j.util.om.monitor.OMSubMonitor; + +/** + * @author Eike Stepper + */ +public class MonitorTest extends AbstractOMTest +{ + private static final String[] CLASSES = { "Pair", "Triple" }; + + private static final String[][] FIELDS = { { "x", "y" }, { "x", "y", "z" } }; + + public void testJoined() throws Exception + { + MonitorUtil.Legacy.startMonitoring(); + readClasses(CLASSES, FIELDS, true); + MonitorUtil.Legacy.stopMonitoring(); + } + + public void testJoinedNotStarted() throws Exception + { + readClasses(CLASSES, FIELDS, true); + } + + public void testJoinedStopNotStarted() throws Exception + { + try + { + readClasses(CLASSES, FIELDS, true); + MonitorUtil.Legacy.stopMonitoring(); + fail("IllegalMonitorNestingException expected"); + } + catch (IllegalMonitorNestingException ex) + { + } + } + + public void testUnjoined() throws Exception + { + try + { + MonitorUtil.Legacy.startMonitoring(); + readClasses(CLASSES, FIELDS, false); + fail("IllegalMonitorNestingException expected"); + } + catch (IllegalMonitorNestingException ex) + { + } + } + + public void testUnjoinedNotStarted() throws Exception + { + try + { + readClasses(CLASSES, FIELDS, false); + fail("MonitorAlreadyBegunException expected"); + } + catch (MonitorAlreadyBegunException ex) + { + } + } + + /** + * Supports {@link MonitorUtil progress monitoring}. + */ + private static void readClasses(String[] classes, String[][] fields, boolean join) + { + int num = classes.length; + OMMonitor monitor = MonitorUtil.begin(2 * num, "Reading " + num + " classes"); + for (int i = 0; i < num; i++) + { + // Create class buffer + monitor.worked(1, "Created class buffer for " + classes[i]); + + // Read class + OMSubMonitor subMonitor = monitor.fork(); + try + { + readFields(fields[i]); + } + finally + { + if (join) + { + subMonitor.join("Read class " + classes[i]); + } + } + } + } + + /** + * Supports {@link MonitorUtil progress monitoring}. + * + * @param i2 + */ + private static void readFields(String[] fields) + { + int num = fields.length; + OMMonitor monitor = MonitorUtil.begin(num, "Reading " + num + " fields"); + for (int i = 0; i < num; i++) + { + // Read field + monitor.worked(1, "Read field " + fields[i]); + } + } +} |