diff --git a/Mage.Common/src/main/java/mage/remote/SessionImpl.java b/Mage.Common/src/main/java/mage/remote/SessionImpl.java index 05edd36263..4730fb3c22 100644 --- a/Mage.Common/src/main/java/mage/remote/SessionImpl.java +++ b/Mage.Common/src/main/java/mage/remote/SessionImpl.java @@ -602,6 +602,14 @@ public class SessionImpl implements Session { return callbackClient.isConnected(); } + @Override + public Boolean isServerReady() { + // Is server works fine, possible use cases: + // - client connected by network, but can't process register/login process due errors like wrong username + // - client connected to broken server that has a wrong config or broken/miss libraries + return isConnected() && serverState != null && serverState.getGameTypes().size() > 0; + } + @Override public PlayerType[] getPlayerTypes() { return serverState.getPlayerTypes(); diff --git a/Mage.Common/src/main/java/mage/remote/interfaces/ServerState.java b/Mage.Common/src/main/java/mage/remote/interfaces/ServerState.java index 1d9bd1867f..077db7f1f1 100644 --- a/Mage.Common/src/main/java/mage/remote/interfaces/ServerState.java +++ b/Mage.Common/src/main/java/mage/remote/interfaces/ServerState.java @@ -29,4 +29,6 @@ public interface ServerState { String getVersionInfo(); + Boolean isServerReady(); + } diff --git a/Mage.Tests/src/test/java/org/mage/test/load/LoadCallbackClient.java b/Mage.Tests/src/test/java/org/mage/test/load/LoadCallbackClient.java index 90f7793636..688ec05e07 100644 --- a/Mage.Tests/src/test/java/org/mage/test/load/LoadCallbackClient.java +++ b/Mage.Tests/src/test/java/org/mage/test/load/LoadCallbackClient.java @@ -7,6 +7,7 @@ import mage.remote.Session; import mage.view.*; import org.apache.log4j.Logger; +import java.util.List; import java.util.UUID; /** @@ -81,6 +82,12 @@ public class LoadCallbackClient implements CallbackClient { break; } + case SHOW_USERMESSAGE: { + List messageData = (List) callback.getData(); + log.info("Warning message: " + String.join(" - ", messageData)); + break; + } + case GAME_TARGET: { GameClientMessage message = (GameClientMessage) callback.getData(); this.gameView = message.getGameView(); diff --git a/Mage.Tests/src/test/java/org/mage/test/load/LoadTest.java b/Mage.Tests/src/test/java/org/mage/test/load/LoadTest.java index 7eb743ca2d..e2f6afb0a9 100644 --- a/Mage.Tests/src/test/java/org/mage/test/load/LoadTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/load/LoadTest.java @@ -43,7 +43,7 @@ public class LoadTest { private static final String TEST_SERVER = "localhost"; private static final int TEST_PORT = 17171; private static final String TEST_PROXY_TYPE = "None"; - private static final String TEST_USER_NAME = "user"; + private static final String TEST_USER_NAME_GLOBAL_PREFIX = "t_"; private static final String TEST_AI_GAME_MODE = "Freeform Commander Free For All"; private static final String TEST_AI_DECK_TYPE = "Variant Magic - Freeform Commander"; private static final String TEST_AI_RANDOM_DECK_SETS = "NEO"; // set for random generated decks (empty for all sets usage) @@ -127,7 +127,7 @@ public class LoadTest { // simple connection to server // monitor other players - LoadPlayer monitor = new LoadPlayer("monitor"); + LoadPlayer monitor = new LoadPlayer("mon"); Assert.assertTrue(monitor.session.isConnected()); int startUsersCount = monitor.getAllRoomUsers().size(); int minimumSleepTime = 2000; @@ -150,11 +150,11 @@ public class LoadTest { public void test_TwoUsersPlayGameUntilEnd() { // monitor other players - LoadPlayer monitor = new LoadPlayer("monitor"); + LoadPlayer monitor = new LoadPlayer("mon"); // users - LoadPlayer player1 = new LoadPlayer("1"); - LoadPlayer player2 = new LoadPlayer("2"); + LoadPlayer player1 = new LoadPlayer("user1"); + LoadPlayer player2 = new LoadPlayer("user2"); // game by user 1 GameTypeView gameType = prepareGameType(player1.session); @@ -213,7 +213,7 @@ public class LoadTest { Assert.assertFalse("need allowed sets", deckAllowedSets.isEmpty()); // monitor and game source - LoadPlayer monitor = new LoadPlayer("monitor", true); + LoadPlayer monitor = new LoadPlayer("mon", true); // game by monitor GameTypeView gameType = prepareGameType(monitor.session); @@ -533,7 +533,7 @@ public class LoadTest { } public LoadPlayer(String userPrefix, boolean joinGameChat) { - this.userName = TEST_USER_NAME + "_" + userPrefix + "_" + RandomUtil.nextInt(10000); + this.userName = TEST_USER_NAME_GLOBAL_PREFIX + userPrefix + "_" + RandomUtil.nextInt(10000); this.connection = createSimpleConnection(this.userName); this.client = new SimpleMageClient(joinGameChat); this.session = new SessionImpl(this.client); @@ -541,6 +541,8 @@ public class LoadTest { this.session.connect(this.connection); this.client.setSession(this.session); this.roomID = this.session.getMainRoomId(); + + Assert.assertTrue("client must be connected to server", this.session.isServerReady()); } public ArrayList getAllRoomUsers() {