Search in sources :

Example 1 with TcpSocketManager

use of org.apache.logging.log4j.core.net.TcpSocketManager in project logging-log4j2 by apache.

the class SecureSocketAppenderSocketOptionsTest method testSocketOptions.

@Test
public void testSocketOptions() throws IOException {
    Assert.assertNotNull(loggerContextRule);
    Assert.assertNotNull(loggerContextRule.getConfiguration());
    final SocketAppender appender = loggerContextRule.getAppender("socket", SocketAppender.class);
    Assert.assertNotNull(appender);
    final TcpSocketManager manager = (TcpSocketManager) appender.getManager();
    Assert.assertNotNull(manager);
    final OutputStream outputStream = manager.getOutputStream();
    Assert.assertFalse(outputStream instanceof NullOutputStream);
    final SocketOptions socketOptions = manager.getSocketOptions();
    Assert.assertNotNull(socketOptions);
    final Socket socket = manager.getSocket();
    Assert.assertNotNull(socket);
    // Test config request
    Assert.assertEquals(false, socketOptions.isKeepAlive());
    Assert.assertEquals(null, socketOptions.isOobInline());
    Assert.assertEquals(false, socketOptions.isReuseAddress());
    Assert.assertEquals(false, socketOptions.isTcpNoDelay());
    Assert.assertEquals(Rfc1349TrafficClass.IPTOS_LOWCOST.value(), socketOptions.getActualTrafficClass().intValue());
    Assert.assertEquals(10000, socketOptions.getReceiveBufferSize().intValue());
    Assert.assertEquals(8000, socketOptions.getSendBufferSize().intValue());
    Assert.assertEquals(12345, socketOptions.getSoLinger().intValue());
    Assert.assertEquals(54321, socketOptions.getSoTimeout().intValue());
    // Test live socket
    Assert.assertEquals(false, socket.getKeepAlive());
    Assert.assertEquals(false, socket.getReuseAddress());
    Assert.assertEquals(false, socket.getTcpNoDelay());
    // Assert.assertEquals(10000, socket.getReceiveBufferSize());
    // This settings changes while we are running, so we cannot assert it.
    // Assert.assertEquals(8000, socket.getSendBufferSize());
    Assert.assertEquals(12345, socket.getSoLinger());
    Assert.assertEquals(54321, socket.getSoTimeout());
}
Also used : TcpSocketManager(org.apache.logging.log4j.core.net.TcpSocketManager) OutputStream(java.io.OutputStream) NullOutputStream(org.apache.logging.log4j.core.util.NullOutputStream) SocketOptions(org.apache.logging.log4j.core.net.SocketOptions) Socket(java.net.Socket) NullOutputStream(org.apache.logging.log4j.core.util.NullOutputStream) Test(org.junit.Test)

Example 2 with TcpSocketManager

use of org.apache.logging.log4j.core.net.TcpSocketManager in project logging-log4j2 by apache.

the class SocketAppenderSocketOptionsTest method testSocketTrafficClass.

@Test
public void testSocketTrafficClass() throws IOException {
    Assume.assumeTrue("Run only on Java 7", System.getProperty("java.specification.version").equals("1.7"));
    Assume.assumeFalse("Do not run on Travis CI", "true".equals(System.getenv("TRAVIS")));
    final SocketAppender appender = loggerContextRule.getAppender("socket", SocketAppender.class);
    final TcpSocketManager manager = (TcpSocketManager) appender.getManager();
    final Socket socket = manager.getSocket();
    Assert.assertEquals(Rfc1349TrafficClass.IPTOS_LOWCOST.value(), socket.getTrafficClass());
}
Also used : TcpSocketManager(org.apache.logging.log4j.core.net.TcpSocketManager) Socket(java.net.Socket) Test(org.junit.Test)

Example 3 with TcpSocketManager

use of org.apache.logging.log4j.core.net.TcpSocketManager in project logging-log4j2 by apache.

the class SocketAppenderSocketOptionsTest method testSocketOptions.

@Test
public void testSocketOptions() throws IOException {
    Assert.assertNotNull(loggerContextRule);
    Assert.assertNotNull(loggerContextRule.getConfiguration());
    final SocketAppender appender = loggerContextRule.getAppender("socket", SocketAppender.class);
    Assert.assertNotNull(appender);
    final TcpSocketManager manager = (TcpSocketManager) appender.getManager();
    Assert.assertNotNull(manager);
    final OutputStream outputStream = manager.getOutputStream();
    Assert.assertFalse(outputStream instanceof NullOutputStream);
    final SocketOptions socketOptions = manager.getSocketOptions();
    Assert.assertNotNull(socketOptions);
    final Socket socket = manager.getSocket();
    Assert.assertNotNull(socket);
    // Test config request
    Assert.assertEquals(false, socketOptions.isKeepAlive());
    Assert.assertEquals(false, socketOptions.isOobInline());
    Assert.assertEquals(false, socketOptions.isReuseAddress());
    Assert.assertEquals(false, socketOptions.isTcpNoDelay());
    Assert.assertEquals(Rfc1349TrafficClass.IPTOS_LOWCOST.value(), socketOptions.getActualTrafficClass().intValue());
    Assert.assertEquals(10000, socketOptions.getReceiveBufferSize().intValue());
    Assert.assertEquals(8000, socketOptions.getSendBufferSize().intValue());
    Assert.assertEquals(12345, socketOptions.getSoLinger().intValue());
    Assert.assertEquals(54321, socketOptions.getSoTimeout().intValue());
    // Test live socket
    Assert.assertEquals(false, socket.getKeepAlive());
    Assert.assertEquals(false, socket.getOOBInline());
    Assert.assertEquals(false, socket.getReuseAddress());
    Assert.assertEquals(false, socket.getTcpNoDelay());
    // Assert.assertEquals(10000, socket.getReceiveBufferSize());
    // This settings changes while we are running, so we cannot assert it.
    // Assert.assertEquals(8000, socket.getSendBufferSize());
    Assert.assertEquals(12345, socket.getSoLinger());
    Assert.assertEquals(54321, socket.getSoTimeout());
}
Also used : TcpSocketManager(org.apache.logging.log4j.core.net.TcpSocketManager) OutputStream(java.io.OutputStream) NullOutputStream(org.apache.logging.log4j.core.util.NullOutputStream) SocketOptions(org.apache.logging.log4j.core.net.SocketOptions) Socket(java.net.Socket) NullOutputStream(org.apache.logging.log4j.core.util.NullOutputStream) Test(org.junit.Test)

Example 4 with TcpSocketManager

use of org.apache.logging.log4j.core.net.TcpSocketManager in project logging-log4j2 by apache.

the class SecureSocketAppenderSocketOptionsTest method testSocketTrafficClass.

@Test
public void testSocketTrafficClass() throws IOException {
    Assume.assumeTrue("Run only on Java 7", System.getProperty("java.specification.version").equals("1.7"));
    Assume.assumeFalse("Do not run on Travis CI", "true".equals(System.getenv("TRAVIS")));
    final SocketAppender appender = loggerContextRule.getAppender("socket", SocketAppender.class);
    final TcpSocketManager manager = (TcpSocketManager) appender.getManager();
    final Socket socket = manager.getSocket();
    Assert.assertEquals(Rfc1349TrafficClass.IPTOS_LOWCOST.value(), socket.getTrafficClass());
}
Also used : TcpSocketManager(org.apache.logging.log4j.core.net.TcpSocketManager) Socket(java.net.Socket) Test(org.junit.Test)

Aggregations

Socket (java.net.Socket)4 TcpSocketManager (org.apache.logging.log4j.core.net.TcpSocketManager)4 Test (org.junit.Test)4 OutputStream (java.io.OutputStream)2 SocketOptions (org.apache.logging.log4j.core.net.SocketOptions)2 NullOutputStream (org.apache.logging.log4j.core.util.NullOutputStream)2