Skip to content

Commit

Permalink
tests: improved game/chat logs in load tests (now it shows in txt for…
Browse files Browse the repository at this point in the history
…mat instead html, example: test_TwoAIPlayGame_Multiple)
  • Loading branch information
JayDi85 committed Oct 11, 2023
1 parent fe8b8e1 commit f653fd4
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 21 deletions.
10 changes: 4 additions & 6 deletions Mage.Client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
<groupId>org.unbescape</groupId>
<artifactId>unbescape</artifactId>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
</dependency>

<dependency>
<!-- inner lib for jboss network implementation -->
Expand Down Expand Up @@ -110,12 +114,6 @@
<artifactId>beansbinding</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<!-- scraping lib to download and parse symbols/images/svg -->
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.3</version>
</dependency>

<!-- music player START -->
<dependency>
Expand Down
4 changes: 4 additions & 0 deletions Mage.Tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@
<groupId>net.java.truevfs</groupId>
<artifactId>truevfs-profile-base</artifactId>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
22 changes: 10 additions & 12 deletions Mage.Tests/src/test/java/org/mage/test/load/LoadCallbackClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mage.remote.Session;
import mage.view.*;
import org.apache.log4j.Logger;
import org.jsoup.Jsoup;

import java.util.List;
import java.util.UUID;
Expand All @@ -31,18 +32,20 @@ public class LoadCallbackClient implements CallbackClient {
private GameView gameView;

private final String logsPrefix;
private final Boolean showLogsAsHtml; // original game logs in HTML, but it can be converted to txt for more readable console

public LoadCallbackClient(boolean joinGameChat, String logsPrefix) {
public LoadCallbackClient(boolean joinGameChat, String logsPrefix, Boolean showLogsAsHtml) {
this.joinGameChat = joinGameChat;
this.logsPrefix = logsPrefix;
this.showLogsAsHtml = showLogsAsHtml;
}

@Override
public void processCallback(ClientCallback callback) {
callback.decompressData();
controlCount = 0;

// ignore bloaded logs
// ignore bloated logs
switch (callback.getMethod()) {
case CHATMESSAGE:
case GAME_UPDATE_AND_INFORM:
Expand All @@ -63,7 +66,8 @@ public void processCallback(ClientCallback callback) {

case CHATMESSAGE: {
ChatMessage message = (ChatMessage) callback.getData();
log.info(getLogStartInfo() + "chat message: " + message.getMessage());
String mes = this.showLogsAsHtml ? message.getMessage() : Jsoup.parse(message.getMessage()).text();
log.info(getLogStartInfo() + "chat message" + (message.getTurnInfo() == null ? "" : " at " + message.getTurnInfo()) + ": " + mes);
break;
}

Expand All @@ -81,7 +85,7 @@ public void processCallback(ClientCallback callback) {
case GAME_INFORM_PERSONAL: {
GameClientMessage message = (GameClientMessage) callback.getData();
gameView = message.getGameView();
//log.info(getLogStartInfo() + "Inform: " + message.getMessage());
// ignore play priority log
break;
}

Expand All @@ -99,17 +103,15 @@ public void processCallback(ClientCallback callback) {
case "Select a starting player":
session.sendPlayerUUID(gameId, playerId);
return;
//break;
case "Select a card to discard":
log.info(getLogStartInfo() + "hand size: " + gameView.getHand().size());
SimpleCardView card = gameView.getHand().values().iterator().next();
session.sendPlayerUUID(gameId, card.getId());
return;
//break;
default:
log.error(getLogStartInfo() + "unknown GAME_TARGET message: " + message.toString());
return;
}
break;
}

case GAME_ASK: {
Expand Down Expand Up @@ -170,8 +172,7 @@ public void processCallback(ClientCallback callback) {
default:
log.error(getLogStartInfo() + "unknown callback: " + callback.getMethod() + ", " + callback.getData().toString());
session.sendPlayerBoolean(gameId, false);
return;
//break;
break;
}
}

Expand All @@ -188,9 +189,6 @@ private PlayerView getPlayer() {

private String getLogStartInfo() {
String mes = "";

//throw new IllegalArgumentException("test exception");

PlayerView p = getPlayer();
if (this.gameView != null && p != null && this.gameView.getStep() != null) {
// never calls for client side client, cause it used as game's watcher, not a player
Expand Down
3 changes: 2 additions & 1 deletion Mage.Tests/src/test/java/org/mage/test/load/LoadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class LoadTest {
private static final int TEST_PORT = 17171;
private static final String TEST_PROXY_TYPE = "None";
private static final String TEST_USER_NAME_GLOBAL_PREFIX = "t_";
private static final Boolean TEST_SHOW_GAME_LOGS_AS_HTML = false; // html is original format with full data, but can be too bloated
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)
Expand Down Expand Up @@ -544,7 +545,7 @@ public LoadPlayer(String userPrefix, String logsPrefix) {
public LoadPlayer(String userPrefix, boolean joinGameChat, String logsPrefix) {
this.userName = TEST_USER_NAME_GLOBAL_PREFIX + userPrefix + "_" + RandomUtil.nextInt(10000);
this.connection = createSimpleConnection(this.userName);
this.client = new SimpleMageClient(joinGameChat, logsPrefix);
this.client = new SimpleMageClient(joinGameChat, logsPrefix, TEST_SHOW_GAME_LOGS_AS_HTML);
this.session = new SessionImpl(this.client);

this.session.connect(this.connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public class SimpleMageClient implements MageClient {

private final LoadCallbackClient callbackClient;

public SimpleMageClient(boolean joinGameChat, String logsPrefix) {
public SimpleMageClient(boolean joinGameChat, String logsPrefix, Boolean showLogsAsHtml) {
clientId = UUID.randomUUID();
callbackClient = new LoadCallbackClient(joinGameChat, logsPrefix);
callbackClient = new LoadCallbackClient(joinGameChat, logsPrefix, showLogsAsHtml);
}

@Override
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<!-- scraping lib to download and parse html/symbols/images/svg -->
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.3</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>

0 comments on commit f653fd4

Please sign in to comment.