summaryrefslogtreecommitdiff
path: root/same/src/test/java/com/orbekk
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-23 22:01:28 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-23 22:01:28 +0100
commit36a5b60d59f1f4e5e179f9800f4dbf08771c1e5b (patch)
tree4f55abb0660138ec790b911087715d522d7d1499 /same/src/test/java/com/orbekk
parentc0839711b16c4d5af4d6818deae97fd7e5f28930 (diff)
Add multi-threaded Paxos test code.
(Doesn't actually make assertions – it just burns CPU cycles :P)
Diffstat (limited to 'same/src/test/java/com/orbekk')
-rw-r--r--same/src/test/java/com/orbekk/paxos/PaxosServiceFunctionalTest.java40
1 files changed, 37 insertions, 3 deletions
diff --git a/same/src/test/java/com/orbekk/paxos/PaxosServiceFunctionalTest.java b/same/src/test/java/com/orbekk/paxos/PaxosServiceFunctionalTest.java
index c537d18..8f20273 100644
--- a/same/src/test/java/com/orbekk/paxos/PaxosServiceFunctionalTest.java
+++ b/same/src/test/java/com/orbekk/paxos/PaxosServiceFunctionalTest.java
@@ -1,10 +1,13 @@
package com.orbekk.paxos;
+import static org.junit.Assert.*;
+
import com.googlecode.jsonrpc4j.JsonRpcServer;
import com.orbekk.same.ConnectionManagerImpl;
import com.orbekk.same.RpcHandler;
import java.util.ArrayList;
import java.util.List;
+import java.util.Random;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Server;
import org.junit.Before;
@@ -20,21 +23,52 @@ public class PaxosServiceFunctionalTest {
@Before
public void setUp() throws Exception {
server = TestServer.create(handler);
- myUrl = "http://localhost:" + server.port + "/";
+ myUrl = "http://localhost:" + server.port;
setupPaxos(5);
}
public void setupPaxos(int instances) {
for (int i = 1; i <= instances; i++) {
JsonRpcServer jsonServer = new JsonRpcServer(
- new PaxosServiceImpl("" + i), PaxosService.class);
+ new PaxosServiceImpl("P" + i + ": "), PaxosService.class);
String serviceId = "/PaxosService" + i + ".json";
handler.addRpcServer(serviceId, jsonServer);
+ paxosUrls.add(myUrl + serviceId);
}
}
@Test
- public void nullTest() {
+ public void testMasterElection() {
+ MasterProposer m1 = new MasterProposer("http://client1", paxosUrls,
+ connections);
+ assertTrue(m1.propose(1, 1));
+ }
+
+ @Test
+ public void testWithCompetition() {
+ int proposers = 5;
+ List<Thread> masterProposers = new ArrayList<Thread>();
+ for (int i = 1; i <= proposers; i++) {
+ final int j = i;
+ masterProposers.add(new Thread() {
+ @Override public void run() {
+ MasterProposer client =
+ new MasterProposer("http:/client" + j, paxosUrls,
+ connections);
+ client.propose(1, 1);
+ }
+ });
+ }
+ for (Thread t : masterProposers) {
+ t.start();
+ }
+ for (Thread t : masterProposers) {
+ try {
+ t.join();
+ } catch (InterruptedException e) {
+ // Ignore.
+ }
+ }
}
public static class TestServer {