Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ public void shutdown() throws Exception {
this.updateOffsetExecutor.shutdown();
this.topicRouteExecutor.shutdown();
this.defaultExecutor.shutdown();
// The constructor schedules the expired-request cleanup on this executor; leaving it running
// keeps a non-daemon thread (and its 100ms task) alive after the server has shut down.
this.timerExecutor.shutdown();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

package org.apache.rocketmq.proxy.remoting;

import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.ScheduledExecutorService;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.rocketmq.proxy.remoting.channel.RemotingChannelManager;
import org.apache.rocketmq.proxy.service.cert.TlsCertificateManager;
import org.apache.rocketmq.remoting.RemotingServer;
import org.apache.rocketmq.remoting.protocol.RequestHeaderRegistry;
import org.junit.Test;
Expand All @@ -26,9 +31,30 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.times;

public class RemotingProtocolServerTest {

@Test
public void testShutdownStopsTheExpiredRequestTimer() throws Exception {
RemotingProtocolServer protocolServer = mock(RemotingProtocolServer.class, Mockito.CALLS_REAL_METHODS);
FieldUtils.writeDeclaredField(protocolServer, "tlsCertificateManager", mock(TlsCertificateManager.class), true);
FieldUtils.writeDeclaredField(protocolServer, "remotingChannelManager", mock(RemotingChannelManager.class), true);
FieldUtils.writeDeclaredField(protocolServer, "defaultRemotingServer", mock(RemotingServer.class), true);
for (String field : new String[] {"sendMessageExecutor", "pullMessageExecutor", "heartbeatExecutor",
"updateOffsetExecutor", "topicRouteExecutor", "defaultExecutor"}) {
FieldUtils.writeDeclaredField(protocolServer, field, mock(ThreadPoolExecutor.class), true);
}
ScheduledExecutorService timerExecutor = mock(ScheduledExecutorService.class);
FieldUtils.writeDeclaredField(protocolServer, "timerExecutor", timerExecutor, true);

protocolServer.shutdown();

// The constructor schedules the expired-request cleanup on this executor; a shutdown that
// leaves it running keeps a non-daemon thread (and its 100ms task) alive after the server.
verify(timerExecutor, times(1)).shutdown();
}

@Test
public void shouldInitializeRequestHeaderRegistryWhenRegisteringProcessors() {
RemotingProtocolServer protocolServer =
Expand Down
Loading