mirror of
https://github.com/correl/mage.git
synced 2024-11-15 03:00:16 +00:00
* Some formatting.
This commit is contained in:
parent
aebc16dc82
commit
55b66315af
3 changed files with 38 additions and 50 deletions
|
@ -1,19 +1,14 @@
|
|||
package org.mage.test.load;
|
||||
|
||||
import mage.constants.PhaseStep;
|
||||
import java.util.UUID;
|
||||
import mage.constants.PlayerAction;
|
||||
import mage.interfaces.callback.CallbackClient;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.player.ai.ComputerPlayer;
|
||||
import mage.remote.Session;
|
||||
import mage.util.RandomUtil;
|
||||
import mage.utils.CompressUtil;
|
||||
import mage.view.*;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
|
@ -39,7 +34,6 @@ public class LoadCallbackClient implements CallbackClient {
|
|||
callback.setData(CompressUtil.decompress(callback.getData()));
|
||||
log.info(getLogStartInfo() + "callback: " + callback.getMethod());
|
||||
|
||||
|
||||
switch (callback.getMethod()) {
|
||||
|
||||
case START_GAME: {
|
||||
|
@ -68,13 +62,13 @@ public class LoadCallbackClient implements CallbackClient {
|
|||
case "Select a starting player":
|
||||
session.sendPlayerUUID(gameId, playerId);
|
||||
return;
|
||||
//break;
|
||||
//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;
|
||||
//break;
|
||||
default:
|
||||
log.error(getLogStartInfo() + "unknown GAME_TARGET message: " + message.toString());
|
||||
}
|
||||
|
@ -109,14 +103,14 @@ public class LoadCallbackClient implements CallbackClient {
|
|||
// end priority step
|
||||
session.sendPlayerBoolean(gameId, false);
|
||||
return;
|
||||
/*
|
||||
/*
|
||||
if (LoadPhaseManager.getInstance().isSkip(message.getGameView(), message.getMessage(), playerId)) {
|
||||
log.info(getLogStartInfo() + "Skipped: " + message.getMessage());
|
||||
session.sendPlayerBoolean(gameId, false);
|
||||
} else {
|
||||
log.error(getLogStartInfo() + "unknown GAME_SELECT or skips message: " + message.toString());
|
||||
}
|
||||
*/
|
||||
*/
|
||||
//break;
|
||||
}
|
||||
|
||||
|
@ -142,13 +136,13 @@ public class LoadCallbackClient implements CallbackClient {
|
|||
log.error(getLogStartInfo() + "Unknown callback: " + callback.getMethod() + ", " + callback.getData().toString());
|
||||
session.sendPlayerBoolean(gameId, false);
|
||||
return;
|
||||
//break;
|
||||
//break;
|
||||
}
|
||||
}
|
||||
|
||||
private PlayerView getPlayer() {
|
||||
if ((this.gameView != null) && (this.playerId != null)) {
|
||||
for (PlayerView p: this.gameView.getPlayers()) {
|
||||
for (PlayerView p : this.gameView.getPlayers()) {
|
||||
if (p.getPlayerId().equals(this.playerId)) {
|
||||
return p;
|
||||
}
|
||||
|
@ -161,7 +155,6 @@ public class LoadCallbackClient implements CallbackClient {
|
|||
String mes = "";
|
||||
|
||||
//throw new IllegalArgumentException("test exception");
|
||||
|
||||
if (this.session != null) {
|
||||
mes += session.getUserName() + ": ";
|
||||
}
|
||||
|
@ -192,7 +185,7 @@ public class LoadCallbackClient implements CallbackClient {
|
|||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if(isGameOver()) {
|
||||
if (isGameOver()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package org.mage.test.load;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.Sets;
|
||||
import mage.cards.decks.Deck;
|
||||
|
@ -10,7 +13,6 @@ import mage.cards.repository.CardRepository;
|
|||
import mage.constants.*;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.player.ai.ComputerPlayer;
|
||||
import mage.players.Player;
|
||||
import mage.players.PlayerType;
|
||||
import mage.remote.Connection;
|
||||
import mage.remote.MageRemoteException;
|
||||
|
@ -23,21 +25,17 @@ import org.junit.Assert;
|
|||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Intended to test Mage server under different load patterns.
|
||||
*
|
||||
* These tests do use server started separately, so Mage server should be started before running them.
|
||||
* In case you want to debug these tests, use -Ddebug.mage that would disable client-server request timeout.
|
||||
* These tests do use server started separately, so Mage server should be
|
||||
* started before running them. In case you want to debug these tests, use
|
||||
* -Ddebug.mage that would disable client-server request timeout.
|
||||
*
|
||||
* Then it's also better to use -Xms256M -Xmx512M JVM options for these stests.
|
||||
*
|
||||
* @author JayDi85
|
||||
*/
|
||||
|
||||
public class LoadTest {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(LoadTest.class);
|
||||
|
@ -53,40 +51,39 @@ public class LoadTest {
|
|||
Deck deck;
|
||||
|
||||
deck = generateRandomDeck("G", false);
|
||||
for(Card card : deck.getCards()) {
|
||||
for (Card card : deck.getCards()) {
|
||||
Assert.assertTrue("card " + card.getName() + " color " + card.getColorIdentity().toString() + " must be in G",
|
||||
card.getColorIdentity().isGreen());
|
||||
}
|
||||
|
||||
deck = generateRandomDeck("U", false);
|
||||
for(Card card : deck.getCards()) {
|
||||
for (Card card : deck.getCards()) {
|
||||
Assert.assertTrue("card " + card.getName() + " color " + card.getColorIdentity().toString() + " must be in U",
|
||||
card.getColorIdentity().isBlue());
|
||||
}
|
||||
|
||||
deck = generateRandomDeck("BR", false);
|
||||
for(Card card : deck.getCards()) {
|
||||
for (Card card : deck.getCards()) {
|
||||
Assert.assertTrue("card " + card.getName() + " color " + card.getColorIdentity().toString() + " must be in BR",
|
||||
card.getColorIdentity().isBlack() || card.getColorIdentity().isRed());
|
||||
}
|
||||
|
||||
deck = generateRandomDeck("BUG", false);
|
||||
for(Card card : deck.getCards()) {
|
||||
for (Card card : deck.getCards()) {
|
||||
Assert.assertTrue("card " + card.getName() + " color " + card.getColorIdentity().toString() + " must be in BUG",
|
||||
card.getColorIdentity().isBlack() || card.getColorIdentity().isBlue() || card.getColorIdentity().isGreen());
|
||||
}
|
||||
|
||||
// lands
|
||||
|
||||
deck = generateRandomDeck("UR", true);
|
||||
for(Card card : deck.getCards()) {
|
||||
for (Card card : deck.getCards()) {
|
||||
Assert.assertTrue("card " + card.getName() + " color " + card.getColorIdentity().toString() + " must be in UR",
|
||||
card.getColorIdentity().isBlue() || card.getColorIdentity().isRed());
|
||||
Assert.assertEquals("card " + card.getName() + " must be basic land ", Rarity.LAND, card.getRarity());
|
||||
}
|
||||
|
||||
deck = generateRandomDeck("B", true);
|
||||
for(Card card : deck.getCards()) {
|
||||
for (Card card : deck.getCards()) {
|
||||
Assert.assertTrue("card " + card.getName() + " color " + card.getColorIdentity().toString() + " must be in B", card.getColorIdentity().isBlack());
|
||||
Assert.assertEquals("card " + card.getName() + " must be basic land ", Rarity.LAND, card.getRarity());
|
||||
}
|
||||
|
@ -97,7 +94,6 @@ public class LoadTest {
|
|||
public void test_UsersConnectToServer() throws Exception {
|
||||
|
||||
// simple connection to server
|
||||
|
||||
// monitor other players
|
||||
LoadPlayer monitor = new LoadPlayer("monitor");
|
||||
Assert.assertTrue(monitor.session.isConnected());
|
||||
|
@ -142,7 +138,6 @@ public class LoadTest {
|
|||
for(DeckCardInfo info: deckList.getCards()) {
|
||||
logger.info(info.getCardName());
|
||||
}*/
|
||||
|
||||
// before connect
|
||||
checkGame = monitor.getTable(tableId);
|
||||
Assert.assertTrue(checkGame.isPresent());
|
||||
|
@ -170,12 +165,12 @@ public class LoadTest {
|
|||
Assert.assertTrue(player1.session.startMatch(player1.roomID, tableId));
|
||||
|
||||
// playing until game over
|
||||
while(!player1.client.isGameOver() && !player2.client.isGameOver()) {
|
||||
while (!player1.client.isGameOver() && !player2.client.isGameOver()) {
|
||||
checkGame = monitor.getTable(tableId);
|
||||
logger.warn(checkGame.get().getTableState());
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e){
|
||||
} catch (InterruptedException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
@ -206,7 +201,7 @@ public class LoadTest {
|
|||
|
||||
// playing until game over
|
||||
boolean startToWatching = false;
|
||||
while(true) {
|
||||
while (true) {
|
||||
checkGame = monitor.getTable(tableId);
|
||||
TableState state = checkGame.get().getTableState();
|
||||
logger.warn(state);
|
||||
|
@ -230,7 +225,7 @@ public class LoadTest {
|
|||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e){
|
||||
} catch (InterruptedException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
@ -330,7 +325,7 @@ public class LoadTest {
|
|||
// creating
|
||||
logger.info("creating " + MAX_GAMES + " games...");
|
||||
ArrayList<LoadGame> gamesList = new ArrayList<>();
|
||||
for(int i = 1; i <= MAX_GAMES; i++) {
|
||||
for (int i = 1; i <= MAX_GAMES; i++) {
|
||||
LoadGame game = new LoadGame(
|
||||
"game" + i,
|
||||
"game" + i,
|
||||
|
@ -357,11 +352,11 @@ public class LoadTest {
|
|||
// waiting all games
|
||||
while (true) {
|
||||
boolean isComplete = true;
|
||||
for(LoadGame game: gamesList) {
|
||||
for (LoadGame game : gamesList) {
|
||||
isComplete = isComplete && !game.isPlaying();
|
||||
}
|
||||
|
||||
if(isComplete) {
|
||||
if (isComplete) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -378,7 +373,7 @@ public class LoadTest {
|
|||
|
||||
// check statuses
|
||||
ArrayList<String> errors = new ArrayList<>();
|
||||
for(LoadGame game: gamesList) {
|
||||
for (LoadGame game : gamesList) {
|
||||
if (!"finished".equals(game.gameResult)) {
|
||||
errors.add(game.gameName + ": not finished, got " + game.gameResult);
|
||||
}
|
||||
|
@ -386,7 +381,7 @@ public class LoadTest {
|
|||
|
||||
if (errors.size() > 0) {
|
||||
System.out.println("Not all games finished, founded " + errors.size() + " errors: ");
|
||||
for (String s: errors) {
|
||||
for (String s : errors) {
|
||||
System.out.println(s);
|
||||
}
|
||||
Assert.fail("Not all games finished");
|
||||
|
@ -452,6 +447,7 @@ public class LoadTest {
|
|||
}
|
||||
|
||||
private class LoadPlayer {
|
||||
|
||||
String userName;
|
||||
Connection connection;
|
||||
SimpleMageClient client;
|
||||
|
@ -479,15 +475,14 @@ public class LoadTest {
|
|||
for (RoomUsersView roomUsers : this.session.getRoomUsers(this.roomID)) {
|
||||
res.addAll(roomUsers.getUsersView());
|
||||
}
|
||||
} catch (MageRemoteException e)
|
||||
{
|
||||
} catch (MageRemoteException e) {
|
||||
logger.error(e);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public UsersView findUser(String userName) {
|
||||
for (UsersView user: this.getAllRoomUsers()) {
|
||||
for (UsersView user : this.getAllRoomUsers()) {
|
||||
if (user.getUserName().equals(userName)) {
|
||||
return user;
|
||||
}
|
||||
|
@ -535,6 +530,7 @@ public class LoadTest {
|
|||
}
|
||||
|
||||
private class LoadGame {
|
||||
|
||||
String gameName = null;
|
||||
Thread runningThread = null;
|
||||
LoadPlayer player1 = null;
|
||||
|
@ -575,10 +571,10 @@ public class LoadTest {
|
|||
this.gameResult = "started";
|
||||
|
||||
// playing until game over or abort
|
||||
while(!abort && (!player1.client.isGameOver() || !player2.client.isGameOver())) {
|
||||
while (!abort && (!player1.client.isGameOver() || !player2.client.isGameOver())) {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e){
|
||||
} catch (InterruptedException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package org.mage.test.load;
|
|||
|
||||
import java.util.UUID;
|
||||
import mage.interfaces.MageClient;
|
||||
import mage.interfaces.callback.CallbackClient;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.remote.Session;
|
||||
import mage.utils.MageVersion;
|
||||
|
@ -17,7 +16,7 @@ import org.apache.log4j.Logger;
|
|||
public class SimpleMageClient implements MageClient {
|
||||
|
||||
private final UUID clientId;
|
||||
private static final MageVersion version = new MageVersion(MageVersion.MAGE_VERSION_MAJOR, MageVersion.MAGE_VERSION_MINOR, MageVersion.MAGE_VERSION_PATCH, MageVersion.MAGE_VERSION_MINOR_PATCH, MageVersion.MAGE_VERSION_INFO);
|
||||
private static final MageVersion version = new MageVersion(MageVersion.MAGE_VERSION_MAJOR, MageVersion.MAGE_VERSION_MINOR, MageVersion.MAGE_VERSION_PATCH, MageVersion.MAGE_VERSION_MINOR_PATCH, MageVersion.MAGE_VERSION_INFO);
|
||||
|
||||
private static final Logger log = Logger.getLogger(SimpleMageClient.class);
|
||||
|
||||
|
@ -63,11 +62,11 @@ public class SimpleMageClient implements MageClient {
|
|||
}
|
||||
|
||||
public void setSession(Session session) {
|
||||
((LoadCallbackClient)callbackClient).setSession(session);
|
||||
((LoadCallbackClient) callbackClient).setSession(session);
|
||||
}
|
||||
|
||||
public boolean isGameOver() {
|
||||
return ((LoadCallbackClient)callbackClient).isGameOver();
|
||||
return ((LoadCallbackClient) callbackClient).isGameOver();
|
||||
}
|
||||
|
||||
public void setConcede(boolean needToConcede) {
|
||||
|
|
Loading…
Reference in a new issue