You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/04/12 18:33:55 UTC
[15/17] logging-log4j2 git commit: LOG4J2-1343 added countdown latch
to ensure the UDP server is listening before logging the event;
split up lines for easier debugging
LOG4J2-1343 added countdown latch to ensure the UDP server is listening before logging the event; split up lines for easier debugging
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/c70775c9
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/c70775c9
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/c70775c9
Branch: refs/heads/master
Commit: c70775c94d90eeb6ff96e25fe516c783a45504ac
Parents: 8d7bf48
Author: rpopma <rp...@apache.org>
Authored: Tue Apr 12 22:24:31 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Tue Apr 12 22:24:31 2016 +0900
----------------------------------------------------------------------
.../log4j/core/appender/SocketAppenderTest.java | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/c70775c9/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java
index 5e4a556..50586f7 100644
--- a/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java
+++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/appender/SocketAppenderTest.java
@@ -33,6 +33,7 @@ import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.apache.logging.log4j.Level;
@@ -148,6 +149,11 @@ public class SocketAppenderTest {
@Test
public void testUdpAppender() throws Exception {
+ try {
+ udpServer.latch.await();
+ } catch (InterruptedException ex) {
+ ex.printStackTrace();
+ }
final SocketAppender appender = SocketAppender.createAppender("localhost", PORT, Protocol.UDP, null, 0, -1,
false, "Test", true, true, null, null, false, null);
@@ -207,6 +213,7 @@ public class SocketAppenderTest {
private final DatagramSocket sock;
private boolean shutdown = false;
private Thread thread;
+ private CountDownLatch latch = new CountDownLatch(1);
public UDPSocketServer() throws IOException {
this.sock = new DatagramSocket(PORT);
@@ -224,12 +231,16 @@ public class SocketAppenderTest {
final DatagramPacket packet = new DatagramPacket(bytes, bytes.length);
try {
while (!shutdown) {
+ latch.countDown();
sock.receive(packet);
final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(packet.getData()));
++udpCount;
- list.add((LogEvent) ois.readObject());
+ final Object received = ois.readObject(); // separate lines for debugging
+ final LogEvent event = (LogEvent) received;
+ list.add(event);
}
- } catch (final Exception ex) {
+ } catch (final Throwable ex) {
+ ex.printStackTrace();
if (!shutdown) {
throw new RuntimeException(ex);
}