MySQLTime2BinlogProtocolValue implements MySQLBinlogProtocolValue { @Override public Serializable read(final MySQLBinlogColumnDef columnDef, final MySQLPacketPayload payload) { int time = payload.getByteBuf().readUnsignedMedium(); if (0x800000 == time) { return MySQLTimeValueUtil.ZERO_OF_TIME; } MySQLFractionalSeconds fractionalSeconds = new MySQLFractionalSeconds(columnDef.getColumnMeta(), payload); return String.format("%02d:%02d:%02d%s", (time >> 12) % (1 << 10), (time >> 6) % (1 << 6), time % (1 << 6), fractionalSeconds); }  @Override Serializable read(final MySQLBinlogColumnDef columnDef, final MySQLPacketPayload payload);  }
@Test public void assertRead() { when(payload.getByteBuf()).thenReturn(byteBuf); when(byteBuf.readUnsignedMedium()).thenReturn(0x800000 | (0x10 << 12) | (0x08 << 6) | 0x04); assertThat(new MySQLTime2BinlogProtocolValue().read(columnDef, payload), is("16:08:04")); }
@Test public void assertReadWithFraction1() { columnDef.setColumnMeta(1); when(payload.getByteBuf()).thenReturn(byteBuf); when(payload.readInt1()).thenReturn(90); when(byteBuf.readUnsignedMedium()).thenReturn(0x800000 | (0x10 << 12) | (0x08 << 6) | 0x04); assertThat(new MySQLTime2BinlogProtocolValue().read(columnDef, payload), is("16:08:04.9")); }
@Test public void assertReadWithFraction3() { columnDef.setColumnMeta(3); when(payload.getByteBuf()).thenReturn(byteBuf); when(byteBuf.readUnsignedShort()).thenReturn(90); when(byteBuf.readUnsignedMedium()).thenReturn(0x800000 | (0x10 << 12) | (0x08 << 6) | 0x04); assertThat(new MySQLTime2BinlogProtocolValue().read(columnDef, payload), is("16:08:04.900")); }
@Test public void assertReadWithFraction6() { columnDef.setColumnMeta(6); when(payload.getByteBuf()).thenReturn(byteBuf); when(byteBuf.readUnsignedMedium()).thenReturn(0x800000 | (0x10 << 12) | (0x08 << 6) | 0x04, 90); assertThat(new MySQLTime2BinlogProtocolValue().read(columnDef, payload), is("16:08:04.900000")); }
@Test public void assertReadNullTime() { when(payload.getByteBuf()).thenReturn(byteBuf); when(byteBuf.readUnsignedMedium()).thenReturn(0x800000); assertThat(new MySQLTime2BinlogProtocolValue().read(columnDef, payload), is(MySQLTimeValueUtil.ZERO_OF_TIME)); }