[lobby-svn] SF.net SVN: lobby:[1052] trunk/test/net/yura/lobby/server/ServerTest.java
Brought to you by:
yuranet
From: <yu...@us...> - 2025-04-26 16:20:55
|
Revision: 1052 http://sourceforge.net/p/lobby/code/1052 Author: yuranet Date: 2025-04-26 16:20:37 +0000 (Sat, 26 Apr 2025) Log Message: ----------- test update Modified Paths: -------------- trunk/test/net/yura/lobby/server/ServerTest.java Modified: trunk/test/net/yura/lobby/server/ServerTest.java =================================================================== --- trunk/test/net/yura/lobby/server/ServerTest.java 2025-04-26 16:01:13 UTC (rev 1051) +++ trunk/test/net/yura/lobby/server/ServerTest.java 2025-04-26 16:20:37 UTC (rev 1052) @@ -3,9 +3,11 @@ import net.yura.lobby.util.LobbyConnection; import java.lang.management.ManagementFactory; import java.util.List; +import java.util.concurrent.BlockingQueue; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import javax.management.JMX; import javax.management.ObjectName; import net.yura.lobby.client.Connection; @@ -229,7 +231,7 @@ LobbyConnection mycom2 = new LobbyConnection(id2); Player user2 = mycom2.connect(server, port).get(); GameType type2 = getMockGameType(mycom2.getGameTypes().get()); - Game game2 = mycom2.getGames(type2).take(); + Game game2 = take(mycom2.getGames(type2)); game2 = mycom2.joinGame(game2.getId(), null).get(); // both players go into the game @@ -285,7 +287,7 @@ mycom1.flagUser(user2.getName()); GameType type2 = getMockGameType(mycom2.getGameTypes().get()); - Game game2 = mycom2.getGames(type2).take(); + Game game2 = take(mycom2.getGames(type2)); try { mycom2.joinGame(game2.getId(), null).get(); @@ -342,7 +344,7 @@ LobbyConnection mycom2 = new LobbyConnection(id2); mycom2.connect(server, port).get(); List<GameType> gameTypes2 = mycom2.getGameTypes().get(); - Game game2 = mycom2.getGames(getMockGameType(gameTypes2)).take(); + Game game2 = take(mycom2.getGames(getMockGameType(gameTypes2))); Game newGame2 = mycom2.joinGame(game2.getId(), null).get(); Assert.assertEquals(2, newGame2.getPlayers().size()); @@ -373,7 +375,7 @@ LobbyConnection mycom2 = new LobbyConnection(id2); mycom2.connect(server, port).get(); try { - mycom2.joinGame(mycom2.getGames(getMockGameType(mycom2.getGameTypes().get())).take().getId(), "abracadabra").get(); + mycom2.joinGame(take(mycom2.getGames(getMockGameType(mycom2.getGameTypes().get()))).getId(), "abracadabra").get(); Assert.fail("should not allow join"); } catch (ExecutionException ex) { @@ -420,7 +422,7 @@ System.out.println("expected error: " + ex); } - int removedGame = mycom1.removedGame().take(); + int removedGame = take(mycom1.removedGame()); Assert.assertEquals(1, removedGame); mycom1.disconnect(); @@ -501,4 +503,12 @@ static void sleep(int time) { try { Thread.sleep(time); }catch(Exception ex) {} } + + static <T> T take(BlockingQueue<T> queue) throws InterruptedException { + T result = queue.poll(10, TimeUnit.SECONDS); + if (result == null) { + throw new RuntimeException("unable to take next item from queue " + queue); + } + return result; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |