From 20e7becfe90b62e8f95bdaf870a8e4de5c8dc48c Mon Sep 17 00:00:00 2001 From: agapple Date: Thu, 28 Mar 2019 10:19:53 +0800 Subject: [PATCH 1/2] fixed format --- .../driver/mysql/MysqlConnectorTest.java | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/driver/src/test/java/com/alibaba/otter/canal/parse/driver/mysql/MysqlConnectorTest.java b/driver/src/test/java/com/alibaba/otter/canal/parse/driver/mysql/MysqlConnectorTest.java index 1af5d1e3..abcd1473 100644 --- a/driver/src/test/java/com/alibaba/otter/canal/parse/driver/mysql/MysqlConnectorTest.java +++ b/driver/src/test/java/com/alibaba/otter/canal/parse/driver/mysql/MysqlConnectorTest.java @@ -3,26 +3,51 @@ package com.alibaba.otter.canal.parse.driver.mysql; import java.io.IOException; import java.net.InetSocketAddress; +import org.junit.Assert; +import org.junit.Test; + import com.alibaba.otter.canal.parse.driver.mysql.packets.server.ResultSetPacket; public class MysqlConnectorTest { - public static void main(String args[]) { - MysqlConnector connector = new MysqlConnector(new InetSocketAddress("yddb01.mysql.database.chinacloudapi.cn", - 3306), "ps-admin01@yddb01", "1qaz3edc"); + @Test + public void testQuery() { + + MysqlConnector connector = new MysqlConnector(new InetSocketAddress("127.0.0.1", 3306), "xxxxx", "xxxxx"); try { connector.connect(); MysqlQueryExecutor executor = new MysqlQueryExecutor(connector); ResultSetPacket result = executor.query("show variables like '%char%';"); System.out.println(result); + result = executor.query("select * from test.test1"); + System.out.println(result); } catch (IOException e) { - e.printStackTrace(); + Assert.fail(e.getMessage()); } finally { try { connector.disconnect(); } catch (IOException e) { + Assert.fail(e.getMessage()); } } } + // @Test + public void testUpdate() { + + MysqlConnector connector = new MysqlConnector(new InetSocketAddress("127.0.0.1", 3306), "xxxxx", "xxxxx"); + try { + connector.connect(); + MysqlUpdateExecutor executor = new MysqlUpdateExecutor(connector); + executor.update("insert into test.test2(id,name,score,text_value) values(null,'中文1',10,'中文2')"); + } catch (IOException e) { + Assert.fail(e.getMessage()); + } finally { + try { + connector.disconnect(); + } catch (IOException e) { + Assert.fail(e.getMessage()); + } + } + } } From 97640b717b855ab8b56e3ca37026732e5d56eebd Mon Sep 17 00:00:00 2001 From: agapple Date: Thu, 28 Mar 2019 10:23:33 +0800 Subject: [PATCH 2/2] fixed compiler --- .../otter/canal/kafka/CanalKafkaProducer.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/server/src/main/java/com/alibaba/otter/canal/kafka/CanalKafkaProducer.java b/server/src/main/java/com/alibaba/otter/canal/kafka/CanalKafkaProducer.java index c4605067..6cc6724f 100644 --- a/server/src/main/java/com/alibaba/otter/canal/kafka/CanalKafkaProducer.java +++ b/server/src/main/java/com/alibaba/otter/canal/kafka/CanalKafkaProducer.java @@ -139,7 +139,7 @@ public class CanalKafkaProducer implements CanalMQProducer { private void send(MQProperties.CanalDestination canalDestination, String topicName, Message message) throws Exception { if (!kafkaProperties.getFlatMessage()) { - List> records = new ArrayList<>(); + List> records = new ArrayList>(); if (canalDestination.getPartitionHash() != null && !canalDestination.getPartitionHash().isEmpty()) { Message[] messages = MQMessageUtils.messagePartition(message, canalDestination.getPartitionsNum(), @@ -148,23 +148,23 @@ public class CanalKafkaProducer implements CanalMQProducer { for (int i = 0; i < length; i++) { Message messagePartition = messages[i]; if (messagePartition != null) { - records.add(new ProducerRecord<>(topicName, i, null, messagePartition)); + records.add(new ProducerRecord(topicName, i, null, messagePartition)); } } } else { final int partition = canalDestination.getPartition() != null ? canalDestination.getPartition() : 0; - records.add(new ProducerRecord<>(topicName, partition, null, message)); + records.add(new ProducerRecord(topicName, partition, null, message)); } - if (!records.isEmpty()) { - for (ProducerRecord record : records) { - producer.send(record).get(); - } - - if (logger.isDebugEnabled()) { - logger.debug("Send message to kafka topic: [{}], packet: {}", topicName, message.toString()); - } - } + if (!records.isEmpty()) { + for (ProducerRecord record : records) { + producer.send(record).get(); + } + + if (logger.isDebugEnabled()) { + logger.debug("Send message to kafka topic: [{}], packet: {}", topicName, message.toString()); + } + } } else { // 发送扁平数据json List flatMessages = MQMessageUtils.messageConverter(message);