Skip to content

Commit

Permalink
[JENKINS-31718] Fix the tests
Browse files Browse the repository at this point in the history
- The tests no longer pass in a null buffered input stream and thus we can remove the null handling from the protocols
- Unsure whether the buffer may affect JnlpProtocol3 performance, but leaving it there to highlight the potential stream corruption if the buffer gets thrown away.
  • Loading branch information
stephenc committed Nov 24, 2015
1 parent 1163157 commit 015e280
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 16 deletions.
Expand Up @@ -76,9 +76,7 @@ boolean performHandshake(DataOutputStream outputStream,

@Override
Channel buildChannel(Socket socket, ChannelBuilder channelBuilder, BufferedInputStream inputStream) throws IOException {
return channelBuilder.build(
inputStream == null ? new BufferedInputStream(socket.getInputStream()) : inputStream, // TODO drop null
new BufferedOutputStream(socket.getOutputStream()));
return channelBuilder.build(inputStream, new BufferedOutputStream(socket.getOutputStream()));
}

static final String NAME = "JNLP-connect";
Expand Down
Expand Up @@ -90,9 +90,7 @@ boolean performHandshake(DataOutputStream outputStream,

@Override
Channel buildChannel(Socket socket, ChannelBuilder channelBuilder, BufferedInputStream inputStream) throws IOException {
return channelBuilder.build(
inputStream == null ? new BufferedInputStream(socket.getInputStream()) : inputStream, // TODO drop null
new BufferedOutputStream(socket.getOutputStream()));
return channelBuilder.build(inputStream, new BufferedOutputStream(socket.getOutputStream()));
}

private void initiateHandshake(DataOutputStream outputStream) throws IOException {
Expand Down
Expand Up @@ -159,9 +159,7 @@ boolean performHandshake(DataOutputStream outputStream,
@Override
Channel buildChannel(Socket socket, ChannelBuilder channelBuilder, BufferedInputStream inputStream) throws IOException {
return channelBuilder.build(
new CipherInputStream(
inputStream == null ? socket.getInputStream() : inputStream, // TODO drop null
channelCiphers.getDecryptCipher()),
new CipherInputStream(inputStream, channelCiphers.getDecryptCipher()),
new CipherOutputStream(socket.getOutputStream(), channelCiphers.getEncryptCipher())
);
}
Expand Down
Expand Up @@ -114,9 +114,8 @@ public void testBuildChannel() throws Exception {
when(mockSocket.getOutputStream()).thenReturn(mockOutputStream);
when(mockSocket.getInputStream()).thenReturn(mockInputStream);
whenNew(BufferedOutputStream.class).withArguments(mockOutputStream).thenReturn(mockBufferedOutputStream);
whenNew(BufferedInputStream.class).withArguments(mockInputStream).thenReturn(mockBufferedInputStream);
when(mockChannelBuilder.build(mockBufferedInputStream, mockBufferedOutputStream)).thenReturn(mockChannel);

assertSame(mockChannel, protocol.buildChannel(mockSocket, mockChannelBuilder, null));
assertSame(mockChannel, protocol.buildChannel(mockSocket, mockChannelBuilder, mockBufferedInputStream));
}
}
Expand Up @@ -178,9 +178,8 @@ public void testBuildChannel() throws Exception {
when(mockSocket.getOutputStream()).thenReturn(mockOutputStream);
when(mockSocket.getInputStream()).thenReturn(mockInputStream);
whenNew(BufferedOutputStream.class).withArguments(mockOutputStream).thenReturn(mockBufferedOutputStream);
whenNew(BufferedInputStream.class).withArguments(mockInputStream).thenReturn(mockBufferedInputStream);
when(mockChannelBuilder.build(mockBufferedInputStream, mockBufferedOutputStream)).thenReturn(mockChannel);

assertSame(mockChannel, protocol.buildChannel(mockSocket, mockChannelBuilder, null));
assertSame(mockChannel, protocol.buildChannel(mockSocket, mockChannelBuilder, mockBufferedInputStream));
}
}
Expand Up @@ -282,11 +282,11 @@ public void testBuildChannel() throws Exception {
.withArguments(mockOutputStream, protocol.getChannelCiphers().getEncryptCipher())
.thenReturn(mockCipherOutputStream);
whenNew(CipherInputStream.class)
.withArguments(mockInputStream, protocol.getChannelCiphers().getDecryptCipher())
.withArguments(mockBufferedInputStream, protocol.getChannelCiphers().getDecryptCipher())
.thenReturn(mockCipherInputStream);
when(mockChannelBuilder.build(mockCipherInputStream, mockCipherOutputStream))
.thenReturn(mockChannel);

assertSame(mockChannel, protocol.buildChannel(mockSocket, mockChannelBuilder, null));
assertSame(mockChannel, protocol.buildChannel(mockSocket, mockChannelBuilder, mockBufferedInputStream));
}
}
Expand Up @@ -80,7 +80,7 @@ public void testHandshakeFails() throws Exception {
@Test
public void testHandshakeSucceeds() throws Exception {
when(mockProtocol.performHandshake(mockDataOutputStream, mockBufferedInputStream)).thenReturn(true);
when(mockProtocol.buildChannel(mockSocket, mockChannelBuilder, null)).thenReturn(mockChannel);
when(mockProtocol.buildChannel(mockSocket, mockChannelBuilder, mockBufferedInputStream)).thenReturn(mockChannel);

assertSame(mockChannel, mockProtocol.establishChannel(mockSocket, mockChannelBuilder));
}
Expand Down

0 comments on commit 015e280

Please sign in to comment.