[load] Updated tests plus some fixes.

This commit is contained in:
magenoxx 2012-05-04 10:25:26 +04:00
parent 4d6b76179f
commit e2bd32fd3d
3 changed files with 84 additions and 1 deletions

View file

@ -2,6 +2,9 @@ package org.mage.test.load;
import mage.interfaces.callback.CallbackClient;
import mage.interfaces.callback.ClientCallback;
import mage.remote.Session;
import mage.utils.CompressUtil;
import mage.view.TableClientMessage;
import org.apache.log4j.Logger;
/**
@ -11,9 +14,21 @@ public class LoadCallbackClient implements CallbackClient {
private static final transient Logger log = Logger.getLogger(LoadCallbackClient.class);
private Session session;
@Override
public void processCallback(ClientCallback callback) {
//TODO
log.info(callback.getMethod());
callback.setData(CompressUtil.decompress(callback.getData()));
if (callback.getMethod().equals("startGame")) {
TableClientMessage message = (TableClientMessage) callback.getData();
session.joinGame(message.getGameId());
}
}
public void setSession(Session session) {
this.session = session;
}
}

View file

@ -69,6 +69,11 @@ public class LoadTest {
*/
private static final int EXECUTION_COUNT = 100;
/**
* Determines how many times test will be executed in a row.
*/
private static final int EXECUTION_COUNT_PLAY_GAME = 1;
/**
* Tests connecting with two players, creating game and starting it.
*
@ -123,6 +128,64 @@ public class LoadTest {
}
}
/**
* Test playing the whole game.
* Player use cheat to add lands, creatures and other cards.
* Then play only lands, one of them plays 1 damage targeting player.
*
* This results in 40 turns of the game.
*/
@Test
@Ignore
public void testPlayGame() throws Exception {
DeckCardLists deckList = createDeck();
for (int i = 0; i < EXECUTION_COUNT_PLAY_GAME; i++) {
Connection connection = createConnection(TEST_USER_NAME + i);
SimpleMageClient mageClient = new SimpleMageClient();
Session session = new SessionImpl(mageClient);
session.connect(connection);
mageClient.setSession(session);
UUID roomId = session.getMainRoomId();
GameTypeView gameTypeView = session.getGameTypes().get(0);
log.info("Game type view: " + gameTypeView.getName());
MatchOptions options = createGameOptions(gameTypeView, session);
TableView table = session.createTable(roomId, options);
if (!session.joinTable(roomId, table.getTableId(), TEST_USER_NAME + i, "Human", 1, deckList)) {
log.error("Error while joining table");
Assert.assertTrue("Error while joining table", false);
return;
}
/*** Connect with a second player ***/
Connection connection2 = createConnection(TEST_USER_NAME_2 + i);
SimpleMageClient mageClient2 = new SimpleMageClient();
Session session2 = new SessionImpl(mageClient2);
session2.connect(connection2);
mageClient2.setSession(session2);
UUID roomId2 = session2.getMainRoomId();
// connect to the table with the same deck
if (!session2.joinTable(roomId2, table.getTableId(), TEST_USER_NAME_2 + i, "Human", 1, deckList)) {
log.error("Error while joining table");
Assert.assertTrue("Error while joining table", false);
return;
}
/*** Start game ***/
session.startGame(roomId, table.getTableId());
Thread.sleep(100);
}
}
/**
* Creates connection to the server.
* Server should run independently.

View file

@ -3,6 +3,7 @@ package org.mage.test.load;
import mage.interfaces.MageClient;
import mage.interfaces.callback.CallbackClient;
import mage.interfaces.callback.ClientCallback;
import mage.remote.Session;
import mage.utils.MageVersion;
import org.apache.log4j.Logger;
@ -20,7 +21,7 @@ public class SimpleMageClient implements MageClient {
private static final transient Logger log = Logger.getLogger(SimpleMageClient.class);
private static CallbackClient callbackClient;
private CallbackClient callbackClient;
public SimpleMageClient() {
clientId = UUID.randomUUID();
@ -61,4 +62,8 @@ public class SimpleMageClient implements MageClient {
public void processCallback(ClientCallback callback) {
callbackClient.processCallback(callback);
}
public void setSession(Session session) {
((LoadCallbackClient)callbackClient).setSession(session);
}
}