Fixing java tests and bugs found by tests.

This commit is contained in:
lotodore
2015-01-17 17:58:47 +01:00
parent 67c444266f
commit eedd86e150
7 changed files with 132 additions and 76 deletions
+3
View File
@@ -1379,6 +1379,7 @@ ServerGameStateHand::CheckPlayerTimeouts(boost::shared_ptr<ServerGame> server)
boost::shared_ptr<SessionData> session = server->GetSessionManager().GetSessionByUniquePlayerId(tmpPlayer->getMyUniqueID()); boost::shared_ptr<SessionData> session = server->GetSessionManager().GetSessionByUniquePlayerId(tmpPlayer->getMyUniqueID());
if (session) { if (session) {
boost::shared_ptr<NetPacket> packet(new NetPacket); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_GameMessage);
GameMessage *netGame = packet->GetMsg()->mutable_gamemessage(); GameMessage *netGame = packet->GetMsg()->mutable_gamemessage();
netGame->set_gameid(server->GetId()); netGame->set_gameid(server->GetId());
netGame->set_messagetype(GameMessage::Type_GameManagementMessage); netGame->set_messagetype(GameMessage::Type_GameManagementMessage);
@@ -1455,6 +1456,7 @@ ServerGameStateHand::PerformRejoin(boost::shared_ptr<ServerGame> server, boost::
if (rejoinPlayer) { if (rejoinPlayer) {
// Notify other clients about id change. // Notify other clients about id change.
boost::shared_ptr<NetPacket> packet(new NetPacket); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_GameMessage);
GameMessage *netGame = packet->GetMsg()->mutable_gamemessage(); GameMessage *netGame = packet->GetMsg()->mutable_gamemessage();
netGame->set_gameid(server->GetId()); netGame->set_gameid(server->GetId());
netGame->set_messagetype(GameMessage::Type_GameManagementMessage); netGame->set_messagetype(GameMessage::Type_GameManagementMessage);
@@ -1486,6 +1488,7 @@ ServerGameStateHand::SendGameData(boost::shared_ptr<ServerGame> server, boost::s
Game &curGame = server->GetGame(); Game &curGame = server->GetGame();
// Send game start notification to rejoining client. // Send game start notification to rejoining client.
boost::shared_ptr<NetPacket> packet(new NetPacket); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_GameMessage);
GameMessage *netGame = packet->GetMsg()->mutable_gamemessage(); GameMessage *netGame = packet->GetMsg()->mutable_gamemessage();
netGame->set_gameid(server->GetId()); netGame->set_gameid(server->GetId());
netGame->set_messagetype(GameMessage::Type_GameManagementMessage); netGame->set_messagetype(GameMessage::Type_GameManagementMessage);
+1
View File
@@ -1345,6 +1345,7 @@ ServerLobbyThread::HandleNetPacketSubscriptionRequest(boost::shared_ptr<SessionD
} else { } else {
session->ResetWantsLobbyMsg(); session->ResetWantsLobbyMsg();
} }
boost::shared_ptr<NetPacket> packet(new NetPacket); boost::shared_ptr<NetPacket> packet(new NetPacket);
packet->GetMsg()->set_messagetype(PokerTHMessage::Type_LobbyMessage); packet->GetMsg()->set_messagetype(PokerTHMessage::Type_LobbyMessage);
LobbyMessage *netLobby = packet->GetMsg()->mutable_lobbymessage(); LobbyMessage *netLobby = packet->GetMsg()->mutable_lobbymessage();
+25 -26
View File
@@ -33,7 +33,6 @@ import de.pokerth.protocol.ProtoBuf.NetGameInfo;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.EndRaiseMode; import de.pokerth.protocol.ProtoBuf.NetGameInfo.EndRaiseMode;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.NetGameType; import de.pokerth.protocol.ProtoBuf.NetGameInfo.NetGameType;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.RaiseIntervalMode; import de.pokerth.protocol.ProtoBuf.NetGameInfo.RaiseIntervalMode;
import de.pokerth.protocol.ProtoBuf.PokerTHMessage.PokerTHMessageType;
import de.pokerth.protocol.ProtoBuf.NetGameMode; import de.pokerth.protocol.ProtoBuf.NetGameMode;
import de.pokerth.protocol.ProtoBuf.PokerTHMessage; import de.pokerth.protocol.ProtoBuf.PokerTHMessage;
@@ -67,7 +66,7 @@ public class GameListTest extends TestBase {
// Waiting for player list update. // Waiting for player list update.
PokerTHMessage msg; PokerTHMessage msg;
msg = receiveMessage(); msg = receiveMessage();
assertTrue(msg.hasPlayerListMessage()); assertTrue(msg.hasLobbyMessage() || msg.getLobbyMessage().hasPlayerListMessage());
// Create a new game. // Create a new game.
Collection<Integer> l = new ArrayList<Integer>(); Collection<Integer> l = new ArrayList<Integer>();
@@ -79,8 +78,8 @@ public class GameListTest extends TestBase {
// Game list message is sent before join game ack. // Game list message is sent before join game ack.
msg = receiveMessage(); msg = receiveMessage();
assertTrue(msg.hasGameListNewMessage()); assertTrue(msg.hasLobbyMessage() || msg.getLobbyMessage().hasGameListNewMessage());
GameListNewMessage gameListNewMsg = msg.getGameListNewMessage(); GameListNewMessage gameListNewMsg = msg.getLobbyMessage().getGameListNewMessage();
int gameId = gameListNewMsg.getGameId(); int gameId = gameListNewMsg.getGameId();
assertTrue(0 != gameListNewMsg.getGameId()); assertTrue(0 != gameListNewMsg.getGameId());
checkGameListNewMsg( checkGameListNewMsg(
@@ -92,14 +91,14 @@ public class GameListTest extends TestBase {
// Next message is join game ack. // Next message is join game ack.
msg = receiveMessage(); msg = receiveMessage();
assertTrue(msg.hasJoinGameAckMessage() && msg.getMessageType() == PokerTHMessageType.Type_JoinGameAckMessage); assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasJoinGameAckMessage());
// Make sure game list id equals join game ack id. // Make sure game list id equals join game ack id.
assertEquals(gameId, msg.getJoinGameAckMessage().getGameId()); assertEquals(gameId, msg.getLobbyMessage().getJoinGameAckMessage().getGameId());
// Next message is game list player joined. // Next message is game list player joined.
msg = receiveMessage(); msg = receiveMessage();
assertTrue(msg.hasGameListPlayerJoinedMessage()); assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasGameListPlayerJoinedMessage());
GameListPlayerJoinedMessage gameListJoinedMsg = msg.getGameListPlayerJoinedMessage(); GameListPlayerJoinedMessage gameListJoinedMsg = msg.getLobbyMessage().getGameListPlayerJoinedMessage();
assertEquals(gameId, gameListJoinedMsg.getGameId()); assertEquals(gameId, gameListJoinedMsg.getGameId());
assertEquals(myId, gameListJoinedMsg.getPlayerId()); assertEquals(myId, gameListJoinedMsg.getPlayerId());
@@ -112,13 +111,13 @@ public class GameListTest extends TestBase {
String password = username; String password = username;
playerId[i] = userInit(s[i], username, password); playerId[i] = userInit(s[i], username, password);
msg = receiveMessage(); msg = receiveMessage();
assertTrue(msg.hasPlayerListMessage()); assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasPlayerListMessage());
do { do {
msg = receiveMessage(s[i]); msg = receiveMessage(s[i]);
} while (msg.hasPlayerListMessage()); } while (msg.hasLobbyMessage() && msg.getLobbyMessage().hasPlayerListMessage());
assertTrue(msg.hasGameListNewMessage()); assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasGameListNewMessage());
gameListNewMsg = msg.getGameListNewMessage(); gameListNewMsg = msg.getLobbyMessage().getGameListNewMessage();
assertEquals(gameId, gameListNewMsg.getGameId()); assertEquals(gameId, gameListNewMsg.getGameId());
assertTrue(0 != gameListNewMsg.getGameId()); assertTrue(0 != gameListNewMsg.getGameId());
checkGameListNewMsg( checkGameListNewMsg(
@@ -135,26 +134,26 @@ public class GameListTest extends TestBase {
sendMessage(joinGameRequestMsg(gameId, "", false), s[i]); sendMessage(joinGameRequestMsg(gameId, "", false), s[i]);
do { do {
msg = receiveMessage(s[i]); msg = receiveMessage(s[i]);
} while (msg.hasPlayerListMessage()); } while (msg.hasLobbyMessage() && msg.getLobbyMessage().hasPlayerListMessage());
for (int j = 0; j < i; j++) { for (int j = 0; j < i; j++) {
assertTrue(msg.hasGameListPlayerJoinedMessage()); assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasGameListPlayerJoinedMessage());
gameListJoinedMsg = msg.getGameListPlayerJoinedMessage(); gameListJoinedMsg = msg.getLobbyMessage().getGameListPlayerJoinedMessage();
assertEquals(gameId, gameListJoinedMsg.getGameId()); assertEquals(gameId, gameListJoinedMsg.getGameId());
assertEquals(playerId[j], gameListJoinedMsg.getPlayerId()); assertEquals(playerId[j], gameListJoinedMsg.getPlayerId());
msg = receiveMessage(s[i]); msg = receiveMessage(s[i]);
} }
failOnErrorMessage(msg); failOnErrorMessage(msg);
// Next message is join game ack. // Next message is join game ack.
assertTrue(msg.hasJoinGameAckMessage()); assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasJoinGameAckMessage());
// Make sure game list id equals join game ack id. // Make sure game list id equals join game ack id.
assertEquals(gameId, msg.getJoinGameAckMessage().getGameId()); assertEquals(gameId, msg.getLobbyMessage().getJoinGameAckMessage().getGameId());
// Next message is game list player joined. // Next message is game list player joined.
do { do {
msg = receiveMessage(s[i]); msg = receiveMessage(s[i]);
} while (msg.hasGamePlayerJoinedMessage()); } while (msg.hasGameMessage() && msg.getGameMessage().hasGameManagementMessage() && msg.getGameMessage().getGameManagementMessage().hasGamePlayerJoinedMessage());
assertTrue(msg.hasGameListPlayerJoinedMessage()); assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasGameListPlayerJoinedMessage());
gameListJoinedMsg = msg.getGameListPlayerJoinedMessage(); gameListJoinedMsg = msg.getLobbyMessage().getGameListPlayerJoinedMessage();
assertEquals(gameId, gameListJoinedMsg.getGameId()); assertEquals(gameId, gameListJoinedMsg.getGameId());
assertEquals(playerId[i], gameListJoinedMsg.getPlayerId()); assertEquals(playerId[i], gameListJoinedMsg.getPlayerId());
} }
@@ -163,9 +162,9 @@ public class GameListTest extends TestBase {
do { do {
msg = receiveMessage(); msg = receiveMessage();
failOnErrorMessage(msg); failOnErrorMessage(msg);
} while (!(msg.hasGameListUpdateMessage())); } while (!(msg.hasLobbyMessage() && msg.getLobbyMessage().hasGameListUpdateMessage()));
assertEquals(NetGameMode.netGameStarted, msg.getGameListUpdateMessage().getGameMode()); assertEquals(NetGameMode.netGameStarted, msg.getLobbyMessage().getGameListUpdateMessage().getGameMode());
// Wait for player left messages. // Wait for player left messages.
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
@@ -173,8 +172,8 @@ public class GameListTest extends TestBase {
do { do {
msg = receiveMessage(); msg = receiveMessage();
failOnErrorMessage(msg); failOnErrorMessage(msg);
} while (!msg.hasGameListPlayerLeftMessage()); } while (!(msg.hasLobbyMessage() && msg.getLobbyMessage().hasGameListPlayerLeftMessage()));
GameListPlayerLeftMessage gameListLeftMsg = msg.getGameListPlayerLeftMessage(); GameListPlayerLeftMessage gameListLeftMsg = msg.getLobbyMessage().getGameListPlayerLeftMessage();
assertEquals(gameId, gameListLeftMsg.getGameId()); assertEquals(gameId, gameListLeftMsg.getGameId());
assertEquals(playerId[i], gameListLeftMsg.getPlayerId()); assertEquals(playerId[i], gameListLeftMsg.getPlayerId());
} }
@@ -183,8 +182,8 @@ public class GameListTest extends TestBase {
do { do {
msg = receiveMessage(); msg = receiveMessage();
failOnErrorMessage(msg); failOnErrorMessage(msg);
} while (!(msg.hasGameListUpdateMessage())); } while (!(msg.hasLobbyMessage() && msg.getLobbyMessage().hasGameListUpdateMessage()));
assertEquals(NetGameMode.netGameClosed, msg.getGameListUpdateMessage().getGameMode()); assertEquals(NetGameMode.netGameClosed, msg.getLobbyMessage().getGameListUpdateMessage().getGameMode());
} }
} }
+35 -17
View File
@@ -26,6 +26,10 @@ import java.util.Collection;
import org.junit.Test; import org.junit.Test;
import de.pokerth.protocol.ProtoBuf.GameEngineMessage;
import de.pokerth.protocol.ProtoBuf.GameMessage;
import de.pokerth.protocol.ProtoBuf.GameEngineMessage.GameEngineMessageType;
import de.pokerth.protocol.ProtoBuf.GameMessage.GameMessageType;
import de.pokerth.protocol.ProtoBuf.NetGameInfo; import de.pokerth.protocol.ProtoBuf.NetGameInfo;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.EndRaiseMode; import de.pokerth.protocol.ProtoBuf.NetGameInfo.EndRaiseMode;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.NetGameType; import de.pokerth.protocol.ProtoBuf.NetGameInfo.NetGameType;
@@ -61,8 +65,9 @@ public class LoadTest extends TestBase {
do { do {
msg = receiveMessage(s[i * 10]); msg = receiveMessage(s[i * 10]);
} while (msg.hasGameListNewMessage() || msg.hasGameListPlayerJoinedMessage() || msg.hasGamePlayerJoinedMessage()); } while ((msg.hasLobbyMessage() && (msg.getLobbyMessage().hasGameListNewMessage() || msg.getLobbyMessage().hasGameListPlayerJoinedMessage()))
if (!msg.hasPlayerListMessage()) { || (msg.hasGameMessage() && msg.getGameMessage().hasGameManagementMessage() && msg.getGameMessage().getGameManagementMessage().hasGamePlayerJoinedMessage()));
if (!(msg.hasLobbyMessage() && msg.getLobbyMessage().hasPlayerListMessage())) {
failOnErrorMessage(msg); failOnErrorMessage(msg);
fail("Invalid message."); fail("Invalid message.");
} }
@@ -80,14 +85,14 @@ public class LoadTest extends TestBase {
do { do {
msg = receiveMessage(s[i * 10]); msg = receiveMessage(s[i * 10]);
failOnErrorMessage(msg); failOnErrorMessage(msg);
} while (msg.hasGameListNewMessage() || msg.hasGameListPlayerJoinedMessage() || msg.hasPlayerListMessage()); } while (msg.hasLobbyMessage() && (msg.getLobbyMessage().hasGameListNewMessage() || msg.getLobbyMessage().hasGameListPlayerJoinedMessage() || msg.getLobbyMessage().hasPlayerListMessage()));
// Join game ack. // Join game ack.
if (!msg.hasJoinGameAckMessage()) { if (!(msg.hasLobbyMessage() && msg.getLobbyMessage().hasJoinGameAckMessage())) {
failOnErrorMessage(msg); failOnErrorMessage(msg);
fail("Could not create game!"); fail("Could not create game!");
} }
gameId[i] = msg.getJoinGameAckMessage().getGameId(); gameId[i] = msg.getLobbyMessage().getJoinGameAckMessage().getGameId();
} }
@@ -103,8 +108,9 @@ public class LoadTest extends TestBase {
// Waiting for player list update. // Waiting for player list update.
do { do {
msg = receiveMessage(s[i]); msg = receiveMessage(s[i]);
} while (msg.hasGameListPlayerJoinedMessage() || msg.hasGamePlayerJoinedMessage()); } while ((msg.hasLobbyMessage() && msg.getLobbyMessage().hasGameListPlayerJoinedMessage())
if (!msg.hasPlayerListMessage()) { || (msg.hasGameMessage() && msg.getGameMessage().hasGameManagementMessage() && msg.getGameMessage().getGameManagementMessage().hasGamePlayerJoinedMessage()));
if (!(msg.hasLobbyMessage() && msg.getLobbyMessage().hasPlayerListMessage())) {
failOnErrorMessage(msg); failOnErrorMessage(msg);
fail("Invalid message."); fail("Invalid message.");
} }
@@ -112,8 +118,8 @@ public class LoadTest extends TestBase {
do { do {
msg = receiveMessage(s[i]); msg = receiveMessage(s[i]);
failOnErrorMessage(msg); failOnErrorMessage(msg);
} while (!msg.hasJoinGameAckMessage() && !msg.hasJoinGameFailedMessage()); } while (!(msg.hasLobbyMessage() && msg.getLobbyMessage().hasJoinGameAckMessage()) && !(msg.hasLobbyMessage() && msg.getLobbyMessage().hasJoinGameFailedMessage()));
if (!msg.hasJoinGameAckMessage()) { if (!(msg.hasLobbyMessage() && msg.getLobbyMessage().hasJoinGameAckMessage())) {
fail("User " + username + " could not join normal game."); fail("User " + username + " could not join normal game.");
} }
} }
@@ -125,26 +131,38 @@ public class LoadTest extends TestBase {
while (s[i].getInputStream().available() > 0) { while (s[i].getInputStream().available() > 0) {
msg = receiveMessage(s[i]); msg = receiveMessage(s[i]);
failOnErrorMessage(msg); failOnErrorMessage(msg);
if (msg.hasHandStartMessage()) { if (msg.hasGameMessage() && msg.getGameMessage().hasGameEngineMessage() && msg.getGameMessage().getGameEngineMessage().hasHandStartMessage()) {
handNum[i / 10]++; handNum[i / 10]++;
} }
else if (msg.hasPlayersTurnMessage()) { else if (msg.hasGameMessage() && msg.getGameMessage().hasGameEngineMessage() && msg.getGameMessage().getGameEngineMessage().hasPlayersTurnMessage()) {
if (msg.getPlayersTurnMessage().getPlayerId() == playerId[i / 10]) { if (msg.getGameMessage().getGameEngineMessage().getPlayersTurnMessage().getPlayerId() == playerId[i / 10]) {
MyActionRequestMessage myRequest = MyActionRequestMessage.newBuilder() MyActionRequestMessage myRequest = MyActionRequestMessage.newBuilder()
.setGameId(gameId[i / 10]) .setGameState(msg.getGameMessage().getGameEngineMessage().getPlayersTurnMessage().getGameState())
.setGameState(msg.getPlayersTurnMessage().getGameState())
.setHandNum(handNum[i / 10]) .setHandNum(handNum[i / 10])
.setMyAction(NetPlayerAction.netActionAllIn) .setMyAction(NetPlayerAction.netActionAllIn)
.setMyRelativeBet(0) .setMyRelativeBet(0)
.build(); .build();
PokerTHMessage outMsg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_MyActionRequestMessage) GameEngineMessage gameEngine = GameEngineMessage.newBuilder()
.setMessageType(GameEngineMessageType.Type_MyActionRequestMessage)
.setMyActionRequestMessage(myRequest) .setMyActionRequestMessage(myRequest)
.build(); .build();
GameMessage game = GameMessage.newBuilder()
.setGameId(gameId[i / 10])
.setMessageType(GameMessageType.Type_GameEngineMessage)
.setGameEngineMessage(gameEngine)
.build();
PokerTHMessage outMsg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_GameMessage)
.setGameMessage(game)
.build();
sendMessage(outMsg, s[i]); sendMessage(outMsg, s[i]);
} }
} }
else if (msg.hasEndOfGameMessage()) { else if (msg.hasGameMessage() && msg.getGameMessage().hasGameManagementMessage() && msg.getGameMessage().getGameManagementMessage().hasEndOfGameMessage()) {
abort = true; abort = true;
} }
} }
@@ -17,8 +17,7 @@
package de.pokerth.test; package de.pokerth.test;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.*;
import static org.junit.Assert.fail;
import java.net.Socket; import java.net.Socket;
import java.util.ArrayList; import java.util.ArrayList;
@@ -27,7 +26,9 @@ import java.util.Collection;
import org.junit.Test; import org.junit.Test;
import de.pokerth.protocol.ProtoBuf.NetGameInfo; import de.pokerth.protocol.ProtoBuf.NetGameInfo;
import de.pokerth.protocol.ProtoBuf.LobbyMessage.LobbyMessageType;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.EndRaiseMode; import de.pokerth.protocol.ProtoBuf.NetGameInfo.EndRaiseMode;
import de.pokerth.protocol.ProtoBuf.LobbyMessage;
import de.pokerth.protocol.ProtoBuf.PokerTHMessage; import de.pokerth.protocol.ProtoBuf.PokerTHMessage;
import de.pokerth.protocol.ProtoBuf.SubscriptionRequestMessage; import de.pokerth.protocol.ProtoBuf.SubscriptionRequestMessage;
import de.pokerth.protocol.ProtoBuf.NetGameInfo.NetGameType; import de.pokerth.protocol.ProtoBuf.NetGameInfo.NetGameType;
@@ -41,22 +42,34 @@ public class LobbySubscriptionTest extends TestBase {
public void testLobbySubscription() throws Exception { public void testLobbySubscription() throws Exception {
guestInit(); guestInit();
final int requestId = 1234;
PokerTHMessage msg; PokerTHMessage msg;
msg = receiveMessage(); msg = receiveMessage();
if (!msg.hasPlayerListMessage()) { if (!(msg.hasLobbyMessage() && msg.getLobbyMessage().hasPlayerListMessage())) {
failOnErrorMessage(msg); failOnErrorMessage(msg);
fail("Invalid message."); fail("Invalid message.");
} }
SubscriptionRequestMessage subscriptionRequest = SubscriptionRequestMessage.newBuilder() SubscriptionRequestMessage subscriptionRequest = SubscriptionRequestMessage.newBuilder()
.setRequestId(requestId)
.setSubscriptionAction(SubscriptionAction.unsubscribeGameList) .setSubscriptionAction(SubscriptionAction.unsubscribeGameList)
.build(); .build();
msg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_SubscriptionRequestMessage) LobbyMessage lobby = LobbyMessage.newBuilder()
.setMessageType(LobbyMessageType.Type_SubscriptionRequestMessage)
.setSubscriptionRequestMessage(subscriptionRequest) .setSubscriptionRequestMessage(subscriptionRequest)
.build(); .build();
msg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_LobbyMessage)
.setLobbyMessage(lobby)
.build();
sendMessage(msg); sendMessage(msg);
msg = receiveMessage();
assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasSubscriptionReplyMessage());
assertEquals(requestId, msg.getLobbyMessage().getSubscriptionReplyMessage().getRequestId());
// Create a new game. // Create a new game.
Collection<Integer> l = new ArrayList<Integer>(); Collection<Integer> l = new ArrayList<Integer>();
NetGameInfo gameInfo = createGameInfo(NetGameType.normalGame, 10, 5, 5, EndRaiseMode.doubleBlinds, 0, 100, GuestUser + " game list normal game", l, 10, 0, 2, 2000); NetGameInfo gameInfo = createGameInfo(NetGameType.normalGame, 10, 5, 5, EndRaiseMode.doubleBlinds, 0, 100, GuestUser + " game list normal game", l, 10, 0, 2, 2000);
@@ -68,8 +81,8 @@ public class LobbySubscriptionTest extends TestBase {
// No game list message should be sent by the server. // No game list message should be sent by the server.
// Next message is join game ack. // Next message is join game ack.
msg = receiveMessage(); msg = receiveMessage();
assertTrue(msg.hasJoinGameAckMessage()); assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasJoinGameAckMessage());
int gameId = msg.getJoinGameAckMessage().getGameId(); int gameId = msg.getLobbyMessage().getJoinGameAckMessage().getGameId();
Socket s[] = new Socket[9]; Socket s[] = new Socket[9];
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
@@ -83,29 +96,42 @@ public class LobbySubscriptionTest extends TestBase {
// No game list message should be received. // No game list message should be received.
do { do {
msg = receiveMessage(); msg = receiveMessage();
if (msg.hasGameListNewMessage() || msg.hasPlayerListMessage()) { if (msg.hasLobbyMessage() && (msg.getLobbyMessage().hasGameListNewMessage() || msg.getLobbyMessage().hasPlayerListMessage())) {
fail("Game/player list messages are switched off!"); fail("Game/player list messages are switched off!");
} }
} while (!msg.hasStartEventMessage()); } while (!(msg.hasGameMessage() && msg.getGameMessage().hasGameManagementMessage() && msg.getGameMessage().getGameManagementMessage().hasStartEventMessage()));
// Resubscribe game list // Resubscribe game list
subscriptionRequest = SubscriptionRequestMessage.newBuilder() subscriptionRequest = SubscriptionRequestMessage.newBuilder()
.setRequestId(requestId + 1)
.setSubscriptionAction(SubscriptionAction.resubscribeGameList) .setSubscriptionAction(SubscriptionAction.resubscribeGameList)
.build(); .build();
msg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_SubscriptionRequestMessage) lobby = LobbyMessage.newBuilder()
.setMessageType(LobbyMessageType.Type_SubscriptionRequestMessage)
.setSubscriptionRequestMessage(subscriptionRequest) .setSubscriptionRequestMessage(subscriptionRequest)
.build(); .build();
msg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_LobbyMessage)
.setLobbyMessage(lobby)
.build();
sendMessage(msg); sendMessage(msg);
// Next messages should player list messages for all 10 players. // Next messages should player list messages for all 10 players.
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
msg = receiveMessage(); msg = receiveMessage();
assertTrue(msg.hasPlayerListMessage()); assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasPlayerListMessage());
} }
// Now there should be one game list message. // Now there should be one game list message.
msg = receiveMessage(); msg = receiveMessage();
assertTrue(msg.hasGameListNewMessage()); assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasGameListNewMessage());
// Next the request should be confirmed.
msg = receiveMessage();
assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasSubscriptionReplyMessage());
assertEquals(requestId + 1, msg.getLobbyMessage().getSubscriptionReplyMessage().getRequestId());
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
s[i].close(); s[i].close();
+21 -12
View File
@@ -27,9 +27,11 @@ import java.util.Collection;
import org.junit.Test; import org.junit.Test;
import de.pokerth.protocol.ProtoBuf.LobbyMessage;
import de.pokerth.protocol.ProtoBuf.NetAvatarType; import de.pokerth.protocol.ProtoBuf.NetAvatarType;
import de.pokerth.protocol.ProtoBuf.NetPlayerInfoRights; import de.pokerth.protocol.ProtoBuf.NetPlayerInfoRights;
import de.pokerth.protocol.ProtoBuf.PlayerInfoReplyMessage; import de.pokerth.protocol.ProtoBuf.PlayerInfoReplyMessage;
import de.pokerth.protocol.ProtoBuf.LobbyMessage.LobbyMessageType;
import de.pokerth.protocol.ProtoBuf.PlayerInfoReplyMessage.PlayerInfoData; import de.pokerth.protocol.ProtoBuf.PlayerInfoReplyMessage.PlayerInfoData;
import de.pokerth.protocol.ProtoBuf.PlayerInfoRequestMessage; import de.pokerth.protocol.ProtoBuf.PlayerInfoRequestMessage;
import de.pokerth.protocol.ProtoBuf.PokerTHMessage; import de.pokerth.protocol.ProtoBuf.PokerTHMessage;
@@ -44,13 +46,20 @@ public class PlayerInfoTest extends TestBase {
} }
protected void sendPlayerInfoRequest(Socket s, Collection<Integer> playerIds) throws Exception { protected void sendPlayerInfoRequest(Socket s, Collection<Integer> playerIds) throws Exception {
PlayerInfoRequestMessage request = PlayerInfoRequestMessage.newBuilder() PlayerInfoRequestMessage infoRequest = PlayerInfoRequestMessage.newBuilder()
.addAllPlayerId(playerIds) .addAllPlayerId(playerIds)
.build(); .build();
PokerTHMessage msg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_PlayerInfoRequestMessage) LobbyMessage lobby = LobbyMessage.newBuilder()
.setPlayerInfoRequestMessage(request) .setMessageType(LobbyMessageType.Type_PlayerInfoRequestMessage)
.setPlayerInfoRequestMessage(infoRequest)
.build(); .build();
PokerTHMessage msg = PokerTHMessage.newBuilder()
.setMessageType(PokerTHMessageType.Type_LobbyMessage)
.setLobbyMessage(lobby)
.build();
sendMessage(msg, s); sendMessage(msg, s);
} }
@@ -92,9 +101,9 @@ public class PlayerInfoTest extends TestBase {
sendPlayerInfoRequest(s[i], firstPlayerId); sendPlayerInfoRequest(s[i], firstPlayerId);
do { do {
msg = receiveMessage(s[i]); msg = receiveMessage(s[i]);
} while (msg.hasPlayerListMessage()); } while (msg.hasLobbyMessage() && msg.getLobbyMessage().hasPlayerListMessage());
assertTrue(msg.hasPlayerInfoReplyMessage() && msg.getMessageType() == PokerTHMessageType.Type_PlayerInfoReplyMessage); assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasPlayerInfoReplyMessage() && msg.getLobbyMessage().getMessageType() == LobbyMessageType.Type_PlayerInfoReplyMessage);
PlayerInfoReplyMessage reply = msg.getPlayerInfoReplyMessage(); PlayerInfoReplyMessage reply = msg.getLobbyMessage().getPlayerInfoReplyMessage();
assertTrue(reply.getPlayerId() == firstPlayerId); assertTrue(reply.getPlayerId() == firstPlayerId);
assertTrue(reply.hasPlayerInfoData()); assertTrue(reply.hasPlayerInfoData());
PlayerInfoData info = reply.getPlayerInfoData(); PlayerInfoData info = reply.getPlayerInfoData();
@@ -112,9 +121,9 @@ public class PlayerInfoTest extends TestBase {
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
do { do {
msg = receiveMessage(); msg = receiveMessage();
} while (msg.hasPlayerListMessage()); } while (msg.hasLobbyMessage() && msg.getLobbyMessage().hasPlayerListMessage());
assertTrue(msg.hasPlayerInfoReplyMessage() && msg.getMessageType() == PokerTHMessageType.Type_PlayerInfoReplyMessage); assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasPlayerInfoReplyMessage() && msg.getLobbyMessage().getMessageType() == LobbyMessageType.Type_PlayerInfoReplyMessage);
PlayerInfoReplyMessage reply = msg.getPlayerInfoReplyMessage(); PlayerInfoReplyMessage reply = msg.getLobbyMessage().getPlayerInfoReplyMessage();
assertTrue(reply.getPlayerId() == playerId[i]); assertTrue(reply.getPlayerId() == playerId[i]);
assertTrue(reply.hasPlayerInfoData()); assertTrue(reply.hasPlayerInfoData());
PlayerInfoData info = reply.getPlayerInfoData(); PlayerInfoData info = reply.getPlayerInfoData();
@@ -134,8 +143,8 @@ public class PlayerInfoTest extends TestBase {
// Request invalid player info. // Request invalid player info.
sendPlayerInfoRequest(sock, maxPlayerId + 1); sendPlayerInfoRequest(sock, maxPlayerId + 1);
msg = receiveMessage(); msg = receiveMessage();
assertTrue(msg.hasPlayerInfoReplyMessage() && msg.getMessageType() == PokerTHMessageType.Type_PlayerInfoReplyMessage); assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasPlayerInfoReplyMessage() && msg.getLobbyMessage().getMessageType() == LobbyMessageType.Type_PlayerInfoReplyMessage);
PlayerInfoReplyMessage reply = msg.getPlayerInfoReplyMessage(); PlayerInfoReplyMessage reply = msg.getLobbyMessage().getPlayerInfoReplyMessage();
assertTrue(reply.getPlayerId() == maxPlayerId + 1); assertTrue(reply.getPlayerId() == maxPlayerId + 1);
assertFalse(reply.hasPlayerInfoData()); assertFalse(reply.hasPlayerInfoData());
@@ -39,10 +39,10 @@ public class PlayerListTest extends TestBase {
// Waiting for player list update. // Waiting for player list update.
PokerTHMessage msg; PokerTHMessage msg;
msg = receiveMessage(); msg = receiveMessage();
assertTrue(msg.hasPlayerListMessage()); assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasPlayerListMessage());
// This should be a "player list new" notification with correct player id. // This should be a "player list new" notification with correct player id.
PlayerListMessage listMsg = msg.getPlayerListMessage(); PlayerListMessage listMsg = msg.getLobbyMessage().getPlayerListMessage();
assertEquals(myId, listMsg.getPlayerId()); assertEquals(myId, listMsg.getPlayerId());
assertEquals(PlayerListNotification.playerListNew, listMsg.getPlayerListNotification()); assertEquals(PlayerListNotification.playerListNew, listMsg.getPlayerListNotification());
@@ -55,8 +55,8 @@ public class PlayerListTest extends TestBase {
playerId[i] = userInit(s[i], username, password); playerId[i] = userInit(s[i], username, password);
msg = receiveMessage(); msg = receiveMessage();
assertTrue(msg.hasPlayerListMessage()); assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasPlayerListMessage());
listMsg = msg.getPlayerListMessage(); listMsg = msg.getLobbyMessage().getPlayerListMessage();
// Id should be different from first id. // Id should be different from first id.
assertTrue(myId != playerId[i]); assertTrue(myId != playerId[i]);
// This should be a "player list new" notification with correct player id. // This should be a "player list new" notification with correct player id.
@@ -67,8 +67,8 @@ public class PlayerListTest extends TestBase {
// After the connection is closed, a "player list left" notification should be received. // After the connection is closed, a "player list left" notification should be received.
msg = receiveMessage(); msg = receiveMessage();
assertTrue(msg.hasPlayerListMessage()); assertTrue(msg.hasLobbyMessage() && msg.getLobbyMessage().hasPlayerListMessage());
listMsg = msg.getPlayerListMessage(); listMsg = msg.getLobbyMessage().getPlayerListMessage();
assertEquals(playerId[i], listMsg.getPlayerId()); assertEquals(playerId[i], listMsg.getPlayerId());
assertEquals(PlayerListNotification.playerListLeft, listMsg.getPlayerListNotification()); assertEquals(PlayerListNotification.playerListLeft, listMsg.getPlayerListNotification());
} }