File: close.java

package info (click to toggle)
mauve 20080616-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 26,856 kB
  • ctags: 21,952
  • sloc: java: 234,107; sh: 2,834; xml: 208; makefile: 59
file content (51 lines) | stat: -rw-r--r-- 1,133 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Tags: JDK1.0

// This test is from Jeff Sturm.
// It tests whether close() on a PipedInputStream will correctly
// notify the writer.

package gnu.testlet.java.io.PipedStream;

import gnu.testlet.Testlet;
import gnu.testlet.TestHarness;
import java.io.*;

public class close implements Runnable, Testlet {
	Thread main;
	PipedInputStream in;
	PipedOutputStream out;
	TestHarness harness;

	public void run() {
		try {
			Thread.sleep(1000);
			harness.debug("Closing pipe input stream:");
			in.close();
			Thread.sleep(1000);
			harness.debug("Interrupting pipe reader:");
			main.interrupt();
		} catch (Throwable t) {
			harness.debug(t);
		}
	}

	public void test (TestHarness harness) {
		int val = 23;
		try {
			close test = new close();
			test.harness = harness;

			test.main = Thread.currentThread();
			test.out = new PipedOutputStream();
			test.in = new PipedInputStream(test.out);

			(new Thread(test)).start();

			val = test.in.read();
		} catch (InterruptedIOException t) {
			harness.check(true,"read() interrupted okay");
		} catch (IOException t) {
			harness.fail("Unexpected IOException thrown");
		}
	}
}