mirror of
https://github.com/apache/activemq-artemis.git
synced 2025-03-03 15:59:53 +00:00
ARTEMIS-4905 fix conversion to millis for periodSeconds comparison in expiry plugin
This commit is contained in:
parent
e65001aead
commit
76877b7fb4
@ -62,6 +62,7 @@ public class ConnectionPeriodicExpiryPlugin implements ActiveMQServerBasePlugin
|
||||
executor = server.getScheduledPool();
|
||||
remotingService = server.getRemotingService();
|
||||
matchPattern = Pattern.compile(acceptorMatchRegex);
|
||||
final long periodMillis = TimeUnit.SECONDS.toMillis(periodSeconds);
|
||||
|
||||
task = executor.scheduleWithFixedDelay(() -> {
|
||||
try {
|
||||
@ -73,7 +74,7 @@ public class ConnectionPeriodicExpiryPlugin implements ActiveMQServerBasePlugin
|
||||
|
||||
for (NettyServerConnection nettyServerConnection : nettyAcceptor.getConnections().values()) {
|
||||
RemotingConnection remotingConnection = remotingService.getConnection(nettyServerConnection.getID());
|
||||
if (remotingConnection != null && currentTime > remotingConnection.getCreationTime() + periodSeconds) {
|
||||
if (remotingConnection != null && currentTime > remotingConnection.getCreationTime() + periodMillis) {
|
||||
executor.schedule(() -> {
|
||||
remotingService.removeConnection(remotingConnection.getID());
|
||||
remotingConnection.fail(new ActiveMQDisconnectedException("terminated by session expiry plugin"));
|
||||
|
@ -32,6 +32,8 @@ import org.junit.jupiter.api.Timeout;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
public class ConnectionPeriodicExpiryPluginTest extends MultiprotocolJMSClientTestSupport {
|
||||
|
||||
protected static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
|
||||
@ -40,7 +42,7 @@ public class ConnectionPeriodicExpiryPluginTest extends MultiprotocolJMSClientTe
|
||||
protected void addConfiguration(ActiveMQServer server) throws Exception {
|
||||
|
||||
ConnectionPeriodicExpiryPlugin plugin = new ConnectionPeriodicExpiryPlugin();
|
||||
plugin.setPeriodSeconds(1);
|
||||
plugin.setPeriodSeconds(2);
|
||||
plugin.setAccuracyWindowSeconds(1);
|
||||
plugin.setAcceptorMatchRegex("netty-acceptor");
|
||||
server.getConfiguration().getBrokerPlugins().add(plugin);
|
||||
@ -67,7 +69,7 @@ public class ConnectionPeriodicExpiryPluginTest extends MultiprotocolJMSClientTe
|
||||
testExpiry(connection);
|
||||
}
|
||||
|
||||
private void testExpiry(Connection connection) throws JMSException {
|
||||
private void testExpiry(Connection connection) throws JMSException, InterruptedException {
|
||||
try {
|
||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
||||
javax.jms.Queue queue = session.createQueue(getQueueName());
|
||||
@ -80,7 +82,8 @@ public class ConnectionPeriodicExpiryPluginTest extends MultiprotocolJMSClientTe
|
||||
connection.setExceptionListener(exception -> {
|
||||
gotExpired.countDown(); });
|
||||
|
||||
Wait.assertTrue(() -> gotExpired.await(100, TimeUnit.MILLISECONDS), 2000, 100);
|
||||
assertFalse(gotExpired.await(1500, TimeUnit.MILLISECONDS));
|
||||
Wait.assertTrue(() -> gotExpired.await(100, TimeUnit.MILLISECONDS), 4000, 100);
|
||||
|
||||
} finally {
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user