summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-07-30 04:38:28 (EDT)
committerEike Stepper2007-07-30 04:38:28 (EDT)
commit7a3b45aae976f1ee63905a44e00f06b6ba54cb6d (patch)
tree1054e6ac8bf480ea8d621d273d51c4fdf3659012
parentf9a96e3a8877d5e353c7d0be1ff3cd4117d450fd (diff)
downloadcdo-7a3b45aae976f1ee63905a44e00f06b6ba54cb6d.zip
cdo-7a3b45aae976f1ee63905a44e00f06b6ba54cb6d.tar.gz
cdo-7a3b45aae976f1ee63905a44e00f06b6ba54cb6d.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractOMTest.java30
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/MonitorTest.java121
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/LegacyTest.java73
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/MON.java11
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java21
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorAlreadyBegunException.java38
6 files changed, 194 insertions, 100 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 a5af3b8..c7eb2e4 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 0000000..8d3ea99
--- /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]);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/LegacyTest.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/LegacyTest.java
deleted file mode 100644
index b0d1438..0000000
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/LegacyTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/***************************************************************************
- * 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.internal.util.om.monitor;
-
-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 LegacyTest
-{
- private static final String[] CLASSES = { "Pair", "Triple" };
-
- private static final String[][] FIELDS = { { "x", "y" }, { "x", "y", "z" } };
-
- public static void main(String[] args)
- {
- MonitorUtil.Legacy.startMonitoring();
- readClasses();
- MonitorUtil.Legacy.stopMonitoring();
- }
-
- /**
- * Supports {@link MonitorUtil progress monitoring}.
- */
- public static void readClasses()
- {
- int num = CLASSES.length;
- OMMonitor monitor = MonitorUtil.begin(2 * num, "Reading " + num + " classes");
- for (int c = 0; c < num; c++)
- {
- // Create class buffer
- monitor.worked(1, "Created class buffer for " + CLASSES[c]);
-
- // Read class
- OMSubMonitor subMonitor = monitor.fork();
- try
- {
- readFields(c);
- }
- finally
- {
- subMonitor.join("Read class " + CLASSES[c]);
- }
- }
- }
-
- /**
- * Supports {@link MonitorUtil progress monitoring}.
- *
- * @param i2
- */
- public static void readFields(int c)
- {
- int num = FIELDS[c].length;
- OMMonitor monitor = MonitorUtil.begin(num, "Reading " + num + " fields");
- for (int f = 0; f < num; f++)
- {
- // Read field
- monitor.worked(1, "Read field " + FIELDS[c][f]);
- }
- }
-}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/MON.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/MON.java
index fabc649..2b97ebb 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/MON.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/MON.java
@@ -11,6 +11,8 @@
package org.eclipse.net4j.internal.util.om.monitor;
import org.eclipse.net4j.util.om.monitor.IllegalMonitorNestingException;
+import org.eclipse.net4j.util.om.monitor.MonitorAlreadyBegunException;
+import org.eclipse.net4j.util.om.monitor.MonitorException;
import org.eclipse.net4j.util.om.monitor.MonitorNotBegunException;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
@@ -67,20 +69,21 @@ public final class MON
if (current.hasBegun())
{
- throw new IllegalStateException("Monitor has already begun");
+ throw new MonitorAlreadyBegunException("Monitor has already begun");
}
current.begin(totalWork, task);
return current;
}
- static void checkMonitor(Monitor monitor)
+ static void checkMonitor(Monitor monitor) throws MonitorException
{
Monitor current = CURRENT.get();
if (current != monitor)
{
- throw new IllegalMonitorNestingException("Illegal monitor nesting\nCurrent:\n" + current.dump() + "Used:\n"
- + monitor.dump());
+ throw new IllegalMonitorNestingException("Illegal monitor nesting\n" + //
+ "Current monitor stack: " + current.dump() + "\n" + //
+ " Used monitor stack: " + monitor.dump() + "\n");
}
if (!current.hasBegun())
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java
index d4013ef..0e76fb3 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/monitor/Monitor.java
@@ -200,7 +200,7 @@ public abstract class Monitor implements OMMonitor, OMSubMonitor
protected String dump()
{
StringBuilder builder = new StringBuilder();
- dump(builder, 0);
+ dump(builder);
return builder.toString();
}
@@ -245,23 +245,14 @@ public abstract class Monitor implements OMMonitor, OMSubMonitor
}
}
- private int dump(StringBuilder builder, int level)
+ private void dump(StringBuilder builder)
{
if (parent != null)
{
- int line = parent.dump(builder, level + 1);
- builder.append(line);
- builder.append(": ");
- builder.append(task);
- builder.append("\n");
- return line + 1;
- }
- else
- {
- builder.append("1: ");
- builder.append(task);
- builder.append("\n");
- return 2;
+ parent.dump(builder);
+ builder.append(", ");
}
+
+ builder.append(task);
}
} \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorAlreadyBegunException.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorAlreadyBegunException.java
new file mode 100644
index 0000000..cdf36f0
--- /dev/null
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/monitor/MonitorAlreadyBegunException.java
@@ -0,0 +1,38 @@
+/***************************************************************************
+ * 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.util.om.monitor;
+
+/**
+ * @author Eike Stepper
+ */
+public class MonitorAlreadyBegunException extends MonitorException
+{
+ private static final long serialVersionUID = 1L;
+
+ public MonitorAlreadyBegunException()
+ {
+ }
+
+ public MonitorAlreadyBegunException(String s)
+ {
+ super(s);
+ }
+
+ public MonitorAlreadyBegunException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ public MonitorAlreadyBegunException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}