ARTEMIS-4691 log.warn on inVM closing

This commit is contained in:
Clebert Suconic 2024-03-18 10:32:29 -04:00 committed by Justin Bertram
parent 50fae08b09
commit 499a4eab6b
3 changed files with 85 additions and 7 deletions

View File

@ -205,23 +205,30 @@ public class RemotingConnectionImpl extends AbstractRemotingConnection implement
ActiveMQClientLogger.LOGGER.connectionClosureDetected(transportConnection.getRemoteAddress(), me.getMessage(), me.getType());
}
// Then call the listeners
callFailureListeners(me, scaleDownTargetNodeID);
close();
for (Channel channel : channels.values()) {
channel.returnBlocking(me);
}
}
@Override
public void close() {
try {
transportConnection.forceClose();
} catch (Throwable e) {
ActiveMQClientLogger.LOGGER.failedForceClose(e);
}
// Then call the listeners
callFailureListeners(me, scaleDownTargetNodeID);
callClosingListeners();
internalClose();
}
for (Channel channel : channels.values()) {
channel.returnBlocking(me);
}
}
@Override
public void destroy() {

View File

@ -198,6 +198,14 @@ public class AssertionLoggerHandler extends AbstractAppender implements Closeabl
}
}
public void clear() {
messages.clear();
}
public int getNumberOfMessages() {
return messages.size();
}
private static class LogEntry {
String message;
String stackTrace;

View File

@ -0,0 +1,63 @@
/*
* 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
* <br>
* http://www.apache.org/licenses/LICENSE-2.0
* <br>
* 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.activemq.artemis.tests.integration;
import org.apache.activemq.artemis.api.core.client.ClientSession;
import org.apache.activemq.artemis.api.core.client.ClientSessionFactory;
import org.apache.activemq.artemis.api.core.client.ServerLocator;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.logs.AssertionLoggerHandler;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class InVMCloseTest extends ActiveMQTestBase {
protected ActiveMQServer server;
@Override
@Before
public void setUp() throws Exception {
super.setUp();
server = createServer(false, createDefaultInVMConfig());
server.start();
}
@Test
public void validateCloseLogging() throws Exception {
ServerLocator locator;
ClientSessionFactory sf;
ClientSession session;
locator = createInVMNonHALocator();
sf = createSessionFactory(locator);
session = addClientSession(sf.createSession(false, true, true));
try (AssertionLoggerHandler loggerHandler = new AssertionLoggerHandler(true)) {
session.close();
sf.close();
locator.close();
Assert.assertFalse(loggerHandler.findText("AMQ212037"));
// additional logging debug might fail the test, but this is meant to be silent on a regular case.
// I wanted to make sure we don't do any extra logging when a connection is closed.
Assert.assertEquals("Logger should be silent for the close operation.", 0, loggerHandler.getNumberOfMessages());
}
}
}