summaryrefslogtreecommitdiff
path: root/same/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'same/src/test')
-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;
- }
- }
}