writeToOutputStream(MESSAGE2, os, true);
writeToOutputStream(MESSAGE1, os, true);
delimited.withInputBytes(os.toByteArray());
// Send and receive first
Connection connection = new SocketConnection(delimited, true);
connection.sendProtoMessage(MESSAGE2);
Builder builder = Request.newBuilder();
connection.receiveProtoMessage(builder);
assertEquals(MESSAGE1, builder.build());
// Receive and send second
builder = Request.newBuilder();
connection.receiveProtoMessage(builder);
assertEquals(MESSAGE2, builder.build());
connection.sendProtoMessage(MESSAGE1);
// Send and receive third
connection.sendProtoMessage(MESSAGE2);
builder = Request.newBuilder();
connection.receiveProtoMessage(builder);
assertEquals(MESSAGE1, builder.build());
// Get 3 messages from output
ByteArrayInputStream is = new ByteArrayInputStream(
delimited.getOutputBytes());