GitBucket
4.21.2
Toggle navigation
Snippets
Sign in
Files
Branches
1
Releases
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
mark.george
/
democall3
Browse code
Tweaked tests a bit. StressTest now loops.
master
1 parent
7c5284f
commit
4fbc3870ade8f37be963ff653622e66c76eba254
Mark
authored
on 8 Aug 2012
Patch
Showing
3 changed files
tests/Calm.java
tests/Panic.java
tests/StressTest.java
Ignore Space
Show notes
View
tests/Calm.java
import network.MessageGenerator; import network.RequestSender; /** * Simulates an entire lab canceling their request at the same time. * * Tests threading and queue overflow. * */ public class Calm { public static void main(String[] args) { final RequestSender requestSender = new RequestSender("127.0.0.1"); final MessageGenerator generator = new MessageGenerator(); // using 2 to 30 since those are numbers that all lab layouts have for (int i = 2; i <= 31; i++) { final int x = i; new Thread(new Runnable() { public void run() { requestSender.sendRequest(generator.cancelRequest(String.valueOf(x))); } }).start(); } } }
import network.MessageGenerator; import network.RequestSender; /** * Simulates an entire lab canceling their request at the same time. * * Tests threading and queue overflow. * */ public class Calm { public static void main(String[] args) { final RequestSender requestSender = new RequestSender("127.0.0.1"); final MessageGenerator generator = new MessageGenerator(); // using 2 to 30 since those are numbers that all lab layouts have for (int i = 2; i <= 30; i++) { final int x = i; new Thread(new Runnable() { public void run() { requestSender.sendRequest(generator.cancelRequest(String.valueOf(x))); } }).start(); } } }
Ignore Space
Show notes
View
tests/Panic.java
import network.MessageGenerator; import network.RequestSender; /** * Simulates an entire lab requesting help at the same time. * * Tests threading and queue overflow. * */ public class Panic { public static void main(String[] args) { final RequestSender requestSender = new RequestSender("127.0.0.1"); final MessageGenerator generator = new MessageGenerator(); // using 2 to 30 since those are numbers that all lab layouts have for (int i = 2; i <= 31; i++) { final int x = i; new Thread(new Runnable() { public void run() { requestSender.sendRequest(generator.requestHelp(String.valueOf(x))); } }).start(); } } }
import network.MessageGenerator; import network.RequestSender; /** * Simulates an entire lab requesting help at the same time. * * Tests threading and queue overflow. * */ public class Panic { public static void main(String[] args) { final RequestSender requestSender = new RequestSender("127.0.0.1"); final MessageGenerator generator = new MessageGenerator(); // using 2 to 30 since those are numbers that all lab layouts have for (int i = 2; i <= 30; i++) { final int x = i; new Thread(new Runnable() { public void run() { requestSender.sendRequest(generator.requestHelp(String.valueOf(x))); } }).start(); } } }
Ignore Space
Show notes
View
tests/StressTest.java
import java.util.ArrayList; import java.util.List; import network.MessageGenerator; import network.RequestSender; /** * Simulates everyone toggling their help status at the same time. * * * Tests concurrency, and ability to handle load. * */ public class StressTest { public static void main(String[] args) throws InterruptedException { final RequestSender requestSender = new RequestSender("127.0.0.1"); final MessageGenerator generator = new MessageGenerator(); List<Thread> threads = new ArrayList<Thread>(); for (int i = 0; i < 100; i++) { // using 2 to 30 since those are numbers that all lab layouts have for (int j = 2; j <= 31; j++) { final int x = j; Thread t = new Thread(new Runnable() { public void run() { requestSender.sendRequest(generator.requestHelp(String.valueOf(x))); } }); t.start(); threads.add(t); } for (Thread thread : threads) { thread.join(); } // give server a chance to sort things out Thread.sleep(100); for (int j = 2; j <= 31; j++) { final int x = j; new Thread(new Runnable() { public void run() { requestSender.sendRequest(generator.cancelRequest(String.valueOf(x))); } }).start(); } // give server a chance to sort things out Thread.sleep(100); } } }
import network.MessageGenerator; import network.RequestSender; /** * Simulates everyone toggling their help status at the same time. * * Tests concurrency, and ability to handle load. * */ public class StressTest { public static void main(String[] args) throws InterruptedException { final RequestSender requestSender = new RequestSender("127.0.0.1"); final MessageGenerator generator = new MessageGenerator(); final int sleepCount = 5; // using 2 to 30 since those are numbers that all lab layouts have for (int i = 2; i <= 30; i++) { final int x = i; new Thread(new Runnable() { public void run() { requestSender.sendRequest(generator.requestHelp(String.valueOf(x))); } }).start(); Thread.sleep(sleepCount); new Thread(new Runnable() { public void run() { requestSender.sendRequest(generator.cancelRequest(String.valueOf(x))); } }).start(); Thread.sleep(sleepCount); } } }
Show line notes below