|
| 1 | +import java.net.InetAddress; |
| 2 | +import java.net.InetSocketAddress; |
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | +import java.util.Map; |
| 6 | +import java.util.concurrent.TimeUnit; |
| 7 | + |
| 8 | +import com.gportal.a2s.PlayerInfo; |
| 9 | +import com.gportal.a2s.QueryClient; |
| 10 | +import com.gportal.a2s.QueryServer; |
| 11 | +import com.gportal.a2s.ServerInfo; |
| 12 | + |
| 13 | +import org.junit.jupiter.api.AfterAll; |
| 14 | +import org.junit.jupiter.api.BeforeAll; |
| 15 | +import org.junit.jupiter.api.Test; |
| 16 | +import static org.junit.jupiter.api.Assertions.*; |
| 17 | + |
| 18 | +public class LargePayloadETETest { |
| 19 | + private static QueryClient client; |
| 20 | + private static QueryServer server; |
| 21 | + private static final int PORT = 27016; |
| 22 | + |
| 23 | + @BeforeAll |
| 24 | + public static void init() throws Exception { |
| 25 | + client = new QueryClient(); |
| 26 | + |
| 27 | + // Create a very long server name (2000 chars) |
| 28 | + StringBuilder longName = new StringBuilder(); |
| 29 | + for (int i = 0; i < 2000; i++) { |
| 30 | + longName.append("A"); |
| 31 | + } |
| 32 | + |
| 33 | + ServerInfo info = new ServerInfo( |
| 34 | + new InetSocketAddress(InetAddress.getLocalHost(), PORT), |
| 35 | + (byte) 17, |
| 36 | + longName.toString(), |
| 37 | + "Map", |
| 38 | + "Folder", |
| 39 | + "Game", |
| 40 | + (short) 0, |
| 41 | + (byte) 0, // players - will be updated by server.players.size() if it was dynamic, but here it's static in ServerInfo |
| 42 | + (byte) 255, |
| 43 | + (byte) 0, |
| 44 | + 'd', |
| 45 | + 'l', |
| 46 | + false, |
| 47 | + true, |
| 48 | + "1.0.0.0", |
| 49 | + null, null, null, null, null, null |
| 50 | + ); |
| 51 | + |
| 52 | + server = new QueryServer(new InetSocketAddress(InetAddress.getLocalHost(), PORT), info); |
| 53 | + |
| 54 | + // Add 200 players to exceed typical MTU/buffer limits |
| 55 | + for (int i = 0; i < 200; i++) { |
| 56 | + server.players.add(new PlayerInfo((byte) i, "Player " + i, i * 10, 100.0f)); |
| 57 | + } |
| 58 | + |
| 59 | + // Update player count in info to reflect actual players |
| 60 | + server.info.setPlayers((byte) 200); |
| 61 | + |
| 62 | + // Add many rules |
| 63 | + for (int i = 0; i < 200; i++) { |
| 64 | + server.rules.put("RuleKey" + i, "RuleValue" + i); |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void testLargeInfoReply() throws Exception { |
| 70 | + ServerInfo info = client.queryServer(new InetSocketAddress(InetAddress.getLocalHost(), PORT)).get(5, TimeUnit.SECONDS); |
| 71 | + assertNotNull(info); |
| 72 | + assertEquals(2000, info.name().length()); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void testLargePlayerReply() throws Exception { |
| 77 | + List<PlayerInfo> players = client.queryPlayers(new InetSocketAddress(InetAddress.getLocalHost(), PORT)).get(5, TimeUnit.SECONDS); |
| 78 | + assertNotNull(players); |
| 79 | + assertEquals(200, players.size()); |
| 80 | + assertEquals("Player 199", players.get(199).name()); |
| 81 | + } |
| 82 | + |
| 83 | + @Test |
| 84 | + public void testLargeRulesReply() throws Exception { |
| 85 | + Map<String, String> rules = client.queryRules(new InetSocketAddress(InetAddress.getLocalHost(), PORT)).get(5, TimeUnit.SECONDS); |
| 86 | + assertNotNull(rules); |
| 87 | + assertEquals(200, rules.size()); |
| 88 | + assertEquals("RuleValue199", rules.get("RuleKey199")); |
| 89 | + } |
| 90 | + |
| 91 | + @AfterAll |
| 92 | + public static void cleanup() { |
| 93 | + if (client != null) client.shutdown(); |
| 94 | + if (server != null) server.shutdown(); |
| 95 | + } |
| 96 | +} |
0 commit comments