Browse Source

- 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 !


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270741 13f79535-47bb-0310-9956-ffa450edef68
master
Stephane Bailliez 23 years ago
parent
commit
c6b949c0c1
5 changed files with 55 additions and 21 deletions
  1. +1
    -1
      proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/OutputAttribute.java
  2. +12
    -1
      proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/TestElement.java
  3. +9
    -9
      proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/MessageReader.java
  4. +28
    -5
      proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/Server.java
  5. +5
    -5
      proposal/sandbox/junit/src/testcases/org/apache/tools/ant/taskdefs/optional/junit/remote/TestRunnerTest.java

+ 1
- 1
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/OutputAttribute.java View File

@@ -100,7 +100,7 @@ public class OutputAttribute extends ProjectComponent {
} else if (STDERR.equals(value)) { } else if (STDERR.equals(value)) {
return new KeepAliveOutputStream(System.err); return new KeepAliveOutputStream(System.err);
} }
File f = project.resolveFile(value);
File f = getProject().resolveFile(value);
try { try {
return new FileOutputStream(f); return new FileOutputStream(f);
} catch (IOException e) { } catch (IOException e) {


+ 12
- 1
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/TestElement.java View File

@@ -64,7 +64,18 @@ import junit.runner.TestCollector;
*/ */
public class TestElement implements TestCollector { public class TestElement implements TestCollector {


/** classname of JUnit test */
private String name;

//@fixme, a path is needed for a test.

public Enumeration collectTests() { public Enumeration collectTests() {
return null;
return Enumerations.fromArray( new String[]{ name } );
}

// Ant bean setters

public String setName(String value){
this.name = value;
} }
} }

+ 9
- 9
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/MessageReader.java View File

@@ -81,17 +81,17 @@ import org.apache.tools.ant.taskdefs.optional.junit.TestRunListener;
public class MessageReader { public class MessageReader {


/** the set of registered listeners */ /** the set of registered listeners */
protected Vector listeners = new Vector();
private Vector listeners = new Vector();


// communication states with client // 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() { public MessageReader() {
} }


+ 28
- 5
proposal/sandbox/junit/src/main/org/apache/tools/ant/taskdefs/optional/junit/remote/Server.java View File

@@ -87,12 +87,17 @@ public class Server {
private MessageReader reader = new MessageReader(); private MessageReader reader = new MessageReader();


/** writer used to send message to clients */ /** writer used to send message to clients */
private PrintWriter writer;
private MessageWriter writer;


public Server(int port) { public Server(int port) {
this.port = port; this.port = port;
} }


protected void finalize() throws Exception {
cancel();
shutdown();
}

/** /**
* add a new listener * add a new listener
* @param listener a instance of a listener. * @param listener a instance of a listener.
@@ -123,20 +128,36 @@ public class Server {
/** cancel the connection to the client */ /** cancel the connection to the client */
public void cancel() { public void cancel() {
if (isRunning()) { if (isRunning()) {
//@fixme
writer.sendMessage(MessageIds.TEST_STOP);
} }
} }


/** shutdown the server and any running client */ /** shutdown the server and any running client */
public void shutdown() { public void shutdown() {
if (writer != null){
writer.close();
writer = null;
}
if (reader != null){
//@fixme what about the stream ?
reader = null;
}
try { try {
if (client != null) { if (client != null) {
client.shutdownInput(); client.shutdownInput();
client.shutdownOutput(); client.shutdownOutput();
client.close();
client = null;
} }
server.close();
} catch (IOException e) { } catch (IOException e) {
} }
try {
if (server != null){
server.close();
server = null;
}
} catch (IOException e){
}
} }


//----- //-----
@@ -146,12 +167,14 @@ public class Server {
try { try {
server = new ServerSocket(port); server = new ServerSocket(port);
client = server.accept(); client = server.accept();
writer = new PrintWriter(client.getOutputStream(), true);
writer = new MessageWriter(client.getOutputStream());
reader.process(client.getInputStream()); reader.process(client.getInputStream());
} catch (IOException e) { } catch (IOException e) {
//@fixme this stacktrace might be normal when closing
// the socket. So decompose the above in distinct steps
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
stop();
cancel();
shutdown(); shutdown();
} }
} }


+ 5
- 5
proposal/sandbox/junit/src/testcases/org/apache/tools/ant/taskdefs/optional/junit/remote/TestRunnerTest.java View File

@@ -116,7 +116,7 @@ public class TestRunnerTest extends TestCase
runner.addTestClassName(TestCases.NullTestCase.class.getName()); runner.addTestClassName(TestCases.NullTestCase.class.getName());
// server.addListener( new DefaultTestRunListener() ); // server.addListener( new DefaultTestRunListener() );
runner.run(); runner.run();
synchronized(this){ if (!done){ wait(); } }
synchronized(this){ while (!done){ wait(); } }
assertEquals(new Integer(3), recorder.runStarted.elementAt(0)); assertEquals(new Integer(3), recorder.runStarted.elementAt(0));
/* /*
assertTrue(recorder.runStarted.elementAt(0).toSt("testSuccess")); assertTrue(recorder.runStarted.elementAt(0).toSt("testSuccess"));
@@ -128,7 +128,7 @@ public class TestRunnerTest extends TestCase
public void testFailSetupTestCase() throws Exception { public void testFailSetupTestCase() throws Exception {
runner.addTestClassName(TestCases.FailSetupTestSuite.class.getName()); runner.addTestClassName(TestCases.FailSetupTestSuite.class.getName());
runner.run(); runner.run();
synchronized(this){ if (!done){ wait(); } }
synchronized(this){ while (!done){ wait(); } }


assertEquals(1, recorder.runStarted.size()); assertEquals(1, recorder.runStarted.size());
assertEquals(1, recorder.runEnded.size()); assertEquals(1, recorder.runEnded.size());
@@ -137,7 +137,7 @@ public class TestRunnerTest extends TestCase
public void testFailSetupTestSuite() throws Exception { public void testFailSetupTestSuite() throws Exception {
runner.addTestClassName(TestCases.FailSetupTestSuite.class.getName()); runner.addTestClassName(TestCases.FailSetupTestSuite.class.getName());
runner.run(); runner.run();
synchronized(this){ if (!done){ wait(); } }
synchronized(this){ while (!done){ wait(); } }
assertEquals(1, recorder.runStarted.size()); assertEquals(1, recorder.runStarted.size());
assertEquals(1, recorder.runEnded.size()); assertEquals(1, recorder.runEnded.size());
} }
@@ -159,14 +159,14 @@ public class TestRunnerTest extends TestCase
public void onTestRunEnded(long elapsedtime) { public void onTestRunEnded(long elapsedtime) {
synchronized(this){ synchronized(this){
done = true; done = true;
notify();
} }
notify();
} }
public void onTestRunStopped(long elapsedtime) { public void onTestRunStopped(long elapsedtime) {
synchronized(this){ synchronized(this){
done = true; done = true;
notify();
} }
notify();
} }
public void onTestRunSystemProperties(Properties props) { public void onTestRunSystemProperties(Properties props) {
} }


Loading…
Cancel
Save