Skip to content

Commit 4c7ad95

Browse files
committed
Add a new test instead of modifying the original
1 parent 55d55ec commit 4c7ad95

File tree

4 files changed

+73
-19
lines changed

4 files changed

+73
-19
lines changed

activemq-runtime-config/src/main/java/org/apache/activemq/plugin/NetworkConnectorsProcessor.java

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.apache.activemq.schema.core.DtoNetworkConnector;
2020

21+
import java.util.ArrayList;
2122
import java.util.List;
2223

2324
public class NetworkConnectorsProcessor extends DefaultConfigurationProcessor {
@@ -36,28 +37,28 @@ public ConfigurationProcessor findProcessor(Object o) {
3637

3738
@Override
3839
protected void applyModifications(List<Object> current, List<Object> modification) {
39-
outer:
40-
for (Object modObj : modification) {
41-
ConfigurationProcessor processor = findProcessor(modObj);
42-
for (Object currentObj : current) {
43-
if (modObj.equals(currentObj)) {
44-
// If the object is already in the current list, we can skip it
45-
plugin.debug("Skipping unchanged network connector: " + modObj);
46-
continue outer; // Skip to the next modObj
40+
// Remove items not in modification
41+
for (Object currentObj : new ArrayList<>(current)) {
42+
if (!modification.contains(currentObj)) {
43+
ConfigurationProcessor processor = findProcessor(currentObj);
44+
if (processor != null) {
45+
processor.remove(currentObj);
4746
} else {
48-
// if the modObj doesn't match, remove it
49-
if (processor != null) {
50-
processor.remove(currentObj);
51-
} else {
52-
remove(currentObj);
53-
}
47+
remove(currentObj);
5448
}
5549
}
56-
// If we reach here, it means the modObj is not in the current list
57-
if (processor != null) {
58-
processor.addNew(modObj);
50+
}
51+
// Add new items from modification
52+
for (Object modObj : modification) {
53+
if (!current.contains(modObj)) {
54+
ConfigurationProcessor processor = findProcessor(modObj);
55+
if (processor != null) {
56+
processor.addNew(modObj);
57+
} else {
58+
addNew(modObj);
59+
}
5960
} else {
60-
addNew(modObj);
61+
plugin.debug("Skipping unchanged network connector: " + modObj);
6162
}
6263
}
6364
}

activemq-runtime-config/src/test/java/org/apache/activemq/NetworkConnectorTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,23 @@ public boolean isSatisified() throws Exception {
141141
assertNotNull(brokerService.getManagementContext().getObjectInstance(
142142
brokerService.createNetworkConnectorObjectName(remainingNetworkConnector)));
143143
}
144+
145+
@Test
146+
public void testUnchangedNetworkConnector() throws Exception {
147+
final String brokerConfig = configurationSeed + "-two-nc-broker";
148+
applyNewConfig(brokerConfig, configurationSeed + "-two-nc");
149+
startBroker(brokerConfig);
150+
assertTrue("broker alive", brokerService.isStarted());
151+
assertEquals("two network connectors", 2, brokerService.getNetworkConnectors().size());
152+
153+
// apply a config that changes the order only
154+
applyNewConfig(brokerConfig, configurationSeed + "-two-b-nc", SLEEP);
155+
156+
assertTrue("expected mod on time", Wait.waitFor(new Wait.Condition() {
157+
@Override
158+
public boolean isSatisified() throws Exception {
159+
return 2 == brokerService.getNetworkConnectors().size();
160+
}
161+
}));
162+
}
144163
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<beans
19+
xmlns="http://www.springframework.org/schema/beans"
20+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
21+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
22+
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
23+
24+
<broker xmlns="http://activemq.apache.org/schema/core" start="false" persistent="false" >
25+
<plugins>
26+
<runtimeConfigurationPlugin checkPeriod="1000" />
27+
</plugins>
28+
29+
<networkConnectors>
30+
<networkConnector uri="static:(tcp://localhost:5555)" networkTTL="1" name="two"/>
31+
<networkConnector uri="static:(tcp://localhost:5555)" networkTTL="1" name="one"/>
32+
</networkConnectors>
33+
</broker>
34+
</beans>

activemq-runtime-config/src/test/resources/org/apache/activemq/networkConnectorTest-two-nc.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
</plugins>
2828

2929
<networkConnectors>
30-
<networkConnector uri="static:(tcp://localhost:5555)" networkTTL="1" name="two"/>
3130
<networkConnector uri="static:(tcp://localhost:5555)" networkTTL="1" name="one"/>
31+
<networkConnector uri="static:(tcp://localhost:5555)" networkTTL="1" name="two"/>
3232
</networkConnectors>
3333
</broker>
3434
</beans>

0 commit comments

Comments
 (0)