2812: added loading test that reproduces the issue

This commit is contained in:
magenoxx 2017-04-19 11:46:13 +03:00 committed by ayratn
parent 4fc47b163a
commit 0bf0bf9760
2 changed files with 64 additions and 5 deletions

View file

@ -26,14 +26,21 @@ public class LoadCallbackClient implements CallbackClient {
private volatile int controlCount;
private volatile int overallMessageCount = 0;
private GameView gameView;
@Override
public void processCallback(ClientCallback callback) {
//TODO
controlCount = 0;
overallMessageCount++;
log.info(callback.getMethod());
//SaveObjectUtil.saveObject(callback.getData(), callback.getMethod().toString());
callback.setData(CompressUtil.decompress(callback.getData()));
switch (callback.getMethod()) {
case START_GAME: {
TableClientMessage message = (TableClientMessage) callback.getData();
@ -46,7 +53,7 @@ public class LoadCallbackClient implements CallbackClient {
case GAME_INFORM: {
GameClientMessage message = (GameClientMessage) callback.getData();
log.info("Inform: " + message.getMessage());
gameView = message.getGameView();
//gameView = message.getGameView();
break;
}
case GAME_INIT:
@ -59,6 +66,7 @@ public class LoadCallbackClient implements CallbackClient {
session.sendPlayerUUID(gameId, playerId);
break;
case "Select a card to discard":
this.gameView = message.getGameView();
log.info("hand size: " + gameView.getHand().size());
SimpleCardView card = gameView.getHand().values().iterator().next();
session.sendPlayerUUID(gameId, card.getId());
@ -83,8 +91,15 @@ public class LoadCallbackClient implements CallbackClient {
}
break;
}
case GAME_UPDATE:
GameClientMessage message = (GameClientMessage) callback.getData();
GameView gameView = message.getGameView();
log.info("data: " + gameView.getPriorityPlayerName());
break;
case GAME_OVER:
log.info("Game over");
log.info("Overall message count: " + overallMessageCount);
gameOver = true;
break;
}

View file

@ -7,6 +7,7 @@ import mage.cards.decks.DeckCardInfo;
import mage.cards.decks.DeckCardLists;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.cards.repository.CardScanner;
import mage.constants.ColoredManaSymbol;
import mage.constants.MultiplayerAttackOption;
import mage.constants.RangeOfInfluence;
@ -20,12 +21,15 @@ import mage.view.GameTypeView;
import mage.view.TableView;
import org.apache.log4j.Logger;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;
/**
* Intended to test Mage server under different load patterns.
@ -77,7 +81,12 @@ public class LoadTest {
/**
* Determines how many times test will be executed in a row.
*/
private static final int EXECUTION_COUNT_PLAY_GAME = 100;
private static final int EXECUTION_COUNT_PLAY_GAME = 1;
@BeforeClass
public static void init() {
CardScanner.scan();
}
/**
* Tests connecting with two players, creating game and starting it.
@ -134,11 +143,13 @@ public class LoadTest {
}
/**
* Tests 10 simple games played one after another.
* Tests EXECUTION_COUNT_PLAY_GAME simple games played one after another.
*
* You have to run Server in test mode (with '-testMode=true' program argument)
*/
@Test
@Ignore
public void testSimpleGame() throws Exception {
public void testSimpleGames() throws Exception {
final DeckCardLists deckList = createDeck();
for (int i = 0; i < EXECUTION_COUNT_PLAY_GAME; i++) {
@ -148,6 +159,7 @@ public class LoadTest {
testSimpleGame0(deckList, j);
} catch (InterruptedException e) {
e.printStackTrace();
Assert.fail("Test failed due to: " + e.getMessage());
}
});
t.start();
@ -155,6 +167,37 @@ public class LoadTest {
}
}
/**
* Tests EXECUTION_COUNT_PLAY_GAME simple games played in parallel
*
* You have to run Server in test mode (with '-testMode=true' program argument)
*/
@Test
public void testSimpleGamesConcurrent() throws Exception {
final DeckCardLists deckList = createDeck();
final CyclicBarrier barrier = new CyclicBarrier(EXECUTION_COUNT_PLAY_GAME + 1);
for (int i = 0; i < EXECUTION_COUNT_PLAY_GAME; i++) {
final int j = i;
Thread t = new Thread(() -> {
try {
testSimpleGame0(deckList, j);
} catch (InterruptedException e) {
log.error(e, e);
Assert.fail("Test failed due to: " + e.getMessage());
}
try {
barrier.await();
} catch (InterruptedException | BrokenBarrierException e) {
log.error(e, e);
}
});
t.start();
}
barrier.await();
log.info("Testing has been finished");
}
/**
* Tests simple game till the end (game over).
* Players do nothing but skip phases and discard cards at the end.
@ -249,6 +292,7 @@ public class LoadTest {
DeckCardLists deckList = new DeckCardLists();
Deck deck = generateRandomDeck();
for (Card card : deck.getCards()) {
CardInfo cardInfo = CardRepository.instance.findCard(card.getExpansionSetCode(), card.getCardNumber());
if (cardInfo != null) {
deckList.getCards().add(new DeckCardInfo(cardInfo.getName(), cardInfo.getCardNumber(), cardInfo.getSetCode()));