This is an automated email from the ASF dual-hosted git repository.

buhhunyx pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new cbf2d26  cxf-rt-transports-udp: minor code improvements to improve 
test stability (#490)
cbf2d26 is described below

commit cbf2d261ac21657a9b1d6dc233e881d2ec71f442
Author: Alexey Markevich <amarkev...@talend.com>
AuthorDate: Fri Jan 4 02:28:45 2019 +0300

    cxf-rt-transports-udp: minor code improvements to improve test stability 
(#490)
    
    
    
    * revert back to support LoggingFeature
---
 .../org/apache/cxf/transport/udp/UDPConduit.java   | 28 ++++---------
 .../apache/cxf/transport/udp/UDPDestination.java   | 48 +++++-----------------
 .../cxf/transport/udp/UDPTransportFactory.java     | 11 ++---
 .../apache/cxf/transport/udp/UDPTransportTest.java | 33 +++++++++------
 4 files changed, 41 insertions(+), 79 deletions(-)

diff --git 
a/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPConduit.java 
b/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPConduit.java
index edeacd2..3805c37 100644
--- 
a/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPConduit.java
+++ 
b/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPConduit.java
@@ -114,11 +114,7 @@ public class UDPConduit extends AbstractConduit {
                     if (queue == null) {
                         queue = queuem.getAutomaticWorkQueue();
                     }
-                    queue.execute(new Runnable() {
-                        public void run() {
-                            incomingObserver.onMessage(inMessage);
-                        }
-                    });
+                    queue.execute(() -> incomingObserver.onMessage(inMessage));
                 } else {
                     incomingObserver.onMessage(inMessage);
                     if (!message.getExchange().isSynchronous() || multi) {
@@ -194,17 +190,13 @@ public class UDPConduit extends AbstractConduit {
                 int port = Integer.parseInt(s);
                 sendViaBroadcast(message, null, port);
             } else {
-                InetSocketAddress isa = null;
-                String hp = "";
-
-                isa = new InetSocketAddress(uri.getHost(), uri.getPort());
-                hp = uri.getHost() + ":" + uri.getPort();
-
+                final InetSocketAddress isa = new 
InetSocketAddress(uri.getHost(), uri.getPort());
                 if (isa.getAddress().isMulticastAddress()) {
                     sendViaBroadcast(message, isa, isa.getPort());
                     return;
                 }
 
+                final String hp = uri.getHost() + ':' + uri.getPort();
                 Queue<ConnectFuture> q = connections.get(hp);
                 ConnectFuture connFuture = null;
                 if (q != null) {
@@ -217,9 +209,9 @@ public class UDPConduit extends AbstractConduit {
                     
((DatagramSessionConfig)connFuture.getSession().getConfig()).setReceiveBufferSize(64
 * 1024);
                 }
                 connFuture.getSession().setAttribute(CXF_MESSAGE_ATTR, 
message);
-                message.setContent(OutputStream.class, new 
UDPConduitOutputStream(connector, connFuture, message));
+                message.setContent(OutputStream.class, new 
UDPConduitOutputStream(connFuture));
                 message.getExchange().put(ConnectFuture.class, connFuture);
-                message.getExchange().put(HOST_PORT, uri.getHost() + ":" + 
uri.getPort());
+                message.getExchange().put(HOST_PORT, hp);
             }
         } catch (Exception ex) {
             throw new IOException(ex);
@@ -340,19 +332,13 @@ public class UDPConduit extends AbstractConduit {
         }
     }
 
-    public class UDPConduitOutputStream extends OutputStream {
+    static class UDPConduitOutputStream extends OutputStream {
         final ConnectFuture future;
-        final NioDatagramConnector connector;
-        final Message message;
         IoBuffer buffer = IoBuffer.allocate(64 * 1024 - 42); //max size
         boolean closed;
 
-        public UDPConduitOutputStream(NioDatagramConnector connector,
-                                      ConnectFuture connFuture,
-                                      Message m) {
-            this.connector = connector;
+        UDPConduitOutputStream(ConnectFuture connFuture) {
             this.future = connFuture;
-            this.message = m;
         }
 
         public void write(int b) throws IOException {
diff --git 
a/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPDestination.java
 
b/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPDestination.java
index c5b8996..d3e22ac 100644
--- 
a/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPDestination.java
+++ 
b/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPDestination.java
@@ -98,22 +98,14 @@ public class UDPDestination extends AbstractDestination {
                         }
                     };
 
-                    UDPConnectionInfo info = new UDPConnectionInfo(null,
-                                                                   out,
-                                                                   new 
ByteArrayInputStream(bytes, 0, p.getLength()));
-
                     final MessageImpl m = new MessageImpl();
                     final Exchange exchange = new ExchangeImpl();
                     exchange.setDestination(UDPDestination.this);
                     m.setDestination(UDPDestination.this);
                     exchange.setInMessage(m);
-                    m.setContent(InputStream.class, info.in);
-                    m.put(UDPConnectionInfo.class, info);
-                    queue.execute(new Runnable() {
-                        public void run() {
-                            getMessageObserver().onMessage(m);
-                        }
-                    });
+                    m.setContent(InputStream.class, new 
ByteArrayInputStream(bytes, 0, p.getLength()));
+                    m.put(OutputStream.class, out);
+                    queue.execute(() -> getMessageObserver().onMessage(m));
                 } catch (IOException ex) {
                     ex.printStackTrace();
                 }
@@ -124,14 +116,13 @@ public class UDPDestination extends AbstractDestination {
 
     /** {@inheritDoc}*/
     @Override
-    protected Conduit getInbuiltBackChannel(Message inMessage) {
+    protected Conduit getInbuiltBackChannel(final Message inMessage) {
         if (inMessage.getExchange().isOneWay()) {
             return null;
         }
-        final UDPConnectionInfo info = inMessage.get(UDPConnectionInfo.class);
         return new AbstractBackChannelConduit() {
             public void prepare(Message message) throws IOException {
-                message.setContent(OutputStream.class, info.out);
+                message.setContent(OutputStream.class, 
inMessage.get(OutputStream.class));
             }
         };
     }
@@ -190,8 +181,9 @@ public class UDPDestination extends AbstractDestination {
                 dcfg.setReuseAddress(true);
                 acceptor.bind();
             }
+        } catch (RuntimeException e) {
+            throw e;
         } catch (Exception ex) {
-            ex.printStackTrace();
             throw new RuntimeException(ex);
         }
     }
@@ -235,22 +227,8 @@ public class UDPDestination extends AbstractDestination {
         }
     }
 
-    static class UDPConnectionInfo {
-        final IoSession session;
-        final OutputStream out;
-        final InputStream in;
-
-        UDPConnectionInfo(IoSession io, OutputStream o, InputStream i) {
-            session = io;
-            out = o;
-            in = i;
-        }
-    }
-
-
     class UDPIOHandler extends StreamIoHandler {
 
-
         @Override
         public void sessionOpened(IoSession session) {
             // Set timeouts
@@ -273,12 +251,8 @@ public class UDPDestination extends AbstractDestination {
             exchange.setInMessage(m);
             m.setContent(InputStream.class, in);
             out = new UDPDestinationOutputStream(out);
-            m.put(UDPConnectionInfo.class, new UDPConnectionInfo(session, out, 
in));
-            queue.execute(new Runnable() {
-                public void run() {
-                    getMessageObserver().onMessage(m);
-                }
-            });
+            m.put(OutputStream.class, out);
+            queue.execute(() -> getMessageObserver().onMessage(m));
         }
 
         public void sessionClosed(IoSession session) throws Exception {
@@ -329,12 +303,12 @@ public class UDPDestination extends AbstractDestination {
         }
     }
 
-    public class UDPDestinationOutputStream extends OutputStream {
+    static class UDPDestinationOutputStream extends OutputStream {
         final OutputStream out;
         IoBuffer buffer = IoBuffer.allocate(64 * 1024 - 42); //max size
         boolean closed;
 
-        public UDPDestinationOutputStream(OutputStream out) {
+        UDPDestinationOutputStream(OutputStream out) {
             this.out = out;
         }
 
diff --git 
a/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPTransportFactory.java
 
b/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPTransportFactory.java
index 5703105..3303715 100644
--- 
a/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPTransportFactory.java
+++ 
b/rt/transports/udp/src/main/java/org/apache/cxf/transport/udp/UDPTransportFactory.java
@@ -20,7 +20,6 @@
 package org.apache.cxf.transport.udp;
 
 import java.io.IOException;
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -45,14 +44,10 @@ public class UDPTransportFactory extends 
AbstractTransportFactory
     implements DestinationFactory, ConduitInitiator {
 
     public static final String TRANSPORT_ID = 
"http://cxf.apache.org/transports/udp";;
-    public static final List<String> DEFAULT_NAMESPACES
-        = Collections.unmodifiableList(Arrays.asList(TRANSPORT_ID));
+    public static final List<String> DEFAULT_NAMESPACES = 
Collections.singletonList(TRANSPORT_ID);
 
     private static final Logger LOG = 
LogUtils.getL7dLogger(UDPTransportFactory.class);
-    private static final Set<String> URI_PREFIXES = new HashSet<>();
-    static {
-        URI_PREFIXES.add("udp://");
-    }
+    private static final Set<String> URI_PREFIXES = 
Collections.singleton("udp://");
 
     private Set<String> uriPrefixes = new HashSet<>(URI_PREFIXES);
 
@@ -94,7 +89,7 @@ public class UDPTransportFactory extends 
AbstractTransportFactory
     public void setUriPrefixes(Set<String> s) {
         uriPrefixes = s;
     }
-    EndpointReferenceType createReference(EndpointInfo ei) {
+    static EndpointReferenceType createReference(EndpointInfo ei) {
         EndpointReferenceType epr = new EndpointReferenceType();
         AttributedURIType address = new AttributedURIType();
         address.setValue(ei.getAddress());
diff --git 
a/rt/transports/udp/src/test/java/org/apache/cxf/transport/udp/UDPTransportTest.java
 
b/rt/transports/udp/src/test/java/org/apache/cxf/transport/udp/UDPTransportTest.java
index fd37f27..2c393a5 100644
--- 
a/rt/transports/udp/src/test/java/org/apache/cxf/transport/udp/UDPTransportTest.java
+++ 
b/rt/transports/udp/src/test/java/org/apache/cxf/transport/udp/UDPTransportTest.java
@@ -22,12 +22,10 @@ package org.apache.cxf.transport.udp;
 import java.net.NetworkInterface;
 import java.util.Enumeration;
 
-import javax.jws.WebService;
-
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
 import org.apache.cxf.jaxws.JaxWsServerFactoryBean;
-import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.apache.cxf.testutil.common.TestUtil;
 import org.apache.hello_world.Greeter;
 
 import org.junit.AfterClass;
@@ -35,21 +33,18 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 /**
  *
  */
-public class UDPTransportTest extends AbstractBusClientServerTestBase {
-    static final String PORT = allocatePort(UDPTransportTest.class);
+public class UDPTransportTest {
+    private static final String PORT = 
TestUtil.getPortNumber(UDPTransportTest.class);
     private static Server server;
 
-    @WebService(serviceName = "SOAPService",
-        endpointInterface = "org.apache.hello_world.Greeter",
-        targetNamespace = "http://apache.org/hello_world";)
     static class GreeterImpl implements Greeter {
         private String myName = "defaultGreeter";
-        GreeterImpl() {
-        }
+
         public String greetMe(String me) {
             return "Hello " + me;
         }
@@ -57,17 +52,18 @@ public class UDPTransportTest extends 
AbstractBusClientServerTestBase {
             return "Bonjour from " + myName;
         }
         public void pingMe() {
+            throw new UnsupportedOperationException();
         }
     }
 
 
     @BeforeClass
     public static void setUpBeforeClass() throws Exception {
-        createStaticBus();
         JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
-        factory.setBus(getStaticBus());
         factory.setAddress("udp://:" + PORT);
+        factory.setServiceClass(Greeter.class);
         factory.setServiceBean(new GreeterImpl());
+        // factory.setFeatures(Collections.singletonList(new 
LoggingFeature()));
         server = factory.create();
     }
 
@@ -84,11 +80,13 @@ public class UDPTransportTest extends 
AbstractBusClientServerTestBase {
         fact.setAddress("udp://localhost:" + PORT);
         Greeter g = fact.create(Greeter.class);
         for (int x = 0; x < 5; x++) {
-            assertEquals("Hello World", g.greetMe("World"));
+            final String message = Integer.toString(x);
+            assertTrue(g.greetMe(message).endsWith(message));
         }
 
         ((java.io.Closeable)g).close();
     }
+
     @Test
     public void testBroadcastUDP() throws Exception {
         // Disable the test on Redhat Enterprise Linux which doesn't enable 
the UDP broadcast by default
@@ -117,6 +115,7 @@ public class UDPTransportTest extends 
AbstractBusClientServerTestBase {
         fact.setAddress("udp://:" + PORT + "/foo");
         Greeter g = fact.create(Greeter.class);
         assertEquals("Hello World", g.greetMe("World"));
+
         ((java.io.Closeable)g).close();
     }
 
@@ -133,4 +132,12 @@ public class UDPTransportTest extends 
AbstractBusClientServerTestBase {
 
         ((java.io.Closeable)g).close();
     }
+
+    @Test(expected = javax.xml.ws.soap.SOAPFaultException.class)
+    public void testFailure() throws Exception {
+        JaxWsProxyFactoryBean fact = new JaxWsProxyFactoryBean();
+        fact.setAddress("udp://localhost:" + PORT);
+        Greeter g = fact.create(Greeter.class);
+        g.pingMe();
+    }
 }

Reply via email to