diff --git a/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/EventHeaderV4Deserializer.java b/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/EventHeaderV4Deserializer.java index 2d8bcdd8..c0569f09 100644 --- a/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/EventHeaderV4Deserializer.java +++ b/src/main/java/com/github/shyiko/mysql/binlog/event/deserialization/EventHeaderV4Deserializer.java @@ -40,9 +40,9 @@ public EventHeaderV4 deserialize(ByteArrayInputStream inputStream) throws IOExce return header; } - private static EventType getEventType(int ordinal) throws IOException { + private static EventType getEventType(int ordinal) { if (ordinal >= EVENT_TYPES.length) { - throw new IOException("Unknown event type " + ordinal); + return EventType.UNKNOWN; } return EVENT_TYPES[ordinal]; } diff --git a/src/test/java/com/github/shyiko/mysql/binlog/BinaryLogFileReaderIntegrationTest.java b/src/test/java/com/github/shyiko/mysql/binlog/BinaryLogFileReaderIntegrationTest.java index cbf523a6..ef9eca57 100644 --- a/src/test/java/com/github/shyiko/mysql/binlog/BinaryLogFileReaderIntegrationTest.java +++ b/src/test/java/com/github/shyiko/mysql/binlog/BinaryLogFileReaderIntegrationTest.java @@ -30,6 +30,7 @@ import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; @@ -70,6 +71,36 @@ public void testChecksumCRC32WithCustomEventDataDeserializer() throws Exception readAll(reader, 303); } + @Test + public void testUnsupportedEventType() throws Exception { + EventDeserializer eventDeserializer = new EventDeserializer(); + + // mysql> SHOW BINLOG EVENTS IN 'mysql-bin.aurora-padding'; + // +--------------------------+------+----------------+-------------+---------------------------------------+ + // | Log_name | Pos | Event_type | End_log_pos | Info | + // +--------------------------+------+----------------+-------------+---------------------------------------+ + // | mysql-bin.aurora-padding | 4 | Format_desc | 185 | Server ver: 5.7.12-log, Binlog ver: 4 | + // | mysql-bin.aurora-padding | 185 | Previous_gtids | 216 | | + // | mysql-bin.aurora-padding | 216 | Anonymous_Gtid | 281 | SET @@SESSION.GTID_NEXT= 'ANONYMOUS' | + // | mysql-bin.aurora-padding | 281 | Aurora_padding | 1209 | Ignorable | + // | mysql-bin.aurora-padding | 1209 | Query | 1294 | BEGIN | + BinaryLogFileReader reader = new BinaryLogFileReader( + new FileInputStream("src/test/resources/mysql-bin.aurora-padding"), eventDeserializer); + try { + for (int i = 0; i < 3; i++) { + assertNotNull(reader.readEvent()); + } + try { + reader.readEvent(); + } catch (IOException e) { + // this simulates the Debezium's event.processing.failure.handling.mode = warn + } + assertEquals(reader.readEvent().getHeader().getEventType(), EventType.QUERY); + } finally { + reader.close(); + } + } + private void readAll(BinaryLogFileReader reader, int expect) throws IOException { try { int numberOfEvents = 0; diff --git a/src/test/resources/mysql-bin.aurora-padding b/src/test/resources/mysql-bin.aurora-padding new file mode 100644 index 00000000..688b51b2 Binary files /dev/null and b/src/test/resources/mysql-bin.aurora-padding differ