mirror of
https://github.com/correl/mage.git
synced 2025-01-11 11:05:23 +00:00
Tests: added chat messages processing in AI load tests;
This commit is contained in:
parent
4931bcd09d
commit
9b685cf14b
3 changed files with 28 additions and 7 deletions
|
@ -1,6 +1,5 @@
|
|||
package org.mage.test.load;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.constants.PlayerAction;
|
||||
import mage.interfaces.callback.CallbackClient;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
|
@ -9,6 +8,8 @@ import mage.utils.CompressUtil;
|
|||
import mage.view.*;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
|
@ -23,11 +24,16 @@ public class LoadCallbackClient implements CallbackClient {
|
|||
private boolean gameOver;
|
||||
private String gameResult = "unknown";
|
||||
private boolean needToConcede = false; // will concede on first priority
|
||||
private boolean joinGameChat = false; // process CHATMESSAGE
|
||||
|
||||
private volatile int controlCount;
|
||||
|
||||
private GameView gameView;
|
||||
|
||||
public LoadCallbackClient(boolean joinGameChat) {
|
||||
this.joinGameChat = joinGameChat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processCallback(ClientCallback callback) {
|
||||
controlCount = 0;
|
||||
|
@ -36,6 +42,19 @@ public class LoadCallbackClient implements CallbackClient {
|
|||
|
||||
switch (callback.getMethod()) {
|
||||
|
||||
case GAME_INIT:
|
||||
this.gameId = callback.getObjectId();
|
||||
if (joinGameChat) {
|
||||
session.joinChat(session.getGameChatId(gameId).get());
|
||||
}
|
||||
break;
|
||||
|
||||
case CHATMESSAGE: {
|
||||
ChatMessage message = (ChatMessage) callback.getData();
|
||||
log.info("Chat message: " + message.getMessage());
|
||||
break;
|
||||
}
|
||||
|
||||
case START_GAME: {
|
||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||
log.info(getLogStartInfo() + "game started");
|
||||
|
@ -126,9 +145,7 @@ public class LoadCallbackClient implements CallbackClient {
|
|||
break;
|
||||
|
||||
// skip callbacks (no need to react)
|
||||
case GAME_INIT:
|
||||
case GAME_UPDATE:
|
||||
case CHATMESSAGE:
|
||||
case JOINED_TABLE:
|
||||
break;
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@ public class LoadTest {
|
|||
Assert.assertFalse("need allowed sets", deckAllowedSets.isEmpty());
|
||||
|
||||
// monitor and game source
|
||||
LoadPlayer monitor = new LoadPlayer("monitor");
|
||||
LoadPlayer monitor = new LoadPlayer("monitor", true);
|
||||
|
||||
// game by monitor
|
||||
GameTypeView gameType = monitor.session.getGameTypes().get(0);
|
||||
|
@ -486,9 +486,13 @@ public class LoadTest {
|
|||
String lastGameResult = "";
|
||||
|
||||
public LoadPlayer(String userPrefix) {
|
||||
this(userPrefix, false);
|
||||
}
|
||||
|
||||
public LoadPlayer(String userPrefix, boolean joinGameChat) {
|
||||
this.userName = TEST_USER_NAME + "_" + userPrefix + "_" + RandomUtil.nextInt(10000);
|
||||
this.connection = createSimpleConnection(this.userName);
|
||||
this.client = new SimpleMageClient();
|
||||
this.client = new SimpleMageClient(joinGameChat);
|
||||
this.session = new SessionImpl(this.client);
|
||||
|
||||
this.session.connect(this.connection);
|
||||
|
|
|
@ -23,9 +23,9 @@ public class SimpleMageClient implements MageClient {
|
|||
|
||||
private final LoadCallbackClient callbackClient;
|
||||
|
||||
public SimpleMageClient() {
|
||||
public SimpleMageClient(boolean joinGameChat) {
|
||||
clientId = UUID.randomUUID();
|
||||
callbackClient = new LoadCallbackClient();
|
||||
callbackClient = new LoadCallbackClient(joinGameChat);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue