ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sbaill...@apache.org
Subject cvs commit: jakarta-ant/proposal/sandbox/junit/src/testcases/org/apache/tools/ant/taskdefs/optional/junit/remote TestRunnerTest.java
Date Sun, 13 Jan 2002 13:55:14 GMT
sbailliez    02/01/13 05:55:14

  Modified:    proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote
                        Server.java MessageReader.java
               proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit
                        TestElement.java OutputAttribute.java
               proposal/sandbox/junit/src/testcases/org/apache/tools/ant/taskdefs/optional/junit/remote
                        TestRunnerTest.java
  Log:
  - Make the socket server cleaning up any connected client
  and its input and output so that the JDK bug on Windows
  does not shows up.
  - Clean up.
  - Fix the test, the thread was not the lock owner..dooh !
  
  Revision  Changes    Path
  1.3       +28 -5     jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/Server.java
  
  Index: Server.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/Server.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Server.java	11 Jan 2002 20:56:28 -0000	1.2
  +++ Server.java	13 Jan 2002 13:55:13 -0000	1.3
  @@ -87,12 +87,17 @@
       private MessageReader reader = new MessageReader();
   
       /** writer used to send message to clients */
  -    private PrintWriter writer;
  +    private MessageWriter writer;
   
       public Server(int port) {
           this.port = port;
       }
   
  +    protected void finalize() throws Exception {
  +        cancel();
  +        shutdown();
  +    }
  +
       /**
        * add a new listener
        * @param listener a instance of a listener.
  @@ -123,20 +128,36 @@
       /** cancel the connection to the client */
       public void cancel() {
           if (isRunning()) {
  -            //@fixme
  +            writer.sendMessage(MessageIds.TEST_STOP);
           }
       }
   
       /** shutdown the server and any running client */
       public void shutdown() {
  +        if (writer != null){
  +            writer.close();
  +            writer = null;
  +        }
  +        if (reader != null){
  +            //@fixme what about the stream ?
  +            reader = null;
  +        }
           try {
               if (client != null) {
                   client.shutdownInput();
                   client.shutdownOutput();
  +                client.close();
  +                client = null;
               }
  -            server.close();
           } catch (IOException e) {
           }
  +        try {
  +            if (server != null){
  +                server.close();
  +                server = null;
  +            }
  +        } catch (IOException e){
  +        }
       }
   
   //-----
  @@ -146,12 +167,14 @@
               try {
                   server = new ServerSocket(port);
                   client = server.accept();
  -                writer = new PrintWriter(client.getOutputStream(), true);
  +                writer = new MessageWriter(client.getOutputStream());
                   reader.process(client.getInputStream());
               } catch (IOException e) {
  +                //@fixme this stacktrace might be normal when closing
  +                // the socket. So decompose the above in distinct steps
                   e.printStackTrace();
               } finally {
  -                stop();
  +                cancel();
                   shutdown();
               }
           }
  
  
  
  1.4       +9 -9      jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/MessageReader.java
  
  Index: MessageReader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/MessageReader.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MessageReader.java	11 Jan 2002 20:56:28 -0000	1.3
  +++ MessageReader.java	13 Jan 2002 13:55:13 -0000	1.4
  @@ -81,17 +81,17 @@
   public class MessageReader {
   
       /** the set of registered listeners */
  -    protected Vector listeners = new Vector();
  +    private Vector listeners = new Vector();
   
       // communication states with client
  -    protected boolean inReadTrace = false;
  -    protected boolean inFailedMessage = false;
  -    protected String failedTest;
  -    protected String failedMessage;
  -    protected String failedTrace;
  -    protected int failureKind;
  -    protected long elapsedTime;
  -    protected Properties sysprops;
  +    private boolean inReadTrace = false;
  +    private boolean inFailedMessage = false;
  +    private String failedTest;
  +    private String failedMessage;
  +    private String failedTrace;
  +    private int failureKind;
  +    private long elapsedTime;
  +    private Properties sysprops;
   
       public MessageReader() {
       }
  
  
  
  1.2       +12 -1     jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/TestElement.java
  
  Index: TestElement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/TestElement.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestElement.java	11 Jan 2002 23:35:43 -0000	1.1
  +++ TestElement.java	13 Jan 2002 13:55:13 -0000	1.2
  @@ -64,7 +64,18 @@
    */
   public class TestElement implements TestCollector {
   
  +    /** classname of JUnit test */
  +    private String name;
  +
  +//@fixme, a path is needed for a test.
  +
       public Enumeration collectTests() {
  -        return null;
  +        return Enumerations.fromArray( new String[]{ name } );
  +    }
  +
  +// Ant bean setters
  +
  +    public String setName(String value){
  +        this.name = value;
       }
   }
  
  
  
  1.3       +1 -1      jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/OutputAttribute.java
  
  Index: OutputAttribute.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/OutputAttribute.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- OutputAttribute.java	11 Jan 2002 20:56:28 -0000	1.2
  +++ OutputAttribute.java	13 Jan 2002 13:55:13 -0000	1.3
  @@ -100,7 +100,7 @@
           } else if (STDERR.equals(value)) {
               return new KeepAliveOutputStream(System.err);
           }
  -        File f = project.resolveFile(value);
  +        File f = getProject().resolveFile(value);
           try {
               return new FileOutputStream(f);
           } catch (IOException e) {
  
  
  
  1.2       +5 -5      jakarta-ant/proposal/sandbox/junit/src/testcases/org/apache/tools/ant/taskdefs/optional/junit/remote/TestRunnerTest.java
  
  Index: TestRunnerTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/proposal/sandbox/junit/src/testcases/org/apache/tools/ant/taskdefs/optional/junit/remote/TestRunnerTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestRunnerTest.java	5 Jan 2002 23:57:21 -0000	1.1
  +++ TestRunnerTest.java	13 Jan 2002 13:55:13 -0000	1.2
  @@ -116,7 +116,7 @@
           runner.addTestClassName(TestCases.NullTestCase.class.getName());
   //        server.addListener( new DefaultTestRunListener() );
           runner.run();
  -        synchronized(this){ if (!done){ wait(); } }
  +        synchronized(this){ while (!done){ wait(); } }
           assertEquals(new Integer(3), recorder.runStarted.elementAt(0));
           /*
           assertTrue(recorder.runStarted.elementAt(0).toSt("testSuccess"));
  @@ -128,7 +128,7 @@
       public void testFailSetupTestCase() throws Exception {
           runner.addTestClassName(TestCases.FailSetupTestSuite.class.getName());
           runner.run();
  -        synchronized(this){ if (!done){ wait(); } }
  +        synchronized(this){ while (!done){ wait(); } }
   
           assertEquals(1, recorder.runStarted.size());
           assertEquals(1, recorder.runEnded.size());
  @@ -137,7 +137,7 @@
       public void testFailSetupTestSuite() throws Exception {
           runner.addTestClassName(TestCases.FailSetupTestSuite.class.getName());
           runner.run();
  -        synchronized(this){ if (!done){ wait(); } }
  +        synchronized(this){ while (!done){ wait(); } }
           assertEquals(1, recorder.runStarted.size());
           assertEquals(1, recorder.runEnded.size());
       }
  @@ -159,14 +159,14 @@
       public void onTestRunEnded(long elapsedtime) {
           synchronized(this){
               done = true;
  +            notify();
           }
  -        notify();
       }
       public void onTestRunStopped(long elapsedtime) {
           synchronized(this){
               done = true;
  +            notify();
           }
  -        notify();
       }
       public void onTestRunSystemProperties(Properties props) {
       }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message