public Connection doTestFactoryTest(RpcConnectionFactory persistentFactory)
throws IOException {
// Send and receive first
Connection persistent = persistentFactory.createConnection();
persistent.sendProtoMessage(MESSAGE2);
Builder builder = Request.newBuilder();
persistent.receiveProtoMessage(builder);
assertEquals(MESSAGE1, builder.build());
persistent.close();
// Receive and send second
persistent = persistentFactory.createConnection();
builder = Request.newBuilder();
persistent.receiveProtoMessage(builder);
assertEquals(MESSAGE2, builder.build());
persistent.sendProtoMessage(MESSAGE1);
persistent.close();
// Send and receive third
persistent = persistentFactory.createConnection();
persistent.sendProtoMessage(MESSAGE2);
builder = Request.newBuilder();
persistent.receiveProtoMessage(builder);
assertEquals(MESSAGE1, builder.build());
persistent.close();
// Get 3 messages from output
ByteArrayInputStream is = new ByteArrayInputStream(
socket.getOutputBytes());