use of bftsmart.communication.ServerCommunicationSystemImpl in project bftsmart by blockchain-jd-com.
the class ConsensusTest_ method mockCsNewLeaderDiscardSync.
private void mockCsNewLeaderDiscardSync(int nodeId) {
ServerCommunicationSystemImpl mockServerCommunicationSystem = (ServerCommunicationSystemImpl) serverNodes[nodeId].getReplica().getServerCommunicationSystem();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
Object[] objs = invocationOnMock.getArguments();
Object obj = objs[1];
if ((obj instanceof LCMessage) && (((LCMessage) obj).getType().CODE == LCType.SYNC.CODE) && !newLeaderDiscardSyncMsgEnable) {
newLeaderDiscardSyncMsgEnable = true;
} else {
invocationOnMock.callRealMethod();
}
return null;
}
}).when(mockServerCommunicationSystem).send(any(), (SystemMessage) any());
}
use of bftsmart.communication.ServerCommunicationSystemImpl in project bftsmart by blockchain-jd-com.
the class ConsensusTest_ method mockMessageHandlerTest4Nodes.
private void mockMessageHandlerTest4Nodes(int nodeId) {
ServerCommunicationSystemImpl serverCommunicationSystem = (ServerCommunicationSystemImpl) serverNodes[nodeId].getReplica().getServerCommunicationSystem();
MessageHandler mockMessageHandler = serverCommunicationSystem.getMessageHandler();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
Object[] objs = invocationOnMock.getArguments();
if (objs == null || objs.length != 1) {
invocationOnMock.callRealMethod();
} else {
Object obj = objs[0];
if (obj instanceof ConsensusMessage) {
// 对于消息不做任何处理
} else if (obj instanceof LCMessage) {
Mockito.reset(mockMessageHandler);
invocationOnMock.callRealMethod();
} else {
invocationOnMock.callRealMethod();
}
}
return null;
}
}).when(mockMessageHandler).processData(any());
}
use of bftsmart.communication.ServerCommunicationSystemImpl in project bftsmart by blockchain-jd-com.
the class ConsensusTest_ method mockCsNormalNode5.
private void mockCsNormalNode5(int nodeId) {
ServerCommunicationSystemImpl mockServerCommunicationSystem = (ServerCommunicationSystemImpl) serverNodes[nodeId].getReplica().getServerCommunicationSystem();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
Object[] objs = invocationOnMock.getArguments();
Object obj = objs[1];
if (newLeaderDiscardSendMsgEnable) {
} else {
invocationOnMock.callRealMethod();
}
return null;
}
}).when(mockServerCommunicationSystem).send(any(), (SystemMessage) any());
}
use of bftsmart.communication.ServerCommunicationSystemImpl in project bftsmart by blockchain-jd-com.
the class TestNodeServer method startNode.
public ServiceReplica startNode(String realmName) {
TOMConfiguration config = initConfig();
try {
// mock messsageHandler and cs
MessageHandler messageHandler = new MessageHandler();
MessageHandler mockMessageHandler = Mockito.spy(messageHandler);
ClientCommunicationServerSide clientCommunication = ClientCommunicationFactory.createServerSide(new ServerViewController(config, new MemoryBasedViewStorage(latestView)));
ServerCommunicationSystem cs = new ServerCommunicationSystemImpl(clientCommunication, mockMessageHandler, new ServerViewController(config, new MemoryBasedViewStorage(latestView)), realmName);
ServerCommunicationSystem mockCs = Mockito.spy(cs);
replica = new ServiceReplica(mockMessageHandler, mockCs, config, this, this, (int) -1, latestView, realmName);
} catch (Exception e) {
e.printStackTrace();
}
return replica;
}
use of bftsmart.communication.ServerCommunicationSystemImpl in project bftsmart by blockchain-jd-com.
the class ConsensusTest_ method mockMessageHandlerNormalNode5.
private void mockMessageHandlerNormalNode5(int nodeId) {
ServerCommunicationSystemImpl serverCommunicationSystem = (ServerCommunicationSystemImpl) serverNodes[nodeId].getReplica().getServerCommunicationSystem();
MessageHandler mockMessageHandler = serverCommunicationSystem.getMessageHandler();
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
Object[] objs = invocationOnMock.getArguments();
if (newLeaderDiscardSendMsgEnable) {
// 什么也不做
} else {
invocationOnMock.callRealMethod();
}
return null;
}
}).when(mockMessageHandler).processData(any());
}
Aggregations