mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 13:02:06 -08:00
moved MultiConnectTest to Mage.Servers.Tests project
This commit is contained in:
parent
e56b1b843b
commit
a0f02fc8b7
3 changed files with 89 additions and 316 deletions
|
|
@ -55,6 +55,10 @@ public class TestClient implements MageClient {
|
|||
return client.connect(connection, MageVersion.getCurrent());
|
||||
}
|
||||
|
||||
public void disconnect(boolean error) {
|
||||
client.disconnect(error);
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return client.isConnected();
|
||||
}
|
||||
|
|
@ -65,7 +69,7 @@ public class TestClient implements MageClient {
|
|||
|
||||
@Override
|
||||
public void disconnected(boolean error) {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,84 @@
|
|||
package org.mage.server.test.load;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import mage.server.ServerMain;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mage.server.test.TestClient;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward
|
||||
*/
|
||||
public class ConnectionLoadTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ServerMain.main(new String[] {"-fastDbMode=true"});
|
||||
// ServerMain.main(new String[] {""});
|
||||
}
|
||||
}).start();
|
||||
try {
|
||||
waitForServer("ACTIVE"); //wait for server to startup
|
||||
} catch (InterruptedException | IOException ex) {
|
||||
}
|
||||
}
|
||||
|
||||
public static void waitForServer(String message) throws FileNotFoundException, IOException, InterruptedException {
|
||||
FileReader fr = new FileReader("mageserver.log");
|
||||
BufferedReader br = new BufferedReader(fr);
|
||||
|
||||
do { //read until end-of-file
|
||||
String line = br.readLine();
|
||||
if (line == null) {
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
|
||||
do { //read only new lines
|
||||
String line = br.readLine();
|
||||
if (line == null) {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
else {
|
||||
if (line.contains(message))
|
||||
break;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
|
||||
private static final Integer USER_CONNECT_COUNT = 200;
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void connectTest() {
|
||||
Map<String, TestClient> users = new HashMap<>();
|
||||
for (int i = 0; i < USER_CONNECT_COUNT; i++) {
|
||||
String username = "player" + i;
|
||||
TestClient client = new TestClient();
|
||||
client.connect(username);
|
||||
users.put(username, client);
|
||||
}
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
for (TestClient client: users.values()) {
|
||||
client.disconnect(false);
|
||||
}
|
||||
for (TestClient client: users.values()) {
|
||||
Assert.assertFalse("user did not disconnect", client.isConnected());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue