BAEL-3603 Update method names and variable name for PR

This commit is contained in:
Roger Yates 2020-03-16 06:23:33 +10:00
parent fad2d2a67c
commit 5c83dddb91
2 changed files with 7 additions and 7 deletions

View File

@ -25,7 +25,7 @@ public class BlockingClientUnitTest {
} }
@Test @Test
public void givenJavaIOSocket_whenReadingAndWritingWithStreams_thenReadSuccessfully() throws IOException { public void givenJavaIOSocket_whenReadingAndWritingWithStreams_thenSuccess() throws IOException {
// given an IO socket and somewhere to store our result // given an IO socket and somewhere to store our result
Socket socket = new Socket("localhost", wireMockRule.port()); Socket socket = new Socket("localhost", wireMockRule.port());
StringBuilder ourStore = new StringBuilder(); StringBuilder ourStore = new StringBuilder();

View File

@ -31,7 +31,7 @@ public class NonBlockingClientUnitTest {
} }
@Test @Test
public void givenJavaNIOSocketChannel_whenReadingAndWriting_thenUseBuffers() throws IOException { public void givenJavaNIOSocketChannel_whenReadingAndWritingWithBuffers_thenSuccess() throws IOException {
// given a NIO SocketChannel and a charset // given a NIO SocketChannel and a charset
InetSocketAddress address = new InetSocketAddress("localhost", wireMockRule.port()); InetSocketAddress address = new InetSocketAddress("localhost", wireMockRule.port());
SocketChannel socketChannel = SocketChannel.open(address); SocketChannel socketChannel = SocketChannel.open(address);
@ -58,25 +58,25 @@ public class NonBlockingClientUnitTest {
} }
@Test @Test
public void givenJavaNIO_whenReadingAndWriting_thenSmallBuffers() throws IOException { public void givenJavaNIOSocketChannel_whenReadingAndWritingWithSmallBuffers_thenSuccess() throws IOException {
// given a NIO SocketChannel and a charset // given a NIO SocketChannel and a charset
InetSocketAddress address = new InetSocketAddress("localhost", wireMockRule.port()); InetSocketAddress address = new InetSocketAddress("localhost", wireMockRule.port());
SocketChannel socket = SocketChannel.open(address); SocketChannel socketChannel = SocketChannel.open(address);
Charset charset = StandardCharsets.UTF_8; Charset charset = StandardCharsets.UTF_8;
// when we write and read using buffers that are too small for our message // when we write and read using buffers that are too small for our message
socket.write(charset.encode(CharBuffer.wrap("GET " + REQUESTED_RESOURCE + " HTTP/1.0\r\n\r\n"))); socketChannel.write(charset.encode(CharBuffer.wrap("GET " + REQUESTED_RESOURCE + " HTTP/1.0\r\n\r\n")));
ByteBuffer buffer = ByteBuffer.allocate(8); // or allocateDirect if we need direct memory access ByteBuffer buffer = ByteBuffer.allocate(8); // or allocateDirect if we need direct memory access
CharBuffer charBuffer = CharBuffer.allocate(8); CharBuffer charBuffer = CharBuffer.allocate(8);
CharsetDecoder decoder = charset.newDecoder(); CharsetDecoder decoder = charset.newDecoder();
StringBuilder ourStore = new StringBuilder(); StringBuilder ourStore = new StringBuilder();
while (socket.read(buffer) != -1 || buffer.position() > 0) { while (socketChannel.read(buffer) != -1 || buffer.position() > 0) {
buffer.flip(); buffer.flip();
storeBufferContents(buffer, charBuffer, decoder, ourStore); storeBufferContents(buffer, charBuffer, decoder, ourStore);
buffer.compact(); buffer.compact();
} }
socket.close(); socketChannel.close();
// then we read and saved our data // then we read and saved our data
assertTrue(ourStore assertTrue(ourStore