-
Notifications
You must be signed in to change notification settings - Fork 5.2k
CAMEL-24789: camel-vertx-websocket - finish an exchange with no peer synchronously #26541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f4e2783
CAMEL-24789: camel-vertx-websocket - finish an exchange with no peer …
oscerd b59fc18
CAMEL-24789: write the test in the assertion style of the module
oscerd 8b95506
CAMEL-24789: camel-vertx-websocket - cover the two gaps left in the n…
oscerd 8a77a8f
CAMEL-24789: log a broadcast that reaches nobody at debug
oscerd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...est/java/org/apache/camel/component/vertx/websocket/VertxWebsocketProducerNoPeerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.camel.component.vertx.websocket; | ||
|
|
||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import java.util.concurrent.atomic.AtomicReference; | ||
|
|
||
| import org.apache.camel.Exchange; | ||
| import org.apache.camel.impl.DefaultCamelContext; | ||
| import org.apache.camel.support.DefaultExchange; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| /** | ||
| * An exchange with no peer to send to is finished by the producer itself, so it has to report that it was done | ||
| * synchronously. Builds the endpoint directly, so nothing reaches a server. | ||
| */ | ||
| class VertxWebsocketProducerNoPeerTest { | ||
|
|
||
| private DefaultCamelContext context; | ||
|
|
||
| @AfterEach | ||
| void tearDown() { | ||
| if (context != null) { | ||
| context.stop(); | ||
| } | ||
| } | ||
|
|
||
| private VertxWebsocketProducer producer() throws Exception { | ||
| context = new DefaultCamelContext(); | ||
|
|
||
| VertxWebsocketComponent component = new VertxWebsocketComponent(); | ||
| component.setCamelContext(context); | ||
|
|
||
| VertxWebsocketEndpoint endpoint | ||
| = (VertxWebsocketEndpoint) component.createEndpoint("vertx-websocket:localhost:1234/test"); | ||
| return (VertxWebsocketProducer) endpoint.createProducer(); | ||
| } | ||
|
|
||
| @Test | ||
| void anExchangeWithNoPeerIsDoneSynchronously() throws Exception { | ||
| VertxWebsocketProducer producer = producer(); | ||
|
|
||
| Exchange exchange = new DefaultExchange(context); | ||
| exchange.getIn().setBody("a message nobody is listening for"); | ||
| // broadcasting to an empty host registry is the one path that reaches no peer without opening a connection | ||
| exchange.getIn().setHeader(VertxWebsocketConstants.SEND_TO_ALL, true); | ||
|
|
||
| AtomicInteger callbacks = new AtomicInteger(); | ||
| AtomicReference<Boolean> doneSync = new AtomicReference<>(); | ||
|
|
||
| // the callback used to be completed with doneSync=true while the method returned false, which says the | ||
| // opposite: that the exchange would be finished from a write handler that never runs | ||
| boolean result = producer.process(exchange, sync -> { | ||
| callbacks.incrementAndGet(); | ||
| doneSync.set(sync); | ||
| }); | ||
|
|
||
| assertTrue(result, "process must report that it finished the exchange itself"); | ||
| assertEquals(1, callbacks.get()); | ||
| assertTrue(doneSync.get()); | ||
| assertNull(exchange.getException()); | ||
| } | ||
|
|
||
| @Test | ||
| void anExchangeWithNoBodyIsDoneSynchronously() throws Exception { | ||
| VertxWebsocketProducer producer = producer(); | ||
|
|
||
| Exchange exchange = new DefaultExchange(context); | ||
|
|
||
| AtomicInteger callbacks = new AtomicInteger(); | ||
| AtomicReference<Boolean> doneSync = new AtomicReference<>(); | ||
| boolean result = producer.process(exchange, sync -> { | ||
| callbacks.incrementAndGet(); | ||
| doneSync.set(sync); | ||
| }); | ||
|
|
||
| assertTrue(result, "process must report that it finished the exchange itself"); | ||
| // the same triple as the first test: completing the callback twice would also satisfy the other two | ||
| assertEquals(1, callbacks.get()); | ||
| assertTrue(doneSync.get()); | ||
|
oscerd marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
oscerd marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.