Skip to content

Commit

Permalink
Fix typo for ResilientSocketOutputStream class
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbabcock committed May 8, 2019
1 parent da00918 commit 1ce02fc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions docs/source/about/release-notes.rst
Expand Up @@ -37,6 +37,7 @@ v2.0.0: Unreleased
* Added PortDescriptor class and method in ServerLifeCycleListener to provide a list of PortDescriptors, detailing all listening information for the application (`#2711 <https://github.com/dropwizard/dropwizard/pull/2711>`_) * Added PortDescriptor class and method in ServerLifeCycleListener to provide a list of PortDescriptors, detailing all listening information for the application (`#2711 <https://github.com/dropwizard/dropwizard/pull/2711>`_)
* Add support for proxy-protocol in http connector configuration (`#2709 <https://github.com/dropwizard/dropwizard/pull/2709>`_) * Add support for proxy-protocol in http connector configuration (`#2709 <https://github.com/dropwizard/dropwizard/pull/2709>`_)
* Disable using ``X-Forwarded-*`` headers by default (`#2748 <https://github.com/dropwizard/dropwizard/pull/2748>`_) * Disable using ``X-Forwarded-*`` headers by default (`#2748 <https://github.com/dropwizard/dropwizard/pull/2748>`_)
* Fix typo by renaming ``ResilentSocketOutputStream`` to ``ResilientSocketOutputStream`` (`#2766 <https://github.com/dropwizard/dropwizard/pull/2766>`_)


.. _rel-1.3.9: .. _rel-1.3.9:


Expand Down
Expand Up @@ -9,11 +9,11 @@
import java.net.Socket; import java.net.Socket;


/** /**
* Represents a resilent persistent connection via TCP as an {@link OutputStream}. * Represents a resilient persistent connection via TCP as an {@link OutputStream}.
* Automatically tries to reconnect to the server if it encounters errors during writing * Automatically tries to reconnect to the server if it encounters errors during writing
* data via a TCP connection. * data via a TCP connection.
*/ */
public class ResilentSocketOutputStream extends ResilientOutputStreamBase { public class ResilientSocketOutputStream extends ResilientOutputStreamBase {


private final String host; private final String host;
private final int port; private final int port;
Expand All @@ -30,8 +30,8 @@ public class ResilentSocketOutputStream extends ResilientOutputStreamBase {
* @param sendBufferSize The size of the send buffer of the socket stream in bytes. * @param sendBufferSize The size of the send buffer of the socket stream in bytes.
* @param socketFactory The factory for customizing the client socket. * @param socketFactory The factory for customizing the client socket.
*/ */
public ResilentSocketOutputStream(String host, int port, int connectionTimeoutMs, int sendBufferSize, public ResilientSocketOutputStream(String host, int port, int connectionTimeoutMs, int sendBufferSize,
SocketFactory socketFactory) { SocketFactory socketFactory) {
this.host = host; this.host = host;
this.port = port; this.port = port;
this.connectionTimeoutMs = connectionTimeoutMs; this.connectionTimeoutMs = connectionTimeoutMs;
Expand Down
@@ -1,14 +1,14 @@
package io.dropwizard.logging.socket; package io.dropwizard.logging.socket;


import ch.qos.logback.core.OutputStreamAppender; import ch.qos.logback.core.OutputStreamAppender;
import ch.qos.logback.core.recovery.ResilentSocketOutputStream; import ch.qos.logback.core.recovery.ResilientSocketOutputStream;
import ch.qos.logback.core.spi.DeferredProcessingAware; import ch.qos.logback.core.spi.DeferredProcessingAware;


import javax.net.SocketFactory; import javax.net.SocketFactory;
import java.io.OutputStream; import java.io.OutputStream;


/** /**
* Sends log events to a TCP server, a connection to which is represented as {@link ResilentSocketOutputStream}. * Sends log events to a TCP server, a connection to which is represented as {@link ResilientSocketOutputStream}.
*/ */
public class DropwizardSocketAppender<E extends DeferredProcessingAware> extends OutputStreamAppender<E> { public class DropwizardSocketAppender<E extends DeferredProcessingAware> extends OutputStreamAppender<E> {


Expand All @@ -34,7 +34,7 @@ public void start() {
} }


protected OutputStream socketOutputStream() { protected OutputStream socketOutputStream() {
final ResilentSocketOutputStream outputStream = new ResilentSocketOutputStream(host, port, final ResilientSocketOutputStream outputStream = new ResilientSocketOutputStream(host, port,
connectionTimeoutMs, sendBufferSize, socketFactory); connectionTimeoutMs, sendBufferSize, socketFactory);
outputStream.setContext(context); outputStream.setContext(context);
return outputStream; return outputStream;
Expand Down
Expand Up @@ -15,9 +15,9 @@
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.Assertions.assertThatIllegalStateException;


public class ResilentSocketOutputStreamTest { public class ResilientSocketOutputStreamTest {


private ResilentSocketOutputStream resilentSocketOutputStream; private ResilientSocketOutputStream resilientSocketOutputStream;


private Thread thread; private Thread thread;
private ServerSocket ss; private ServerSocket ss;
Expand All @@ -41,42 +41,42 @@ public void setUp() throws Exception {
} }
}); });
thread.start(); thread.start();
resilentSocketOutputStream = new ResilentSocketOutputStream("localhost", ss.getLocalPort(), resilientSocketOutputStream = new ResilientSocketOutputStream("localhost", ss.getLocalPort(),
1024, 500, SocketFactory.getDefault()); 1024, 500, SocketFactory.getDefault());
} }


@AfterEach @AfterEach
public void tearDown() throws Exception { public void tearDown() throws Exception {
ss.close(); ss.close();
thread.interrupt(); thread.interrupt();
resilentSocketOutputStream.close(); resilientSocketOutputStream.close();
} }


@Test @Test
public void testCreatesCleanOutputStream() throws Exception { public void testCreatesCleanOutputStream() throws Exception {
assertThat(resilentSocketOutputStream.presumedClean).isTrue(); assertThat(resilientSocketOutputStream.presumedClean).isTrue();
assertThat(resilentSocketOutputStream.os).isNotNull(); assertThat(resilientSocketOutputStream.os).isNotNull();
} }


@Test @Test
public void testThrowsExceptionIfCantCreateOutputStream() throws Exception { public void testThrowsExceptionIfCantCreateOutputStream() throws Exception {
assertThatIllegalStateException().isThrownBy(() -> new ResilentSocketOutputStream("256.256.256.256", 1024, assertThatIllegalStateException().isThrownBy(() -> new ResilientSocketOutputStream("256.256.256.256", 1024,
100, 1024, SocketFactory.getDefault())) 100, 1024, SocketFactory.getDefault()))
.withMessage("Unable to create a TCP connection to 256.256.256.256:1024"); .withMessage("Unable to create a TCP connection to 256.256.256.256:1024");
} }


@Test @Test
public void testWriteMessage() throws Exception { public void testWriteMessage() throws Exception {
resilentSocketOutputStream.write("Test message".getBytes(StandardCharsets.UTF_8)); resilientSocketOutputStream.write("Test message".getBytes(StandardCharsets.UTF_8));
resilentSocketOutputStream.flush(); resilientSocketOutputStream.flush();


latch.await(5, TimeUnit.SECONDS); latch.await(5, TimeUnit.SECONDS);
assertThat(latch.getCount()).isEqualTo(0); assertThat(latch.getCount()).isEqualTo(0);
} }


@Test @Test
public void testGetDescription() { public void testGetDescription() {
assertThat(resilentSocketOutputStream.getDescription()).isEqualTo(String.format("tcp [localhost:%d]", assertThat(resilientSocketOutputStream.getDescription()).isEqualTo(String.format("tcp [localhost:%d]",
ss.getLocalPort())); ss.getLocalPort()));
} }
} }

0 comments on commit 1ce02fc

Please sign in to comment.