-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-1419: Fix Early Exit in NodeLocator
If a node was returned by the REST call and the node was not in the map of nodes to addreses, the loop exited early. The incorrect variable was being tested (never null). Also add a more sophisticated integration test - using 2 brokers, ensure that the correct broker is located for the queue.
- Loading branch information
1 parent
8b4dd86
commit 8045f2c
Showing
9 changed files
with
158 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
69 changes: 69 additions & 0 deletions
69
spring-rabbit/src/test/java/org/springframework/amqp/rabbit/connection/NodeLocatorTests.java
This file contains 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,69 @@ | ||
/* | ||
* Copyright 2022 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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.springframework.amqp.rabbit.connection; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import java.net.URISyntaxException; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import org.springframework.amqp.rabbit.connection.LocalizedQueueConnectionFactory.NodeLocator; | ||
import org.springframework.lang.Nullable; | ||
|
||
/** | ||
* @author Gary Russell | ||
* @since 3.0 | ||
* | ||
*/ | ||
public class NodeLocatorTests { | ||
|
||
@Test | ||
@DisplayName("don't exit early when node to address missing") | ||
void missingNode() throws URISyntaxException { | ||
|
||
NodeLocator<Object> nodeLocator = spy(new NodeLocator<Object>() { | ||
|
||
@Override | ||
public Object createClient(String userName, String password) { | ||
return null; | ||
} | ||
|
||
@Override | ||
@Nullable | ||
public Map<String, Object> restCall(Object client, String baseUri, String vhost, String queue) { | ||
if (baseUri.contains("foo")) { | ||
return Map.of("node", "c@d"); | ||
} | ||
else { | ||
return Map.of("node", "a@b"); | ||
} | ||
} | ||
}); | ||
ConnectionFactory factory = nodeLocator.locate(new String[] { "http://foo", "http://bar" }, | ||
Map.of("a@b", "baz"), null, "q", null, null, (q, n, u) -> { | ||
return null; | ||
}); | ||
verify(nodeLocator, times(2)).restCall(any(), any(), any(), any()); | ||
} | ||
|
||
} |