summaryrefslogtreecommitdiff
path: root/same/src/test/java/com
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-16 19:50:36 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-16 19:50:36 +0100
commit40cab510c223512a4f947414ae13659a7bcd607b (patch)
treef90f0b07fba6bd8d410e6ff7f2b7669dcbc8eb84 /same/src/test/java/com
parent25d3d6d1ff6f57ad354f03a0b6cc4f1a897bb342 (diff)
Replace Master with new implementation.
Diffstat (limited to 'same/src/test/java/com')
-rw-r--r--same/src/test/java/com/orbekk/same/MasterServiceImplTest.java133
-rw-r--r--same/src/test/java/com/orbekk/same/MasterTest.java (renamed from same/src/test/java/com/orbekk/same/NewMasterTest.java)6
2 files changed, 3 insertions, 136 deletions
diff --git a/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java b/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java
deleted file mode 100644
index 0e7c81d..0000000
--- a/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package com.orbekk.same;
-
-import static org.junit.Assert.*;
-
-import java.util.List;
-
-import org.codehaus.jackson.type.TypeReference;
-import org.junit.Test;
-import org.junit.Before;
-
-public class MasterServiceImplTest {
- private State state = new State("TestNetwork");
- private TestConnectionManager connections = new TestConnectionManager();
- private TestBroadcaster broadcaster = new TestBroadcaster();
- private Master master;
-
- public static class UnreachableClient implements ClientService {
- @Override
- public void notifyNetwork(String networkName, String masterUrl)
- throws Exception {
- throw new Exception("Unreachable client");
- }
-
- @Override
- public void setState(String component, String data, long revision)
- throws Exception {
- throw new Exception("Unreachable client");
- }
-
- @Override
- public void discoveryRequest(String remoteUrl) throws Exception {
- throw new Exception("Unreachable client");
- }
- }
-
- @Before
- public void setUp() {
- state.update(".masterUrl", "http://master/MasterService.json", 1);
- master = new Master(state, connections, broadcaster);
- connections.masterMap.put("http://master/MasterService.json", master);
- }
-
- @Test
- public void testJsonState() {
- List<String> participants =
- state.getParsedData(".participants",
- new TypeReference<List<String>>() { });
- assertEquals(participants.size(), 0);
- participants.add("http://SomeUrl/");
- state.updateFromObject(".participants", participants, 1);
- }
-
- @Test
- public void joinNetworkAddsClient() {
- master.joinNetworkRequest("http://clientUrl");
- List<String> participants = state.getList(".participants");
- assertTrue(participants.contains("http://clientUrl"));
- }
-
- @Test
- public void workLoopClearsUpdatedComponents() {
- state.update("Test", "Content", 0);
- assertTrue(master._performWork());
- assertTrue(state.getAndClearUpdatedComponents().isEmpty());
- }
-
- @Test
- public void clientJoin() {
- Client client = new Client(
- new State("ClientNetwork"), connections,
- "http://client/ClientService.json");
- ClientService clientS = client.getService();
- connections.clientMap.put("http://client/ClientService.json", clientS);
- client.joinNetwork("http://master/MasterService.json");
- assertTrue(master._performWork());
- assertTrue(state.getList(".participants").contains("http://client/ClientService.json"));
- assertEquals(state, client.testGetState());
- }
-
- @Test
- public void validStateRequest() {
- Client client1 = new Client(
- new State("ClientNetwork"), connections,
- "http://client/ClientService.json");
- ClientService client1S = client1.getService();
- connections.clientMap.put("http://client/ClientService.json", client1S);
- Client client2 = new Client(
- new State("ClientNetwork"), connections,
- "http://client2/ClientService.json");
- ClientService client2S = client2.getService();
- connections.clientMap.put("http://client2/ClientService.json", client2S);
-
- client1.joinNetwork("http://master/MasterService.json");
- client2.joinNetwork("http://master/MasterService.json");
-
- assertTrue(master._performWork());
- assertTrue(state.getList(".participants").contains("http://client/ClientService.json"));
- assertTrue(state.getList(".participants").contains("http://client2/ClientService.json"));
- assertEquals(state, client1.testGetState());
-
- assertTrue(master.updateStateRequest("A", "1", 0));
- assertTrue(master._performWork());
-
- assertEquals(state, client1.testGetState());
- assertEquals(state, client2.testGetState());
-
- assertFalse(master.updateStateRequest("A", "2", 0));
- assertTrue(master.updateStateRequest("A", "3", 1));
- assertTrue(master._performWork());
-
- assertEquals(state, client1.testGetState());
- assertEquals(state, client2.testGetState());
- }
-
- @Test
- public void masterRemovesParticipant() {
- Client client = new Client(
- new State("ClientNetwork"), connections,
- "http://client/ClientService.json");
- ClientService clientS = client.getService();
- connections.clientMap.put("http://client/ClientService.json", clientS);
- client.joinNetwork("http://master/MasterService.json");
- assertTrue(master._performWork());
- assertTrue(state.getList(".participants").contains("http://client/ClientService.json"));
-
- connections.clientMap.put("http://client/ClientService.json",
- new UnreachableClient());
- master.updateStateRequest("NewState", "NewStateData", 0);
- master._performWork();
-
- assertEquals("[]", state.getDataOf(".participants"));
- }
-}
diff --git a/same/src/test/java/com/orbekk/same/NewMasterTest.java b/same/src/test/java/com/orbekk/same/MasterTest.java
index 273fb3c..09ac6a1 100644
--- a/same/src/test/java/com/orbekk/same/NewMasterTest.java
+++ b/same/src/test/java/com/orbekk/same/MasterTest.java
@@ -7,11 +7,11 @@ import org.codehaus.jackson.type.TypeReference;
import org.junit.Before;
import org.junit.Test;
-public class NewMasterTest {
+public class MasterTest {
private State state = new State("TestNetwork");
private TestConnectionManager connections = new TestConnectionManager();
private TestBroadcaster broadcaster = new TestBroadcaster();
- private NewMaster master;
+ private Master master;
private MasterService masterS;
public static class UnreachableClient implements ClientService {
@@ -36,7 +36,7 @@ public class NewMasterTest {
@Before
public void setUp() {
state.update(".masterUrl", "http://master/MasterService.json", 1);
- master = new NewMaster(state, connections, broadcaster);
+ master = new Master(state, connections, broadcaster);
masterS = master.getService();
connections.masterMap.put("http://master/MasterService.json",
masterS);