summaryrefslogtreecommitdiff
path: root/same/src/test/java/com/orbekk
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-23 20:03:05 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-23 20:03:05 +0100
commit1ae55b79f849cfd2e8b24311b63caa04baa5d3c2 (patch)
tree157faa372ad7d74808ea8ae2235b2e46ac1bdcf5 /same/src/test/java/com/orbekk
parent060274f31ea04b9fe284d91f457f3d82c11dbaed (diff)
Add MasterProposer.
MasterProposer tries to propose a value to a list of PaxosServices.
Diffstat (limited to 'same/src/test/java/com/orbekk')
-rw-r--r--same/src/test/java/com/orbekk/paxos/MasterProposerTest.java36
1 files changed, 16 insertions, 20 deletions
diff --git a/same/src/test/java/com/orbekk/paxos/MasterProposerTest.java b/same/src/test/java/com/orbekk/paxos/MasterProposerTest.java
index 74c817f..8056ab6 100644
--- a/same/src/test/java/com/orbekk/paxos/MasterProposerTest.java
+++ b/same/src/test/java/com/orbekk/paxos/MasterProposerTest.java
@@ -8,7 +8,7 @@ import org.junit.Test;
import com.orbekk.same.TestConnectionManager;
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
public class MasterProposerTest {
@@ -18,18 +18,6 @@ public class MasterProposerTest {
PaxosService p3 = mock(PaxosService.class);
PaxosService p4 = mock(PaxosService.class);
PaxosService p5 = mock(PaxosService.class);
- String master = null;
-
- private class TestMasterAction implements Runnable {
- String tag;
- TestMasterAction(String tag) {
- this.tag = tag;
- }
-
- @Override public void run() {
- master = tag;
- }
- }
@Before public void setUp() {
}
@@ -39,7 +27,7 @@ public class MasterProposerTest {
urls.addAll(connections.paxosMap.keySet());
return urls;
}
-
+
@Test public void successfulProposal() {
connections.paxosMap.put("p1", p1);
when(p1.propose("client1", 1, 1)).thenReturn(true);
@@ -48,11 +36,19 @@ public class MasterProposerTest {
MasterProposer c1 = new MasterProposer(
"client1",
paxosUrls(),
- 0,
- connections,
- MasterProposer.getTimeoutAction(0),
- new TestMasterAction("c1"));
- c1.run();
- assertEquals("c1", master);
+ connections);
+ assertTrue(c1.propose(1, 1));
+ }
+
+ @Test public void unsucessfulProposal() {
+ connections.paxosMap.put("p1", p1);
+ when(p1.propose("client1", 1, 1)).thenReturn(true);
+ when(p1.acceptRequest("client1", 1, 1)).thenReturn(false);
+
+ MasterProposer c1 = new MasterProposer(
+ "client1",
+ paxosUrls(),
+ connections);
+ assertFalse(c1.propose(1, 1));
}
}