org.productivity.java.syslog4j.server.impl.net.tcp.TCPNetSyslogServerConfig Java Examples

The following examples show how to use org.productivity.java.syslog4j.server.impl.net.tcp.TCPNetSyslogServerConfig. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractNetSyslog4jTest.java    From syslog4j with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void startServerThread(String protocol) {
	assertTrue(SyslogServer.exists(protocol));
	
	this.server = SyslogServer.getInstance(protocol);
	
	if (isSyslogServerTcpBacklog() && this.server.getConfig() instanceof TCPNetSyslogServerConfig) {
		((TCPNetSyslogServerConfig) this.server.getConfig()).setBacklog(0);
	}
	
	AbstractNetSyslogServerConfig config = (AbstractNetSyslogServerConfig) this.server.getConfig();
	config.setPort(TEST_PORT);
	config.addEventHandler(this.recorderEventHandler);

	if (this.server.getThread() == null) {
		Thread t = new Thread(this.server);
		t.setName("SyslogServer: " + protocol);
		t.start();
		
		this.server.setThread(t);
		
		assertEquals(t,this.server.getThread());
	}
}
 
Example #2
Source File: Syslog4jAppenderTest.java    From logback-syslog4j with MIT License 6 votes vote down vote up
protected void setUp() {
    serverStream = new ByteArrayOutputStream();
    PrintStream ps = new PrintStream(serverStream);

    final TCPNetSyslogServerConfig tcpNetSyslogServerConfig = new TCPNetSyslogServerConfig(45553);
    tcpNetSyslogServerConfig.addEventHandler(new PrintStreamSyslogServerEventHandler(ps));

    final UDPNetSyslogServerConfig udpNetSyslogServerConfig = new UDPNetSyslogServerConfig(45553);
    udpNetSyslogServerConfig.addEventHandler(new PrintStreamSyslogServerEventHandler(ps));

    final SSLTCPNetSyslogServerConfig ssltcpNetSyslogServerConfig = new SSLTCPNetSyslogServerConfig();
    ssltcpNetSyslogServerConfig.setPort(45554);
    ssltcpNetSyslogServerConfig.addEventHandler(new PrintStreamSyslogServerEventHandler(ps));
    ssltcpNetSyslogServerConfig.setKeyStore(this.getClass().getClassLoader().getResource("test-keystore.jks").getFile());
    ssltcpNetSyslogServerConfig.setKeyStorePassword("password");
    ssltcpNetSyslogServerConfig.setTrustStore(this.getClass().getClassLoader().getResource("test-keystore.jks").getFile());
    ssltcpNetSyslogServerConfig.setTrustStorePassword("password");

    SyslogServer.createThreadedInstance("testTcp", tcpNetSyslogServerConfig);
    SyslogServer.createThreadedInstance("testUdp", udpNetSyslogServerConfig);
    SyslogServer.createThreadedInstance("testTls", ssltcpNetSyslogServerConfig);
}
 
Example #3
Source File: MaxActiveSocketsTest.java    From syslog4j with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testMaxActiveSocketsWithBlock() {
	TCPNetSyslogServerConfigIF serverConfig = new TCPNetSyslogServerConfig(8888);
	serverConfig.setMaxActiveSocketsBehavior(TCPNetSyslogServerConfigIF.MAX_ACTIVE_SOCKETS_BEHAVIOR_BLOCK);
	int count = _testMaxActiveSockets(serverConfig);
	
	assertEquals(3,count);
}
 
Example #4
Source File: MaxActiveSocketsTest.java    From syslog4j with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testMaxActiveSocketsWithReject() {
	TCPNetSyslogServerConfigIF serverConfig = new TCPNetSyslogServerConfig(8888);
	serverConfig.setMaxActiveSocketsBehavior(TCPNetSyslogServerConfigIF.MAX_ACTIVE_SOCKETS_BEHAVIOR_REJECT);
	int count = _testMaxActiveSockets(serverConfig);		

	assertEquals(2,count);
}
 
Example #5
Source File: FreshConnectionIntervalTest.java    From syslog4j with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void testFreshConnectionInterval() {
	TCPNetSyslogServerConfigIF serverConfig = new TCPNetSyslogServerConfig();
	serverConfig.setPort(8888);
	
	SocketCounter counter = new SocketCounter();
	serverConfig.addEventHandler(counter);
	
	SyslogServerIF server = SyslogServer.createThreadedInstance("tcp_8888",serverConfig);

	SyslogUtility.sleep(100);

	TCPNetSyslogConfigIF config = new TCPNetSyslogConfig();
	config.setPort(8888);
	config.setFreshConnectionInterval(300);
	
	SyslogIF syslog = Syslog.createInstance("tcp_8888",config);

	for(int i=0; i<10; i++) {
		syslog.info("message " + i);
		SyslogUtility.sleep(100);
	}
	
	SyslogUtility.sleep(100);
	
	SyslogServer.destroyInstance(server);
	Syslog.destroyInstance(syslog);

	SyslogUtility.sleep(100);

	assertEquals("OpenCounter",3,counter.openCounter);
	assertEquals("EventCounter",10,counter.eventCounter);
	assertEquals("CloseCounter",3,counter.closeCounter);
}
 
Example #6
Source File: SyslogServer.java    From syslog4j with GNU Lesser General Public License v2.1 4 votes vote down vote up
public synchronized static void initialize() {
	createInstance(UDP,new UDPNetSyslogServerConfig());
	createInstance(TCP,new TCPNetSyslogServerConfig());
}
 
Example #7
Source File: TCPNetSyslog4jTest.java    From syslog4j with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testTimeout() {
	TCPNetSyslogServerConfigIF serverConfig = new TCPNetSyslogServerConfig();
	serverConfig.setTimeout(150);
	serverConfig.setPort(7777);
	serverConfig.addEventHandler(new TimeoutHandler());

	TCPNetSyslogConfigIF clientConfig = new TCPNetSyslogConfig();
	clientConfig.setPort(7777);
	clientConfig.setThreaded(false);

	SyslogServer.createThreadedInstance("tcp_to",serverConfig);
	SyslogUtility.sleep(250);
	
	SyslogIF syslog = Syslog.createInstance("tcp_to",clientConfig);
	SyslogUtility.sleep(250);
	
	int mark = 0;
	
	for(int i=1; i<=10; i++) {
		if (i > 5) {
			mark--;
			
		} else {
			mark++;
		}
		
		int timeout = 35 * mark + 25;
		
		syslog.info("Test " + i + " (" + timeout + "ms) Should Timeout: " + (timeout > serverConfig.getTimeout() ? "yes" : "no"));
		SyslogUtility.sleep(timeout);
	}
	
	syslog.flush();
	SyslogUtility.sleep(200);
	
	SyslogServer.destroyInstance("tcp_to");
	
	SyslogUtility.sleep(200);
	
	Syslog.destroyInstance("tcp_to");
}
 
Example #8
Source File: SyslogServerSessionTest.java    From syslog4j with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void testTCPSession() {
	SyslogServerConfigIF serverConfig = new TCPNetSyslogServerConfig(9999);
	
	TCPSessionHandler handler1 = new TCPSessionHandler("a");
	serverConfig.addEventHandler(handler1);
	
	TCPSessionHandler handler2 = new TCPSessionHandler("b");
	serverConfig.addEventHandler(handler2);
	
	SyslogServerIF server = SyslogServer.createThreadedInstance("tcp_session",serverConfig);
	
	SyslogUtility.sleep(100);
	
	assertTrue(handler1.initialized);
	assertTrue(handler2.initialized);
	
	SyslogConfigIF config = new TCPNetSyslogConfig();
	config.setPort(9999);
	
	TCPNetSyslogServer tcpServer = (TCPNetSyslogServer) server;
	
	SyslogIF syslog1 = Syslog.createInstance("tcp_session_1",config);
	
	syslog1.info("1");
	syslog1.info("2");

	SyslogUtility.sleep(100);

	assertEquals(1,tcpServer.getSessions().size());

	SyslogIF syslog2 = Syslog.createInstance("tcp_session_2",config);
	
	syslog2.info("3");
	syslog2.info("4");

	syslog1.info("5");
	syslog1.info("6");

	syslog2.info("7");
	syslog2.info("8");

	SyslogUtility.sleep(100);
	
	assertEquals(2,tcpServer.getSessions().size());

	syslog1.shutdown();
	syslog2.shutdown();
	SyslogServer.destroyInstance("tcp_session");
	
	try {
		SyslogServer.getInstance("tcp_session");
		fail();
		
	} catch (SyslogRuntimeException sre) {
		//
	}
	
	assertEquals(4,handler1.eventCount[0]);
	assertEquals(0,handler1.eventCount[1]);
	assertEquals(4,handler1.eventCount[2]);
	assertEquals(0,handler1.eventCount[3]);
	
	assertEquals(0,handler2.eventCount[0]);
	assertEquals(4,handler2.eventCount[1]);
	assertEquals(0,handler2.eventCount[2]);
	assertEquals(4,handler2.eventCount[3]);

	assertEquals(1,handler1.closeCount[0]);
	assertEquals(0,handler1.closeCount[1]);
	assertEquals(1,handler1.closeCount[2]);
	assertEquals(0,handler1.closeCount[3]);
	
	assertEquals(0,handler2.closeCount[0]);
	assertEquals(1,handler2.closeCount[1]);
	assertEquals(0,handler2.closeCount[2]);
	assertEquals(1,handler2.closeCount[3]);

	SyslogUtility.sleep(100);

	assertTrue(handler1.destroyed);
	assertTrue(handler2.destroyed);
}
 
Example #9
Source File: PooledTCPNetSyslog4jTest.java    From syslog4j with GNU Lesser General Public License v2.1 3 votes vote down vote up
protected String getServerProtocol() {
	TCPNetSyslogServerConfig serverConfig = new TCPNetSyslogServerConfig();
	
	SyslogServer.createThreadedInstance("pooledTcp", serverConfig);
	
	return "pooledTcp";
}