Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

package org.apache.rocketmq.client.impl.mqclient;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import java.util.List;
import java.util.concurrent.ScheduledExecutorService;
Expand All @@ -27,30 +28,30 @@
import org.apache.rocketmq.common.MixAll;
import org.apache.rocketmq.common.utils.ThreadUtils;
import org.apache.rocketmq.remoting.RPCHook;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

class MQClientAPITest {
public class MQClientAPITest {

private NameserverAccessConfig nameserverAccessConfig;
private final ClientRemotingProcessor clientRemotingProcessor = new DoNothingClientRemotingProcessor(null);
private final RPCHook rpcHook = null;
private ScheduledExecutorService scheduledExecutorService;
private MQClientAPIFactory mqClientAPIFactory;

@BeforeEach
void setUp() {
@Before
public void setUp() {
scheduledExecutorService = ThreadUtils.newSingleThreadScheduledExecutor("TestScheduledExecutorService", true);
}

@AfterEach
@After
public void tearDown() {
scheduledExecutorService.shutdownNow();
}

@Test
void testInitWithNamesrvAddr() {
public void testInitWithNamesrvAddr() {
nameserverAccessConfig = new NameserverAccessConfig("127.0.0.1:9876", "", "");

mqClientAPIFactory = new MQClientAPIFactory(
Expand All @@ -66,7 +67,7 @@ void testInitWithNamesrvAddr() {
}

@Test
void testInitWithNamesrvDomain() {
public void testInitWithNamesrvDomain() {
nameserverAccessConfig = new NameserverAccessConfig("", "test-domain", "");

mqClientAPIFactory = new MQClientAPIFactory(
Expand All @@ -82,7 +83,7 @@ void testInitWithNamesrvDomain() {
}

@Test
void testInitThrowsExceptionWhenBothEmpty() {
public void testInitThrowsExceptionWhenBothEmpty() {
nameserverAccessConfig = new NameserverAccessConfig("", "", "");

RuntimeException exception = assertThrows(RuntimeException.class, () -> new MQClientAPIFactory(
Expand All @@ -98,7 +99,7 @@ void testInitThrowsExceptionWhenBothEmpty() {
}

@Test
void testStartCreatesClients() throws Exception {
public void testStartCreatesClients() throws Exception {
nameserverAccessConfig = new NameserverAccessConfig("127.0.0.1:9876", "", "");

mqClientAPIFactory = new MQClientAPIFactory(
Expand All @@ -122,7 +123,7 @@ void testStartCreatesClients() throws Exception {
}

@Test
void testOnNameServerAddressChangeUpdatesAllClients() throws Exception {
public void testOnNameServerAddressChangeUpdatesAllClients() throws Exception {
nameserverAccessConfig = new NameserverAccessConfig("127.0.0.1:9876", "", "");

mqClientAPIFactory = new MQClientAPIFactory(
Expand All @@ -141,6 +142,6 @@ void testOnNameServerAddressChangeUpdatesAllClients() throws Exception {
MQClientAPIExt client = mqClientAPIFactory.getClient();
List<String> nameServerAddressList = client.getNameServerAddressList();
assertEquals(2, nameServerAddressList.size());
assertEquals("new-address0", nameServerAddressList.get(0));
assertTrue(nameServerAddressList.contains("new-address0"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,24 @@
*/
package org.apache.rocketmq.proxy.service.cert;

import java.io.FileWriter;
import org.apache.rocketmq.proxy.config.ConfigurationManager;
import org.apache.rocketmq.proxy.config.ProxyConfig;
import org.apache.rocketmq.remoting.netty.TlsSystemConfig;
import org.apache.rocketmq.srvutil.FileWatchService;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.MockitoJUnitRunner;

import java.io.File;
import java.io.FileWriter;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -49,17 +48,14 @@
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
@RunWith(MockitoJUnitRunner.class)
public class TlsCertificateManagerTest {

@TempDir
Path tempDir;
@Rule
public TemporaryFolder tempDir = new TemporaryFolder();

private TlsCertificateManager manager;

@Mock
private ProxyConfig proxyConfig;

@Mock
private TlsCertificateManager.TlsContextReloadListener listener1;

Expand All @@ -72,17 +68,13 @@ public class TlsCertificateManagerTest {
private Field configField;
private ProxyConfig originalConfig;

@BeforeAll
public static void setUpAll() throws Exception {
@Before
public void setUp() throws Exception {
ConfigurationManager.initEnv();
ConfigurationManager.intConfig();
}

@BeforeEach
public void setUp() throws Exception {
// Create temporary certificate and key files
certFile = new File(tempDir.toFile(), "server.crt");
keyFile = new File(tempDir.toFile(), "server.key");
certFile = tempDir.newFile("server.crt");
keyFile = tempDir.newFile("server.key");
try (FileWriter certWriter = new FileWriter(certFile);
FileWriter keyWriter = new FileWriter(keyFile)) {
certWriter.write("test certificate content");
Expand All @@ -100,7 +92,7 @@ public void setUp() throws Exception {
fileWatchListener = extractFileWatchListener(manager);
}

@AfterEach
@After
public void tearDown() throws Exception {
// Restore the original config
if (configField != null && originalConfig != null) {
Expand Down
Loading