Skip to content

Commit

Permalink
[#9915] Replace SocketUtils in springframework
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Apr 28, 2023
1 parent 433a9d6 commit 0953cde
Show file tree
Hide file tree
Showing 16 changed files with 24 additions and 585 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.util.SocketUtils;
import org.springframework.test.util.TestSocketUtils;

import java.util.Collections;
import java.util.concurrent.CountDownLatch;
Expand Down Expand Up @@ -243,11 +243,11 @@ private DataReceiverGroupProperties createMockProperties(boolean tcpEnable, bool

when(properties.isTcpEnable()).thenReturn(tcpEnable);
when(properties.getTcpBindIp()).thenReturn("0.0.0.0");
when(properties.getTcpBindPort()).thenReturn(SocketUtils.findAvailableTcpPort(19099));
when(properties.getTcpBindPort()).thenReturn(TestSocketUtils.findAvailableTcpPort());

when(properties.isUdpEnable()).thenReturn(udpEnable);
when(properties.getUdpBindIp()).thenReturn("0.0.0.0");
when(properties.getUdpBindPort()).thenReturn(SocketUtils.findAvailableTcpPort(29099));
when(properties.getUdpBindPort()).thenReturn(TestSocketUtils.findAvailableTcpPort());
when(properties.getUdpReceiveBufferSize()).thenReturn(65535);

when(properties.getWorkerThreadSize()).thenReturn(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.util.SocketUtils;
import org.springframework.test.util.TestSocketUtils;

import java.io.IOException;
import java.net.DatagramPacket;
Expand All @@ -44,7 +44,7 @@
@Disabled
public class NettyUdpReceiverTest {

public static final int PORT = SocketUtils.findAvailableUdpPort(30011);
public static final int PORT = TestSocketUtils.findAvailableTcpPort();
private final Logger logger = LogManager.getLogger(this.getClass());

private final CountDownLatch latch = new CountDownLatch(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.util.SocketUtils;
import org.springframework.test.util.TestSocketUtils;

import java.io.Closeable;
import java.io.IOException;
Expand Down Expand Up @@ -66,7 +66,7 @@ public void receive(DatagramSocket localSocket, PooledObject<DatagramPacket> pac

@BeforeEach
public void setUp() throws Exception {
this.port = SocketUtils.findAvailableUdpPort(10999);
this.port = TestSocketUtils.findAvailableTcpPort();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.navercorp.pinpoint.common.server.cluster.zookeeper;

import com.navercorp.pinpoint.testcase.util.SocketUtils;
import org.apache.curator.test.TestingServer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -30,6 +29,7 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.TestSocketUtils;

import java.util.concurrent.TimeUnit;

Expand All @@ -55,7 +55,7 @@ private ConditionFactory awaitility() {

@BeforeAll
public static void setUp() throws Exception {
zookeeperPort = SocketUtils.findAvailableTcpPort();
zookeeperPort = TestSocketUtils.findAvailableTcpPort();
ts = createTestingServer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.BadOperationException;
import com.navercorp.pinpoint.common.server.cluster.zookeeper.exception.PinpointZookeeperException;
import com.navercorp.pinpoint.testcase.util.SocketUtils;
import org.apache.curator.test.TestingServer;
import org.apache.curator.utils.ZKPaths;
import org.apache.logging.log4j.LogManager;
Expand All @@ -37,6 +36,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.test.util.TestSocketUtils;

import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -68,7 +68,7 @@ private ConditionFactory awaitility() {

@BeforeAll
public static void setUpClass() throws Exception {
int availablePort = SocketUtils.findAvailableTcpPort();
int availablePort = TestSocketUtils.findAvailableTcpPort();
ts = new TestingServer(availablePort);

eventHoldingZookeeperEventWatcher = new EventHoldingZookeeperEventWatcher();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.navercorp.pinpoint.plugin.grpc;

import com.navercorp.pinpoint.common.util.CpuUtils;
import com.navercorp.pinpoint.pluginit.utils.SocketUtils;
import com.navercorp.pinpoint.testcase.util.SocketUtils;
import io.grpc.Server;
import io.grpc.examples.helloworld.GreeterGrpc;
import io.grpc.examples.helloworld.HelloReply;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package com.navercorp.pinpoint.plugin.grpc;

import com.navercorp.pinpoint.common.util.CpuUtils;
import com.navercorp.pinpoint.pluginit.utils.SocketUtils;

import com.navercorp.pinpoint.testcase.util.SocketUtils;
import io.grpc.Server;
import io.grpc.Status;
import io.grpc.examples.manualflowcontrol.HelloReply;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.navercorp.pinpoint.plugin.grpc;

import com.navercorp.pinpoint.common.util.CpuUtils;
import com.navercorp.pinpoint.pluginit.utils.SocketUtils;
import com.navercorp.pinpoint.testcase.util.SocketUtils;
import io.grpc.Server;
import io.grpc.examples.helloworld.GreeterGrpc;
import io.grpc.examples.helloworld.HelloReply;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.navercorp.pinpoint.plugin.grpc;

import com.navercorp.pinpoint.common.util.CpuUtils;
import com.navercorp.pinpoint.pluginit.utils.SocketUtils;
import com.navercorp.pinpoint.testcase.util.SocketUtils;
import io.grpc.Server;
import io.grpc.Status;
import io.grpc.examples.manualflowcontrol.HelloReply;
Expand Down
5 changes: 5 additions & 0 deletions plugins-it/plugins-it-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-commons</artifactId>
</dependency>
<dependency>
<groupId>com.navercorp.pinpoint</groupId>
<artifactId>pinpoint-testcase</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.nanohttpd</groupId>
<artifactId>nanohttpd</artifactId>
Expand Down
Loading

0 comments on commit 0953cde

Please sign in to comment.