mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
= code cleanup
- for loop replaceable with enhanced 'for' loop - using diamond in generic type - collapse try catch exception - using try-with-resource - using List#sort instead of Collections#sort - replaced lambda with method reference - using native compare method to compare numbers - using switch instead of if for in ESSyncUtil
This commit is contained in:
@@ -108,9 +108,7 @@ public class SimpleAdminConnector implements AdminConnector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
connected = true;
|
connected = true;
|
||||||
} catch (IOException e) {
|
} catch (IOException | NoSuchAlgorithmException e) {
|
||||||
throw new ServiceException(e);
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
throw new ServiceException(e);
|
throw new ServiceException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ class DefaultPropertyNamePatternsMatcher implements PropertyNamePatternsMatcher
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < match.length; i++) {
|
for (boolean b : match) {
|
||||||
if (match[i]) {
|
if (b) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -130,8 +130,7 @@ public abstract class YamlProcessor {
|
|||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("Loading from YAML: " + resource);
|
logger.debug("Loading from YAML: " + resource);
|
||||||
}
|
}
|
||||||
Reader reader = new UnicodeReader(resource.getInputStream());
|
try (Reader reader = new UnicodeReader(resource.getInputStream())) {
|
||||||
try {
|
|
||||||
for (Object object : yaml.loadAll(reader)) {
|
for (Object object : yaml.loadAll(reader)) {
|
||||||
if (object != null && process(asMap(object), callback)) {
|
if (object != null && process(asMap(object), callback)) {
|
||||||
count++;
|
count++;
|
||||||
@@ -144,8 +143,6 @@ public abstract class YamlProcessor {
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
"Loaded " + count + " document" + (count > 1 ? "s" : "") + " from YAML resource: " + resource);
|
"Loaded " + count + " document" + (count > 1 ? "s" : "") + " from YAML resource: " + resource);
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
reader.close();
|
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
handleProcessError(resource, ex);
|
handleProcessError(resource, ex);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.io.InputStreamReader;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -317,10 +318,8 @@ public class ExtensionLoader<T> {
|
|||||||
while (urls.hasMoreElements()) {
|
while (urls.hasMoreElements()) {
|
||||||
URL url = urls.nextElement();
|
URL url = urls.nextElement();
|
||||||
try {
|
try {
|
||||||
BufferedReader reader = null;
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), StandardCharsets.UTF_8))) {
|
||||||
try {
|
String line;
|
||||||
reader = new BufferedReader(new InputStreamReader(url.openStream(), "utf-8"));
|
|
||||||
String line = null;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
while ((line = reader.readLine()) != null) {
|
||||||
final int ci = line.indexOf('#');
|
final int ci = line.indexOf('#');
|
||||||
if (ci >= 0) line = line.substring(0, ci);
|
if (ci >= 0) line = line.substring(0, ci);
|
||||||
@@ -382,10 +381,6 @@ public class ExtensionLoader<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // end of while read lines
|
} // end of while read lines
|
||||||
} finally {
|
|
||||||
if (reader != null) {
|
|
||||||
reader.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
logger.error("Exception when load extension class(interface: " + type + ", class file: " + url
|
logger.error("Exception when load extension class(interface: " + type + ", class file: " + url
|
||||||
|
|||||||
@@ -63,43 +63,52 @@ public class ESSyncUtil {
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
Object res = null;
|
Object res = null;
|
||||||
if ("integer".equals(esType)) {
|
switch (esType) {
|
||||||
|
case "integer":
|
||||||
if (val instanceof Number) {
|
if (val instanceof Number) {
|
||||||
res = ((Number) val).intValue();
|
res = ((Number) val).intValue();
|
||||||
} else {
|
} else {
|
||||||
res = Integer.parseInt(val.toString());
|
res = Integer.parseInt(val.toString());
|
||||||
}
|
}
|
||||||
} else if ("long".equals(esType)) {
|
break;
|
||||||
|
case "long":
|
||||||
if (val instanceof Number) {
|
if (val instanceof Number) {
|
||||||
res = ((Number) val).longValue();
|
res = ((Number) val).longValue();
|
||||||
} else {
|
} else {
|
||||||
res = Long.parseLong(val.toString());
|
res = Long.parseLong(val.toString());
|
||||||
}
|
}
|
||||||
} else if ("short".equals(esType)) {
|
break;
|
||||||
|
case "short":
|
||||||
if (val instanceof Number) {
|
if (val instanceof Number) {
|
||||||
res = ((Number) val).shortValue();
|
res = ((Number) val).shortValue();
|
||||||
} else {
|
} else {
|
||||||
res = Short.parseShort(val.toString());
|
res = Short.parseShort(val.toString());
|
||||||
}
|
}
|
||||||
} else if ("byte".equals(esType)) {
|
break;
|
||||||
|
case "byte":
|
||||||
if (val instanceof Number) {
|
if (val instanceof Number) {
|
||||||
res = ((Number) val).byteValue();
|
res = ((Number) val).byteValue();
|
||||||
} else {
|
} else {
|
||||||
res = Byte.parseByte(val.toString());
|
res = Byte.parseByte(val.toString());
|
||||||
}
|
}
|
||||||
} else if ("double".equals(esType)) {
|
break;
|
||||||
|
case "double":
|
||||||
if (val instanceof Number) {
|
if (val instanceof Number) {
|
||||||
res = ((Number) val).doubleValue();
|
res = ((Number) val).doubleValue();
|
||||||
} else {
|
} else {
|
||||||
res = Double.parseDouble(val.toString());
|
res = Double.parseDouble(val.toString());
|
||||||
}
|
}
|
||||||
} else if ("float".equals(esType) || "half_float".equals(esType) || "scaled_float".equals(esType)) {
|
break;
|
||||||
|
case "float":
|
||||||
|
case "half_float":
|
||||||
|
case "scaled_float":
|
||||||
if (val instanceof Number) {
|
if (val instanceof Number) {
|
||||||
res = ((Number) val).floatValue();
|
res = ((Number) val).floatValue();
|
||||||
} else {
|
} else {
|
||||||
res = Float.parseFloat(val.toString());
|
res = Float.parseFloat(val.toString());
|
||||||
}
|
}
|
||||||
} else if ("boolean".equals(esType)) {
|
break;
|
||||||
|
case "boolean":
|
||||||
if (val instanceof Boolean) {
|
if (val instanceof Boolean) {
|
||||||
res = val;
|
res = val;
|
||||||
} else if (val instanceof Number) {
|
} else if (val instanceof Number) {
|
||||||
@@ -108,7 +117,8 @@ public class ESSyncUtil {
|
|||||||
} else {
|
} else {
|
||||||
res = Boolean.parseBoolean(val.toString());
|
res = Boolean.parseBoolean(val.toString());
|
||||||
}
|
}
|
||||||
} else if ("date".equals(esType)) {
|
break;
|
||||||
|
case "date":
|
||||||
if (val instanceof java.sql.Time) {
|
if (val instanceof java.sql.Time) {
|
||||||
DateTime dateTime = new DateTime(((java.sql.Time) val).getTime());
|
DateTime dateTime = new DateTime(((java.sql.Time) val).getTime());
|
||||||
if (dateTime.getMillisOfSecond() != 0) {
|
if (dateTime.getMillisOfSecond() != 0) {
|
||||||
@@ -172,7 +182,8 @@ public class ESSyncUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ("binary".equals(esType)) {
|
break;
|
||||||
|
case "binary":
|
||||||
if (val instanceof byte[]) {
|
if (val instanceof byte[]) {
|
||||||
Base64 base64 = new Base64();
|
Base64 base64 = new Base64();
|
||||||
res = base64.encodeAsString((byte[]) val);
|
res = base64.encodeAsString((byte[]) val);
|
||||||
@@ -186,7 +197,8 @@ public class ESSyncUtil {
|
|||||||
Base64 base64 = new Base64();
|
Base64 base64 = new Base64();
|
||||||
res = base64.encodeAsString(b);
|
res = base64.encodeAsString(b);
|
||||||
}
|
}
|
||||||
} else if ("geo_point".equals(esType)) {
|
break;
|
||||||
|
case "geo_point":
|
||||||
if (!(val instanceof String)) {
|
if (!(val instanceof String)) {
|
||||||
logger.error("es type is geo_point, but source type is not String");
|
logger.error("es type is geo_point, but source type is not String");
|
||||||
return val;
|
return val;
|
||||||
@@ -202,7 +214,7 @@ public class ESSyncUtil {
|
|||||||
location.put("lat", Double.valueOf(point[0].trim()));
|
location.put("lat", Double.valueOf(point[0].trim()));
|
||||||
location.put("lon", Double.valueOf(point[1].trim()));
|
location.put("lon", Double.valueOf(point[1].trim()));
|
||||||
return location;
|
return location;
|
||||||
} else if ("array".equals(esType)) {
|
case "array":
|
||||||
if ("".equals(val.toString().trim())) {
|
if ("".equals(val.toString().trim())) {
|
||||||
res = new ArrayList<>();
|
res = new ArrayList<>();
|
||||||
} else {
|
} else {
|
||||||
@@ -220,15 +232,18 @@ public class ESSyncUtil {
|
|||||||
String[] values = value.split(separator);
|
String[] values = value.split(separator);
|
||||||
return Arrays.asList(values);
|
return Arrays.asList(values);
|
||||||
}
|
}
|
||||||
} else if ("object".equals(esType)) {
|
break;
|
||||||
|
case "object":
|
||||||
if ("".equals(val.toString().trim())) {
|
if ("".equals(val.toString().trim())) {
|
||||||
res = new HashMap<>();
|
res = new HashMap<>();
|
||||||
} else {
|
} else {
|
||||||
res = JSON.parseObject(val.toString(), Map.class);
|
res = JSON.parseObject(val.toString(), Map.class);
|
||||||
}
|
}
|
||||||
} else {
|
break;
|
||||||
|
default:
|
||||||
// 其他类全以字符串处理
|
// 其他类全以字符串处理
|
||||||
res = val.toString();
|
res = val.toString();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -115,12 +115,7 @@ public class KuduEtlService extends AbstractEtlService {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException | KuduException e) {
|
||||||
e.printStackTrace();
|
|
||||||
logger.error(kuduMapping.getTargetTable() + " etl failed! ==>" + e.getMessage(), e);
|
|
||||||
errMsg.add(kuduMapping.getTargetTable() + " etl failed! ==>" + e.getMessage());
|
|
||||||
return false;
|
|
||||||
} catch (KuduException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
logger.error(kuduMapping.getTargetTable() + " etl failed! ==>" + e.getMessage(), e);
|
logger.error(kuduMapping.getTargetTable() + " etl failed! ==>" + e.getMessage(), e);
|
||||||
errMsg.add(kuduMapping.getTargetTable() + " etl failed! ==>" + e.getMessage());
|
errMsg.add(kuduMapping.getTargetTable() + " etl failed! ==>" + e.getMessage());
|
||||||
|
|||||||
@@ -18,20 +18,11 @@ public class AddressUtils {
|
|||||||
private static final Pattern IP_PATTERN = Pattern.compile("[0-9]{1,3}(\\.[0-9]{1,3}){3,}");
|
private static final Pattern IP_PATTERN = Pattern.compile("[0-9]{1,3}(\\.[0-9]{1,3}){3,}");
|
||||||
|
|
||||||
public static boolean isAvailablePort(int port) {
|
public static boolean isAvailablePort(int port) {
|
||||||
ServerSocket ss = null;
|
try (ServerSocket ss = new ServerSocket(port)) {
|
||||||
try {
|
|
||||||
ss = new ServerSocket(port);
|
|
||||||
ss.bind(null);
|
ss.bind(null);
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return false;
|
return false;
|
||||||
} finally {
|
|
||||||
if (ss != null) {
|
|
||||||
try {
|
|
||||||
ss.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,14 +71,11 @@ public class JsonUtils {
|
|||||||
*/
|
*/
|
||||||
public static String marshalToString(Object obj, String... fliterFields) {
|
public static String marshalToString(Object obj, String... fliterFields) {
|
||||||
final List<String> propertyFliters = Arrays.asList(fliterFields);
|
final List<String> propertyFliters = Arrays.asList(fliterFields);
|
||||||
SerializeWriter out = new SerializeWriter();
|
try (SerializeWriter out = new SerializeWriter()) {
|
||||||
try {
|
|
||||||
JSONSerializer serializer = new JSONSerializer(out);
|
JSONSerializer serializer = new JSONSerializer(out);
|
||||||
serializer.getPropertyFilters().add((source, name, value) -> !propertyFliters.contains(name));
|
serializer.getPropertyFilters().add((source, name, value) -> !propertyFliters.contains(name));
|
||||||
serializer.write(obj);
|
serializer.write(obj);
|
||||||
return out.toString();
|
return out.toString();
|
||||||
} finally {
|
|
||||||
out.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class AviaterRegexFilter {
|
|||||||
// 对pattern按照从长到短的排序
|
// 对pattern按照从长到短的排序
|
||||||
// 因为 foo|foot 匹配 foot 会出错,原因是 foot 匹配了 foo 之后,会返回 foo,但是 foo 的长度和 foot
|
// 因为 foo|foot 匹配 foot 会出错,原因是 foot 匹配了 foo 之后,会返回 foo,但是 foo 的长度和 foot
|
||||||
// 的长度不一样
|
// 的长度不一样
|
||||||
Collections.sort(list, COMPARATOR);
|
list.sort(COMPARATOR);
|
||||||
// 对pattern进行头尾完全匹配
|
// 对pattern进行头尾完全匹配
|
||||||
list = completionPattern(list);
|
list = completionPattern(list);
|
||||||
this.pattern = StringUtils.join(list, PATTERN_SPLIT);
|
this.pattern = StringUtils.join(list, PATTERN_SPLIT);
|
||||||
@@ -88,13 +88,7 @@ public class AviaterRegexFilter {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(String str1, String str2) {
|
public int compare(String str1, String str2) {
|
||||||
if (str1.length() > str2.length()) {
|
return Integer.compare(str2.length(), str1.length());
|
||||||
return -1;
|
|
||||||
} else if (str1.length() < str2.length()) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ public class CanalMessageSerializerUtil {
|
|||||||
messageSize += CodedOutputStream.computeInt64Size(1, data.getId());
|
messageSize += CodedOutputStream.computeInt64Size(1, data.getId());
|
||||||
|
|
||||||
int dataSize = 0;
|
int dataSize = 0;
|
||||||
for (int i = 0; i < rowEntries.size(); i++) {
|
for (ByteString rowEntry : rowEntries) {
|
||||||
dataSize += CodedOutputStream.computeBytesSizeNoTag(rowEntries.get(i));
|
dataSize += CodedOutputStream.computeBytesSizeNoTag(rowEntry);
|
||||||
}
|
}
|
||||||
messageSize += dataSize;
|
messageSize += dataSize;
|
||||||
messageSize += 1 * rowEntries.size();
|
messageSize += 1 * rowEntries.size();
|
||||||
@@ -53,8 +53,8 @@ public class CanalMessageSerializerUtil {
|
|||||||
output.writeRawVarint32(messageSize);
|
output.writeRawVarint32(messageSize);
|
||||||
// message
|
// message
|
||||||
output.writeInt64(1, data.getId());
|
output.writeInt64(1, data.getId());
|
||||||
for (int i = 0; i < rowEntries.size(); i++) {
|
for (ByteString rowEntry : rowEntries) {
|
||||||
output.writeBytes(2, rowEntries.get(i));
|
output.writeBytes(2, rowEntry);
|
||||||
}
|
}
|
||||||
output.checkNoSpaceLeft();
|
output.checkNoSpaceLeft();
|
||||||
return body;
|
return body;
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ import com.taobao.tddl.dbsync.binlog.LogEvent;
|
|||||||
public class FetcherPerformanceTest {
|
public class FetcherPerformanceTest {
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
DirectLogFetcher fetcher = new DirectLogFetcher();
|
try (DirectLogFetcher fetcher = new DirectLogFetcher()) {
|
||||||
try {
|
|
||||||
Class.forName("com.mysql.jdbc.Driver");
|
Class.forName("com.mysql.jdbc.Driver");
|
||||||
Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306", "root", "hello");
|
Connection connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306", "root", "hello");
|
||||||
Statement statement = connection.createStatement();
|
Statement statement = connection.createStatement();
|
||||||
@@ -40,11 +39,6 @@ public class FetcherPerformanceTest {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
fetcher.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -192,7 +192,7 @@ public class CanalAdminController implements CanalAdmin {
|
|||||||
Collection<File> files = org.apache.commons.io.FileUtils.listFiles(new File("../logs/canal/"),
|
Collection<File> files = org.apache.commons.io.FileUtils.listFiles(new File("../logs/canal/"),
|
||||||
TrueFileFilter.TRUE,
|
TrueFileFilter.TRUE,
|
||||||
TrueFileFilter.TRUE);
|
TrueFileFilter.TRUE);
|
||||||
List<String> names = files.stream().map(f -> f.getName()).collect(Collectors.toList());
|
List<String> names = files.stream().map(File::getName).collect(Collectors.toList());
|
||||||
return Joiner.on(",").join(names);
|
return Joiner.on(",").join(names);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,7 +206,7 @@ public class CanalAdminController implements CanalAdmin {
|
|||||||
Collection<File> files = org.apache.commons.io.FileUtils.listFiles(new File("../logs/" + destination + "/"),
|
Collection<File> files = org.apache.commons.io.FileUtils.listFiles(new File("../logs/" + destination + "/"),
|
||||||
TrueFileFilter.TRUE,
|
TrueFileFilter.TRUE,
|
||||||
TrueFileFilter.TRUE);
|
TrueFileFilter.TRUE);
|
||||||
List<String> names = files.stream().map(f -> f.getName()).collect(Collectors.toList());
|
List<String> names = files.stream().map(File::getName).collect(Collectors.toList());
|
||||||
return Joiner.on(",").join(names);
|
return Joiner.on(",").join(names);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,8 +89,8 @@ public class MysqlGTIDSet implements GTIDSet {
|
|||||||
// 存在多个GTID时会有回车符
|
// 存在多个GTID时会有回车符
|
||||||
String[] uuidStrs = gtidData.replaceAll("\n", "").split(",");
|
String[] uuidStrs = gtidData.replaceAll("\n", "").split(",");
|
||||||
m = new HashMap<>(uuidStrs.length);
|
m = new HashMap<>(uuidStrs.length);
|
||||||
for (int i = 0; i < uuidStrs.length; i++) {
|
for (String uuidStr : uuidStrs) {
|
||||||
UUIDSet uuidSet = UUIDSet.parse(uuidStrs[i]);
|
UUIDSet uuidSet = UUIDSet.parse(uuidStr);
|
||||||
m.put(uuidSet.SID.toString(), uuidSet);
|
m.put(uuidSet.SID.toString(), uuidSet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public class UUIDSet {
|
|||||||
if (equals(o)) {
|
if (equals(o)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return start > o.start ? 1 : (start == o.start ? 0 : -1);
|
return Long.compare(start, o.start);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class AviaterRegexFilter implements CanalEventFilter<String> {
|
|||||||
// 对pattern按照从长到短的排序
|
// 对pattern按照从长到短的排序
|
||||||
// 因为 foo|foot 匹配 foot 会出错,原因是 foot 匹配了 foo 之后,会返回 foo,但是 foo 的长度和 foot
|
// 因为 foo|foot 匹配 foot 会出错,原因是 foot 匹配了 foo 之后,会返回 foo,但是 foo 的长度和 foot
|
||||||
// 的长度不一样
|
// 的长度不一样
|
||||||
Collections.sort(list, COMPARATOR);
|
list.sort(COMPARATOR);
|
||||||
// 对pattern进行头尾完全匹配
|
// 对pattern进行头尾完全匹配
|
||||||
list = completionPattern(list);
|
list = completionPattern(list);
|
||||||
this.pattern = StringUtils.join(list, PATTERN_SPLIT);
|
this.pattern = StringUtils.join(list, PATTERN_SPLIT);
|
||||||
@@ -90,13 +90,7 @@ public class AviaterRegexFilter implements CanalEventFilter<String> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(String str1, String str2) {
|
public int compare(String str1, String str2) {
|
||||||
if (str1.length() > str2.length()) {
|
return Integer.compare(str2.length(), str1.length());
|
||||||
return -1;
|
|
||||||
} else if (str1.length() < str2.length()) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ public class ZooKeeperMetaManager extends AbstractCanalLifeCycle implements Cana
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 找到最小的Id
|
// 找到最小的Id
|
||||||
ArrayList<Long> batchIds = new ArrayList<Long>(nodes.size());
|
ArrayList<Long> batchIds = new ArrayList<>(nodes.size());
|
||||||
for (String batchIdString : nodes) {
|
for (String batchIdString : nodes) {
|
||||||
batchIds.add(Long.valueOf(batchIdString));
|
batchIds.add(Long.valueOf(batchIdString));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,10 +81,9 @@ public class LocalBinLogConnection implements ErosaConnection {
|
|||||||
public void dump(String binlogfilename, Long binlogPosition, SinkFunction func) throws IOException {
|
public void dump(String binlogfilename, Long binlogPosition, SinkFunction func) throws IOException {
|
||||||
File current = new File(directory, binlogfilename);
|
File current = new File(directory, binlogfilename);
|
||||||
|
|
||||||
FileLogFetcher fetcher = new FileLogFetcher(bufferSize);
|
try (FileLogFetcher fetcher = new FileLogFetcher(bufferSize)) {
|
||||||
LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
|
LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
|
||||||
LogContext context = new LogContext();
|
LogContext context = new LogContext();
|
||||||
try {
|
|
||||||
fetcher.open(current, binlogPosition);
|
fetcher.open(current, binlogPosition);
|
||||||
context.setLogPosition(new LogPosition(binlogfilename, binlogPosition));
|
context.setLogPosition(new LogPosition(binlogfilename, binlogPosition));
|
||||||
while (running) {
|
while (running) {
|
||||||
@@ -129,10 +128,6 @@ public class LocalBinLogConnection implements ErosaConnection {
|
|||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
logger.warn("LocalBinLogConnection dump interrupted");
|
logger.warn("LocalBinLogConnection dump interrupted");
|
||||||
} finally {
|
|
||||||
if (fetcher != null) {
|
|
||||||
fetcher.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,10 +221,9 @@ public class LocalBinLogConnection implements ErosaConnection {
|
|||||||
throw new CanalParseException("binlog:" + binlogfilename + " is not found");
|
throw new CanalParseException("binlog:" + binlogfilename + " is not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
FileLogFetcher fetcher = new FileLogFetcher(bufferSize);
|
try (FileLogFetcher fetcher = new FileLogFetcher(bufferSize)) {
|
||||||
LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
|
LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
|
||||||
LogContext context = new LogContext();
|
LogContext context = new LogContext();
|
||||||
try {
|
|
||||||
fetcher.open(current, binlogPosition);
|
fetcher.open(current, binlogPosition);
|
||||||
context.setLogPosition(new LogPosition(binlogfilename, binlogPosition));
|
context.setLogPosition(new LogPosition(binlogfilename, binlogPosition));
|
||||||
while (running) {
|
while (running) {
|
||||||
@@ -273,10 +267,6 @@ public class LocalBinLogConnection implements ErosaConnection {
|
|||||||
}
|
}
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
logger.warn("LocalBinLogConnection dump interrupted");
|
logger.warn("LocalBinLogConnection dump interrupted");
|
||||||
} finally {
|
|
||||||
if (fetcher != null) {
|
|
||||||
fetcher.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -191,8 +191,7 @@ public class MysqlConnection implements ErosaConnection {
|
|||||||
loadBinlogChecksum();
|
loadBinlogChecksum();
|
||||||
sendBinlogDumpGTID(gtidSet);
|
sendBinlogDumpGTID(gtidSet);
|
||||||
|
|
||||||
DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize());
|
try (DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize())) {
|
||||||
try {
|
|
||||||
fetcher.start(connector.getChannel());
|
fetcher.start(connector.getChannel());
|
||||||
LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
|
LogDecoder decoder = new LogDecoder(LogEvent.UNKNOWN_EVENT, LogEvent.ENUM_END_EVENT);
|
||||||
LogContext context = new LogContext();
|
LogContext context = new LogContext();
|
||||||
@@ -212,8 +211,6 @@ public class MysqlConnection implements ErosaConnection {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
fetcher.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -229,8 +226,7 @@ public class MysqlConnection implements ErosaConnection {
|
|||||||
sendBinlogDump(binlogfilename, binlogPosition);
|
sendBinlogDump(binlogfilename, binlogPosition);
|
||||||
((MysqlMultiStageCoprocessor) coprocessor).setConnection(this);
|
((MysqlMultiStageCoprocessor) coprocessor).setConnection(this);
|
||||||
((MysqlMultiStageCoprocessor) coprocessor).setBinlogChecksum(binlogChecksum);
|
((MysqlMultiStageCoprocessor) coprocessor).setBinlogChecksum(binlogChecksum);
|
||||||
DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize());
|
try (DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize())) {
|
||||||
try {
|
|
||||||
fetcher.start(connector.getChannel());
|
fetcher.start(connector.getChannel());
|
||||||
while (fetcher.fetch()) {
|
while (fetcher.fetch()) {
|
||||||
accumulateReceivedBytes(fetcher.limit());
|
accumulateReceivedBytes(fetcher.limit());
|
||||||
@@ -240,8 +236,6 @@ public class MysqlConnection implements ErosaConnection {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
fetcher.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,8 +251,7 @@ public class MysqlConnection implements ErosaConnection {
|
|||||||
sendBinlogDumpGTID(gtidSet);
|
sendBinlogDumpGTID(gtidSet);
|
||||||
((MysqlMultiStageCoprocessor) coprocessor).setConnection(this);
|
((MysqlMultiStageCoprocessor) coprocessor).setConnection(this);
|
||||||
((MysqlMultiStageCoprocessor) coprocessor).setBinlogChecksum(binlogChecksum);
|
((MysqlMultiStageCoprocessor) coprocessor).setBinlogChecksum(binlogChecksum);
|
||||||
DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize());
|
try (DirectLogFetcher fetcher = new DirectLogFetcher(connector.getReceiveBufferSize())) {
|
||||||
try {
|
|
||||||
fetcher.start(connector.getChannel());
|
fetcher.start(connector.getChannel());
|
||||||
while (fetcher.fetch()) {
|
while (fetcher.fetch()) {
|
||||||
accumulateReceivedBytes(fetcher.limit());
|
accumulateReceivedBytes(fetcher.limit());
|
||||||
@@ -268,8 +261,6 @@ public class MysqlConnection implements ErosaConnection {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
fetcher.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -245,18 +245,6 @@ public class MysqlEventParser extends AbstractMysqlEventParser implements CanalE
|
|||||||
if (haController != null && haController instanceof HeartBeatCallback) {
|
if (haController != null && haController instanceof HeartBeatCallback) {
|
||||||
((HeartBeatCallback) haController).onSuccess(costTime);
|
((HeartBeatCallback) haController).onSuccess(costTime);
|
||||||
}
|
}
|
||||||
} catch (SocketTimeoutException e) {
|
|
||||||
if (haController != null && haController instanceof HeartBeatCallback) {
|
|
||||||
((HeartBeatCallback) haController).onFailed(e);
|
|
||||||
}
|
|
||||||
reconnect = true;
|
|
||||||
logger.warn("connect failed by ", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
if (haController != null && haController instanceof HeartBeatCallback) {
|
|
||||||
((HeartBeatCallback) haController).onFailed(e);
|
|
||||||
}
|
|
||||||
reconnect = true;
|
|
||||||
logger.warn("connect failed by ", e);
|
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
if (haController != null && haController instanceof HeartBeatCallback) {
|
if (haController != null && haController instanceof HeartBeatCallback) {
|
||||||
((HeartBeatCallback) haController).onFailed(e);
|
((HeartBeatCallback) haController).onFailed(e);
|
||||||
|
|||||||
@@ -150,11 +150,7 @@ public class DirectLogFetcher extends LogFetcher {
|
|||||||
close(); /* Do cleanup */
|
close(); /* Do cleanup */
|
||||||
logger.error("Socket timeout expired, closing connection", e);
|
logger.error("Socket timeout expired, closing connection", e);
|
||||||
throw e;
|
throw e;
|
||||||
} catch (InterruptedIOException e) {
|
} catch (InterruptedIOException | ClosedByInterruptException e) {
|
||||||
close(); /* Do cleanup */
|
|
||||||
logger.info("I/O interrupted while reading from client socket", e);
|
|
||||||
throw e;
|
|
||||||
} catch (ClosedByInterruptException e) {
|
|
||||||
close(); /* Do cleanup */
|
close(); /* Do cleanup */
|
||||||
logger.info("I/O interrupted while reading from client socket", e);
|
logger.info("I/O interrupted while reading from client socket", e);
|
||||||
throw e;
|
throw e;
|
||||||
|
|||||||
@@ -230,7 +230,7 @@ public class BinLogFileQueue {
|
|||||||
}
|
}
|
||||||
}, null));
|
}, null));
|
||||||
// 排一下序列
|
// 排一下序列
|
||||||
Collections.sort(files, Comparator.comparing(File::getName));
|
files.sort(Comparator.comparing(File::getName));
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,8 +56,7 @@ public class HttpHelper {
|
|||||||
HttpGet httpGet = new HttpGet(uri);
|
HttpGet httpGet = new HttpGet(uri);
|
||||||
HttpClientContext context = HttpClientContext.create();
|
HttpClientContext context = HttpClientContext.create();
|
||||||
context.setRequestConfig(config);
|
context.setRequestConfig(config);
|
||||||
CloseableHttpResponse response = httpclient.execute(httpGet, context);
|
try (CloseableHttpResponse response = httpclient.execute(httpGet, context)) {
|
||||||
try {
|
|
||||||
int statusCode = response.getStatusLine().getStatusCode();
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
long end = System.currentTimeMillis();
|
long end = System.currentTimeMillis();
|
||||||
long cost = end - start;
|
long cost = end - start;
|
||||||
@@ -72,7 +71,6 @@ public class HttpHelper {
|
|||||||
+ ", error msg=" + errorMsg);
|
+ ", error msg=" + errorMsg);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
response.close();
|
|
||||||
httpGet.releaseConnection();
|
httpGet.releaseConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public class PeriodMixedLogPositionManager extends AbstractLogPositionManager {
|
|||||||
|
|
||||||
// 启动定时工作任务
|
// 启动定时工作任务
|
||||||
executorService.scheduleAtFixedRate(() -> {
|
executorService.scheduleAtFixedRate(() -> {
|
||||||
List<String> tasks = new ArrayList<String>(persistTasks);
|
List<String> tasks = new ArrayList<>(persistTasks);
|
||||||
for (String destination : tasks) {
|
for (String destination : tasks) {
|
||||||
try {
|
try {
|
||||||
// 定时将内存中的最新值刷到zookeeper中,多次变更只刷一次
|
// 定时将内存中的最新值刷到zookeeper中,多次变更只刷一次
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ public class MysqlBinlogEventPerformanceTest {
|
|||||||
protected static Charset charset = Charset.forName("utf-8");
|
protected static Charset charset = Charset.forName("utf-8");
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
DirectLogFetcher fetcher = new DirectLogFetcher();
|
try (DirectLogFetcher fetcher = new DirectLogFetcher()) {
|
||||||
try {
|
|
||||||
MysqlConnector connector = new MysqlConnector(new InetSocketAddress("127.0.0.1", 3306), "root", "hello");
|
MysqlConnector connector = new MysqlConnector(new InetSocketAddress("127.0.0.1", 3306), "root", "hello");
|
||||||
connector.connect();
|
connector.connect();
|
||||||
updateSettings(connector);
|
updateSettings(connector);
|
||||||
@@ -49,11 +48,6 @@ public class MysqlBinlogEventPerformanceTest {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
fetcher.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,8 +34,7 @@ public class MysqlBinlogParsePerformanceTest {
|
|||||||
protected static Charset charset = Charset.forName("utf-8");
|
protected static Charset charset = Charset.forName("utf-8");
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
DirectLogFetcher fetcher = new DirectLogFetcher();
|
try (DirectLogFetcher fetcher = new DirectLogFetcher()) {
|
||||||
try {
|
|
||||||
MysqlConnector connector = new MysqlConnector(new InetSocketAddress("127.0.0.1", 3306), "root", "hello");
|
MysqlConnector connector = new MysqlConnector(new InetSocketAddress("127.0.0.1", 3306), "root", "hello");
|
||||||
connector.connect();
|
connector.connect();
|
||||||
updateSettings(connector);
|
updateSettings(connector);
|
||||||
@@ -45,9 +44,7 @@ public class MysqlBinlogParsePerformanceTest {
|
|||||||
Thread thread = new Thread(() -> {
|
Thread thread = new Thread(() -> {
|
||||||
try {
|
try {
|
||||||
consumer(buffer);
|
consumer(buffer);
|
||||||
} catch (IOException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -59,11 +56,6 @@ public class MysqlBinlogParsePerformanceTest {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
fetcher.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,24 +18,24 @@ public class Message implements Serializable {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1234034768477580009L;
|
private static final long serialVersionUID = 1234034768477580009L;
|
||||||
private long id;
|
private long id;
|
||||||
private List<CanalEntry.Entry> entries = new ArrayList<CanalEntry.Entry>();
|
private List<CanalEntry.Entry> entries = new ArrayList<>();
|
||||||
// row data for performance, see:
|
// row data for performance, see:
|
||||||
// https://github.com/alibaba/canal/issues/726
|
// https://github.com/alibaba/canal/issues/726
|
||||||
private boolean raw = true;
|
private boolean raw = true;
|
||||||
private List<ByteString> rawEntries = new ArrayList<ByteString>();
|
private List<ByteString> rawEntries = new ArrayList<>();
|
||||||
|
|
||||||
public Message(long id, List<Entry> entries){
|
public Message(long id, List<Entry> entries){
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.entries = entries == null ? new ArrayList<Entry>() : entries;
|
this.entries = entries == null ? new ArrayList<>() : entries;
|
||||||
this.raw = false;
|
this.raw = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message(long id, boolean raw, List entries){
|
public Message(long id, boolean raw, List entries){
|
||||||
this.id = id;
|
this.id = id;
|
||||||
if (raw) {
|
if (raw) {
|
||||||
this.rawEntries = entries == null ? new ArrayList<ByteString>() : entries;
|
this.rawEntries = entries == null ? new ArrayList<>() : entries;
|
||||||
} else {
|
} else {
|
||||||
this.entries = entries == null ? new ArrayList<Entry>() : entries;
|
this.entries = entries == null ? new ArrayList<>() : entries;
|
||||||
}
|
}
|
||||||
this.raw = raw;
|
this.raw = raw;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,8 +84,8 @@ public class SecurityUtil {
|
|||||||
*/
|
*/
|
||||||
public static String byte2HexStr(byte[] b) {
|
public static String byte2HexStr(byte[] b) {
|
||||||
StringBuilder hs = new StringBuilder();
|
StringBuilder hs = new StringBuilder();
|
||||||
for (int n = 0; n < b.length; n++) {
|
for (byte value : b) {
|
||||||
String hex = (Integer.toHexString(b[n] & 0XFF));
|
String hex = (Integer.toHexString(value & 0XFF));
|
||||||
if (hex.length() == 1) {
|
if (hex.length() == 1) {
|
||||||
hs.append("0" + hex);
|
hs.append("0" + hex);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -161,8 +161,8 @@ public class SessionHandler extends SimpleChannelHandler {
|
|||||||
messageSize += com.google.protobuf.CodedOutputStream.computeInt64Size(1, message.getId());
|
messageSize += com.google.protobuf.CodedOutputStream.computeInt64Size(1, message.getId());
|
||||||
|
|
||||||
int dataSize = 0;
|
int dataSize = 0;
|
||||||
for (int i = 0; i < rowEntries.size(); i++) {
|
for (ByteString rowEntry : rowEntries) {
|
||||||
dataSize += com.google.protobuf.CodedOutputStream.computeBytesSizeNoTag(rowEntries.get(i));
|
dataSize += CodedOutputStream.computeBytesSizeNoTag(rowEntry);
|
||||||
}
|
}
|
||||||
messageSize += dataSize;
|
messageSize += dataSize;
|
||||||
messageSize += 1 * rowEntries.size();
|
messageSize += 1 * rowEntries.size();
|
||||||
@@ -194,8 +194,8 @@ public class SessionHandler extends SimpleChannelHandler {
|
|||||||
output.writeRawVarint32(messageSize);
|
output.writeRawVarint32(messageSize);
|
||||||
// message
|
// message
|
||||||
output.writeInt64(1, message.getId());
|
output.writeInt64(1, message.getId());
|
||||||
for (int i = 0; i < rowEntries.size(); i++) {
|
for (ByteString rowEntry : rowEntries) {
|
||||||
output.writeBytes(2, rowEntries.get(i));
|
output.writeBytes(2, rowEntry);
|
||||||
}
|
}
|
||||||
output.checkNoSpaceLeft();
|
output.checkNoSpaceLeft();
|
||||||
NettyUtils.write(ctx.getChannel(), body, new ChannelFutureAggregator(get.getDestination(),
|
NettyUtils.write(ctx.getChannel(), body, new ChannelFutureAggregator(get.getDestination(),
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ public class ProtocolTest {
|
|||||||
messageSize += com.google.protobuf.CodedOutputStream.computeInt64Size(1, message.getId());
|
messageSize += com.google.protobuf.CodedOutputStream.computeInt64Size(1, message.getId());
|
||||||
|
|
||||||
int dataSize = 0;
|
int dataSize = 0;
|
||||||
for (int i = 0; i < rowEntries.size(); i++) {
|
for (ByteString rowEntry : rowEntries) {
|
||||||
dataSize += com.google.protobuf.CodedOutputStream.computeBytesSizeNoTag(rowEntries.get(i));
|
dataSize += CodedOutputStream.computeBytesSizeNoTag(rowEntry);
|
||||||
}
|
}
|
||||||
messageSize += dataSize;
|
messageSize += dataSize;
|
||||||
messageSize += 1 * rowEntries.size();
|
messageSize += 1 * rowEntries.size();
|
||||||
@@ -82,8 +82,8 @@ public class ProtocolTest {
|
|||||||
output.writeRawVarint32(messageSize);
|
output.writeRawVarint32(messageSize);
|
||||||
// message
|
// message
|
||||||
output.writeInt64(1, message.getId());
|
output.writeInt64(1, message.getId());
|
||||||
for (int i = 0; i < rowEntries.size(); i++) {
|
for (ByteString rowEntry : rowEntries) {
|
||||||
output.writeBytes(2, rowEntries.get(i));
|
output.writeBytes(2, rowEntry);
|
||||||
}
|
}
|
||||||
output.checkNoSpaceLeft();
|
output.checkNoSpaceLeft();
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class Events<EVENT> implements Serializable {
|
|||||||
private static final long serialVersionUID = -7337454954300706044L;
|
private static final long serialVersionUID = -7337454954300706044L;
|
||||||
|
|
||||||
private PositionRange positionRange = new PositionRange();
|
private PositionRange positionRange = new PositionRange();
|
||||||
private List<EVENT> events = new ArrayList<EVENT>();
|
private List<EVENT> events = new ArrayList<>();
|
||||||
|
|
||||||
public List<EVENT> getEvents() {
|
public List<EVENT> getEvents() {
|
||||||
return events;
|
return events;
|
||||||
|
|||||||
@@ -81,9 +81,7 @@ public class MemoryEventStoreMemBatchTest extends MemoryEventStoreBase {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
result = eventStore.put(buildEvent("1", 1L, 1L + bufferSize), 1000L, TimeUnit.MILLISECONDS);
|
result = eventStore.put(buildEvent("1", 1L, 1L + bufferSize), 1000L, TimeUnit.MILLISECONDS);
|
||||||
} catch (CanalStoreException e) {
|
} catch (CanalStoreException | InterruptedException e) {
|
||||||
Assert.fail(e.getMessage());
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Assert.fail(e.getMessage());
|
Assert.fail(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,8 +160,7 @@ public class MemoryEventStoreMemBatchTest extends MemoryEventStoreBase {
|
|||||||
Assert.assertTrue(entrys.getEvents().size() == batchSize);
|
Assert.assertTrue(entrys.getEvents().size() == batchSize);
|
||||||
Assert.assertEquals(position, entrys.getPositionRange().getStart());
|
Assert.assertEquals(position, entrys.getPositionRange().getStart());
|
||||||
Assert.assertEquals(position, entrys.getPositionRange().getEnd());
|
Assert.assertEquals(position, entrys.getPositionRange().getEnd());
|
||||||
} catch (CanalStoreException e) {
|
} catch (CanalStoreException | InterruptedException e) {
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ExecutorService executor = Executors.newFixedThreadPool(1);
|
ExecutorService executor = Executors.newFixedThreadPool(1);
|
||||||
|
|||||||
@@ -109,8 +109,7 @@ public class MemoryEventStoreMultiThreadTest extends MemoryEventStoreBase {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
eventStore.put(event);
|
eventStore.put(event);
|
||||||
} catch (CanalStoreException e) {
|
} catch (CanalStoreException | InterruptedException e) {
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,9 +64,7 @@ public class MemoryEventStorePutAndGetTest extends MemoryEventStoreBase {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
result = eventStore.put(buildEvent("1", 1L, 1L + bufferSize), 1000L, TimeUnit.MILLISECONDS);
|
result = eventStore.put(buildEvent("1", 1L, 1L + bufferSize), 1000L, TimeUnit.MILLISECONDS);
|
||||||
} catch (CanalStoreException e) {
|
} catch (CanalStoreException | InterruptedException e) {
|
||||||
Assert.fail(e.getMessage());
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
Assert.fail(e.getMessage());
|
Assert.fail(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,8 +138,7 @@ public class MemoryEventStorePutAndGetTest extends MemoryEventStoreBase {
|
|||||||
Assert.assertTrue(entrys.getEvents().size() == batchSize);
|
Assert.assertTrue(entrys.getEvents().size() == batchSize);
|
||||||
Assert.assertEquals(position, entrys.getPositionRange().getStart());
|
Assert.assertEquals(position, entrys.getPositionRange().getStart());
|
||||||
Assert.assertEquals(position, entrys.getPositionRange().getEnd());
|
Assert.assertEquals(position, entrys.getPositionRange().getEnd());
|
||||||
} catch (CanalStoreException e) {
|
} catch (CanalStoreException | InterruptedException e) {
|
||||||
} catch (InterruptedException e) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ExecutorService executor = Executors.newFixedThreadPool(1);
|
ExecutorService executor = Executors.newFixedThreadPool(1);
|
||||||
|
|||||||
Reference in New Issue
Block a user