MySQLTimestamp2BinlogProtocolValue implements MySQLBinlogProtocolValue { @Override public Serializable read(final MySQLBinlogColumnDef columnDef, final MySQLPacketPayload payload) { int seconds = payload.getByteBuf().readInt(); if (0 == seconds) { return MySQLTimeValueUtil.DATETIME_OF_ZERO; } String result = MySQLTimeValueUtil.getSimpleDateFormat().format(new Timestamp(seconds * 1000L)); return columnDef.getColumnMeta() > 0 ? result + new MySQLFractionalSeconds(columnDef.getColumnMeta(), payload) : result; }  @Override Serializable read(final MySQLBinlogColumnDef columnDef, final MySQLPacketPayload payload);  }
@Test public void assertReadWithoutFraction() { int currentSeconds = new Long(System.currentTimeMillis() / 1000).intValue(); when(byteBuf.readInt()).thenReturn(currentSeconds); assertThat(new MySQLTimestamp2BinlogProtocolValue().read(columnDef, payload), is(MySQLTimeValueUtil.getSimpleDateFormat().format(new Timestamp(currentSeconds * 1000L)))); }
@Test public void assertReadWithFraction() { columnDef.setColumnMeta(1); long currentTimeMillis = System.currentTimeMillis(); int currentSeconds = new Long(currentTimeMillis / 1000).intValue(); int currentMilliseconds = new Long(currentTimeMillis % 10).intValue(); when(payload.readInt1()).thenReturn(currentMilliseconds); when(byteBuf.readInt()).thenReturn(currentSeconds); assertThat(new MySQLTimestamp2BinlogProtocolValue().read(columnDef, payload), is(MySQLTimeValueUtil.getSimpleDateFormat().format(new Timestamp(currentSeconds * 1000L)) + "." + currentMilliseconds)); }
@Test public void assertReadNullTime() { when(byteBuf.readInt()).thenReturn(0); assertThat(new MySQLTimestamp2BinlogProtocolValue().read(columnDef, payload), is(MySQLTimeValueUtil.DATETIME_OF_ZERO)); }