chore: test

This commit is contained in:
godotg committed 2024-11-09 12:15:47 +08:00
1 parent 3528da2db6
commit d3d2d93dc5
3 files changed
+18 -17

No files matched your search

@@ -18,7 +18,7 @@ import com.zfoo.net.core.HostAndPort;
import com.zfoo.net.core.tcp.TcpClient; import com.zfoo.net.core.tcp.TcpClient;
import com.zfoo.net.packet.gateway.GatewayToProviderRequest; import com.zfoo.net.packet.gateway.GatewayToProviderRequest;
import com.zfoo.net.packet.gateway.GatewayToProviderResponse; import com.zfoo.net.packet.gateway.GatewayToProviderResponse;
import com.zfoo.net.session.SessionUtils; import com.zfoo.net.util.SessionUtilsTest;
import com.zfoo.protocol.util.JsonUtils; import com.zfoo.protocol.util.JsonUtils;
import com.zfoo.protocol.util.ThreadUtils; import com.zfoo.protocol.util.ThreadUtils;
import org.junit.Ignore; import org.junit.Ignore;
@@ -51,21 +51,21 @@ public class GatewayTest {
@Test @Test
public void startProvider0() { public void startProvider0() {
var context = new ClassPathXmlApplicationContext("provider/provider_config.xml"); var context = new ClassPathXmlApplicationContext("provider/provider_config.xml");
SessionUtils.printSessionInfo(); SessionUtilsTest.printSessionInfo();
ThreadUtils.sleep(Long.MAX_VALUE); ThreadUtils.sleep(Long.MAX_VALUE);
} }
@Test @Test
public void startProvider1() { public void startProvider1() {
var context = new ClassPathXmlApplicationContext("provider/provider_config.xml"); var context = new ClassPathXmlApplicationContext("provider/provider_config.xml");
SessionUtils.printSessionInfo(); SessionUtilsTest.printSessionInfo();
ThreadUtils.sleep(Long.MAX_VALUE); ThreadUtils.sleep(Long.MAX_VALUE);
} }
@Test @Test
public void startProvider2() { public void startProvider2() {
var context = new ClassPathXmlApplicationContext("provider/provider_config.xml"); var context = new ClassPathXmlApplicationContext("provider/provider_config.xml");
SessionUtils.printSessionInfo(); SessionUtilsTest.printSessionInfo();
ThreadUtils.sleep(Long.MAX_VALUE); ThreadUtils.sleep(Long.MAX_VALUE);
} }
@@ -75,7 +75,7 @@ public class GatewayTest {
@Test @Test
public void startGateway() { public void startGateway() {
var context = new ClassPathXmlApplicationContext("gateway/gateway_config.xml"); var context = new ClassPathXmlApplicationContext("gateway/gateway_config.xml");
SessionUtils.printSessionInfo(); SessionUtilsTest.printSessionInfo();
// 注意:这里创建的是GatewayServer里面是GatewayRouteHandler(而不是BaseRouteHandler),里面会通过ConsumerSession把消息转发到Provider // 注意:这里创建的是GatewayServer里面是GatewayRouteHandler(而不是BaseRouteHandler),里面会通过ConsumerSession把消息转发到Provider
var gatewayServer = new GatewayServer(HostAndPort.valueOf("127.0.0.1:9000"), null); var gatewayServer = new GatewayServer(HostAndPort.valueOf("127.0.0.1:9000"), null);
@@ -89,7 +89,7 @@ public class GatewayTest {
@Test @Test
public void clientSyncTest() { public void clientSyncTest() {
var context = new ClassPathXmlApplicationContext("gateway/gateway_client_config.xml"); var context = new ClassPathXmlApplicationContext("gateway/gateway_client_config.xml");
SessionUtils.printSessionInfo(); SessionUtilsTest.printSessionInfo();
// 这里的地址是网关的地址 // 这里的地址是网关的地址
var client = new TcpClient(HostAndPort.valueOf("127.0.0.1:9000")); var client = new TcpClient(HostAndPort.valueOf("127.0.0.1:9000"));
@@ -124,7 +124,7 @@ public class GatewayTest {
@Test @Test
public void clientAsyncTest() { public void clientAsyncTest() {
var context = new ClassPathXmlApplicationContext("gateway/gateway_client_config.xml"); var context = new ClassPathXmlApplicationContext("gateway/gateway_client_config.xml");
SessionUtils.printSessionInfo(); SessionUtilsTest.printSessionInfo();
// 这里的地址是网关的地址 // 这里的地址是网关的地址
var client = new TcpClient(HostAndPort.valueOf("127.0.0.1:9000")); var client = new TcpClient(HostAndPort.valueOf("127.0.0.1:9000"));
@@ -16,7 +16,7 @@ package com.zfoo.net.core.provider;
import com.zfoo.net.NetContext; import com.zfoo.net.NetContext;
import com.zfoo.net.packet.provider.ProviderMessAnswer; import com.zfoo.net.packet.provider.ProviderMessAnswer;
import com.zfoo.net.packet.provider.ProviderMessAsk; import com.zfoo.net.packet.provider.ProviderMessAsk;
import com.zfoo.net.session.SessionUtils; import com.zfoo.net.util.SessionUtilsTest;
import com.zfoo.protocol.util.JsonUtils; import com.zfoo.protocol.util.JsonUtils;
import com.zfoo.protocol.util.ThreadUtils; import com.zfoo.protocol.util.ThreadUtils;
import org.junit.Ignore; import org.junit.Ignore;
@@ -45,21 +45,21 @@ public class ProviderTest {
@Test @Test
public void startProvider0() { public void startProvider0() {
var context = new ClassPathXmlApplicationContext("provider/provider_config.xml"); var context = new ClassPathXmlApplicationContext("provider/provider_config.xml");
SessionUtils.printSessionInfo(); SessionUtilsTest.printSessionInfo();
ThreadUtils.sleep(Long.MAX_VALUE); ThreadUtils.sleep(Long.MAX_VALUE);
} }
@Test @Test
public void startProvider1() { public void startProvider1() {
var context = new ClassPathXmlApplicationContext("provider/provider_config.xml"); var context = new ClassPathXmlApplicationContext("provider/provider_config.xml");
SessionUtils.printSessionInfo(); SessionUtilsTest.printSessionInfo();
ThreadUtils.sleep(Long.MAX_VALUE); ThreadUtils.sleep(Long.MAX_VALUE);
} }
@Test @Test
public void startProvider2() { public void startProvider2() {
var context = new ClassPathXmlApplicationContext("provider/provider_config.xml"); var context = new ClassPathXmlApplicationContext("provider/provider_config.xml");
SessionUtils.printSessionInfo(); SessionUtilsTest.printSessionInfo();
ThreadUtils.sleep(Long.MAX_VALUE); ThreadUtils.sleep(Long.MAX_VALUE);
} }
@@ -69,7 +69,7 @@ public class ProviderTest {
@Test @Test
public void startSyncRandomConsumer() throws Exception { public void startSyncRandomConsumer() throws Exception {
var context = new ClassPathXmlApplicationContext("provider/consumer_random_config.xml"); var context = new ClassPathXmlApplicationContext("provider/consumer_random_config.xml");
SessionUtils.printSessionInfo(); SessionUtilsTest.printSessionInfo();
var ask = new ProviderMessAsk(); var ask = new ProviderMessAsk();
ask.setMessage("Hello, this is the consumer!"); ask.setMessage("Hello, this is the consumer!");
@@ -88,7 +88,7 @@ public class ProviderTest {
@Test @Test
public void startAsyncRandomConsumer() { public void startAsyncRandomConsumer() {
var context = new ClassPathXmlApplicationContext("provider/consumer_random_config.xml"); var context = new ClassPathXmlApplicationContext("provider/consumer_random_config.xml");
SessionUtils.printSessionInfo(); SessionUtilsTest.printSessionInfo();
var ask = new ProviderMessAsk(); var ask = new ProviderMessAsk();
ask.setMessage("Hello, this is the consumer!"); ask.setMessage("Hello, this is the consumer!");
@@ -110,7 +110,7 @@ public class ProviderTest {
@Test @Test
public void startConsistentHashConsumer() { public void startConsistentHashConsumer() {
var context = new ClassPathXmlApplicationContext("provider/consumer_consistent_hash_config.xml"); var context = new ClassPathXmlApplicationContext("provider/consumer_consistent_hash_config.xml");
SessionUtils.printSessionInfo(); SessionUtilsTest.printSessionInfo();
var ask = new ProviderMessAsk(); var ask = new ProviderMessAsk();
ask.setMessage("Hello, this is the consumer!"); ask.setMessage("Hello, this is the consumer!");
@@ -132,7 +132,7 @@ public class ProviderTest {
@Test @Test
public void startCachedConsistentHashConsumer() { public void startCachedConsistentHashConsumer() {
var context = new ClassPathXmlApplicationContext("provider/consumer_cached_consistent_config.xml"); var context = new ClassPathXmlApplicationContext("provider/consumer_cached_consistent_config.xml");
SessionUtils.printSessionInfo(); SessionUtilsTest.printSessionInfo();
var ask = new ProviderMessAsk(); var ask = new ProviderMessAsk();
ask.setMessage("Hello, this is the consumer!"); ask.setMessage("Hello, this is the consumer!");
@@ -11,9 +11,10 @@
* See the License for the specific language governing permissions and limitations under the License. * See the License for the specific language governing permissions and limitations under the License.
*/ */
package com.zfoo.net.session; package com.zfoo.net.util;
import com.zfoo.net.NetContext; import com.zfoo.net.NetContext;
import com.zfoo.net.session.Session;
import com.zfoo.protocol.util.FileUtils; import com.zfoo.protocol.util.FileUtils;
import com.zfoo.protocol.util.StringUtils; import com.zfoo.protocol.util.StringUtils;
import com.zfoo.protocol.util.ThreadUtils; import com.zfoo.protocol.util.ThreadUtils;
@@ -23,7 +24,7 @@ import java.util.function.Consumer;
/** /**
* @author godotg * @author godotg
*/ */
public abstract class SessionUtils { public class SessionUtilsTest {
public static void printSessionInfo() { public static void printSessionInfo() {
Thread thread = new Thread(() -> { Thread thread = new Thread(() -> {