|
| 1 | +package com.github.shyiko.mysql.binlog; |
| 2 | + |
| 3 | +import static org.testng.Assert.assertEquals; |
| 4 | + |
| 5 | +import java.sql.SQLException; |
| 6 | +import java.sql.Statement; |
| 7 | +import java.util.BitSet; |
| 8 | +import java.util.concurrent.TimeUnit; |
| 9 | +import java.util.logging.Level; |
| 10 | +import java.util.logging.Logger; |
| 11 | + |
| 12 | +import org.testng.SkipException; |
| 13 | +import org.testng.annotations.BeforeMethod; |
| 14 | +import org.testng.annotations.Test; |
| 15 | + |
| 16 | +import com.github.shyiko.mysql.binlog.BinaryLogClientIntegrationTest.Callback; |
| 17 | +import com.github.shyiko.mysql.binlog.event.EventType; |
| 18 | +import com.github.shyiko.mysql.binlog.event.TableMapEventData; |
| 19 | +import com.github.shyiko.mysql.binlog.event.TableMapEventMetadata; |
| 20 | + |
| 21 | +public class OptionalMetaDataIntegrationTest extends AbstractIntegrationTest { |
| 22 | + protected static final long DEFAULT_TIMEOUT = TimeUnit.SECONDS.toMillis(3); |
| 23 | + |
| 24 | + private final Logger logger = Logger.getLogger(getClass().getSimpleName()); |
| 25 | + |
| 26 | + { |
| 27 | + logger.setLevel(Level.FINEST); |
| 28 | + } |
| 29 | + |
| 30 | + public void checkMysqlVersion() throws Exception { |
| 31 | + if (!mysqlVersion.atLeast(8, 0)) { |
| 32 | + throw new SkipException("For Optional Meta Data Test MYSQL VERSION SHOULD BE MORE THAN 8.0"); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + @BeforeMethod |
| 37 | + public void beforeEachTest() throws Exception { |
| 38 | + checkMysqlVersion(); |
| 39 | + master.execute(new Callback<Statement>() { |
| 40 | + @Override |
| 41 | + public void execute(Statement statement) throws SQLException { |
| 42 | + statement.execute("drop table if exists optionalMetaDataIntegrationTest"); |
| 43 | + statement.execute( |
| 44 | + "create table optionalMetaDataIntegrationTest (col1 int unsigned , col2 int, col3 varchar(30), col4 int unsigned)"); |
| 45 | + } |
| 46 | + }); |
| 47 | + eventListener.waitForAtLeast(EventType.QUERY, 2, DEFAULT_TIMEOUT); |
| 48 | + eventListener.reset(); |
| 49 | + } |
| 50 | + |
| 51 | + @Test |
| 52 | + public void testSignedness() throws Exception { |
| 53 | + CapturingEventListener capturingEventListener = new CapturingEventListener(); |
| 54 | + client.registerEventListener(capturingEventListener); |
| 55 | + // ensure "capturingEventListener -> eventListener" order |
| 56 | + client.unregisterEventListener(eventListener); |
| 57 | + client.registerEventListener(eventListener); |
| 58 | + try { |
| 59 | + master.execute(new Callback<Statement>() { |
| 60 | + @Override |
| 61 | + public void execute(Statement statement) throws SQLException { |
| 62 | + statement.execute("insert into optionalMetaDataIntegrationTest values (1,2,3,4)"); |
| 63 | + } |
| 64 | + }); |
| 65 | + eventListener.waitFor(TableMapEventData.class, 1, DEFAULT_TIMEOUT); |
| 66 | + TableMapEventMetadata eventMetadata = capturingEventListener.getEvents(TableMapEventData.class).get( |
| 67 | + 0).getEventMetadata(); |
| 68 | + BitSet expectBitSet = new BitSet(); |
| 69 | + expectBitSet.set(0); |
| 70 | + expectBitSet.set(3); |
| 71 | + assertEquals(eventMetadata.getSignedness(), expectBitSet); |
| 72 | + |
| 73 | + } finally { |
| 74 | + client.unregisterEventListener(capturingEventListener); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | +} |
0 commit comments