@Test public void testFormatDescriptionEvent() { eventHeader.setEventType(EventType.FORMAT_DESCRIPTION); FormatDescriptionEventData eventData = new FormatDescriptionEventData(); Optional<BinlogEvent> binlogEvent = BinaryLogConnectorEventMapper.INSTANCE.map( new Event(eventHeader, eventData), BINLOG_FILE_POS); assertTrue(binlogEvent.isPresent()); assertTrue(binlogEvent.get() instanceof StartEvent); StartEvent startEvent = (StartEvent) (binlogEvent.get()); assertEquals(BINLOG_FILE_POS, startEvent.getBinlogFilePos()); assertEquals(SERVER_ID, startEvent.getServerId()); assertEquals(TIMESTAMP, startEvent.getTimestamp()); }
public Optional<BinlogEvent> map( @NonNull final Event event, @NonNull final BinlogFilePos position) { final EventHeaderV4 header = event.getHeader(); final EventType eventType = header.getEventType(); final long serverId = header.getServerId(); final long timestamp = header.getTimestamp(); if (EventType.isWrite(eventType)) { final WriteRowsEventData data = event.getData(); return Optional.of( new WriteEvent(data.getTableId(), serverId, timestamp, position, data.getRows())); } else if (EventType.isUpdate(eventType)) { final UpdateRowsEventData data = event.getData(); return Optional.of( new UpdateEvent(data.getTableId(), serverId, timestamp, position, data.getRows())); } else if (EventType.isDelete(eventType)) { final DeleteRowsEventData data = event.getData(); return Optional.of( new DeleteEvent(data.getTableId(), serverId, timestamp, position, data.getRows())); } else { switch (eventType) { case TABLE_MAP: TableMapEventData tableMapData = event.getData(); return Optional.of( new TableMapEvent( tableMapData.getTableId(), serverId, timestamp, position, tableMapData.getDatabase(), tableMapData.getTable(), tableMapData.getColumnTypes())); case XID: final XidEventData xidData = event.getData(); return Optional.of(new XidEvent(serverId, timestamp, position, xidData.getXid())); case GTID: final GtidEventData gtidEventData = event.getData(); return Optional.of(new GTIDEvent(serverId, timestamp, position, gtidEventData.getGtid())); case QUERY: final QueryEventData queryData = event.getData(); return Optional.of( new QueryEvent( serverId, timestamp, position, queryData.getDatabase(), queryData.getSql())); case FORMAT_DESCRIPTION: return Optional.of(new StartEvent(serverId, timestamp, position)); default: return Optional.empty(); } } }
BinaryLogConnectorEventMapper { public Optional<BinlogEvent> map( @NonNull final Event event, @NonNull final BinlogFilePos position) { final EventHeaderV4 header = event.getHeader(); final EventType eventType = header.getEventType(); final long serverId = header.getServerId(); final long timestamp = header.getTimestamp(); if (EventType.isWrite(eventType)) { final WriteRowsEventData data = event.getData(); return Optional.of( new WriteEvent(data.getTableId(), serverId, timestamp, position, data.getRows())); } else if (EventType.isUpdate(eventType)) { final UpdateRowsEventData data = event.getData(); return Optional.of( new UpdateEvent(data.getTableId(), serverId, timestamp, position, data.getRows())); } else if (EventType.isDelete(eventType)) { final DeleteRowsEventData data = event.getData(); return Optional.of( new DeleteEvent(data.getTableId(), serverId, timestamp, position, data.getRows())); } else { switch (eventType) { case TABLE_MAP: TableMapEventData tableMapData = event.getData(); return Optional.of( new TableMapEvent( tableMapData.getTableId(), serverId, timestamp, position, tableMapData.getDatabase(), tableMapData.getTable(), tableMapData.getColumnTypes())); case XID: final XidEventData xidData = event.getData(); return Optional.of(new XidEvent(serverId, timestamp, position, xidData.getXid())); case GTID: final GtidEventData gtidEventData = event.getData(); return Optional.of(new GTIDEvent(serverId, timestamp, position, gtidEventData.getGtid())); case QUERY: final QueryEventData queryData = event.getData(); return Optional.of( new QueryEvent( serverId, timestamp, position, queryData.getDatabase(), queryData.getSql())); case FORMAT_DESCRIPTION: return Optional.of(new StartEvent(serverId, timestamp, position)); default: return Optional.empty(); } } } }
BinaryLogConnectorEventMapper { public Optional<BinlogEvent> map( @NonNull final Event event, @NonNull final BinlogFilePos position) { final EventHeaderV4 header = event.getHeader(); final EventType eventType = header.getEventType(); final long serverId = header.getServerId(); final long timestamp = header.getTimestamp(); if (EventType.isWrite(eventType)) { final WriteRowsEventData data = event.getData(); return Optional.of( new WriteEvent(data.getTableId(), serverId, timestamp, position, data.getRows())); } else if (EventType.isUpdate(eventType)) { final UpdateRowsEventData data = event.getData(); return Optional.of( new UpdateEvent(data.getTableId(), serverId, timestamp, position, data.getRows())); } else if (EventType.isDelete(eventType)) { final DeleteRowsEventData data = event.getData(); return Optional.of( new DeleteEvent(data.getTableId(), serverId, timestamp, position, data.getRows())); } else { switch (eventType) { case TABLE_MAP: TableMapEventData tableMapData = event.getData(); return Optional.of( new TableMapEvent( tableMapData.getTableId(), serverId, timestamp, position, tableMapData.getDatabase(), tableMapData.getTable(), tableMapData.getColumnTypes())); case XID: final XidEventData xidData = event.getData(); return Optional.of(new XidEvent(serverId, timestamp, position, xidData.getXid())); case GTID: final GtidEventData gtidEventData = event.getData(); return Optional.of(new GTIDEvent(serverId, timestamp, position, gtidEventData.getGtid())); case QUERY: final QueryEventData queryData = event.getData(); return Optional.of( new QueryEvent( serverId, timestamp, position, queryData.getDatabase(), queryData.getSql())); case FORMAT_DESCRIPTION: return Optional.of(new StartEvent(serverId, timestamp, position)); default: return Optional.empty(); } } }  }
BinaryLogConnectorEventMapper { public Optional<BinlogEvent> map( @NonNull final Event event, @NonNull final BinlogFilePos position) { final EventHeaderV4 header = event.getHeader(); final EventType eventType = header.getEventType(); final long serverId = header.getServerId(); final long timestamp = header.getTimestamp(); if (EventType.isWrite(eventType)) { final WriteRowsEventData data = event.getData(); return Optional.of( new WriteEvent(data.getTableId(), serverId, timestamp, position, data.getRows())); } else if (EventType.isUpdate(eventType)) { final UpdateRowsEventData data = event.getData(); return Optional.of( new UpdateEvent(data.getTableId(), serverId, timestamp, position, data.getRows())); } else if (EventType.isDelete(eventType)) { final DeleteRowsEventData data = event.getData(); return Optional.of( new DeleteEvent(data.getTableId(), serverId, timestamp, position, data.getRows())); } else { switch (eventType) { case TABLE_MAP: TableMapEventData tableMapData = event.getData(); return Optional.of( new TableMapEvent( tableMapData.getTableId(), serverId, timestamp, position, tableMapData.getDatabase(), tableMapData.getTable(), tableMapData.getColumnTypes())); case XID: final XidEventData xidData = event.getData(); return Optional.of(new XidEvent(serverId, timestamp, position, xidData.getXid())); case GTID: final GtidEventData gtidEventData = event.getData(); return Optional.of(new GTIDEvent(serverId, timestamp, position, gtidEventData.getGtid())); case QUERY: final QueryEventData queryData = event.getData(); return Optional.of( new QueryEvent( serverId, timestamp, position, queryData.getDatabase(), queryData.getSql())); case FORMAT_DESCRIPTION: return Optional.of(new StartEvent(serverId, timestamp, position)); default: return Optional.empty(); } } }  Optional<BinlogEvent> map(
      @NonNull final Event event, @NonNull final BinlogFilePos position); }
BinaryLogConnectorEventMapper { public Optional<BinlogEvent> map( @NonNull final Event event, @NonNull final BinlogFilePos position) { final EventHeaderV4 header = event.getHeader(); final EventType eventType = header.getEventType(); final long serverId = header.getServerId(); final long timestamp = header.getTimestamp(); if (EventType.isWrite(eventType)) { final WriteRowsEventData data = event.getData(); return Optional.of( new WriteEvent(data.getTableId(), serverId, timestamp, position, data.getRows())); } else if (EventType.isUpdate(eventType)) { final UpdateRowsEventData data = event.getData(); return Optional.of( new UpdateEvent(data.getTableId(), serverId, timestamp, position, data.getRows())); } else if (EventType.isDelete(eventType)) { final DeleteRowsEventData data = event.getData(); return Optional.of( new DeleteEvent(data.getTableId(), serverId, timestamp, position, data.getRows())); } else { switch (eventType) { case TABLE_MAP: TableMapEventData tableMapData = event.getData(); return Optional.of( new TableMapEvent( tableMapData.getTableId(), serverId, timestamp, position, tableMapData.getDatabase(), tableMapData.getTable(), tableMapData.getColumnTypes())); case XID: final XidEventData xidData = event.getData(); return Optional.of(new XidEvent(serverId, timestamp, position, xidData.getXid())); case GTID: final GtidEventData gtidEventData = event.getData(); return Optional.of(new GTIDEvent(serverId, timestamp, position, gtidEventData.getGtid())); case QUERY: final QueryEventData queryData = event.getData(); return Optional.of( new QueryEvent( serverId, timestamp, position, queryData.getDatabase(), queryData.getSql())); case FORMAT_DESCRIPTION: return Optional.of(new StartEvent(serverId, timestamp, position)); default: return Optional.empty(); } } }  Optional<BinlogEvent> map(
      @NonNull final Event event, @NonNull final BinlogFilePos position); static final BinaryLogConnectorEventMapper INSTANCE; }