diff options
author | pjain <pjain@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1996-11-12 00:53:03 +0000 |
---|---|---|
committer | pjain <pjain@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1996-11-12 00:53:03 +0000 |
commit | d34b1eeafa3fa94370d9daea349b13b3f1d2046f (patch) | |
tree | 89af770048cabc399c0d028e6dabcf43defd3170 | |
parent | e8d6c3f71e9fc8d3d58e7d0e7cacbdd5c9737753 (diff) | |
download | ATCD-d34b1eeafa3fa94370d9daea349b13b3f1d2046f.tar.gz |
image files
test files
source files
24 files changed, 1616 insertions, 0 deletions
diff --git a/java/tests/ASX/Makefile b/java/tests/ASX/Makefile new file mode 100644 index 00000000000..ae62fad49a2 --- /dev/null +++ b/java/tests/ASX/Makefile @@ -0,0 +1,25 @@ +# Makefile + +.SUFFIXES: .java .class + +JACE_WRAPPER = ../.. +CLASSDIR = $(JACE_WRAPPER)/classes + +CLASSPATH := $(CLASSDIR):$(CLASSPATH) + +all: + javac -d ${JACE_WRAPPER}/classes $(files) +doc: + javadoc -d ${JACE_WRAPPER}/doc $(files) $(packages) + + +files = MessageQueueTest.java \ + TaskTest.java \ + PriorityBufferTest.java \ + ThreadPoolTest.java + +packages = tests.ASX + +realclean: + find ${JACE_WRAPPER}/classes/tests/ASX -name '*.class' -print | xargs ${RM} + diff --git a/java/tests/ASX/MessageQueueTest.java b/java/tests/ASX/MessageQueueTest.java new file mode 100644 index 00000000000..0dfc3428330 --- /dev/null +++ b/java/tests/ASX/MessageQueueTest.java @@ -0,0 +1,50 @@ +// ============================================================================ +// +// = PACKAGE +// tests.ASX +// +// = FILENAME +// MessageQueueTest.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package tests.ASX; + +import java.io.*; +import ACE.OS.*; +import ACE.ASX.*; + +public class MessageQueueTest +{ + public static void main (String args[]) + { + try + { + MessageBlock conMb; + MessageQueue msgQueue = new MessageQueue (); + MessageBlock mb1 = new MessageBlock ("hello"); + MessageBlock mb2 = new MessageBlock ("world"); + mb1.msgPriority (5); + mb2.msgPriority (7); + + // Enqueue in priority order. + if (msgQueue.enqueue (mb1) == -1) + ACE.ERROR ("put_next"); + + if (msgQueue.enqueue (mb2) == -1) + ACE.ERROR ("put_next"); + + // Now try to dequeue + if ((conMb = msgQueue.dequeueHead ()) == null) + ACE.ERROR ("dequeueHead"); + else + ACE.DEBUG ("Consumer: removed item " + conMb.base () + " of priority " + conMb.msgPriority ()); + } + catch (InterruptedException e) + { + } + } +} + diff --git a/java/tests/ASX/PriorityBufferTest.java b/java/tests/ASX/PriorityBufferTest.java new file mode 100644 index 00000000000..79a3ffebfb2 --- /dev/null +++ b/java/tests/ASX/PriorityBufferTest.java @@ -0,0 +1,116 @@ +// ============================================================================ +// +// = PACKAGE +// tests.ASX +// +// = FILENAME +// PriorityBufferTest.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package tests.ASX; + +import java.io.*; +import ACE.OS.*; +import ACE.ASX.*; + +class consumer extends Thread +{ + public void run () + { + MessageBlock mb = null; + long curPriority = 0; + int length = 0; + + try + { + // Keep looping, reading a message out of the queue, until we + // get a message with a length == 0, which signals us to quit. + for (;;) + { + if ((mb = PriorityBufferTest.msgQueue.dequeueHead ()) == null) + break; + + length = mb.length (); + curPriority = mb.msgPriority (); + + if (length > 0) + ACE.DEBUG ("Consumer: removed item \"" + mb.base () + "\" of priority: " + curPriority); + + if (length == 0) + break; + } + } + catch (InterruptedException e) + { + } + } +} + +class producer extends Thread +{ + producer (int delay) + { + this.delay_ = delay; + } + + public void run () + { + try + { + long count = 0; + for (char c = 'a'; c <= 'z'; c++) + { + count++; + // Allocate a new message + MessageBlock mb = new MessageBlock (new Character (c).toString ()); + // Set the priority + mb.msgPriority (count); + + // Enqueue in priority order. + if (PriorityBufferTest.msgQueue.enqueue (mb) == -1) + ACE.ERROR ("put_next"); + else + { + ACE.DEBUG ("Producer: inserted item \"" + mb.base () + "\" of priority: " + count); + if (this.delay_ > 0) + this.sleep (this.delay_); + } + } + + // Now send a 0-sized shutdown message to the other thread + if (PriorityBufferTest.msgQueue.enqueueTail (new MessageBlock (0)) == -1) + ACE.ERROR ("put_next"); + } + catch (InterruptedException e) + { + } + } + + private int delay_; +} + +public class PriorityBufferTest +{ + public static MessageQueue msgQueue = new MessageQueue (); + + public static void main (String args[]) + { + int delay = 0; + if (args.length == 1) + { + try + { + delay = Integer.parseInt (args[0]); + } + catch (NumberFormatException e) + { + ACE.ERROR ("Illegal argument."); + } + } + new producer (delay).start (); + new consumer ().start (); + } +} diff --git a/java/tests/ASX/TaskTest.java b/java/tests/ASX/TaskTest.java new file mode 100644 index 00000000000..a1958f2a8dc --- /dev/null +++ b/java/tests/ASX/TaskTest.java @@ -0,0 +1,86 @@ +// ============================================================================ +// +// = PACKAGE +// tests.ASX +// +// = FILENAME +// TaskTest.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package tests.ASX; + +import java.io.*; +import ACE.OS.*; +import ACE.ASX.*; +import ACE.Reactor.*; + +public class TaskTest extends Task +{ + int nThreads_; + int nIterations_; + + public TaskTest (int nThreads, int nIterations) + { + this.nIterations_ = nIterations; + this.nThreads_ = nThreads; + if (this.activate (0, nThreads, true) == -1) + ACE.ERROR ("activate failed"); + } + + public int open (Object obj) + { + return 0; + } + + public int close (long flags) + { + return 0; + } + + public int put (MessageBlock mb, TimeValue tv) + { + return 0; + } + + public int handleTimeout (TimeValue tv, Object obj) + { + return 0; + } + + public int svc () + { + for (int i = 1; i <= this.nIterations_; i++) + { + ACE.DEBUG (Thread.currentThread ().toString () + " in iteration " + i); + // Allow other threads to run + Thread.yield (); + } + return 0; + } + + public static void main (String args[]) + { + int nThreads = 1; + int nIterations = 1; + try + { + if (args.length == 2) + { + nThreads = Integer.parseInt (args[0]); + nIterations = Integer.parseInt (args[1]); + } + else if (args.length == 1) + { + nThreads = Integer.parseInt (args[0]); + } + } + catch (NumberFormatException e) + { + ACE.ERROR ("Illegal argument."); + } + TaskTest tt = new TaskTest (nThreads, nIterations); + } +} diff --git a/java/tests/ASX/ThreadPoolTest.java b/java/tests/ASX/ThreadPoolTest.java new file mode 100644 index 00000000000..6367452131a --- /dev/null +++ b/java/tests/ASX/ThreadPoolTest.java @@ -0,0 +1,185 @@ +// ============================================================================ +// +// = PACKAGE +// tests.ASX +// +// = FILENAME +// ThreadPoolTest.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package tests.ASX; + +import java.io.*; +import ACE.OS.*; +import ACE.ASX.*; +import ACE.Reactor.*; + +public class ThreadPoolTest extends Task +{ + int nThreads_; + int nIterations_; + + public static int MAX_MB_SIZE = 1024; + + public ThreadPoolTest (int nThreads, int nIterations) + { + this.nIterations_ = nIterations; + this.nThreads_ = nThreads; + if (this.activate (0, nThreads, true) == -1) + ACE.ERROR ("activate failed"); + } + + public int handleTimeout (TimeValue tv, Object obj) + { + return 0; + } + + public int open (Object obj) + { + return 0; + } + + public int close (long flags) + { + return 0; + } + + public int put (MessageBlock mb, TimeValue tv) + { + try + { + return this.putq (mb, tv); + } + catch (InterruptedException e) + { + } + return 0; + } + + public int svc () + { + int result = 0; + int count = 1; + + // Keep looping, reading a message out of the queue, until we get a + // message with a length == 0, which signals us to quit. + try + { + for (;; count++) + { + MessageBlock mb = this.getq (new TimeValue ()); + if (mb == null) + { + ACE.ERROR (Thread.currentThread ().toString () + " in iteration " + count + ", got result -1, exiting"); + break; + } + int length = mb.length (); + + if (length > 0) + ACE.DEBUG (Thread.currentThread ().toString () + + " in iteration " + count + ", length = " + + length + ", text = \"" + mb.base () + "\""); + + if (length == 0) + { + ACE.DEBUG (Thread.currentThread ().toString () + + " in iteration " + count + + ", got NULL message, exiting"); + break; + } + Thread.yield (); + } + } + catch (InterruptedException e) + { + } + return 0; + } + + public static void produce (ThreadPoolTest threadPool, int nIterations) + { + int count = 0; + for (int n = 0;;) + { + // Allocate a new message. + MessageBlock mb = new MessageBlock (new Integer (count).toString ()); + + if (count == nIterations) + n = 1; // Indicate that we need to shut down. + else + count++; + + if (count == 0 || (count % 20 == 0)) + { + try + { + Thread.sleep (1); + } + catch (InterruptedException e) + { + } + } + if (n != 1) + { + ACE.DEBUG ("Producing..."); + // Pass the message to the Thread_Pool. + if (threadPool.put (mb, new TimeValue ()) == -1) + ACE.ERROR ("put"); + } + else + { + // Send a shutdown message to the waiting threads and exit. + ACE.DEBUG ("start loop, dump of task"); + + for (int i = threadPool.thrCount (); i > 0; i--) + { + ACE.DEBUG (Thread.currentThread ().toString () + + "EOF, enqueueing NULL block for thread " + i); + + // Enqueue a NULL message to flag each consumer to + // shutdown. + if (threadPool.put (new MessageBlock (0), new TimeValue ()) == -1) + ACE.ERROR ("put"); + } + + break; + } + } + } + + public static void main (String args[]) + { + int nThreads = 1; + int nIterations = 100; + try + { + if (args.length == 2) + { + nThreads = Integer.parseInt (args[0]); + nIterations = Integer.parseInt (args[1]); + } + else if (args.length == 1) + { + nThreads = Integer.parseInt (args[0]); + } + } + catch (NumberFormatException e) + { + ACE.ERROR ("Illegal argument."); + } + ACE.DEBUG ("Threads = " + nThreads + " Iterations = " + nIterations); + + // Create the worker tasks. + ThreadPoolTest threadPool = new ThreadPoolTest (nThreads, + nIterations); + + // Create work for the worker tasks to process in their own threads. + produce (threadPool, nIterations); + ACE.DEBUG ("exiting..."); + } +} + + diff --git a/java/tests/Concurrency/Makefile b/java/tests/Concurrency/Makefile new file mode 100644 index 00000000000..2b777e63c55 --- /dev/null +++ b/java/tests/Concurrency/Makefile @@ -0,0 +1,22 @@ +# Makefile + +.SUFFIXES: .java .class + +JACE_WRAPPER = ../.. +CLASSDIR = $(JACE_WRAPPER)/classes + +CLASSPATH := $(CLASSDIR):$(CLASSPATH) + +all: + javac -d ${JACE_WRAPPER}/classes $(files) +doc: + javadoc -d ${JACE_WRAPPER}/doc $(files) $(packages) + +files = MutexTest.java \ + SemaphoreTest.java \ + RWMutexTest.java + +packages = tests.Concurrency + +realclean: + find ${JACE_WRAPPER}/classes/tests/Concurrency -name '*.class' -print | xargs ${RM} diff --git a/java/tests/Concurrency/MutexTest.java b/java/tests/Concurrency/MutexTest.java new file mode 100644 index 00000000000..3241fab2a98 --- /dev/null +++ b/java/tests/Concurrency/MutexTest.java @@ -0,0 +1,154 @@ +/************************************************* + * + * = PACKAGE + * tests.Concurrency + * + * = FILENAME + * MutexTest.java + * + *@author Prashant Jain + * + *************************************************/ +package tests.Concurrency; + +import java.io.*; +import ACE.OS.*; +import ACE.Concurrency.*; + +class MutexReader extends Thread +{ + MutexReader (int nIterations, Mutex mutex) + { + this.nIterations_ = nIterations; + this.mutex_ = mutex; + } + + public void run () + { + for (int i = 1; i <= this.nIterations_; i++) + { + // Acquire the mutex (will block until it gets it) + try + { + this.mutex_.acquire (); + } + catch (InterruptedException e) + { + ACE.ERROR (e); + } + + MutexTest.count++; + ACE.DEBUG (Thread.currentThread ().toString () + + " reader acquired mutex in iteration " + i + + ", count = " + MutexTest.count); + + try + { + Thread.sleep (1); + } + catch (InterruptedException e) + { + } + // Release the mutex + this.mutex_.release (); + try + { + Thread.sleep (1); + } + catch (InterruptedException e) + { + } + + } + } + + int nIterations_; + Mutex mutex_; +} + +class MutexWriter extends Thread +{ + MutexWriter (int nIterations, Mutex mutex) + { + this.nIterations_ = nIterations; + this.mutex_ = mutex; + } + + public void run () + { + for (int i = 1; i <= this.nIterations_; i++) + { + // Acquire the mutex (will block until it gets it) + try + { + this.mutex_.acquire (); + } + catch (InterruptedException e) + { + ACE.ERROR (e); + } + + MutexTest.count++; + ACE.DEBUG (Thread.currentThread ().toString () + + " writer acquired mutex in iteration " + i + + ", count = " + MutexTest.count); + + try + { + Thread.sleep (1); + } + catch (InterruptedException e) + { + } + + // Release the mutex + this.mutex_.release (); + try + { + Thread.sleep (1); + } + catch (InterruptedException e) + { + } + + } + } + + int nIterations_; + Mutex mutex_; +} + +public class MutexTest +{ + public static void main (String args[]) + { + int nReaders = 1; + int nWriters = 1; + int nIterations = 100; + int i; + try + { + if (args.length == 3) + { + nReaders = Integer.parseInt (args[0]); + nWriters = Integer.parseInt (args[1]); + nIterations = Integer.parseInt (args[2]); + } + } + catch (NumberFormatException e) + { + ACE.ERROR ("Illegal argument."); + } + + // Create a lock + Mutex mutex = new Mutex (); + + // Now spawn off the readers and writers + for (i = 0; i < nReaders; i++) + new MutexReader (nIterations, mutex).start (); + + for (i = 0; i < nWriters; i++) + new MutexWriter (nIterations, mutex).start (); + } + public static int count; +} diff --git a/java/tests/Concurrency/RWMutexTest.java b/java/tests/Concurrency/RWMutexTest.java new file mode 100644 index 00000000000..ee8054d3088 --- /dev/null +++ b/java/tests/Concurrency/RWMutexTest.java @@ -0,0 +1,91 @@ +/************************************************* + * + * = PACKAGE + * tests.Concurrency + * + * = FILENAME + * RWMutexTest.java + * + *@author Ross Dargahi (rossd@krinfo.com) + * + *************************************************/ +package tests.Concurrency; + +import ACE.OS.*; +import ACE.Concurrency.*; + +class TestThread extends Thread +{ + TestThread(String name, + boolean writer, + RWMutex lock) + { + super (name); + mWriter = writer; + mLock = lock; + } + + public void run() + { + for (int i = 0; i < 10; i++) + { + try + { + if (!mWriter) + { + mLock.acquireRead(); + ACE.DEBUG (getName() + ": Acquired Read Lock"); + + sleep ((int) (Math.random () * 1000)); + + mLock.release (); + ACE.DEBUG (getName () + ": Released Read Lock"); + } + else + { + mLock.acquireWrite (); + ACE.DEBUG (getName () + ": Acquired Write Lock"); + + sleep ((int) (Math.random ()* 1000)); + + mLock.release (); + ACE.DEBUG (getName () + ": Released Write Lock"); + } + } + catch (InterruptedException ex) + { + ACE.ERROR ("InterruptedException"); + } + } + } + + RWMutex mLock; + boolean mWriter; +} + +public class RWMutexTest +{ + public static void main(String [] args) + { + RWMutex lock = new RWMutex(); + + TestThread t1 = new TestThread ("1", false, lock); + TestThread t2 = new TestThread ("2", false, lock); + TestThread t3 = new TestThread ("3", false, lock); + TestThread t4 = new TestThread ("4", true, lock); + TestThread t5 = new TestThread ("5", false, lock); + TestThread t6 = new TestThread ("6", false, lock); + TestThread t7 = new TestThread ("7", false, lock); + TestThread t8 = new TestThread ("8", true, lock); + + t1.start (); + t2.start (); + t3.start (); + t4.start (); + t5.start (); + t6.start (); + t7.start (); + t8.start (); + } +} + diff --git a/java/tests/Concurrency/SemaphoreTest.java b/java/tests/Concurrency/SemaphoreTest.java new file mode 100644 index 00000000000..489f2cb0307 --- /dev/null +++ b/java/tests/Concurrency/SemaphoreTest.java @@ -0,0 +1,102 @@ +/************************************************* + * + * = PACKAGE + * tests.Concurrency + * + * = FILENAME + * SemaphoreTest.java + * + *@author Prashant Jain + * + *************************************************/ +package tests.Concurrency; + +import java.io.*; +import ACE.OS.*; +import ACE.Concurrency.*; + +class SemaphoreWriter extends Thread +{ + SemaphoreWriter (int nIterations, Semaphore s) + { + this.nIterations_ = nIterations; + this.s_ = s; + } + + public void run () + { + for (int i = 1; i <= this.nIterations_; i++) + { + // Acquire the semaphore (will block until it gets it) + try + { + this.s_.acquire (); + } + catch (InterruptedException e) + { + ACE.ERROR (e); + } + + SemaphoreTest.counter++; + ACE.DEBUG (Thread.currentThread ().toString () + + " acquired semaphore in iteration " + i + + ", counter = " + SemaphoreTest.counter); + + try + { + Thread.sleep (1); + } + catch (InterruptedException e) + { + } + + // Release the semaphore + this.s_.release (); + ACE.DEBUG (Thread.currentThread ().toString () + + " released semaphore in iteration " + i); + try + { + Thread.sleep (1); + } + catch (InterruptedException e) + { + } + + } + } + + int nIterations_; + Semaphore s_; +} + +public class SemaphoreTest +{ + public static void main (String args[]) + { + int nThreads = 1; + int count = 1; + int nIterations = 100; + int i; + try + { + if (args.length == 3) + { + nThreads = Integer.parseInt (args[0]); + count = Integer.parseInt (args[1]); + nIterations = Integer.parseInt (args[2]); + } + } + catch (NumberFormatException e) + { + ACE.ERROR ("Illegal argument."); + } + + // Create a lock + Semaphore s = new Semaphore (count); + + // Spawn off n_threads + for (i = 0; i < nThreads; i++) + new SemaphoreWriter (nIterations, s).start (); + } + public static int counter; +} diff --git a/java/tests/Connection/AcceptorTest.java b/java/tests/Connection/AcceptorTest.java new file mode 100644 index 00000000000..864a7dbe5a1 --- /dev/null +++ b/java/tests/Connection/AcceptorTest.java @@ -0,0 +1,79 @@ +// ============================================================================ +// +// = PACKAGE +// tests.Connection +// +// = FILENAME +// AcceptorTest.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package tests.Connection; + +import java.io.*; +import java.net.*; +import ACE.OS.*; +import ACE.Connection.*; + +public class AcceptorTest +{ + void print_usage_and_die () + { + System.out.println ("Usage: test_server [<port>]"); + System.exit (0); + } + + public void init (int port) + { + try + { + Acceptor acceptor = new Acceptor (Class.forName ("tests.Connection.ServerHandler")); + acceptor.open (port); + while (true) + { + acceptor.accept (); + } + } + catch (ClassNotFoundException e) + { + ACE.ERROR (e); + } + catch (SocketException e) + { + ACE.ERROR ("Socket Exception: " + e); + } + catch (InstantiationException e) + { + ACE.ERROR (e); + } + catch (IllegalAccessException e) + { + ACE.ERROR ("Dang!" + e); + } + catch (IOException e) + { + ACE.ERROR (e); + } + } + + public static void main (String [] args) + { + int port = ACE.DEFAULT_SERVER_PORT; + AcceptorTest acceptorTest = new AcceptorTest (); + + if (args.length == 1) + { + try + { + port = Integer.parseInt (args[0]); + } + catch (NumberFormatException e) + { + acceptorTest.print_usage_and_die (); + } + } + acceptorTest.init (port); + } +} diff --git a/java/tests/Connection/ClientHandler.java b/java/tests/Connection/ClientHandler.java new file mode 100644 index 00000000000..cb2bde1df85 --- /dev/null +++ b/java/tests/Connection/ClientHandler.java @@ -0,0 +1,76 @@ +// ============================================================================ +// +// = PACKAGE +// tests.Connection +// +// = FILENAME +// ClientHandler.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package tests.Connection; + +import java.io.*; +import java.net.*; +import ACE.OS.*; +import ACE.Connection.*; + +public class ClientHandler extends SvcHandler +{ + public ClientHandler () + { + } + + public int open (Object obj) + { + new Thread (this).start (); + return 0; + } + + public void run () + { + DataInputStream in = new DataInputStream (System.in); + String msg; + StringBuffer ack = new StringBuffer (); + int ack_len; + try + { + while (true) + { + System.out.print ("Enter input: "); + System.out.flush (); + msg = in.readLine (); + if (msg == null) + break; + this.peer ().send (new StringBuffer (msg)); + System.out.println ("Waiting for ack..."); + ack_len = this.peer ().recv (ack); + if (ack_len == 0) + break; + else + System.out.println (ack); + } + } + catch (NullPointerException e) + { + ACE.ERROR ("connection reset by peer"); + } + catch (IOException e) + { + ACE.ERROR (e); + } + finally + { + try + { + this.peer ().close (); + } + catch (IOException e) + { + } + } + + } +} diff --git a/java/tests/Connection/ConnectorTest.java b/java/tests/Connection/ConnectorTest.java new file mode 100644 index 00000000000..d3722b768ea --- /dev/null +++ b/java/tests/Connection/ConnectorTest.java @@ -0,0 +1,76 @@ +// ============================================================================ +// +// = PACKAGE +// tests.Connection +// +// = FILENAME +// ConnectorTest.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package tests.Connection; + +import java.io.*; +import java.net.*; +import ACE.OS.*; +import ACE.Connection.*; + +public class ConnectorTest +{ + void print_usage_and_die () + { + System.out.println ("Usage: test_Connector <hostname> [<port>]"); + System.exit (0); + } + + public void init (String hostname, int port) + { + try + { + Connector connector = new Connector (); + connector.open (hostname, port); + connector.connect (new ClientHandler ()); + } + catch (UnknownHostException e) + { + ACE.ERROR (e); + } + catch (SocketException e) + { + ACE.ERROR ("Connection refused"); + } + catch (InstantiationException e) + { + ACE.ERROR (e); + } + catch (IllegalAccessException e) + { + ACE.ERROR (e); + } + catch (IOException e) + { + ACE.ERROR (e); + } + } + + public static void main (String [] args) + { + int port = ACE.DEFAULT_SERVER_PORT; + ConnectorTest connectorTest = new ConnectorTest (); + + if (args.length == 2) + { + try + { + port = Integer.parseInt (args[1]); + } + catch (NumberFormatException e) + { + connectorTest.print_usage_and_die (); + } + } + connectorTest.init (args[0], port); + } +} diff --git a/java/tests/Connection/Makefile b/java/tests/Connection/Makefile new file mode 100644 index 00000000000..de076f71237 --- /dev/null +++ b/java/tests/Connection/Makefile @@ -0,0 +1,24 @@ +# Makefile + +.SUFFIXES: .java .class + +JACE_WRAPPER = ../.. +CLASSDIR = $(JACE_WRAPPER)/classes + +CLASSPATH := $(CLASSDIR):$(CLASSPATH) + +all: + javac -d ${JACE_WRAPPER}/classes $(files) +doc: + javadoc -d ${JACE_WRAPPER}/doc $(files) $(packages) + + +files = ServerHandler.java \ + ClientHandler.java \ + ConnectorTest.java \ + AcceptorTest.java + +packages = tests.Connection + +realclean: + find ${JACE_WRAPPER}/classes/tests/Connection -name '*.class' -print | xargs ${RM} diff --git a/java/tests/Connection/ServerHandler.java b/java/tests/Connection/ServerHandler.java new file mode 100644 index 00000000000..d46a6e1e125 --- /dev/null +++ b/java/tests/Connection/ServerHandler.java @@ -0,0 +1,68 @@ +// ============================================================================ +// +// = PACKAGE +// tests.Connection +// +// = FILENAME +// ServerHandler.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package tests.Connection; + +import java.io.*; +import java.net.*; +import ACE.OS.*; +import ACE.Connection.*; + +public class ServerHandler extends SvcHandler +{ + public ServerHandler () + { + } + + public int open (Object obj) + { + new Thread (this).start (); + return 0; + } + + public void run () + { + int msg_len; + System.out.println ("Waiting for messages..."); + try + { + while (true) + { + StringBuffer msg = new StringBuffer (); + msg_len = this.peer ().recv (msg); + if (msg_len == 0) + break; + System.out.println ("Received: " + msg); + this.peer ().send (new StringBuffer ("Got it!")); + } + } + catch (NullPointerException e) + { + ACE.ERROR ("connection reset by peer"); + } + catch (IOException e) + { + ACE.ERROR (e); + } + finally + { + try + { + this.peer ().close (); + } + catch (IOException e) + { + } + } + + } +} diff --git a/java/tests/Misc/Makefile b/java/tests/Misc/Makefile new file mode 100644 index 00000000000..2ea3d10fba5 --- /dev/null +++ b/java/tests/Misc/Makefile @@ -0,0 +1,21 @@ +# Makefile + +.SUFFIXES: .java .class + +JACE_WRAPPER = ../.. +CLASSDIR = $(JACE_WRAPPER)/classes + +CLASSPATH := $(CLASSDIR):$(CLASSPATH) + +all: + javac -d ${JACE_WRAPPER}/classes $(files) +doc: + javadoc -d ${JACE_WRAPPER}/doc $(files) $(packages) + + +files = ParseArgsTest.java + +packages = tests.Misc + +realclean: + find ${JACE_WRAPPER}/classes/tests/Misc -name '*.class' -print | xargs ${RM} diff --git a/java/tests/Misc/ParseArgsTest.java b/java/tests/Misc/ParseArgsTest.java new file mode 100644 index 00000000000..f2976ddcb11 --- /dev/null +++ b/java/tests/Misc/ParseArgsTest.java @@ -0,0 +1,45 @@ +// ============================================================================ +// +// = PACKAGE +// tests.Misc +// +// = FILENAME +// ParseArgsTest.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package tests.Misc; + +import ACE.OS.*; +import ACE.Misc.*; + +public class ParseArgsTest +{ + public static void main (String args[]) + { + String s; + GetOpt opt = new GetOpt (args, "p:rs:"); + for (int c; (c = opt.next ()) != -1; ) + { + switch (c) + { + case 'p': + s = opt.optarg (); + ACE.DEBUG ("Option <p> selected with argument " + s); + break; + case 'r': + ACE.DEBUG ("Option <r> selected"); + break; + case 's': + s = opt.optarg (); + ACE.DEBUG ("Option <s> selected with argument " + s); + break; + default: + ACE.DEBUG ("Usage: java tests.Misc.ParseArgsTest [-p arg1] [-r] [-s arg2]"); + break; + } + } + } +} diff --git a/java/tests/Reactor/Makefile b/java/tests/Reactor/Makefile new file mode 100644 index 00000000000..2826f2f5920 --- /dev/null +++ b/java/tests/Reactor/Makefile @@ -0,0 +1,21 @@ +# Makefile + +.SUFFIXES: .java .class + +JACE_WRAPPER = ../.. +CLASSDIR = $(JACE_WRAPPER)/classes + +CLASSPATH := $(CLASSDIR):$(CLASSPATH) + +all: + javac -d ${JACE_WRAPPER}/classes $(files) +doc: + javadoc -d ${JACE_WRAPPER}/doc $(files) $(packages) + + +files = TimeValueTest.java + +packages = tests.Reactor + +realclean: + find ${JACE_WRAPPER}/classes/tests/Reactor -name '*.class' -print | xargs ${RM} diff --git a/java/tests/Reactor/TimeValueTest.java b/java/tests/Reactor/TimeValueTest.java new file mode 100644 index 00000000000..4e1d2816dcc --- /dev/null +++ b/java/tests/Reactor/TimeValueTest.java @@ -0,0 +1,50 @@ +/************************************************* + * + * = PACKAGE + * ACE.Reactor + * + * = FILENAME + * TimeValueTest.java + * + *@author Prashant Jain + * + *************************************************/ +package tests.Reactor; + +import ACE.OS.*; +import ACE.Reactor.*; + +public class TimeValueTest +{ + public void ASSERT (boolean expression, int i) + { + if (!expression) + ACE.DEBUG ("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) + { + new TimeValueTest ().runTest (); + } +} diff --git a/java/tests/SOCK_SAP/Makefile b/java/tests/SOCK_SAP/Makefile new file mode 100644 index 00000000000..1481d8e566f --- /dev/null +++ b/java/tests/SOCK_SAP/Makefile @@ -0,0 +1,22 @@ +# Makefile + +.SUFFIXES: .java .class + +JACE_WRAPPER = ../.. +CLASSDIR = $(JACE_WRAPPER)/classes + +CLASSPATH := $(CLASSDIR):$(CLASSPATH) + +all: + javac -d ${JACE_WRAPPER}/classes $(files) +doc: + javadoc -d ${JACE_WRAPPER}/doc $(files) $(packages) + + +files = SOCKConnectorTest.java \ + SOCKAcceptorTest.java + +packages = tests.SOCK_SAP + +realclean: + find ${JACE_WRAPPER}/classes/tests/SOCK_SAP -name '*.class' -print | xargs ${RM} diff --git a/java/tests/SOCK_SAP/SOCKAcceptorTest.java b/java/tests/SOCK_SAP/SOCKAcceptorTest.java new file mode 100644 index 00000000000..432784e3bb4 --- /dev/null +++ b/java/tests/SOCK_SAP/SOCKAcceptorTest.java @@ -0,0 +1,108 @@ +// ============================================================================ +// +// = PACKAGE +// tests.SOCK_SAP +// +// = FILENAME +// SOCKAcceptorTest.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package tests.SOCK_SAP; + +import java.io.*; +import java.net.*; +import ACE.OS.*; +import ACE.SOCK_SAP.*; + +class TestHandler extends Thread +{ + public TestHandler (SOCKStream stream) + { + this.stream_ = stream; + this.start (); + } + + public void run () + { + int msgLen; + System.out.println ("Waiting for messages..."); + try + { + while (true) + { + StringBuffer msg = new StringBuffer (); + msgLen = this.stream_.recv (msg); + if (msgLen == 0) + break; + ACE.DEBUG ("Received: " + msg); + this.stream_.send ("Got it!"); + } + } + catch (NullPointerException e) + { + ACE.ERROR ("connection reset by peer"); + } + catch (IOException e) + { + ACE.ERROR (e); + } + finally + { + try + { + this.stream_.close (); + } + catch (IOException e) + { + } + } + } + SOCKStream stream_; +} + +public class SOCKAcceptorTest +{ + void print_usage_and_die () + { + ACE.DEBUG ("Usage: SOCKAcceptorTest [<port>]"); + System.exit (0); + } + + public void init (int port) + { + try + { + SOCKAcceptor acceptor = new SOCKAcceptor (port); + while (true) + { + SOCKStream stream = new SOCKStream (); + acceptor.accept (stream); + TestHandler handler = new TestHandler (stream); + } + } + catch (IOException e) + { + } + } + + public static void main (String [] args) + { + int port = ACE.DEFAULT_SERVER_PORT; + SOCKAcceptorTest server = new SOCKAcceptorTest (); + if (args.length == 1) + { + try + { + port = Integer.parseInt (args[0]); + } + catch (NumberFormatException e) + { + server.print_usage_and_die (); + } + } + server.init (port); + } +} diff --git a/java/tests/SOCK_SAP/SOCKConnectorTest.java b/java/tests/SOCK_SAP/SOCKConnectorTest.java new file mode 100644 index 00000000000..3717b202a02 --- /dev/null +++ b/java/tests/SOCK_SAP/SOCKConnectorTest.java @@ -0,0 +1,86 @@ +// ============================================================================ +// +// = PACKAGE +// tests.SOCK_SAP +// +// = FILENAME +// SOCKConnectorTest.java +// +// = AUTHOR +// Prashant Jain +// +// ============================================================================ +package tests.SOCK_SAP; + +import java.io.*; +import java.net.*; +import ACE.OS.*; +import ACE.SOCK_SAP.*; + +public class SOCKConnectorTest +{ + void print_usage_and_die () + { + System.out.println ("Usage: SOCKConnectorTest <hostname> [<port>]"); + System.exit (0); + } + + void processRequests (SOCKStream stream) throws IOException + { + DataInputStream in = new DataInputStream (System.in); + String msg; + int ack_len; + + while (true) + { + StringBuffer ack = new StringBuffer (); + ACE.DEBUG ("Enter input: "); + ACE.FLUSH (); + msg = in.readLine (); + if (msg == null) + break; + stream.send (msg); + ACE.DEBUG ("Waiting for ack..."); + ack_len = stream.recv (ack); + if (ack_len == 0) + break; + else + ACE.DEBUG (OS.createString (ack)); + } + } + + public void init (String host, int port) + { + SOCKStream stream = new SOCKStream (); + SOCKConnector connector = new SOCKConnector (); + try + { + connector.connect (stream, + host, + port); + processRequests (stream); + } + catch (IOException e) + { + ACE.ERROR (e); + } + } + + public static void main (String [] args) + { + int port = ACE.DEFAULT_SERVER_PORT; + SOCKConnectorTest client = new SOCKConnectorTest (); + if (args.length == 2) + { + try + { + port = Integer.parseInt (args[1]); + } + catch (NumberFormatException e) + { + client.print_usage_and_die (); + } + } + client.init (args[0], port); + } +} diff --git a/java/tests/ServiceConfigurator/Makefile b/java/tests/ServiceConfigurator/Makefile new file mode 100644 index 00000000000..32b949ef298 --- /dev/null +++ b/java/tests/ServiceConfigurator/Makefile @@ -0,0 +1,24 @@ +# Makefile + +.SUFFIXES: .java .class + +JACE_WRAPPER = ../.. +CLASSDIR = $(JACE_WRAPPER)/classes + +CLASSPATH := $(CLASSDIR):$(CLASSPATH) + +all: + javac -d ${JACE_WRAPPER}/classes $(files) +doc: + javadoc -d ${JACE_WRAPPER}/doc $(files) $(packages) + + +files = TestService.java \ + mainTest.java + +packages = tests.Service_Configurator + +realclean: + find ${JACE_WRAPPER}/classes/tests/ServiceConfigurator -name '*.class' -print | xargs ${RM} + + diff --git a/java/tests/ServiceConfigurator/TestService.java b/java/tests/ServiceConfigurator/TestService.java new file mode 100644 index 00000000000..d8923cd83a5 --- /dev/null +++ b/java/tests/ServiceConfigurator/TestService.java @@ -0,0 +1,29 @@ +/************************************************* + * + * = PACKAGE + * tests.ServiceConfigurator + * + * = FILENAME + * TestService.java + * + *@author Prashant Jain + * + *************************************************/ +package tests.ServiceConfigurator; + +import ACE.ServiceConfigurator.*; +import ACE.OS.*; + +public class TestService extends ServiceObject +{ + public int init (String [] args) + { + ACE.DEBUG ("In Test_Service::init() with arguments: " + + args[0] + args[1]); + + //ACE.DEBUG ("In new Test_Service::init() with arguments: " + + // args[0] + args[1]); + return 0; + } + +} diff --git a/java/tests/ServiceConfigurator/mainTest.java b/java/tests/ServiceConfigurator/mainTest.java new file mode 100644 index 00000000000..6dc3149cc61 --- /dev/null +++ b/java/tests/ServiceConfigurator/mainTest.java @@ -0,0 +1,56 @@ +/************************************************* + * + * = PACKAGE + * tests.ServiceConfigurator + * + * = FILENAME + * mainTest.java + * + *@author Prashant Jain + * + *************************************************/ +package tests.ServiceConfigurator; + +import ACE.ServiceConfigurator.*; +import ACE.OS.*; +import java.io.*; + +public class mainTest +{ + + public static void main (String args []) + { + ServiceConfig daemon = new ServiceConfig (); + try + { + daemon.open (args); + Thread.sleep (10000); + daemon.open (args); + } + catch (InterruptedException e) + { + ACE.ERROR (e); + } + catch (FileNotFoundException e) + { + ACE.ERROR (e); + } + catch (IOException e) + { + ACE.ERROR (e); + } + catch (ClassNotFoundException e) + { + ACE.ERROR (e); + } + catch (IllegalAccessException e) + { + ACE.ERROR (e); + } + catch (InstantiationException e) + { + ACE.ERROR (e); + } + } + +} |