summaryrefslogtreecommitdiff
path: root/same/src/test/java/com/orbekk/paxos
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-06 13:44:04 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-06 13:53:15 +0100
commitbac2fa8e7e6286d64b50cdf6b7fd32f958080ceb (patch)
tree95e43cf95350e4a9508c3cf419ade35716fe5c9d /same/src/test/java/com/orbekk/paxos
parent922ce7491ade85b084f365b8bdcf9f8ef251cf82 (diff)
Add a class that holds server information.
– Provides access to the context and port, used in testing.
Diffstat (limited to 'same/src/test/java/com/orbekk/paxos')
-rw-r--r--same/src/test/java/com/orbekk/paxos/PaxosServiceFunctionalTest.java43
1 files changed, 17 insertions, 26 deletions
diff --git a/same/src/test/java/com/orbekk/paxos/PaxosServiceFunctionalTest.java b/same/src/test/java/com/orbekk/paxos/PaxosServiceFunctionalTest.java
index b09b76e..5042168 100644
--- a/same/src/test/java/com/orbekk/paxos/PaxosServiceFunctionalTest.java
+++ b/same/src/test/java/com/orbekk/paxos/PaxosServiceFunctionalTest.java
@@ -4,37 +4,46 @@ import static org.junit.Assert.*;
import com.googlecode.jsonrpc4j.JsonRpcServer;
import com.orbekk.same.ConnectionManagerImpl;
-import com.orbekk.same.http.RpcHandler;
+import com.orbekk.same.http.RpcServlet;
+import com.orbekk.same.http.ServerBuilder;
+import com.orbekk.same.http.ServerContainer;
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.After;
import org.junit.Before;
import org.junit.Test;
public class PaxosServiceFunctionalTest {
ConnectionManagerImpl connections = new ConnectionManagerImpl(500, 500);
List<String> paxosUrls = new ArrayList<String>();
- RpcHandler handler = new RpcHandler(null);
- TestServer server;
+ // RpcHandler handler = new RpcHandler(null);
+ ServerContainer server;
String myUrl;
int successfulProposals = 0;
@Before
public void setUp() throws Exception {
- server = TestServer.create(handler);
- myUrl = "http://localhost:" + server.port;
- setupPaxos(10);
+ ServerBuilder builder = new ServerBuilder(0);
+ setupPaxos(builder, 10);
+ server = builder.build();
+ myUrl = "http://localhost:" + server.getPort();
}
- public void setupPaxos(int instances) {
+ @After
+ public void tearDown() throws Exception {
+ server.stop();
+ }
+
+ public void setupPaxos(ServerBuilder builder, int instances) {
for (int i = 1; i <= instances; i++) {
JsonRpcServer jsonServer = new JsonRpcServer(
new PaxosServiceImpl("P" + i + ": "), PaxosService.class);
String serviceId = "/PaxosService" + i + ".json";
- handler.addRpcServer(serviceId, jsonServer);
+ builder.withServlet(new RpcServlet(jsonServer), serviceId);
paxosUrls.add(myUrl + serviceId);
}
}
@@ -79,22 +88,4 @@ public class PaxosServiceFunctionalTest {
public synchronized void incrementSuccessfulProposals() {
successfulProposals += 1;
}
-
- public static class TestServer {
- public Server server;
- public int port;
-
- public static TestServer create(Handler handler) throws Exception {
- Server server = new Server(0);
- server.setHandler(handler);
- server.start();
- int port = server.getConnectors()[0].getLocalPort();
- return new TestServer(server, port);
- }
-
- private TestServer(Server server, int port) {
- this.server = server;
- this.port = port;
- }
- }
}