mirror of
https://github.com/apache/rocketmq.git
synced 2026-09-01 15:47:01 +08:00
* [ISSUE #9658] Replace JUnit 5 imports with JUnit 4 * Update test
This commit is contained in:
+16
-15
@@ -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;
|
||||
@@ -27,11 +28,11 @@ import org.apache.rocketmq.client.impl.ClientRemotingProcessor;
|
||||
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);
|
||||
@@ -39,18 +40,18 @@ class MQClientAPITest {
|
||||
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(
|
||||
@@ -66,7 +67,7 @@ class MQClientAPITest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInitWithNamesrvDomain() {
|
||||
public void testInitWithNamesrvDomain() {
|
||||
nameserverAccessConfig = new NameserverAccessConfig("", "test-domain", "");
|
||||
|
||||
mqClientAPIFactory = new MQClientAPIFactory(
|
||||
@@ -82,7 +83,7 @@ class MQClientAPITest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInitThrowsExceptionWhenBothEmpty() {
|
||||
public void testInitThrowsExceptionWhenBothEmpty() {
|
||||
nameserverAccessConfig = new NameserverAccessConfig("", "", "");
|
||||
|
||||
RuntimeException exception = assertThrows(RuntimeException.class, () -> new MQClientAPIFactory(
|
||||
@@ -98,7 +99,7 @@ class MQClientAPITest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStartCreatesClients() throws Exception {
|
||||
public void testStartCreatesClients() throws Exception {
|
||||
nameserverAccessConfig = new NameserverAccessConfig("127.0.0.1:9876", "", "");
|
||||
|
||||
mqClientAPIFactory = new MQClientAPIFactory(
|
||||
@@ -122,7 +123,7 @@ class MQClientAPITest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOnNameServerAddressChangeUpdatesAllClients() throws Exception {
|
||||
public void testOnNameServerAddressChangeUpdatesAllClients() throws Exception {
|
||||
nameserverAccessConfig = new NameserverAccessConfig("127.0.0.1:9876", "", "");
|
||||
|
||||
mqClientAPIFactory = new MQClientAPIFactory(
|
||||
@@ -141,6 +142,6 @@ class MQClientAPITest {
|
||||
MQClientAPIExt client = mqClientAPIFactory.getClient();
|
||||
List<String> nameServerAddressList = client.getNameServerAddressList();
|
||||
assertEquals(2, nameServerAddressList.size());
|
||||
assertEquals("new-address0", nameServerAddressList.get(0));
|
||||
assertTrue(nameServerAddressList.contains("new-address0"));
|
||||
}
|
||||
}
|
||||
|
||||
+16
-24
@@ -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;
|
||||
@@ -49,17 +48,14 @@ import static org.mockito.Mockito.spy;
|
||||
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;
|
||||
|
||||
@@ -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");
|
||||
@@ -100,7 +92,7 @@ public class TlsCertificateManagerTest {
|
||||
fileWatchListener = extractFileWatchListener(manager);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
// Restore the original config
|
||||
if (configField != null && originalConfig != null) {
|
||||
|
||||
Reference in New Issue
Block a user