summaryrefslogtreecommitdiff
path: root/same/src/test/java/com/orbekk/paxos/MasterProposerTest.java
blob: e753d6eaa7ade2434b31e251ee806769d7fffd76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.orbekk.paxos;

import java.util.ArrayList;
import java.util.List;

import org.junit.Before;
import org.junit.Test;

import com.orbekk.same.Services.ClientState;
import com.orbekk.same.TestConnectionManager;

import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

public class MasterProposerTest {
    TestConnectionManager connections = new TestConnectionManager();
    ClientState client = ClientState.newBuilder()
            .setLocation("client1Location")
            .build();
    PaxosService p1 = mock(PaxosService.class);
    PaxosService p2 = mock(PaxosService.class);
    PaxosService p3 = mock(PaxosService.class);
    PaxosService p4 = mock(PaxosService.class);
    PaxosService p5 = mock(PaxosService.class);
    
    @Before public void setUp() {
    }
    
    List<String> paxosUrls() {
        List<String> urls = new ArrayList<String>();
        urls.addAll(connections.paxosMap.keySet());
        return urls;
    }

    @Test public void successfulProposal() throws Exception {
        connections.paxosMap.put("p1", p1);
        when(p1.propose("client1", 1)).thenReturn(1);
        when(p1.acceptRequest("client1", 1)).thenReturn(1);
        
        MasterProposer c1 = new MasterProposer(
                client,
                paxosUrls(),
                connections);
        assertTrue(c1.propose(1));
    }

    @Test public void unsucessfulProposal() throws Exception {
        connections.paxosMap.put("p1", p1);
        when(p1.propose("client1", 1)).thenReturn(-1);
        when(p1.acceptRequest("client1", 1)).thenReturn(-1);
        
        MasterProposer c1 = new MasterProposer(
                client,
                paxosUrls(),
                connections);
        assertFalse(c1.propose(1));
    }
}