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

The following examples show how to use org.productivity.java.syslog4j.server.impl.net.tcp.TCPNetSyslogServer. 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: 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);
}