Skip to content

Commit fb609bf

Browse files
committed
added LoadTesterTask, a runnable to emulate a single client
The overall load tester will create a number of these, each running in a separate thread, with a mix of edit sequences being played by each thread.
1 parent 94b790c commit fb609bf

2 files changed

Lines changed: 102 additions & 0 deletions

File tree

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package org.cloudcoder.app.loadtester;
2+
3+
import java.util.Arrays;
4+
5+
import org.cloudcoder.app.shared.model.Change;
6+
import org.cloudcoder.app.shared.model.ChangeType;
7+
import org.cloudcoder.app.shared.model.CompilationOutcome;
8+
import org.cloudcoder.app.shared.model.ICallback;
9+
import org.cloudcoder.app.shared.model.SubmissionResult;
10+
11+
public class LoadTesterTask implements Runnable {
12+
private HostConfig hostConfig;
13+
private String userName;
14+
private String password;
15+
private EditSequence editSequence;
16+
private int repeatCount;
17+
18+
public void setHostConfig(HostConfig hostConfig) {
19+
this.hostConfig = hostConfig;
20+
}
21+
22+
public void setUserName(String userName) {
23+
this.userName = userName;
24+
}
25+
26+
public void setPassword(String password) {
27+
this.password = password;
28+
}
29+
30+
public void setEditSequence(EditSequence editSequence) {
31+
this.editSequence = editSequence;
32+
}
33+
34+
public void setRepeatCount(int repeatCount) {
35+
this.repeatCount = repeatCount;
36+
}
37+
38+
@Override
39+
public void run() {
40+
try {
41+
doRun();
42+
} catch (Exception e) {
43+
System.err.println("LoadTesterTask caught exception: " + e.toString());
44+
}
45+
}
46+
47+
private void doRun() throws Exception {
48+
Client client = new Client(hostConfig);
49+
50+
client.login(userName, password);
51+
52+
PlayEditSequence player = new PlayEditSequence();
53+
player.setClient(client);
54+
player.setEditSequence(editSequence);
55+
player.setSubmitOnFullTextChange(true);
56+
57+
player.setOnSend(new ICallback<Change[]>() {
58+
@Override
59+
public void call(Change[] value) {
60+
if (value.length == 1 && value[0].getType() == ChangeType.FULL_TEXT) {
61+
System.out.print("\u2191");
62+
} else {
63+
char[] a = new char[value.length];
64+
Arrays.fill(a, '.');
65+
System.out.print(new String(a));
66+
}
67+
System.out.flush();
68+
}
69+
});
70+
player.setOnSubmissionResult(new ICallback<SubmissionResult>() {
71+
public void call(SubmissionResult value) {
72+
char c;
73+
if (value.getCompilationResult().getOutcome() != CompilationOutcome.SUCCESS
74+
|| value.getNumTestsPassed() < value.getNumTestsAttempted()) {
75+
c = '\u2639';
76+
} else {
77+
c = '\u263A';
78+
}
79+
System.out.print(String.valueOf(c));
80+
System.out.flush();
81+
}
82+
});
83+
84+
player.setup();
85+
86+
for (int i = 0; i < repeatCount; i++) {
87+
player.play();
88+
}
89+
}
90+
91+
}

CloudCoderLoadTester/src/org/cloudcoder/app/loadtester/Main.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public static void main(String[] args) throws Exception {
1212

1313
Mix mix = MixDatabase.forName("default");
1414

15+
/*
1516
Client client = new Client(hostConfig);
1617
if (!client.login("user2", "user2")) {
1718
throw new IllegalStateException("Could not login");
@@ -46,6 +47,16 @@ public void call(SubmissionResult value) {
4647
4748
player.setup();
4849
player.play();
50+
*/
51+
52+
LoadTesterTask task = new LoadTesterTask();
53+
task.setHostConfig(hostConfig);
54+
task.setEditSequence(mix.get(0));
55+
task.setUserName("user1");
56+
task.setPassword("user1");
57+
task.setRepeatCount(10);
58+
task.run();
59+
4960
System.out.println("Done!");
5061
}
5162
}

0 commit comments

Comments
 (0)