diff options
author | eea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-08-24 23:13:29 +0000 |
---|---|---|
committer | eea1 <eea1@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1999-08-24 23:13:29 +0000 |
commit | 8b948632e15be50020e0087ce6f846120fb662b8 (patch) | |
tree | 5d7138887ffda243c8bd7b97da41d0d678bee537 /java | |
parent | 8bd3483e15b78016dde514251b613090b8eadeb3 (diff) | |
download | ATCD-8b948632e15be50020e0087ce6f846120fb662b8.tar.gz |
Updated source files for tests/Reactor.
Diffstat (limited to 'java')
-rw-r--r-- | java/JACE/tests/Reactor/TimeValueTest.java | 52 | ||||
-rw-r--r-- | java/JACE/tests/Reactor/TimerQueueTest.java | 84 |
2 files changed, 136 insertions, 0 deletions
diff --git a/java/JACE/tests/Reactor/TimeValueTest.java b/java/JACE/tests/Reactor/TimeValueTest.java new file mode 100644 index 00000000000..559f6d15176 --- /dev/null +++ b/java/JACE/tests/Reactor/TimeValueTest.java @@ -0,0 +1,52 @@ +/************************************************* + * + * = PACKAGE + * ACE.Reactor + * + * = FILENAME + * TimeValueTest.java + * + *@author Prashant Jain + * + *************************************************/ +package JACE.tests.Reactor; + +import JACE.OS.*; +import JACE.ASX.*; + +public class TimeValueTest +{ + public void ASSERT (boolean expression, int i) + { + if (!expression) + ACE.ERROR ("ASSERT failed for " + i); + } + + public void runTest () + { + TimeValue tv1 = new TimeValue (); + TimeValue tv2 = new TimeValue (2); + TimeValue tv3 = new TimeValue (100); + TimeValue tv4 = new TimeValue (1, 1000000000); + TimeValue tv5 = new TimeValue (2); + TimeValue tv6 = new TimeValue (1, -1000000000); + + this.ASSERT (tv1.equals (new TimeValue (0)), 1); + this.ASSERT (tv2.lessThan (tv3), 2); + this.ASSERT (tv2.lessThanEqual (tv2), 3); + this.ASSERT (tv2.greaterThanEqual (tv4), 4); + this.ASSERT (tv5.greaterThanEqual (tv6), 5); + this.ASSERT (tv2.equals (new TimeValue (1, 1000000000)), 6); + this.ASSERT (tv5.equals (tv4), 7); + this.ASSERT (tv2.equals (tv4), 8); + this.ASSERT (tv1.notEquals (tv2), 9); + this.ASSERT (tv6.equals (tv1), 10); + } + + public static void main (String [] args) + { + ACE.enableDebugging (); + + new TimeValueTest ().runTest (); + } +} diff --git a/java/JACE/tests/Reactor/TimerQueueTest.java b/java/JACE/tests/Reactor/TimerQueueTest.java new file mode 100644 index 00000000000..93845ccb6ec --- /dev/null +++ b/java/JACE/tests/Reactor/TimerQueueTest.java @@ -0,0 +1,84 @@ +// ============================================================================ +// +// = PACKAGE +// tests.Reactor +// +// = FILENAME +// TimerQueueTest.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package JACE.tests.Reactor; + +import JACE.OS.*; +import JACE.ASX.*; +import JACE.Reactor.*; + +public class TimerQueueTest implements EventHandler +{ + public int handleTimeout (TimeValue tv, Object obj) + { + ACE.DEBUG ("handleTimeout: " + tv.toString () + " " + (String) obj); + return 0; + } + + public static void main (String args []) + { + ACE.enableDebugging (); + + TimerQueue tq = new TimerQueue (true); + TimerQueueTest th1 = new TimerQueueTest (); + int n = 5; + + ACE.enableDebugging (); + + try + { + if (args.length == 1) + { + n = Integer.parseInt (args[0]); + } + } + catch (NumberFormatException e) + { + ACE.ERROR ("Illegal argument."); + } + + // Set a periodic timer + int id = tq.scheduleTimer (th1, + "periodic", + new TimeValue (2), + new TimeValue (3)); + + int i; + // Set a bunch of single timers + for (i=1; i <= n; i++) + { + tq.scheduleTimer (th1, + "A-timer-" + new Integer (i), + new TimeValue (i*2)); + } + + TimerQueueTest th2 = new TimerQueueTest (); + for (i=1; i <= n; i++) + { + tq.scheduleTimer (th2, + "B-timer-" + new Integer (i), + new TimeValue (i*3)); + } + // Cancel all timers associated with this handler + tq.cancelTimer (th2); + + try + { + Thread.sleep (30000); + } + catch (InterruptedException e) + { + } + tq.cancelTimer (id); + System.exit (0); + } +} |