MySQLVarcharBinlogProtocolValue implements MySQLBinlogProtocolValue { @Override public Serializable read(final MySQLBinlogColumnDef columnDef, final MySQLPacketPayload payload) { return payload.readStringFix(VARCHAR_LENGTH_META_POINT > columnDef.getColumnMeta() ? payload.getByteBuf().readUnsignedByte() : payload.getByteBuf().readUnsignedShortLE()); }  @Override Serializable read(final MySQLBinlogColumnDef columnDef, final MySQLPacketPayload payload);  }
@Test public void assertReadVarcharValueWithMeta1() { String expected = "test_value"; columnDef.setColumnMeta(10); when(payload.getByteBuf()).thenReturn(byteBuf); when(byteBuf.readUnsignedByte()).thenReturn((short) expected.length()); when(payload.readStringFix(expected.length())).thenReturn(expected); assertThat(new MySQLVarcharBinlogProtocolValue().read(columnDef, payload), is(expected)); }
@Test public void assertReadVarcharValueWithMeta2() { StringBuilder expectedStringBuilder = new StringBuilder("test string for length more than 256"); for (int i = 0; i < 256; i++) { expectedStringBuilder.append(i); } String expected = expectedStringBuilder.toString(); columnDef.setColumnMeta(expected.length()); when(payload.getByteBuf()).thenReturn(byteBuf); when(byteBuf.readUnsignedShortLE()).thenReturn(expected.length()); when(payload.readStringFix(expected.length())).thenReturn(expected); assertThat(new MySQLVarcharBinlogProtocolValue().read(columnDef, payload), is(expected)); }