Skip to content

Commit 175d32d

Browse files
jbertramclebertsuconic
authored andcommitted
ARTEMIS-5861 fix doc & test issue
This commit also increases the DEFAULT_SHUTDOWN_TIMEOUT used on the test-suite from 0 to 7200000 (i.e. 2 hours) in order to ensure the timeout code is exercised and to expose any issues with closing the Netty ChannelGroups or EventLoopGroup.
1 parent 14e2c1a commit 175d32d

File tree

6 files changed

+62
-21
lines changed

6 files changed

+62
-21
lines changed

artemis-core-client/src/test/java/org/apache/activemq/artemis/core/remoting/impl/netty/TransportConstantTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ public class TransportConstantTest {
2929
@Test
3030
public void testDefaultOnPom() {
3131
assertEquals(0, TransportConstants.DEFAULT_QUIET_PERIOD, "It is expected to have the default at 0 on the testsuite");
32-
assertEquals(0, TransportConstants.DEFAULT_SHUTDOWN_TIMEOUT, "It is expected to have the default at 0 on the testsuite");
32+
assertEquals(7200000, TransportConstants.DEFAULT_SHUTDOWN_TIMEOUT, "It is expected to have the default at 0 on the testsuite");
3333
}
3434
}

artemis-server/src/main/java/org/apache/activemq/artemis/core/remoting/impl/netty/NettyAcceptor.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -852,12 +852,16 @@ public synchronized void asyncStop(Runnable callback) {
852852
}
853853

854854
private void closeChannelGroup(ChannelGroup channelGroup) {
855-
if (channelGroup != null && !channelGroup.close().awaitUninterruptibly(shutdownTimeout, TimeUnit.MILLISECONDS)) {
856-
ActiveMQServerLogger.LOGGER.nettyChannelGroupError(getName());
857-
for (Channel channel : channelGroup) {
858-
if (channel.isActive()) {
859-
ActiveMQServerLogger.LOGGER.nettyChannelStillOpen(channel, ProxyProtocolUtil.getRemoteAddress(channel), getName());
855+
if (channelGroup != null) {
856+
if (shutdownTimeout > 0 && !channelGroup.close().awaitUninterruptibly(shutdownTimeout, TimeUnit.MILLISECONDS)) {
857+
ActiveMQServerLogger.LOGGER.nettyChannelGroupError(getName(), shutdownTimeout);
858+
for (Channel channel : channelGroup) {
859+
if (channel.isActive()) {
860+
ActiveMQServerLogger.LOGGER.nettyChannelStillOpen(channel, ProxyProtocolUtil.getRemoteAddress(channel), getName());
861+
}
860862
}
863+
} else {
864+
channelGroup.close();
861865
}
862866
}
863867
}
@@ -895,13 +899,15 @@ public synchronized void pause() {
895899

896900
// We *pause* the acceptor so no new connections are made
897901
if (serverChannelGroup != null) {
898-
if (!serverChannelGroup.close().awaitUninterruptibly(shutdownTimeout, TimeUnit.MILLISECONDS)) {
899-
ActiveMQServerLogger.LOGGER.nettyChannelGroupBindError();
902+
if (shutdownTimeout > 0 && !serverChannelGroup.close().awaitUninterruptibly(shutdownTimeout, TimeUnit.MILLISECONDS)) {
903+
ActiveMQServerLogger.LOGGER.nettyChannelGroupBindErrorOnPause(getName(), shutdownTimeout);
900904
for (Channel channel : serverChannelGroup) {
901905
if (channel.isActive()) {
902-
ActiveMQServerLogger.LOGGER.nettyChannelStillBound(channel, ProxyProtocolUtil.getRemoteAddress(channel));
906+
ActiveMQServerLogger.LOGGER.nettyChannelStillBoundOnPause(channel, ProxyProtocolUtil.getRemoteAddress(channel), getName());
903907
}
904908
}
909+
} else {
910+
serverChannelGroup.close();
905911
}
906912
}
907913
paused = true;

artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServerLogger.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,17 +492,17 @@ void slowConsumerDetected(String sessionID,
492492
@LogMessage(id = 222072, value = "Timed out flushing channel on InVMConnection", level = LogMessage.Level.WARN)
493493
void timedOutFlushingInvmChannel();
494494

495-
@LogMessage(id = 222074, value = "Netty ChannelGroup did not completely close for acceptor '{}'", level = LogMessage.Level.WARN)
496-
void nettyChannelGroupError(String acceptor);
495+
@LogMessage(id = 222074, value = "Netty ChannelGroup for acceptor '{}' did not completely close within {}ms timeout", level = LogMessage.Level.WARN)
496+
void nettyChannelGroupError(String acceptor, int timeout);
497497

498498
@LogMessage(id = 222075, value = "{} is still connected to {} for acceptor '{}'", level = LogMessage.Level.WARN)
499499
void nettyChannelStillOpen(Channel channel, String remoteAddress, String acceptor);
500500

501-
@LogMessage(id = 222076, value = "channel group did not completely unbind", level = LogMessage.Level.WARN)
502-
void nettyChannelGroupBindError();
501+
@LogMessage(id = 222076, value = "Netty ChannelGroup did not completely unbind within {}ms timeout when pausing acceptor '{}'", level = LogMessage.Level.WARN)
502+
void nettyChannelGroupBindErrorOnPause(String acceptor, int timeout);
503503

504-
@LogMessage(id = 222077, value = "{} is still bound to {}", level = LogMessage.Level.WARN)
505-
void nettyChannelStillBound(Channel channel, String remoteAddress);
504+
@LogMessage(id = 222077, value = "{} is still bound to {} when pausing acceptor '{}'", level = LogMessage.Level.WARN)
505+
void nettyChannelStillBoundOnPause(Channel channel, String remoteAddress, String acceptor);
506506

507507
@LogMessage(id = 222080, value = "Error creating acceptor: {}", level = LogMessage.Level.WARN)
508508
void errorCreatingAcceptor(String name, Exception e);

artemis-unit-test-support/src/main/java/org/apache/activemq/artemis/logs/AssertionLoggerHandler.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,43 @@ public void close() throws IOException {
7979
}
8080

8181
/**
82-
* is there any record matching Level?
82+
* Determines whether there is any log entry matching the specified log level.
83+
*
84+
* @param level the log level to check for in the log entries
85+
* @return true if a log entry matches the specified log level; otherwise, false
8386
*/
8487
public boolean hasLevel(LogLevel level) {
88+
return hasLevel(level, null);
89+
}
90+
91+
/**
92+
* Determines whether there is any log entry matching the specified log level while optionally ignoring messages that
93+
* contain specified substrings.
94+
*
95+
* @param level the log level to check for in the log entries
96+
* @param ignores a list of substrings; log messages containing any of these substrings will be ignored during the
97+
* check
98+
* @return true if a log entry matches the specified log level and does not contain any of the ignored substrings;
99+
* otherwise, false
100+
*/
101+
public boolean hasLevel(LogLevel level, List<String> ignores) {
85102
Level implLevel = level.toImplLevel();
86103
for (LogEntry logEntry : messages) {
87104
if (implLevel == logEntry.level) {
88-
return true;
105+
if (ignores != null) {
106+
boolean ignoreFound = false;
107+
for (String ignore : ignores) {
108+
if (logEntry.message.contains(ignore)) {
109+
ignoreFound = true;
110+
break;
111+
}
112+
}
113+
if (!ignoreFound) {
114+
return true;
115+
}
116+
} else {
117+
return true;
118+
}
89119
}
90120
}
91121

docs/user-manual/configuring-transports.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ shutdownTimeout::
240240
This is only valid for acceptors.
241241
It is the number of milliseconds the broker will wait when shutting down each of the various Netty `ChannelGroup` instances as well as the `EventLoopGroup` instance associated with the acceptor.
242242
The default is `3000`.
243-
The default can also be set with the Java system property `DEFAULT_SHUTDOWN_TIMEOUT`.
243+
The default can also be set with the Java system property `org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants.DEFAULT_SHUTDOWN_TIMEOUT`.
244244

245245
=== Configuring Netty Native Transport
246246

pom.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,14 @@
256256
<!-- for tests that will need a new server created -->
257257
<artemis.distribution.output>${activemq.basedir}/artemis-distribution/target/apache-artemis-${project.version}-bin/apache-artemis-${project.version}</artemis.distribution.output>
258258

259-
<activemq-surefire-argline>-Dbrokerconfig.maxDiskUsage=100 -Dorg.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants.DEFAULT_QUIET_PERIOD=0 -Dorg.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants.DEFAULT_SHUTDOWN_TIMEOUT=0
260-
-Djava.library.path="${activemq.basedir}/target/bin/lib/linux-x86_64:${activemq.basedir}/target/bin/lib/linux-i686" -Djgroups.bind_addr=localhost
261-
-Djava.net.preferIPv4Stack=true -Dbasedir=${basedir}
259+
<activemq-surefire-argline>
260+
-Dbrokerconfig.maxDiskUsage=100
261+
-Dorg.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants.DEFAULT_QUIET_PERIOD=0
262+
-Dorg.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants.DEFAULT_SHUTDOWN_TIMEOUT=7200000
263+
-Djava.library.path="${activemq.basedir}/target/bin/lib/linux-x86_64:${activemq.basedir}/target/bin/lib/linux-i686"
264+
-Djgroups.bind_addr=localhost
265+
-Djava.net.preferIPv4Stack=true
266+
-Dbasedir=${basedir}
262267
-Djdk.attach.allowAttachSelf=true
263268
-Dartemis.distribution.output="${artemis.distribution.output}"
264269
-Dlog4j2.configurationFile="file:${activemq.basedir}/tests/config/${logging.config}"

0 commit comments

Comments
 (0)