File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\test\java\hudson\ChannelTestCase.java.html

1 package hudson;
2
3 import junit.framework.TestCase;
4
5 import java.io.IOException;
6 import java.util.concurrent.Future;
7 import java.util.concurrent.Callable;
8 import java.util.concurrent.ExecutorService;
9 import java.util.concurrent.Executors;
10
11 import hudson.remoting.Channel;
12 import hudson.remoting.FastPipedInputStream;
13 import hudson.remoting.FastPipedOutputStream;
14
15 /**
16 * Test that uses a connected channel.
17 *
18 * @author Kohsuke Kawaguchi
19 */
20 public abstract class ChannelTestCase extends TestCase {
21 /**
22 * Two channels that are connected to each other, but shares the same classloader.
23 */
24 protected Channel french;
25 protected Channel british;
26 private ExecutorService executors = Executors.newCachedThreadPool();
27
28 @Override
29 protected void setUp() throws Exception {
30 super.setUp();
31 final FastPipedInputStream p1i = new FastPipedInputStream();
32 final FastPipedInputStream p2i = new FastPipedInputStream();
33 final FastPipedOutputStream p1o = new FastPipedOutputStream(p1i);
34 final FastPipedOutputStream p2o = new FastPipedOutputStream(p2i);
35
36 Future<Channel> f1 = executors.submit(new Callable<Channel>() {
37 public Channel call() throws Exception {
38 return new Channel("This side of the channel", executors, p1i, p2o);
39 }
40 });
41 Future<Channel> f2 = executors.submit(new Callable<Channel>() {
42 public Channel call() throws Exception {
43 return new Channel("The other side of the channel", executors, p2i, p1o);
44 }
45 });
46 french = f1.get();
47 british = f2.get();
48 }
49
50 @Override
51 protected void tearDown() throws Exception {
52 try {
53 french.close(); // this will automatically initiate the close on the other channel, too.
54 french.join();
55 british.join();
56 } catch (IOException e) {
57 // perhaps this exception is caused by earlier abnormal termination of the channel?
58 /* for the record, this is the failure.
59 Nov 12, 2009 6:18:55 PM hudson.remoting.Channel$CloseCommand execute
60 SEVERE: close command failed on This side of the channel
61 java.io.IOException: Pipe is already closed
62 at hudson.remoting.FastPipedOutputStream.write(FastPipedOutputStream.java:127)
63 at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1838)
64 at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1747)
65 at java.io.ObjectOutputStream.writeNonProxyDesc(ObjectOutputStream.java:1249)
66 at java.io.ObjectOutputStream.writeClassDesc(ObjectOutputStream.java:1203)
67 at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1387)
68 at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
69 at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1538)
70 at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:329)
71 at hudson.remoting.Channel.send(Channel.java:413)
72 at hudson.remoting.Channel.close(Channel.java:717)
73 at hudson.remoting.Channel$CloseCommand.execute(Channel.java:676)
74 at hudson.remoting.Channel$ReaderThread.run(Channel.java:860)
75 Caused by: hudson.remoting.FastPipedInputStream$ClosedBy: The pipe was closed at...
76 at hudson.remoting.FastPipedInputStream.close(FastPipedInputStream.java:103)
77 at java.io.ObjectInputStream$PeekInputStream.close(ObjectInputStream.java:2305)
78 at java.io.ObjectInputStream$BlockDataInputStream.close(ObjectInputStream.java:2643)
79 at java.io.ObjectInputStream.close(ObjectInputStream.java:873)
80 at hudson.remoting.Channel$ReaderThread.run(Channel.java:866)
81 Nov 12, 2009 6:18:55 PM hudson.remoting.Channel$CloseCommand execute
82 INFO: close command created at
83 Command close created at
84 at hudson.remoting.Command.<init>(Command.java:58)
85 at hudson.remoting.Command.<init>(Command.java:47)
86 at hudson.remoting.Channel$CloseCommand.<init>(Channel.java:673)
87 at hudson.remoting.Channel$CloseCommand.<init>(Channel.java:673)
88 at hudson.remoting.Channel.close(Channel.java:717)
89 at hudson.remoting.Channel$CloseCommand.execute(Channel.java:676)
90 at hudson.remoting.Channel$ReaderThread.run(Channel.java:860)
91 Nov 12, 2009 6:18:55 PM hudson.remoting.Channel$ReaderThread run
92 SEVERE: I/O error in channel This side of the channel
93 java.io.EOFException
94 at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2554)
95 at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1297)
96 at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351)
97 at hudson.remoting.Channel$ReaderThread.run(Channel.java:849)
98
99 */
100 e.printStackTrace();
101 }
102 executors.shutdownNow();
103 }
104 }
105