fixed testcase

This commit is contained in:
agapple
2016-09-29 11:43:35 +08:00
parent b23e814c48
commit 5d9d5b1e44

View File

@@ -13,6 +13,7 @@ import com.alibaba.otter.canal.parse.stub.AbstractCanalEventSinkTest;
import com.alibaba.otter.canal.parse.stub.AbstractCanalLogPositionManager; import com.alibaba.otter.canal.parse.stub.AbstractCanalLogPositionManager;
import com.alibaba.otter.canal.parse.support.AuthenticationInfo; import com.alibaba.otter.canal.parse.support.AuthenticationInfo;
import com.alibaba.otter.canal.protocol.CanalEntry.Entry; import com.alibaba.otter.canal.protocol.CanalEntry.Entry;
import com.alibaba.otter.canal.protocol.CanalEntry.EntryType;
import com.alibaba.otter.canal.protocol.position.EntryPosition; import com.alibaba.otter.canal.protocol.position.EntryPosition;
import com.alibaba.otter.canal.protocol.position.LogIdentity; import com.alibaba.otter.canal.protocol.position.LogIdentity;
import com.alibaba.otter.canal.protocol.position.LogPosition; import com.alibaba.otter.canal.protocol.position.LogPosition;
@@ -22,8 +23,8 @@ public class MysqlEventParserTest {
private static final String DETECTING_SQL = "insert into retl.xdual values(1,now()) on duplicate key update x=now()"; private static final String DETECTING_SQL = "insert into retl.xdual values(1,now()) on duplicate key update x=now()";
private static final String MYSQL_ADDRESS = "127.0.0.1"; private static final String MYSQL_ADDRESS = "127.0.0.1";
private static final String USERNAME = "xxxxx"; private static final String USERNAME = "root";
private static final String PASSWORD = "xxxxx"; private static final String PASSWORD = "xxxxxx";
@Test @Test
public void test_position() throws InterruptedException { public void test_position() throws InterruptedException {
@@ -45,20 +46,23 @@ public class MysqlEventParserTest {
public boolean sink(List<Entry> entrys, InetSocketAddress remoteAddress, String destination) public boolean sink(List<Entry> entrys, InetSocketAddress remoteAddress, String destination)
throws CanalSinkException { throws CanalSinkException {
for (Entry entry : entrys) { for (Entry entry : entrys) {
entryCount.incrementAndGet(); if (entry.getEntryType() != EntryType.HEARTBEAT) {
String logfilename = entry.getHeader().getLogfileName(); entryCount.incrementAndGet();
long logfileoffset = entry.getHeader().getLogfileOffset(); String logfilename = entry.getHeader().getLogfileName();
long executeTime = entry.getHeader().getExecuteTime(); long logfileoffset = entry.getHeader().getLogfileOffset();
entryPosition.setJournalName(logfilename); long executeTime = entry.getHeader().getExecuteTime();
entryPosition.setPosition(logfileoffset); entryPosition.setJournalName(logfilename);
entryPosition.setTimestamp(executeTime); entryPosition.setPosition(logfileoffset);
entryPosition.setTimestamp(executeTime);
break; break;
}
} }
controller.stop(); if (entryCount.get() > 0) {
timeoutChecker.stop(); controller.stop();
timeoutChecker.touch(); timeoutChecker.stop();
timeoutChecker.touch();
}
return true; return true;
} }
}); });
@@ -92,14 +96,14 @@ public class MysqlEventParserTest {
@Test @Test
public void test_timestamp() throws InterruptedException { public void test_timestamp() throws InterruptedException {
final TimeoutChecker timeoutChecker = new TimeoutChecker(30 * 1000); final TimeoutChecker timeoutChecker = new TimeoutChecker(3000 * 1000);
final AtomicLong entryCount = new AtomicLong(0); final AtomicLong entryCount = new AtomicLong(0);
final EntryPosition entryPosition = new EntryPosition(); final EntryPosition entryPosition = new EntryPosition();
final MysqlEventParser controller = new MysqlEventParser(); final MysqlEventParser controller = new MysqlEventParser();
final EntryPosition defaultPosition = buildPosition(null, null, 1322803601000L); final EntryPosition defaultPosition = buildPosition(null, null, 1475116855000L);
controller.setSlaveId(3344L); controller.setSlaveId(3344L);
controller.setDetectingEnable(true); controller.setDetectingEnable(false);
controller.setDetectingSQL(DETECTING_SQL); controller.setDetectingSQL(DETECTING_SQL);
controller.setMasterInfo(buildAuthentication()); controller.setMasterInfo(buildAuthentication());
controller.setMasterPosition(defaultPosition); controller.setMasterPosition(defaultPosition);
@@ -109,22 +113,25 @@ public class MysqlEventParserTest {
public boolean sink(List<Entry> entrys, InetSocketAddress remoteAddress, String destination) public boolean sink(List<Entry> entrys, InetSocketAddress remoteAddress, String destination)
throws CanalSinkException { throws CanalSinkException {
for (Entry entry : entrys) { for (Entry entry : entrys) {
entryCount.incrementAndGet(); if (entry.getEntryType() != EntryType.HEARTBEAT) {
entryCount.incrementAndGet();
String logfilename = entry.getHeader().getLogfileName(); String logfilename = entry.getHeader().getLogfileName();
long logfileoffset = entry.getHeader().getLogfileOffset(); long logfileoffset = entry.getHeader().getLogfileOffset();
long executeTime = entry.getHeader().getExecuteTime(); long executeTime = entry.getHeader().getExecuteTime();
entryPosition.setJournalName(logfilename); entryPosition.setJournalName(logfilename);
entryPosition.setPosition(logfileoffset); entryPosition.setPosition(logfileoffset);
entryPosition.setTimestamp(executeTime); entryPosition.setTimestamp(executeTime);
break;
break; }
} }
controller.stop(); if (entryCount.get() > 0) {
timeoutChecker.stop(); controller.stop();
timeoutChecker.touch(); timeoutChecker.stop();
timeoutChecker.touch();
}
return true; return true;
} }
}); });
@@ -174,21 +181,26 @@ public class MysqlEventParserTest {
public boolean sink(List<Entry> entrys, InetSocketAddress remoteAddress, String destination) public boolean sink(List<Entry> entrys, InetSocketAddress remoteAddress, String destination)
throws CanalSinkException { throws CanalSinkException {
for (Entry entry : entrys) { for (Entry entry : entrys) {
entryCount.incrementAndGet(); if (entry.getEntryType() != EntryType.HEARTBEAT) {
String logfilename = entry.getHeader().getLogfileName(); entryCount.incrementAndGet();
long logfileoffset = entry.getHeader().getLogfileOffset();
long executeTime = entry.getHeader().getExecuteTime();
entryPosition.setJournalName(logfilename); String logfilename = entry.getHeader().getLogfileName();
entryPosition.setPosition(logfileoffset); long logfileoffset = entry.getHeader().getLogfileOffset();
entryPosition.setTimestamp(executeTime); long executeTime = entry.getHeader().getExecuteTime();
break;
entryPosition.setJournalName(logfilename);
entryPosition.setPosition(logfileoffset);
entryPosition.setTimestamp(executeTime);
break;
}
} }
controller.stop(); if (entryCount.get() > 0) {
timeoutChecker.stop(); controller.stop();
timeoutChecker.touch(); timeoutChecker.stop();
timeoutChecker.touch();
}
return true; return true;
} }
}); });
@@ -244,22 +256,27 @@ public class MysqlEventParserTest {
public boolean sink(List<Entry> entrys, InetSocketAddress remoteAddress, String destination) public boolean sink(List<Entry> entrys, InetSocketAddress remoteAddress, String destination)
throws CanalSinkException { throws CanalSinkException {
for (Entry entry : entrys) { for (Entry entry : entrys) {
entryCount.incrementAndGet(); if (entry.getEntryType() != EntryType.HEARTBEAT) {
entryCount.incrementAndGet();
// String logfilename = entry.getHeader().getLogfileName(); // String logfilename =
// long logfileoffset = // entry.getHeader().getLogfileName();
// entry.getHeader().getLogfileOffset(); // long logfileoffset =
long executeTime = entry.getHeader().getExecuteTime(); // entry.getHeader().getLogfileOffset();
long executeTime = entry.getHeader().getExecuteTime();
// entryPosition.setJournalName(logfilename); // entryPosition.setJournalName(logfilename);
// entryPosition.setPosition(logfileoffset); // entryPosition.setPosition(logfileoffset);
entryPosition.setTimestamp(executeTime); entryPosition.setTimestamp(executeTime);
break; break;
}
} }
controller.stop(); if (entryCount.get() > 0) {
timeoutChecker.stop(); controller.stop();
timeoutChecker.touch(); timeoutChecker.stop();
timeoutChecker.touch();
}
return true; return true;
} }
}); });