View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.net.server;
15  
16  import java.io.ObjectInputStream;
17  import java.net.InetAddress;
18  import java.net.ServerSocket;
19  import java.net.Socket;
20  import java.util.concurrent.ScheduledExecutorService;
21  import java.util.concurrent.TimeUnit;
22  
23  import org.junit.jupiter.api.AfterEach;
24  import org.junit.jupiter.api.Assertions;
25  import org.junit.jupiter.api.BeforeEach;
26  import org.junit.jupiter.api.Disabled;
27  import org.junit.jupiter.api.Test;
28  
29  import ch.qos.logback.core.net.mock.MockContext;
30  import ch.qos.logback.core.net.server.test.ServerSocketUtil;
31  import ch.qos.logback.core.util.ExecutorServiceUtil;
32  
33  /**
34   * A functional test for {@link AbstractServerSocketAppender}.
35   *
36   * @author Carl Harris
37   */
38  @Disabled
39  public class ServerSocketAppenderBaseFunctionalTest {
40  
41      private static final String TEST_EVENT = "test event";
42  
43      private static final int EVENT_COUNT = 10;
44  
45      private ScheduledExecutorService executor = ExecutorServiceUtil.newScheduledExecutorService();
46      private MockContext context = new MockContext(executor);
47      private ServerSocket serverSocket;
48      private InstrumentedServerSocketAppenderBase appender;
49  
50      @BeforeEach
51      public void setUp() throws Exception {
52  
53          serverSocket = ServerSocketUtil.createServerSocket();
54  
55          appender = new InstrumentedServerSocketAppenderBase(serverSocket);
56          appender.setContext(context);
57      }
58  
59      @AfterEach
60      public void tearDown() throws Exception {
61          executor.shutdownNow();
62          executor.awaitTermination(10000, TimeUnit.MILLISECONDS);
63          Assertions.assertTrue(executor.isTerminated());
64      }
65  
66      @Test
67      public void testLogEventClient() throws Exception {
68          appender.start();
69          Socket socket = new Socket(InetAddress.getLocalHost(), serverSocket.getLocalPort());
70  
71          socket.setSoTimeout(1000);
72          ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
73  
74          for (int i = 0; i < EVENT_COUNT; i++) {
75              appender.append(TEST_EVENT + i);
76              Assertions.assertEquals(TEST_EVENT + i, ois.readObject());
77          }
78  
79          socket.close();
80          appender.stop();
81      }
82  
83  }