fixed non-idempotent unit tests (#14172)
This commit is contained in:
parent
5d916cd2c1
commit
8e2eb332a1
|
|
@ -57,7 +57,8 @@ class ClassGeneratorTest {
|
||||||
ClassGenerator cg = ClassGenerator.newInstance();
|
ClassGenerator cg = ClassGenerator.newInstance();
|
||||||
|
|
||||||
// add className, interface, superClass
|
// add className, interface, superClass
|
||||||
String className = BaseClass.class.getPackage().getName() + ".TestClass";
|
String className = BaseClass.class.getPackage().getName() + ".TestClass"
|
||||||
|
+ UUID.randomUUID().toString().replace("-", "");
|
||||||
cg.setClassName(className);
|
cg.setClassName(className);
|
||||||
cg.addInterface(BaseInterface.class);
|
cg.addInterface(BaseInterface.class);
|
||||||
cg.setSuperClass(BaseClass.class);
|
cg.setSuperClass(BaseClass.class);
|
||||||
|
|
@ -212,7 +213,7 @@ class ClassGeneratorTest {
|
||||||
fname.setAccessible(true);
|
fname.setAccessible(true);
|
||||||
|
|
||||||
ClassGenerator cg = ClassGenerator.newInstance();
|
ClassGenerator cg = ClassGenerator.newInstance();
|
||||||
cg.setClassName(Bean.class.getName() + "$Builder2");
|
cg.setClassName(Bean.class.getName() + "$Builder2" + UUID.randomUUID().toString());
|
||||||
cg.addInterface(Builder.class);
|
cg.addInterface(Builder.class);
|
||||||
|
|
||||||
cg.addField("FNAME", Modifier.PUBLIC | Modifier.STATIC, java.lang.reflect.Field.class);
|
cg.addField("FNAME", Modifier.PUBLIC | Modifier.STATIC, java.lang.reflect.Field.class);
|
||||||
|
|
|
||||||
|
|
@ -172,7 +172,6 @@ class MultipleRegistryCenterExportMetadataIntegrationTest implements Integration
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void tearDown() throws IOException {
|
public void tearDown() throws IOException {
|
||||||
DubboBootstrap.reset();
|
DubboBootstrap.reset();
|
||||||
PROVIDER_APPLICATION_NAME = null;
|
|
||||||
serviceConfig = null;
|
serviceConfig = null;
|
||||||
// The exported service has been unexported
|
// The exported service has been unexported
|
||||||
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
|
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
|
||||||
|
|
|
||||||
|
|
@ -239,7 +239,6 @@ class MultipleRegistryCenterExportProviderIntegrationTest implements Integration
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void tearDown() throws IOException {
|
public void tearDown() throws IOException {
|
||||||
DubboBootstrap.reset();
|
DubboBootstrap.reset();
|
||||||
PROVIDER_APPLICATION_NAME = null;
|
|
||||||
serviceConfig = null;
|
serviceConfig = null;
|
||||||
// The exported service has been unexported
|
// The exported service has been unexported
|
||||||
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
|
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,6 @@ class MultipleRegistryCenterInjvmIntegrationTest implements IntegrationTest {
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void tearDown() throws IOException {
|
public void tearDown() throws IOException {
|
||||||
DubboBootstrap.reset();
|
DubboBootstrap.reset();
|
||||||
PROVIDER_APPLICATION_NAME = null;
|
|
||||||
serviceConfig = null;
|
serviceConfig = null;
|
||||||
// The exported service has been unexported
|
// The exported service has been unexported
|
||||||
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
|
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
|
||||||
|
|
|
||||||
|
|
@ -201,7 +201,6 @@ class MultipleRegistryCenterServiceDiscoveryRegistryIntegrationTest implements I
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void tearDown() throws IOException {
|
public void tearDown() throws IOException {
|
||||||
DubboBootstrap.reset();
|
DubboBootstrap.reset();
|
||||||
PROVIDER_APPLICATION_NAME = null;
|
|
||||||
serviceConfig = null;
|
serviceConfig = null;
|
||||||
// TODO: we need to check whether this scenario is normal
|
// TODO: we need to check whether this scenario is normal
|
||||||
// TODO: the Exporter and ServiceDiscoveryRegistry are same in multiple registry center
|
// TODO: the Exporter and ServiceDiscoveryRegistry are same in multiple registry center
|
||||||
|
|
|
||||||
|
|
@ -169,7 +169,6 @@ class SingleRegistryCenterExportMetadataIntegrationTest implements IntegrationTe
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void tearDown() throws IOException {
|
public void tearDown() throws IOException {
|
||||||
DubboBootstrap.reset();
|
DubboBootstrap.reset();
|
||||||
PROVIDER_APPLICATION_NAME = null;
|
|
||||||
serviceConfig = null;
|
serviceConfig = null;
|
||||||
// The exported service has been unexported
|
// The exported service has been unexported
|
||||||
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
|
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
|
||||||
|
|
|
||||||
|
|
@ -240,7 +240,6 @@ class SingleRegistryCenterExportProviderIntegrationTest implements IntegrationTe
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void tearDown() throws IOException {
|
public void tearDown() throws IOException {
|
||||||
DubboBootstrap.reset();
|
DubboBootstrap.reset();
|
||||||
PROVIDER_APPLICATION_NAME = null;
|
|
||||||
serviceConfig = null;
|
serviceConfig = null;
|
||||||
// The exported service has been unexported
|
// The exported service has been unexported
|
||||||
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
|
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
|
||||||
|
|
|
||||||
|
|
@ -185,7 +185,6 @@ class SingleRegistryCenterInjvmIntegrationTest implements IntegrationTest {
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void tearDown() throws IOException {
|
public void tearDown() throws IOException {
|
||||||
DubboBootstrap.reset();
|
DubboBootstrap.reset();
|
||||||
PROVIDER_APPLICATION_NAME = null;
|
|
||||||
serviceConfig = null;
|
serviceConfig = null;
|
||||||
// The exported service has been unexported
|
// The exported service has been unexported
|
||||||
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
|
Assertions.assertTrue(serviceListener.getExportedServices().isEmpty());
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ class ReferenceCacheTest {
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
DubboBootstrap.reset();
|
DubboBootstrap.reset();
|
||||||
MockReferenceConfig.setCounter(0);
|
MockReferenceConfig.setCounter(0);
|
||||||
|
XxxMockReferenceConfig.setCounter(0);
|
||||||
SimpleReferenceCache.CACHE_HOLDER.clear();
|
SimpleReferenceCache.CACHE_HOLDER.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ class PrometheusMetricsReporterTest {
|
||||||
private MetricsConfig metricsConfig;
|
private MetricsConfig metricsConfig;
|
||||||
private ApplicationModel applicationModel;
|
private ApplicationModel applicationModel;
|
||||||
private FrameworkModel frameworkModel;
|
private FrameworkModel frameworkModel;
|
||||||
|
HttpServer prometheusExporterHttpServer;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
|
|
@ -64,6 +65,9 @@ class PrometheusMetricsReporterTest {
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void teardown() {
|
public void teardown() {
|
||||||
applicationModel.destroy();
|
applicationModel.destroy();
|
||||||
|
if (prometheusExporterHttpServer != null) {
|
||||||
|
prometheusExporterHttpServer.stop(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -146,7 +150,7 @@ class PrometheusMetricsReporterTest {
|
||||||
private void exportHttpServer(PrometheusMetricsReporter reporter, int port) {
|
private void exportHttpServer(PrometheusMetricsReporter reporter, int port) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
HttpServer prometheusExporterHttpServer = HttpServer.create(new InetSocketAddress(port), 0);
|
prometheusExporterHttpServer = HttpServer.create(new InetSocketAddress(port), 0);
|
||||||
prometheusExporterHttpServer.createContext("/metrics", httpExchange -> {
|
prometheusExporterHttpServer.createContext("/metrics", httpExchange -> {
|
||||||
reporter.resetIfSamplesChanged();
|
reporter.resetIfSamplesChanged();
|
||||||
String response = reporter.getPrometheusRegistry().scrape();
|
String response = reporter.getPrometheusRegistry().scrape();
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,8 @@ public class PrometheusMetricsThreadPoolTest {
|
||||||
|
|
||||||
DefaultMetricsCollector metricsCollector;
|
DefaultMetricsCollector metricsCollector;
|
||||||
|
|
||||||
|
HttpServer prometheusExporterHttpServer;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
applicationModel = ApplicationModel.defaultModel();
|
applicationModel = ApplicationModel.defaultModel();
|
||||||
|
|
@ -77,6 +79,9 @@ public class PrometheusMetricsThreadPoolTest {
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void teardown() {
|
public void teardown() {
|
||||||
applicationModel.destroy();
|
applicationModel.destroy();
|
||||||
|
if (prometheusExporterHttpServer != null) {
|
||||||
|
prometheusExporterHttpServer.stop(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -121,7 +126,7 @@ public class PrometheusMetricsThreadPoolTest {
|
||||||
|
|
||||||
private void exportHttpServer(PrometheusMetricsReporter reporter, int port) {
|
private void exportHttpServer(PrometheusMetricsReporter reporter, int port) {
|
||||||
try {
|
try {
|
||||||
HttpServer prometheusExporterHttpServer = HttpServer.create(new InetSocketAddress(port), 0);
|
prometheusExporterHttpServer = HttpServer.create(new InetSocketAddress(port), 0);
|
||||||
prometheusExporterHttpServer.createContext("/metrics", httpExchange -> {
|
prometheusExporterHttpServer.createContext("/metrics", httpExchange -> {
|
||||||
reporter.resetIfSamplesChanged();
|
reporter.resetIfSamplesChanged();
|
||||||
String response = reporter.getPrometheusRegistry().scrape();
|
String response = reporter.getPrometheusRegistry().scrape();
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ import org.apache.dubbo.rpc.ProxyFactory;
|
||||||
import org.apache.dubbo.rpc.Result;
|
import org.apache.dubbo.rpc.Result;
|
||||||
import org.apache.dubbo.rpc.RpcException;
|
import org.apache.dubbo.rpc.RpcException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.ServerSocket;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -139,7 +141,13 @@ class DubboMonitorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testMonitorFactory() {
|
void testMonitorFactory() throws IOException {
|
||||||
|
int port;
|
||||||
|
try (ServerSocket socket = new ServerSocket(0)) {
|
||||||
|
port = socket.getLocalPort();
|
||||||
|
socket.close();
|
||||||
|
}
|
||||||
|
|
||||||
MockMonitorService monitorService = new MockMonitorService();
|
MockMonitorService monitorService = new MockMonitorService();
|
||||||
URL statistics = new URLBuilder(DUBBO_PROTOCOL, "10.20.153.10", 0)
|
URL statistics = new URLBuilder(DUBBO_PROTOCOL, "10.20.153.10", 0)
|
||||||
.addParameter(APPLICATION_KEY, "morgan")
|
.addParameter(APPLICATION_KEY, "morgan")
|
||||||
|
|
@ -163,12 +171,12 @@ class DubboMonitorTest {
|
||||||
Exporter<MonitorService> exporter = protocol.export(proxyFactory.getInvoker(
|
Exporter<MonitorService> exporter = protocol.export(proxyFactory.getInvoker(
|
||||||
monitorService,
|
monitorService,
|
||||||
MonitorService.class,
|
MonitorService.class,
|
||||||
URL.valueOf("dubbo://127.0.0.1:17979/" + MonitorService.class.getName())));
|
URL.valueOf("dubbo://127.0.0.1:" + port + "/" + MonitorService.class.getName())));
|
||||||
try {
|
try {
|
||||||
Monitor monitor = null;
|
Monitor monitor = null;
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
while (System.currentTimeMillis() - start < 60000) {
|
while (System.currentTimeMillis() - start < 60000) {
|
||||||
monitor = monitorFactory.getMonitor(URL.valueOf("dubbo://127.0.0.1:17979?interval=10"));
|
monitor = monitorFactory.getMonitor(URL.valueOf("dubbo://127.0.0.1:" + port + "?interval=10"));
|
||||||
if (monitor == null) {
|
if (monitor == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ class LiveTest {
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void reset() {
|
public void reset() {
|
||||||
frameworkModel.destroy();
|
frameworkModel.destroy();
|
||||||
|
MockLivenessProbe.setCheckReturnValue(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
|
|
@ -24,12 +24,18 @@ import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
class ChannelHandlerDispatcherTest {
|
class ChannelHandlerDispatcherTest {
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void tearDown() {
|
||||||
|
MockChannelHandler.reset();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void test() {
|
void test() {
|
||||||
ChannelHandlerDispatcher channelHandlerDispatcher = new ChannelHandlerDispatcher();
|
ChannelHandlerDispatcher channelHandlerDispatcher = new ChannelHandlerDispatcher();
|
||||||
|
|
@ -138,4 +144,12 @@ class MockChannelHandler extends ChannelHandlerAdapter {
|
||||||
public static int getCaughtCount() {
|
public static int getCaughtCount() {
|
||||||
return caughtCount;
|
return caughtCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void reset() {
|
||||||
|
sentCount = 0;
|
||||||
|
connectedCount = 0;
|
||||||
|
disconnectedCount = 0;
|
||||||
|
receivedCount = 0;
|
||||||
|
caughtCount = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,10 @@ class RpcStatusTest {
|
||||||
URL url = new ServiceConfigURL("dubbo", "127.0.0.1", 91031, DemoService.class.getName());
|
URL url = new ServiceConfigURL("dubbo", "127.0.0.1", 91031, DemoService.class.getName());
|
||||||
String methodName = "testBeginCountEndCount";
|
String methodName = "testBeginCountEndCount";
|
||||||
int max = 2;
|
int max = 2;
|
||||||
|
|
||||||
|
RpcStatus.removeStatus(url);
|
||||||
|
RpcStatus.removeStatus(url, methodName);
|
||||||
|
|
||||||
boolean flag = RpcStatus.beginCount(url, methodName, max);
|
boolean flag = RpcStatus.beginCount(url, methodName, max);
|
||||||
RpcStatus urlRpcStatus = RpcStatus.getStatus(url);
|
RpcStatus urlRpcStatus = RpcStatus.getStatus(url);
|
||||||
RpcStatus methodRpcStatus = RpcStatus.getStatus(url, methodName);
|
RpcStatus methodRpcStatus = RpcStatus.getStatus(url, methodName);
|
||||||
|
|
@ -65,6 +69,10 @@ class RpcStatusTest {
|
||||||
void testBeginCountEndCountInMultiThread() throws Exception {
|
void testBeginCountEndCountInMultiThread() throws Exception {
|
||||||
URL url = new ServiceConfigURL("dubbo", "127.0.0.1", 91032, DemoService.class.getName());
|
URL url = new ServiceConfigURL("dubbo", "127.0.0.1", 91032, DemoService.class.getName());
|
||||||
String methodName = "testBeginCountEndCountInMultiThread";
|
String methodName = "testBeginCountEndCountInMultiThread";
|
||||||
|
|
||||||
|
RpcStatus.removeStatus(url);
|
||||||
|
RpcStatus.removeStatus(url, methodName);
|
||||||
|
|
||||||
int max = 50;
|
int max = 50;
|
||||||
int threadNum = 10;
|
int threadNum = 10;
|
||||||
AtomicInteger successCount = new AtomicInteger();
|
AtomicInteger successCount = new AtomicInteger();
|
||||||
|
|
@ -99,6 +107,10 @@ class RpcStatusTest {
|
||||||
URL url = new ServiceConfigURL("dubbo", "127.0.0.1", 91033, DemoService.class.getName());
|
URL url = new ServiceConfigURL("dubbo", "127.0.0.1", 91033, DemoService.class.getName());
|
||||||
String methodName = "testStatistics";
|
String methodName = "testStatistics";
|
||||||
int max = 0;
|
int max = 0;
|
||||||
|
|
||||||
|
RpcStatus.removeStatus(url);
|
||||||
|
RpcStatus.removeStatus(url, methodName);
|
||||||
|
|
||||||
RpcStatus.beginCount(url, methodName, max);
|
RpcStatus.beginCount(url, methodName, max);
|
||||||
RpcStatus.beginCount(url, methodName, max);
|
RpcStatus.beginCount(url, methodName, max);
|
||||||
RpcStatus.beginCount(url, methodName, max);
|
RpcStatus.beginCount(url, methodName, max);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue