Search in sources :

Example 1 with MysqlConnector

use of com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector in project canal by alibaba.

the class DirectLogFetcherTest method testSimple.

@Test
public void testSimple() {
    DirectLogFetcher fetcher = new DirectLogFetcher();
    try {
        MysqlConnector connector = new MysqlConnector(new InetSocketAddress("127.0.0.1", 3306), "xxxxx", "xxxxx");
        connector.connect();
        sendBinlogDump(connector, "mysql-bin.001016", 4L, 3);
        fetcher.start(connector.getChannel());
        LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
        LogContext context = new LogContext();
        while (fetcher.fetch()) {
            LogEvent event = null;
            event = decoder.decode(fetcher, context);
            if (event == null) {
                throw new RuntimeException("parse failed");
            }
            int eventType = event.getHeader().getType();
            switch(eventType) {
                case LogEvent.ROTATE_EVENT:
                    // event).getFilename();
                    break;
                case LogEvent.WRITE_ROWS_EVENT_V1:
                case LogEvent.WRITE_ROWS_EVENT:
                    // parseRowsEvent((WriteRowsLogEvent) event);
                    break;
                case LogEvent.UPDATE_ROWS_EVENT_V1:
                case LogEvent.UPDATE_ROWS_EVENT:
                    // parseRowsEvent((UpdateRowsLogEvent) event);
                    break;
                case LogEvent.DELETE_ROWS_EVENT_V1:
                case LogEvent.DELETE_ROWS_EVENT:
                    // parseRowsEvent((DeleteRowsLogEvent) event);
                    break;
                case LogEvent.QUERY_EVENT:
                    // parseQueryEvent((QueryLogEvent) event);
                    break;
                case LogEvent.ROWS_QUERY_LOG_EVENT:
                    // parseRowsQueryEvent((RowsQueryLogEvent) event);
                    break;
                case LogEvent.ANNOTATE_ROWS_EVENT:
                    break;
                case LogEvent.XID_EVENT:
                    break;
                default:
                    break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    } finally {
        try {
            fetcher.close();
        } catch (IOException e) {
            Assert.fail(e.getMessage());
        }
    }
}
Also used : MysqlConnector(com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector) DirectLogFetcher(com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher) LogEvent(com.taobao.tddl.dbsync.binlog.LogEvent) InetSocketAddress(java.net.InetSocketAddress) LogContext(com.taobao.tddl.dbsync.binlog.LogContext) LogDecoder(com.taobao.tddl.dbsync.binlog.LogDecoder) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

MysqlConnector (com.alibaba.otter.canal.parse.driver.mysql.MysqlConnector)1 DirectLogFetcher (com.alibaba.otter.canal.parse.inbound.mysql.dbsync.DirectLogFetcher)1 LogContext (com.taobao.tddl.dbsync.binlog.LogContext)1 LogDecoder (com.taobao.tddl.dbsync.binlog.LogDecoder)1 LogEvent (com.taobao.tddl.dbsync.binlog.LogEvent)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Test (org.junit.Test)1