Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,17 @@ public class CommunicationtTestMocker {

public static ViewTopology mockTopology(int currentId, int[] processIds) {
ReplicaConfiguration conf = mockConfiguration(currentId, processIds);

return mockTopology(currentId, processIds, conf);
}

public static ViewTopology mockTopology(int currentId, int[] processIds, ReplicaConfiguration conf) {
ViewTopology topology = Mockito.mock(ViewTopology.class);
when(topology.getCurrentProcessId()).thenReturn(currentId);
when(topology.getCurrentViewProcesses()).thenReturn(processIds);
when(topology.isInCurrentView()).thenReturn(contains(currentId, processIds));
when(topology.isCurrentViewMember(anyInt())).thenAnswer(new Answer<Boolean>() {
when(topology.getStaticConf()).thenReturn(conf);

@Override
public Boolean answer(InvocationOnMock invocation) throws Throwable {
int id = invocation.getArgument(0);
return contains(id, processIds);
}
});

when(topology.getStaticConf()).thenReturn(conf);

return topology;
}

Expand All @@ -63,17 +54,10 @@ public Boolean answer(InvocationOnMock invocation) throws Throwable {

public static ReplicaConfiguration mockConfiguration(int currentId, int[] processIds) {
ReplicaConfiguration conf = Mockito.mock(ReplicaConfiguration.class);
when(conf.getProcessId()).thenReturn(currentId);
when(conf.getInitialView()).thenReturn(processIds);
when(conf.getInQueueSize()).thenReturn(100000);
when(conf.getOutQueueSize()).thenReturn(100000);
when(conf.getSendRetryCount()).thenReturn(10);

try {
DefaultRSAKeyLoader defaultRSAKeyLoader = new DefaultRSAKeyLoader();
when(conf.getRSAPrivateKey()).thenReturn(defaultRSAKeyLoader.loadPrivateKey(currentId));
when(conf.getRSAPublicKey(currentId)).thenReturn(defaultRSAKeyLoader.loadPublicKey(currentId));
} catch (Exception e) {
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
}
return conf;
Expand All @@ -89,15 +73,15 @@ public static ReplicaConfiguration mockDefaultConfiguration(int currentId, int[]
hosts.add(processIds[i], "localhost", port, 0);
}
TOMConfiguration conf = new TOMConfiguration(currentId, new Properties(), hosts);

conf = Mockito.spy(conf);

when(conf.getProcessId()).thenReturn(currentId);
when(conf.getInQueueSize()).thenReturn(100000);
when(conf.getOutQueueSize()).thenReturn(100000);

return conf;

// ReplicaConfiguration conf = mockConfiguration(currentId, processIds);
//
// when(conf.getServerToServerPort(anyInt())).thenAnswer(new Answer<Integer>() {
Expand Down Expand Up @@ -125,4 +109,16 @@ private static boolean contains(int v, int[] values) {
return false;
}

public static ReplicaTopology mockTopologyWithTCP2(int currentId, int[] processIds, int[] ports) {
ReplicaTopology topology = Mockito.mock(ReplicaTopology.class);
when(topology.getCurrentProcessId()).thenReturn(currentId);
when(topology.getCurrentViewProcesses()).thenReturn(processIds);
when(topology.isInCurrentView()).thenReturn(contains(currentId, processIds));

ReplicaConfiguration conf = mockDefaultConfiguration(currentId, processIds, ports);
when(topology.getStaticConf()).thenReturn(conf);

return topology;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public void testDoubleNettyNodes() throws InterruptedException {
int[] viewProcessIds = { 0, 1};
int[] ports = { 14100, 14110};

CommunicationLayer[] servers = prepareNettyNodes(realmName, viewProcessIds, ports);
CommunicationLayer[] servers = prepareNettyNodes2(realmName, viewProcessIds, ports);
MessageCounter[] counters = prepareMessageCounters(servers);

for (CommunicationLayer server : servers) {
Expand Down Expand Up @@ -272,7 +272,7 @@ public void testNettyNodesNetwork() {
int[] viewProcessIds = { 0, 1, 2, 3 };
int[] ports = { 15100, 15110, 15120, 15130 };

CommunicationLayer[] servers = prepareNettyNodes(realmName, viewProcessIds, ports);
CommunicationLayer[] servers = prepareNettyNodes2(realmName, viewProcessIds, ports);
MessageCounter[] counters = prepareMessageCounters(servers);

for (CommunicationLayer srv : servers) {
Expand Down Expand Up @@ -435,4 +435,14 @@ public void assertMessagesEquals(SystemMessage... expectedMessages) {
}
}

private CommunicationLayer[] prepareNettyNodes2(String realmName, int[] viewProcessIds, int[] ports) {
CommunicationLayer[] comLayers = new CommunicationLayer[viewProcessIds.length];
for (int i = 0; i < comLayers.length; i++) {
ReplicaTopology topology = CommunicationtTestMocker.mockTopologyWithTCP2(viewProcessIds[i], viewProcessIds, ports);
CommunicationLayer comLayer = new NettyServerCommunicationLayer(realmName, topology);
comLayers[i] = comLayer;
}
return comLayers;
}

}