InMemoryMessageTransceiver extends InMemoryMessageTransceiver2 { public int send(final int numberOfMessages, final int messageLength, final long timestamp, final long checksum) { final long[] messages = this.messages; final long index = sendIndex; if (0L != UNSAFE.getLongVolatile(messages, offset(index + 1 + messageIndexOffset(numberOfMessages)))) { return 0; } for (int i = numberOfMessages; i > 1; i--) { UNSAFE.putLong(messages, offset(index + messageIndexOffset(i)), timestamp); UNSAFE.putLong(messages, offset(index + 1 + messageIndexOffset(i)), checksum); } UNSAFE.putLong(messages, offset(index), timestamp); UNSAFE.putOrderedLong(messages, offset(index + 1), checksum); sendIndex += messageIndexOffset(numberOfMessages + 1); return numberOfMessages; } InMemoryMessageTransceiver(final MessageRecorder messageRecorder); void init(final Configuration configuration); void destroy(); int send(final int numberOfMessages, final int messageLength, final long timestamp, final long checksum); void receive();  }
@Test void sendASingleMessage() { final int result = messageTransceiver.send(1, 16, 123, MIN_VALUE); assertEquals(1, result); }
@Test void sendMultipleMessages() { final int result = messageTransceiver.send(4, 64, 800, -222); assertEquals(4, result); }
@Test void sendReturnsZeroIfItCantFitAnEntireBatch() { messageTransceiver.send(InMemoryMessageTransceiver.SIZE, 8, 777, 100); final int result = messageTransceiver.send(1, 100, 555, 21); assertEquals(0, result); }