diff options
Diffstat (limited to 'same/src/test/java')
5 files changed, 6 insertions, 123 deletions
diff --git a/same/src/test/java/com/orbekk/net/BroadcastListenerTest.java b/same/src/test/java/com/orbekk/net/BroadcastListenerTest.java deleted file mode 100644 index 67d4ece..0000000 --- a/same/src/test/java/com/orbekk/net/BroadcastListenerTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.orbekk.net; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class BroadcastListenerTest { - private Logger logger = LoggerFactory.getLogger(getClass()); - - @Test - public void interruptWorks() throws Exception { - final BroadcastListener listener = new BroadcastListener(0); - - Thread t = new Thread() { - @Override public void run() { - listener.listen(); - } - }; - t.start(); - - while (listener.socket == null) { - logger.info("Waiting for listener to start."); - Thread.sleep(100); - } - - listener.interrupt(); - t.join(); - } - -} diff --git a/same/src/test/java/com/orbekk/paxos/PaxosServiceTest.java b/same/src/test/java/com/orbekk/paxos/PaxosServiceTest.java index c07ca87..3160d2d 100644 --- a/same/src/test/java/com/orbekk/paxos/PaxosServiceTest.java +++ b/same/src/test/java/com/orbekk/paxos/PaxosServiceTest.java @@ -29,11 +29,11 @@ public class PaxosServiceTest { @Before public void setUp() { Collections.addAll(servers, p1, p2, p3, p4, p5); - connections.paxosMap.put("p1", p1); - connections.paxosMap.put("p2", p2); - connections.paxosMap.put("p3", p3); - connections.paxosMap.put("p4", p4); - connections.paxosMap.put("p5", p5); + connections.paxosMap0.put("p1", p1.getService()); + connections.paxosMap0.put("p2", p2.getService()); + connections.paxosMap0.put("p3", p3.getService()); + connections.paxosMap0.put("p4", p4.getService()); + connections.paxosMap0.put("p5", p5.getService()); } @Test @@ -58,7 +58,7 @@ public class PaxosServiceTest { } public List<String> paxosUrls() { - return new ArrayList<String>(connections.paxosMap.keySet()); + return new ArrayList<String>(connections.paxosMap0.keySet()); } @Test diff --git a/same/src/test/java/com/orbekk/same/ClientTest.java b/same/src/test/java/com/orbekk/same/ClientTest.java deleted file mode 100644 index 4dbc408..0000000 --- a/same/src/test/java/com/orbekk/same/ClientTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.orbekk.same; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import com.orbekk.util.DelayedOperation; - -public class ClientTest { - private State state = new State("ClientNetwork"); - private TestConnectionManager connections = new TestConnectionManager(); - private Client client = new Client(state, connections, - "http://client/ClientService.json", "clientLocation"); - private ClientService clientS = client.getService(); - private MasterService mockMaster = mock(MasterService.class); - - @Before public void setUp() { - connections.masterMap.put("master", mockMaster); - } - - @Test public void disconnectedFailsUpdate() throws Exception { - ClientInterface clientI = client.getInterface(); - DelayedOperation op = clientI.set(null); - assertTrue(op.isDone()); - assertFalse(op.getStatus().isOk()); - } - - // TODO: Fix this test with protobuf rpc. - @Ignore - @Test public void connectedUpdateWorks() throws Exception { - clientS.masterTakeover("master", "MyNetwork", 1, "master"); - ClientInterface clientI = client.getInterface(); - State.Component component = new State.Component( - "TestVariable", 1, "meow"); - when(mockMaster.updateStateRequest("TestVariable", "meow", 1)) - .thenReturn(true); - DelayedOperation op = clientI.set(component); - assertTrue(op.getStatus().isOk()); - } - - @Test public void testSetState() throws Exception { - clientS.setState("TestState", "Test data", 100); - assertEquals(100, state.getRevision("TestState")); - assertEquals("Test data", state.getDataOf("TestState")); - } - - @Test public void stateListenerReceivesUpdate() throws Exception { - StateChangedListener listener = mock(StateChangedListener.class); - client.getInterface().addStateListener(listener); - clientS.setState("StateListenerVariable", "100", 1); - State.Component component = state.getComponent("StateListenerVariable"); - assertEquals("100", component.getData()); - verify(listener).stateChanged(eq(component)); - } -} diff --git a/same/src/test/java/com/orbekk/same/FunctionalTest.java b/same/src/test/java/com/orbekk/same/FunctionalTest.java index da1faca..839b107 100644 --- a/same/src/test/java/com/orbekk/same/FunctionalTest.java +++ b/same/src/test/java/com/orbekk/same/FunctionalTest.java @@ -49,12 +49,10 @@ public class FunctionalTest { Client newClient(String clientName, String clientUrl, String location) { Client client = new Client(new State(clientName), connections, clientUrl, location); - connections.clientMap.put(clientUrl, client.getService()); connections.clientMap0.put(location, client.getNewService()); clients.add(client); String paxosUrl = clientUrl.replace("ClientService", "PaxosService"); PaxosServiceImpl paxos = new PaxosServiceImpl(paxosUrl); - connections.paxosMap.put(paxosUrl, paxos); connections.paxosMap0.put(location, paxos.getService()); return client; } diff --git a/same/src/test/java/com/orbekk/same/MasterTest.java b/same/src/test/java/com/orbekk/same/MasterTest.java index b3cfb94..4fa0a5f 100644 --- a/same/src/test/java/com/orbekk/same/MasterTest.java +++ b/same/src/test/java/com/orbekk/same/MasterTest.java @@ -15,26 +15,6 @@ public class MasterTest { private TestConnectionManager connections = new TestConnectionManager(); private TestBroadcaster broadcaster = new TestBroadcaster(); private Master master; - - public static class UnreachableClient implements ClientService { - @Override - public void setState(String component, String data, long revision) - throws Exception { - throw new Exception("Unreachable client"); - } - - @Override - public void masterTakeover(String masterUrl, String networkName, - int masterId, String masterLocation) - throws Exception { - throw new Exception("Unreachable client"); - } - - @Override - public void masterDown(int masterId) throws Exception { - throw new Exception("Unreachable client"); - } - } @Before public void setUp() { |