public int putAscii(final int index, final String string) { final byte[] bytes = string.getBytes(US_ASCII); putBytes(index, bytes); return bytes.length; }
private void moveRemainingDataToBufferStart(final int offset) { usedBufferData -= offset; buffer.putBytes(0, buffer, offset, usedBufferData); // position set to ensure that back pressure is applied to TCP when read(byteBuffer) called. ByteBufferUtil.position(byteBuffer, usedBufferData); }
private void putMessage(final int offset) { buffer.putBytes(offset, EG_MESSAGE); }
public Action onMessage( final DirectBuffer buffer, final int offset, final int length, final int libraryId, final Session session, final int sequenceIndex, final int messageType, final long timestampInNs, final long position) { testReqId = null; parser.onMessage(buffer, offset, length); if (testReqId != null) { latestTestRequestMessageBuffer.putBytes(0, buffer, offset, length); latestTestRequestMessageLength = length; } return CONTINUE; }
private void putAscii(final String value) { buffer.putBytes(0, value.getBytes(US_ASCII)); } }
@Before public void setUp() { buffer.putBytes(OFFSET, BYTES); }
@Theory public void notifiesAcceptorOfInvalidChecksum(final int offset) { buffer.putBytes(offset, INVALID_CHECKSUM_MSG); parser.onMessage(buffer, offset, INVALID_CHECKSUM_LEN); verify(mockAcceptor).onError(eq(INVALID_CHECKSUM), eq((int)'D'), eq(10), any(AsciiFieldFlyweight.class)); }
@Theory public void parsesZeroChecksumMessages(final int offset) { buffer.putBytes(offset, ZERO_CHECKSUM_MESSAGE); parser.onMessage(buffer, offset, ZERO_CHECKSUM_MESSAGE.length); verify(mockAcceptor, never()).onError(any(), anyInt(), anyInt(), any()); }
@Theory public void notifiesAcceptorOfInvalidMessage(final int offset) { buffer.putBytes(offset, INVALID_MESSAGE); parser.onMessage(buffer, offset, INVALID_LEN); verify(mockAcceptor).onError(eq(PARSE_ERROR), eq((int)'D'), eq(11), any(AsciiFieldFlyweight.class)); }
@Theory public void notifiesAcceptorOfOnlyHeaderForEmptyGroup(final int offset) { understandsContraBrokersGroup(); buffer.putBytes(offset, ZERO_REPEATING_GROUP); parser.onMessage(buffer, offset, ZERO_REPEATING_GROUP.length); verifyGroupHeader(382, 0); inOrder.verify(mockAcceptor, never()).onGroupBegin(anyInt(), anyInt(), anyInt()); inOrder.verify(mockAcceptor, never()).onGroupEnd(anyInt(), anyInt(), anyInt()); }
mutableAsciiFlyweight.putBytes( index, mutableAsciiFlyweight,
private void canParseTimestamp(final int length) { final long expectedEpochMillis = toEpochMillis(timestamp); final byte[] bytes = timestamp.getBytes(US_ASCII); final MutableAsciiBuffer buffer = new MutableAsciiBuffer(new byte[LENGTH_WITH_MICROSECONDS + 2]); buffer.putBytes(1, bytes); final long epochMillis = UtcTimestampDecoder.decode(buffer, 1, length); assertEquals("Failed Millis testcase for: " + timestamp, expectedEpochMillis, epochMillis); long expectedEpochMicros = expectedEpochMillis * MICROS_IN_MILLIS; // If they've got the suffix field, then test microseconds, add 1 to the value if (timestamp.length() == LENGTH_WITH_MILLISECONDS) { expectedEpochMicros++; buffer.putAscii(timestamp.length() + 1, "001"); } final long epochMicros = UtcTimestampDecoder.decodeMicros(buffer, 1, length + 3); assertEquals("Failed Micros testcase for: " + timestamp, expectedEpochMicros, epochMicros); }
@Theory public void notifiesAcceptorOfMultiElementRepeatingGroup(final int offset) { understandsNoOrdersGroup(); buffer.putBytes(offset, REPEATING_GROUP); parser.onMessage(buffer, offset, REPEATING_GROUP.length); verifyGroupHeader(NO_ORDERS, 2); verifyNoOrdersGroup(0); verifyNoOrdersGroup(1); }
private void canDecodeDecimalFloatFromBytes(final byte[] bytes) { final MutableAsciiBuffer string = new MutableAsciiBuffer(new byte[bytes.length + 2]); string.putBytes(1, bytes); final DecimalFloat price = new DecimalFloat(); string.getFloat(price, 1, bytes.length); Assert.assertEquals("Incorrect Value", value, price.value()); Assert.assertEquals("Incorrect Scale", scale, price.scale()); }
@Theory public void notifiesAcceptorOfNestedRepeatingGroup(final int offset) { understandsNoOrdersGroup(); understandsNoAllocsGroup(); buffer.putBytes(offset, NESTED_REPEATING_GROUP); parser.onMessage(buffer, offset, NESTED_REPEATING_GROUP.length); verifyGroupHeader(NO_ORDERS, 2); verifyNestedNoAllocsGroup(0); verifyNoOrdersGroup(1); }
@Theory public void notifiesAcceptorOfRepeatingGroup(final int offset) { understandsContraBrokersGroup(); buffer.putBytes(offset, EXECUTION_REPORT); parser.onMessage(buffer, offset, EXECUTION_REPORT.length); verifyGroupHeader(382, 1); verifyGroupBegin(382, 1, 0); verifyInOrderField(375); verifyInOrderField(337); verifyInOrderField(437); verifyInOrderField(438); verifyGroupEnd(382, 1, 0); }