This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch exchange-factory
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/exchange-factory by this push:
new 7020d53 CAMEL-16222: PooledExchangeFactory experiment
7020d53 is described below
commit 7020d533cb5e9dd744d0ee4dae8a15cfbe0dddd0
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Feb 24 09:17:22 2021 +0100
CAMEL-16222: PooledExchangeFactory experiment
---
.../component/websocket/WebsocketConsumerTest.java | 23 ++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git
a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerTest.java
b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerTest.java
index 9a703e1..f52092f 100644
---
a/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerTest.java
+++
b/components/camel-websocket/src/test/java/org/apache/camel/component/websocket/WebsocketConsumerTest.java
@@ -18,10 +18,12 @@ package org.apache.camel.component.websocket;
import java.net.InetSocketAddress;
-import org.apache.camel.Exchange;
+import org.apache.camel.ExtendedCamelContext;
+import org.apache.camel.ExtendedExchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.spi.ExceptionHandler;
+import org.apache.camel.spi.ExchangeFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InOrder;
@@ -49,28 +51,37 @@ public class WebsocketConsumerTest {
@Mock
private Processor processor;
@Mock
- private Exchange exchange;
+ private ExtendedExchange exchange;
@Mock
private Message outMessage;
+ @Mock
+ private ExtendedCamelContext context;
+ @Mock
+ private ExchangeFactory exchangeFactory;
private Exception exception = new Exception("BAD NEWS EVERYONE!");
private WebsocketConsumer websocketConsumer;
@BeforeEach
public void setUp() throws Exception {
+ when(endpoint.getCamelContext()).thenReturn(context);
+ when(context.adapt(ExtendedCamelContext.class)).thenReturn(context);
+ when(context.getExchangeFactory()).thenReturn(exchangeFactory);
+
when(exchangeFactory.newExchangeFactory(any())).thenReturn(exchangeFactory);
+ when(exchangeFactory.create(endpoint, true)).thenReturn(exchange);
+ when(exchange.adapt(ExtendedExchange.class)).thenReturn(exchange);
+
websocketConsumer = new WebsocketConsumer(endpoint, processor);
websocketConsumer.setExceptionHandler(exceptionHandler);
}
@Test
public void testSendExchange() throws Exception {
- when(endpoint.createExchange()).thenReturn(exchange);
when(exchange.getIn()).thenReturn(outMessage);
websocketConsumer.sendMessage(CONNECTION_KEY, MESSAGE, ADDRESS);
InOrder inOrder = inOrder(endpoint, exceptionHandler, processor,
exchange, outMessage);
- inOrder.verify(endpoint, times(1)).createExchange();
inOrder.verify(exchange, times(1)).getIn();
inOrder.verify(outMessage,
times(1)).setHeader(WebsocketConstants.CONNECTION_KEY, CONNECTION_KEY);
inOrder.verify(exchange, times(1)).getIn();
@@ -82,7 +93,6 @@ public class WebsocketConsumerTest {
@Test
public void testSendExchangeWithException() throws Exception {
- when(endpoint.createExchange()).thenReturn(exchange);
when(exchange.getIn()).thenReturn(outMessage);
doThrow(exception).when(processor).process(exchange);
when(exchange.getException()).thenReturn(exception);
@@ -90,7 +100,6 @@ public class WebsocketConsumerTest {
websocketConsumer.sendMessage(CONNECTION_KEY, MESSAGE, ADDRESS);
InOrder inOrder = inOrder(endpoint, exceptionHandler, processor,
exchange, outMessage);
- inOrder.verify(endpoint, times(1)).createExchange();
inOrder.verify(exchange, times(1)).getIn();
inOrder.verify(outMessage,
times(1)).setHeader(WebsocketConstants.CONNECTION_KEY, CONNECTION_KEY);
inOrder.verify(exchange, times(1)).getIn();
@@ -103,7 +112,6 @@ public class WebsocketConsumerTest {
@Test
public void testSendExchangeWithExchangeExceptionIsNull() throws Exception
{
- when(endpoint.createExchange()).thenReturn(exchange);
when(exchange.getIn()).thenReturn(outMessage);
doThrow(exception).when(processor).process(exchange);
when(exchange.getException()).thenReturn(null);
@@ -111,7 +119,6 @@ public class WebsocketConsumerTest {
websocketConsumer.sendMessage(CONNECTION_KEY, MESSAGE, ADDRESS);
InOrder inOrder = inOrder(endpoint, exceptionHandler, processor,
exchange, outMessage);
- inOrder.verify(endpoint, times(1)).createExchange();
inOrder.verify(exchange, times(1)).getIn();
inOrder.verify(outMessage,
times(1)).setHeader(WebsocketConstants.CONNECTION_KEY, CONNECTION_KEY);
inOrder.verify(exchange, times(1)).getIn();