Package org.productivity.java.syslog4j.server

Examples of org.productivity.java.syslog4j.server.SyslogServerIF


     * SyslogHosts can send messages to the syslog server.
     * @throws Exception If something goes wrong
     */
    @Test
    public void sendsMessagesToServer() throws Exception {
        final SyslogServerIF server = SyslogServer.getInstance("udp");
        final int port = port();
        server.getConfig().setPort(port);
        final BlockingQueue<String> messages =
            new LinkedBlockingQueue<String>();
        server.getConfig().addEventHandler(
            new SyslogServerEventHandlerIF() {
                /**
                 * Serial Version UID.
                 */
                private static final long serialVersionUID =
                    -7043255643054178133L;
                @Override
                public void event(final SyslogServerIF syslg,
                    final SyslogServerEventIF event) {
                    messages.add(event.getMessage());
                }
            }
        );
        final ExecutorService exec = Executors.newSingleThreadExecutor();
        try {
            exec.execute(server);
            final Hosts hosts = Mockito.mock(Hosts.class);
            final String path = "/path/to/fetch";
            final Host host = new HostMocker()
                .withContent(URI.create(path), "blah")
                .withSyslog(String.format("localhost:%d", port))
                .mock();
            Mockito.doReturn(host).when(hosts)
                .find(Mockito.anyString());
            ResourceMocker.toByteArray(
                new SyslogHosts(hosts).find("dummy")
                    .fetch(URI.create(path), Range.ENTIRE, Version.LATEST)
            );
            MatcherAssert.assertThat(
                messages.poll(1, TimeUnit.MINUTES),
                Matchers.containsString(String.format("from %s", path))
            );
        } finally {
            server.shutdown();
            exec.shutdown();
        }
    }
View Full Code Here

TOP

Related Classes of org.productivity.java.syslog4j.server.SyslogServerIF

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.