camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1301940 - in /camel/trunk/components/camel-websocket/src: main/java/org/apache/camel/component/websocket/ test/java/org/apache/camel/component/websocket/
Date Sat, 17 Mar 2012 14:05:56 GMT
Author: davsclaus
Date: Sat Mar 17 14:05:55 2012
New Revision: 1301940

URL: http://svn.apache.org/viewvc?rev=1301940&view=rev
Log:
CAMEL-5061: Polish camel-websocket. Remove incomplete code. Clean resources when stopping.

Removed:
    camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketConfiguration.java
    camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConfigurationTest.java
Modified:
    camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/DefaultNodeSynchronization.java
    camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/DefaultWebsocket.java
    camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/MemoryWebsocketStore.java
    camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java
    camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponentServlet.java
    camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketConstants.java
    camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketConsumer.java
    camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java
    camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketProducer.java
    camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketStore.java
    camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/DefaultWebsocketTest.java
    camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/NodeSynchronizationImplTest.java
    camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketComponentServletTest.java
    camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketComponentTest.java
    camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerTest.java
    camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketEndpointTest.java

Modified: camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/DefaultNodeSynchronization.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/DefaultNodeSynchronization.java?rev=1301940&r1=1301939&r2=1301940&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/DefaultNodeSynchronization.java
(original)
+++ camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/DefaultNodeSynchronization.java
Sat Mar 17 14:05:55 2012
@@ -18,13 +18,7 @@ package org.apache.camel.component.webso
 
 public class DefaultNodeSynchronization implements NodeSynchronization {
 
-    private WebsocketStore memoryStore;
-    private WebsocketStore globalStore;
-
-    public DefaultNodeSynchronization(WebsocketStore memoryStore, WebsocketStore globalStore)
{
-        this.memoryStore = memoryStore;
-        this.globalStore = globalStore;
-    }
+    private final WebsocketStore memoryStore;
 
     public DefaultNodeSynchronization(WebsocketStore memoryStore) {
         this.memoryStore = memoryStore;
@@ -33,25 +27,16 @@ public class DefaultNodeSynchronization 
     @Override
     public void addSocket(DefaultWebsocket socket) {
         memoryStore.add(socket);
-        if (globalStore != null) {
-            globalStore.add(socket);
-        }
     }
 
     @Override
     public void removeSocket(String id) {
         memoryStore.remove(id);
-        if (globalStore != null) {
-            globalStore.remove(id);
-        }
     }
 
     @Override
     public void removeSocket(DefaultWebsocket socket) {
         memoryStore.remove(socket);
-        if (globalStore != null) {
-            globalStore.remove(socket);
-        }
     }
 
 }

Modified: camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/DefaultWebsocket.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/DefaultWebsocket.java?rev=1301940&r1=1301939&r2=1301940&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/DefaultWebsocket.java
(original)
+++ camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/DefaultWebsocket.java
Sat Mar 17 14:05:55 2012
@@ -26,11 +26,10 @@ import org.slf4j.LoggerFactory;
 
 public class DefaultWebsocket implements WebSocket, OnTextMessage, Serializable {
 
-    private static final long serialVersionUID = -575701599776801400L;
     private static final Logger LOG = LoggerFactory.getLogger(DefaultWebsocket.class);
-    private transient Connection connection;
-    private transient WebsocketConsumer consumer;
-    private transient NodeSynchronization sync;
+    private final WebsocketConsumer consumer;
+    private final NodeSynchronization sync;
+    private Connection connection;
     private String connectionKey;
 
     public DefaultWebsocket(NodeSynchronization sync, WebsocketConsumer consumer) {
@@ -40,11 +39,13 @@ public class DefaultWebsocket implements
 
     @Override
     public void onClose(int closeCode, String message) {
+        LOG.trace("onClose {} {}", closeCode, message);
         sync.removeSocket(this);
     }
 
     @Override
     public void onOpen(Connection connection) {
+        LOG.trace("onOpen {}", connection);
         this.connection = connection;
         this.connectionKey = UUID.randomUUID().toString();
         sync.addSocket(this);
@@ -54,7 +55,7 @@ public class DefaultWebsocket implements
     public void onMessage(String message) {
         LOG.debug("onMessage: {}", message);
         if (this.consumer != null) {
-            this.consumer.sendExchange(this.connectionKey, message);
+            this.consumer.sendMessage(this.connectionKey, message);
         } else {
             LOG.debug("No consumer to handle message received: {}", message);
         }
@@ -76,8 +77,4 @@ public class DefaultWebsocket implements
         this.connectionKey = connectionKey;
     }
 
-    public void setConsumer(WebsocketConsumer consumer) {
-        this.consumer = consumer;
-    }
-
 }

Modified: camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/MemoryWebsocketStore.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/MemoryWebsocketStore.java?rev=1301940&r1=1301939&r2=1301940&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/MemoryWebsocketStore.java
(original)
+++ camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/MemoryWebsocketStore.java
Sat Mar 17 14:05:55 2012
@@ -48,4 +48,13 @@ public class MemoryWebsocketStore extend
         return super.values();
     }
 
+    @Override
+    public void start() throws Exception {
+        // noop
+    }
+
+    @Override
+    public void stop() throws Exception {
+        clear();
+    }
 }

Modified: camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java?rev=1301940&r1=1301939&r2=1301940&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java
(original)
+++ camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponent.java
Sat Mar 17 14:05:55 2012
@@ -60,28 +60,35 @@ public class WebsocketComponent extends 
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
         WebsocketEndpoint endpoint = endpoints.get(remaining);
         if (endpoint == null) {
-            WebsocketConfiguration websocketConfiguration = new WebsocketConfiguration();
-            setProperties(websocketConfiguration, parameters);
-            endpoint = new WebsocketEndpoint(uri, this, remaining, websocketConfiguration);
+            endpoint = new WebsocketEndpoint(uri, this, remaining);
+            setProperties(endpoint, parameters);
             endpoints.put(remaining, endpoint);
         }
         return endpoint;
     }
 
-    public void setHost(String host) {
-        this.host = host;
-    }
-
-    public void setPort(int port) {
-        this.port = port;
+    public String getStaticResources() {
+        return staticResources;
     }
 
     public void setStaticResources(String staticResources) {
         this.staticResources = staticResources;
     }
 
-    ServletContextHandler createContext() {
-        return new ServletContextHandler(ServletContextHandler.SESSIONS);
+    public String getHost() {
+        return host;
+    }
+
+    public void setHost(String host) {
+        this.host = host;
+    }
+
+    public int getPort() {
+        return port;
+    }
+
+    public void setPort(int port) {
+        this.port = port;
     }
 
     protected Server createServer(ServletContextHandler context, String host, int port, String
home) {
@@ -116,18 +123,10 @@ public class WebsocketComponent extends 
         if (servlet == null) {
             servlet = createServlet(sync, pathSpec, servlets, context);
         }
-        setServletConsumer(servlet, consumer);
-        return servlet;
-    }
-
-    String createPathSpec(String remaining) {
-        return String.format("/%s/*", remaining);
-    }
-
-    void setServletConsumer(WebsocketComponentServlet servlet, WebsocketConsumer consumer)
{
         if (servlet.getConsumer() == null && consumer != null) {
             servlet.setConsumer(consumer);
         }
+        return servlet;
     }
 
     WebsocketComponentServlet createServlet(NodeSynchronization sync, String pathSpec, Map<String,
WebsocketComponentServlet> servlets, ServletContextHandler handler) {
@@ -137,10 +136,18 @@ public class WebsocketComponent extends 
         return servlet;
     }
 
+    ServletContextHandler createContext() {
+        return new ServletContextHandler(ServletContextHandler.SESSIONS);
+    }
+
+    private static String createPathSpec(String remaining) {
+        return String.format("/%s/*", remaining);
+    }
+
     @Override
     protected void doStart() throws Exception {
         super.doStart();
-        LOG.info("Starting server {}:{}; static resources: {}", new Object[] {host, port,
staticResources});
+        LOG.info("Starting server {}:{}; static resources: {}", new Object[]{host, port,
staticResources});
         context = createContext();
         server = createServer(context, host, port, staticResources);
         server.start();
@@ -149,8 +156,11 @@ public class WebsocketComponent extends 
     @Override
     public void doStop() throws Exception {
         if (server != null) {
+            LOG.info("Stopping server {}:{}", host, port);
             server.stop();
+            server = null;
         }
+        endpoints.clear();
     }
 
 }

Modified: camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponentServlet.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponentServlet.java?rev=1301940&r1=1301939&r2=1301940&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponentServlet.java
(original)
+++ camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketComponentServlet.java
Sat Mar 17 14:05:55 2012
@@ -16,21 +16,15 @@
  */
 package org.apache.camel.component.websocket;
 
-import java.io.IOException;
-
-import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 
 import org.eclipse.jetty.websocket.WebSocket;
 import org.eclipse.jetty.websocket.WebSocketServlet;
 
 public class WebsocketComponentServlet extends WebSocketServlet {
 
-    private static final long serialVersionUID = 207837507742337364L;
-
+    private final NodeSynchronization sync;
     private WebsocketConsumer consumer;
-    private NodeSynchronization sync;
 
     public WebsocketComponentServlet(NodeSynchronization sync) {
         this.sync = sync;
@@ -49,10 +43,4 @@ public class WebsocketComponentServlet e
         return new DefaultWebsocket(sync, consumer);
     }
 
-    @Override
-    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
-        // TODO: why do we grab the default servlet?
-        getServletContext().getNamedDispatcher("default").forward(request, response);
-    }
-
 }

Modified: camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketConstants.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketConstants.java?rev=1301940&r1=1301939&r2=1301940&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketConstants.java
(original)
+++ camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketConstants.java
Sat Mar 17 14:05:55 2012
@@ -19,9 +19,10 @@ package org.apache.camel.component.webso
 public final class WebsocketConstants {
 
     public static final int DEFAULT_PORT = 9292;
+    public static final String DEFAULT_HOST = "0.0.0.0";
+
     public static final String CONNECTION_KEY = "websocket.connectionKey";
     public static final String SEND_TO_ALL = "websocket.sendToAll";
-    public static final String DEFAULT_HOST = "0.0.0.0";
 
     private WebsocketConstants() {
     };

Modified: camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketConsumer.java?rev=1301940&r1=1301939&r2=1301940&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketConsumer.java
(original)
+++ camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketConsumer.java
Sat Mar 17 14:05:55 2012
@@ -28,7 +28,7 @@ public class WebsocketConsumer extends D
         super(endpoint, processor);
     }
 
-    public void sendExchange(final String connectionKey, final String message) {
+    public void sendMessage(final String connectionKey, final String message) {
         final Exchange exchange = getEndpoint().createExchange();
 
         // set header and body
@@ -39,8 +39,7 @@ public class WebsocketConsumer extends D
         getAsyncProcessor().process(exchange, new AsyncCallback() {
             public void done(boolean doneSync) {
                 if (exchange.getException() != null) {
-                    getExceptionHandler().handleException(String.format("Error processing
exchange for websocket consumer on message '%s'.", message),
-                            exchange, exchange.getException());
+                    getExceptionHandler().handleException("Error processing exchange", exchange,
exchange.getException());
                 }
             }
         });

Modified: camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java?rev=1301940&r1=1301939&r2=1301940&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java
(original)
+++ camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketEndpoint.java
Sat Mar 17 14:05:55 2012
@@ -20,67 +20,38 @@ import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultEndpoint;
-import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.ServiceHelper;
 
 public class WebsocketEndpoint extends DefaultEndpoint {
 
-    // Todo: Change to Options
     private NodeSynchronization sync;
     private String remaining;
-
     private WebsocketStore memoryStore;
-    private WebsocketStore globalStore;
-
-    private WebsocketConfiguration websocketConfiguration;
-
-    public WebsocketEndpoint() {
 
-    }
-    
-    public WebsocketEndpoint(String uri, WebsocketComponent component, String remaining,
WebsocketConfiguration websocketConfiguration) throws InstantiationException, IllegalAccessException
{
+    public WebsocketEndpoint(String uri, WebsocketComponent component, String remaining)
{
         super(uri, component);
         this.remaining = remaining;
 
         this.memoryStore = new MemoryWebsocketStore();
-        // TODO: init globalStore
-
-        this.websocketConfiguration = websocketConfiguration;
-
-        if (websocketConfiguration.getGlobalStore() != null) {
-            this.globalStore = (WebsocketStore) ObjectHelper.loadClass(this.websocketConfiguration.getGlobalStore()).newInstance();
-        }
-
-        // this.sync = new NodeSynchronizationImpl(this.memoryStore, null);
-        this.sync = new DefaultNodeSynchronization(this.memoryStore, this.globalStore);
+        this.sync = new DefaultNodeSynchronization(memoryStore);
     }
 
-    public WebsocketStore getMemoryStore() {
-        return memoryStore;
-    }
-
-    public WebsocketStore getGlobalStore() {
-        return globalStore;
+    @Override
+    public WebsocketComponent getComponent() {
+        return (WebsocketComponent) super.getComponent();
     }
 
     @Override
     public Consumer createConsumer(Processor processor) throws Exception {
-
-        // init consumer
         WebsocketConsumer consumer = new WebsocketConsumer(this, processor);
-
-        // register servlet
-        ((WebsocketComponent) super.getComponent()).addServlet(this.sync, consumer, this.remaining);
-
+        getComponent().addServlet(sync, consumer, remaining);
         return consumer;
     }
 
     @Override
     public Producer createProducer() throws Exception {
-
-        // register servlet without consumer
-        ((WebsocketComponent) super.getComponent()).addServlet(this.sync, null, this.remaining);
-
-        return new WebsocketProducer(this, this.memoryStore);
+        getComponent().addServlet(sync, null, remaining);
+        return new WebsocketProducer(this, memoryStore);
     }
 
     @Override
@@ -88,5 +59,15 @@ public class WebsocketEndpoint extends D
         return true;
     }
 
-    // TODO --> implement store factory
+    @Override
+    protected void doStart() throws Exception {
+        ServiceHelper.startService(memoryStore);
+        super.doStart();
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        ServiceHelper.stopService(memoryStore);
+        super.doStop();
+    }
 }

Modified: camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketProducer.java?rev=1301940&r1=1301939&r2=1301940&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketProducer.java
(original)
+++ camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketProducer.java
Sat Mar 17 14:05:55 2012
@@ -26,11 +26,7 @@ import org.apache.camel.Message;
 import org.apache.camel.impl.DefaultProducer;
 
 public class WebsocketProducer extends DefaultProducer {
-    private WebsocketStore store;
-
-    public WebsocketProducer(Endpoint endpoint) {
-        super(endpoint);
-    }
+    private final WebsocketStore store;
 
     public WebsocketProducer(Endpoint endpoint, WebsocketStore store) {
         super(endpoint);

Modified: camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketStore.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketStore.java?rev=1301940&r1=1301939&r2=1301940&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketStore.java
(original)
+++ camel/trunk/components/camel-websocket/src/main/java/org/apache/camel/component/websocket/WebsocketStore.java
Sat Mar 17 14:05:55 2012
@@ -18,7 +18,9 @@ package org.apache.camel.component.webso
 
 import java.util.Collection;
 
-public interface WebsocketStore {
+import org.apache.camel.Service;
+
+public interface WebsocketStore extends Service {
 
     void add(DefaultWebsocket ws);
 

Modified: camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/DefaultWebsocketTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/DefaultWebsocketTest.java?rev=1301940&r1=1301939&r2=1301940&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/DefaultWebsocketTest.java
(original)
+++ camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/DefaultWebsocketTest.java
Sat Mar 17 14:05:55 2012
@@ -82,7 +82,7 @@ public class DefaultWebsocketTest {
         defaultWebsocket.setConnectionKey(CONNECTION_KEY);
         defaultWebsocket.onMessage(MESSAGE);
         InOrder inOrder = inOrder(connection, consumer, sync);
-        inOrder.verify(consumer, times(1)).sendExchange(CONNECTION_KEY, MESSAGE);
+        inOrder.verify(consumer, times(1)).sendMessage(CONNECTION_KEY, MESSAGE);
         inOrder.verifyNoMoreInteractions();
     }
 
@@ -92,7 +92,7 @@ public class DefaultWebsocketTest {
         defaultWebsocket.setConnectionKey(CONNECTION_KEY);
         defaultWebsocket.onMessage(MESSAGE);
         InOrder inOrder = inOrder(connection, consumer, sync);
-        inOrder.verify(consumer, times(0)).sendExchange(CONNECTION_KEY, MESSAGE);
+        inOrder.verify(consumer, times(0)).sendMessage(CONNECTION_KEY, MESSAGE);
         inOrder.verifyNoMoreInteractions();
     }
 

Modified: camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/NodeSynchronizationImplTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/NodeSynchronizationImplTest.java?rev=1301940&r1=1301939&r2=1301940&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/NodeSynchronizationImplTest.java
(original)
+++ camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/NodeSynchronizationImplTest.java
Sat Mar 17 14:05:55 2012
@@ -46,7 +46,6 @@ public class NodeSynchronizationImplTest
     private NodeSynchronization sync;
 
     private MemoryWebsocketStore store1;
-    private MemoryWebsocketStore store2;
 
     /**
      * @throws Exception
@@ -55,7 +54,6 @@ public class NodeSynchronizationImplTest
     public void setUp() throws Exception {
 
         store1 = new MemoryWebsocketStore();
-        store2 = new MemoryWebsocketStore();
 
         websocket1 = new DefaultWebsocket(sync, consumer);
         websocket1.setConnectionKey(KEY_1);
@@ -72,15 +70,13 @@ public class NodeSynchronizationImplTest
      */
     @Test
     public void testAddSocketMemoryAndGlobal() {
-        sync = new DefaultNodeSynchronization(store1, store2);
+        sync = new DefaultNodeSynchronization(store1);
 
         sync.addSocket(websocket1);
         assertEquals(websocket1, store1.get(KEY_1));
-        assertEquals(store1.get(KEY_1), store2.get(KEY_1));
 
         sync.addSocket(websocket2);
         assertEquals(websocket2, store1.get(KEY_2));
-        assertEquals(store1.get(KEY_2), store2.get(KEY_2));
     }
 
     /**
@@ -97,17 +93,6 @@ public class NodeSynchronizationImplTest
     /**
      * Test method for {@link org.apache.camel.component.websocket.NodeSynchronization#addSocket(org.apache.camel.component.websocket.DefaultWebsocket)}
.
      */
-    @Test
-    public void testAddSocketMemoryAndNullGlobal() {
-        sync = new DefaultNodeSynchronization(store1, null);
-
-        sync.addSocket(websocket1);
-        assertEquals(websocket1, store1.get(KEY_1));
-    }
-
-    /**
-     * Test method for {@link org.apache.camel.component.websocket.NodeSynchronization#addSocket(org.apache.camel.component.websocket.DefaultWebsocket)}
.
-     */
     @Test(expected = NullPointerException.class)
     public void testAddNullValue() {
         sync.addSocket(null);
@@ -118,28 +103,23 @@ public class NodeSynchronizationImplTest
      */
     @Test
     public void testRemoveDefaultWebsocket() {
-        sync = new DefaultNodeSynchronization(store1, store2);
+        sync = new DefaultNodeSynchronization(store1);
 
         // first call of websocket1.getConnectionKey()
         sync.addSocket(websocket1);
         assertEquals(websocket1, store1.get(KEY_1));
-        assertEquals(store1.get(KEY_1), store2.get(KEY_1));
 
         sync.addSocket(websocket2);
         assertEquals(websocket2, store1.get(KEY_2));
-        assertEquals(store1.get(KEY_2), store2.get(KEY_2));
 
         // second call of websocket1.getConnectionKey()
         sync.removeSocket(websocket1);
         assertNull(store1.get(KEY_1));
-        assertNull(store2.get(KEY_1));
 
         assertNotNull(store1.get(KEY_2));
-        assertNotNull(store2.get(KEY_2));
 
         sync.removeSocket(websocket2);
         assertNull(store1.get(KEY_2));
-        assertNull(store2.get(KEY_2));
     }
 
     /**
@@ -188,28 +168,23 @@ public class NodeSynchronizationImplTest
      */
     @Test
     public void testRemoveString() {
-        sync = new DefaultNodeSynchronization(store1, store2);
+        sync = new DefaultNodeSynchronization(store1);
 
         // first call of websocket1.getConnectionKey()
         sync.addSocket(websocket1);
         assertEquals(websocket1, store1.get(KEY_1));
-        assertEquals(store1.get(KEY_1), store2.get(KEY_1));
 
         sync.addSocket(websocket2);
         assertEquals(websocket2, store1.get(KEY_2));
-        assertEquals(store1.get(KEY_2), store2.get(KEY_2));
 
         // second call of websocket1.getConnectionKey()
         sync.removeSocket(KEY_1);
         assertNull(store1.get(KEY_1));
-        assertNull(store2.get(KEY_1));
 
         assertNotNull(store1.get(KEY_2));
-        assertNotNull(store2.get(KEY_2));
 
         sync.removeSocket(KEY_2);
         assertNull(store1.get(KEY_2));
-        assertNull(store2.get(KEY_2));
     }
 
     /**

Modified: camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketComponentServletTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketComponentServletTest.java?rev=1301940&r1=1301939&r2=1301940&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketComponentServletTest.java
(original)
+++ camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketComponentServletTest.java
Sat Mar 17 14:05:55 2012
@@ -80,7 +80,7 @@ public class WebsocketComponentServletTe
         defaultWebsocket.setConnectionKey(CONNECTION_KEY);
         defaultWebsocket.onMessage(MESSAGE);
         InOrder inOrder = inOrder(consumer, sync, request);
-        inOrder.verify(consumer, times(1)).sendExchange(CONNECTION_KEY, MESSAGE);
+        inOrder.verify(consumer, times(1)).sendMessage(CONNECTION_KEY, MESSAGE);
         inOrder.verifyNoMoreInteractions();
     }
 

Modified: camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketComponentTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketComponentTest.java?rev=1301940&r1=1301939&r2=1301940&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketComponentTest.java
(original)
+++ camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketComponentTest.java
Sat Mar 17 14:05:55 2012
@@ -41,7 +41,6 @@ import static org.junit.Assert.assertTru
 import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.inOrder;
 import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.when;
 
 /**
  *
@@ -133,20 +132,6 @@ public class WebsocketComponentTest {
     }
 
     @Test
-    public void testSetServletConsumer() throws Exception {
-        when(servlet.getConsumer()).thenReturn(null, null, consumer);
-        InOrder inOrder = inOrder(servlet, consumer, sync);
-        component.setServletConsumer(servlet, null); // null && null
-        inOrder.verify(servlet, times(0)).setConsumer(null);
-        component.setServletConsumer(servlet, consumer); // null && not null
-        inOrder.verify(servlet, times(1)).setConsumer(consumer);
-        component.setServletConsumer(servlet, null); // not null && null
-        inOrder.verify(servlet, times(0)).setConsumer(consumer);
-        component.setServletConsumer(servlet, consumer); // not null && not null
-        inOrder.verify(servlet, times(0)).setConsumer(consumer);
-    }
-
-    @Test
     public void testCreateServlet() throws Exception {
         component.createServlet(sync, PATH_SPEC_ONE, servlets, handler);
         InOrder inOrder = inOrder(servlet, consumer, sync, servlets, handler);
@@ -159,12 +144,6 @@ public class WebsocketComponentTest {
     }
 
     @Test
-    public void testCreatePathSpec() {
-        assertEquals(PATH_SPEC_ONE, component.createPathSpec(PATH_ONE));
-        assertEquals(PATH_SPEC_TWO, component.createPathSpec(PATH_TWO));
-    }
-
-    @Test
     public void testAddServletProducersOnly() throws Exception {
         component.setCamelContext(camelContext);
         component.setPort(0);

Modified: camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerTest.java?rev=1301940&r1=1301939&r2=1301940&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerTest.java
(original)
+++ camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerTest.java
Sat Mar 17 14:05:55 2012
@@ -69,7 +69,7 @@ public class WebsocketConsumerTest {
         when(endpoint.createExchange()).thenReturn(exchange);
         when(exchange.getIn()).thenReturn(outMessage);
 
-        websocketConsumer.sendExchange(CONNECTION_KEY, MESSAGE);
+        websocketConsumer.sendMessage(CONNECTION_KEY, MESSAGE);
 
         InOrder inOrder = inOrder(endpoint, exceptionHandler, processor, exchange, outMessage);
         inOrder.verify(endpoint, times(1)).createExchange();
@@ -89,7 +89,7 @@ public class WebsocketConsumerTest {
         doThrow(exception).when(processor).process(exchange);
         when(exchange.getException()).thenReturn(exception);
 
-        websocketConsumer.sendExchange(CONNECTION_KEY, MESSAGE);
+        websocketConsumer.sendMessage(CONNECTION_KEY, MESSAGE);
 
         InOrder inOrder = inOrder(endpoint, exceptionHandler, processor, exchange, outMessage);
         inOrder.verify(endpoint, times(1)).createExchange();
@@ -110,7 +110,7 @@ public class WebsocketConsumerTest {
         doThrow(exception).when(processor).process(exchange);
         when(exchange.getException()).thenReturn(null);
 
-        websocketConsumer.sendExchange(CONNECTION_KEY, MESSAGE);
+        websocketConsumer.sendMessage(CONNECTION_KEY, MESSAGE);
 
         InOrder inOrder = inOrder(endpoint, exceptionHandler, processor, exchange, outMessage);
         inOrder.verify(endpoint, times(1)).createExchange();

Modified: camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketEndpointTest.java?rev=1301940&r1=1301939&r2=1301940&view=diff
==============================================================================
--- camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketEndpointTest.java
(original)
+++ camel/trunk/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketEndpointTest.java
Sat Mar 17 14:05:55 2012
@@ -57,7 +57,7 @@ public class WebsocketEndpointTest {
      */
     @Before
     public void setUp() throws Exception {
-        websocketEndpoint = new WebsocketEndpoint(URI, component, REMAINING, new WebsocketConfiguration());
+        websocketEndpoint = new WebsocketEndpoint(URI, component, REMAINING);
     }
 
     /**



Mime
View raw message