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,6 +46,7 @@ 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) {
if (entry.getEntryType() != EntryType.HEARTBEAT) {
entryCount.incrementAndGet(); entryCount.incrementAndGet();
String logfilename = entry.getHeader().getLogfileName(); String logfilename = entry.getHeader().getLogfileName();
long logfileoffset = entry.getHeader().getLogfileOffset(); long logfileoffset = entry.getHeader().getLogfileOffset();
@@ -52,13 +54,15 @@ public class MysqlEventParserTest {
entryPosition.setJournalName(logfilename); entryPosition.setJournalName(logfilename);
entryPosition.setPosition(logfileoffset); entryPosition.setPosition(logfileoffset);
entryPosition.setTimestamp(executeTime); entryPosition.setTimestamp(executeTime);
break; break;
} }
}
if (entryCount.get() > 0) {
controller.stop(); controller.stop();
timeoutChecker.stop(); timeoutChecker.stop();
timeoutChecker.touch(); 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,6 +113,7 @@ 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) {
if (entry.getEntryType() != EntryType.HEARTBEAT) {
entryCount.incrementAndGet(); entryCount.incrementAndGet();
String logfilename = entry.getHeader().getLogfileName(); String logfilename = entry.getHeader().getLogfileName();
@@ -118,13 +123,15 @@ public class MysqlEventParserTest {
entryPosition.setJournalName(logfilename); entryPosition.setJournalName(logfilename);
entryPosition.setPosition(logfileoffset); entryPosition.setPosition(logfileoffset);
entryPosition.setTimestamp(executeTime); entryPosition.setTimestamp(executeTime);
break; break;
} }
}
if (entryCount.get() > 0) {
controller.stop(); controller.stop();
timeoutChecker.stop(); timeoutChecker.stop();
timeoutChecker.touch(); timeoutChecker.touch();
}
return true; return true;
} }
}); });
@@ -174,6 +181,8 @@ 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) {
if (entry.getEntryType() != EntryType.HEARTBEAT) {
entryCount.incrementAndGet(); entryCount.incrementAndGet();
String logfilename = entry.getHeader().getLogfileName(); String logfilename = entry.getHeader().getLogfileName();
@@ -185,10 +194,13 @@ public class MysqlEventParserTest {
entryPosition.setTimestamp(executeTime); entryPosition.setTimestamp(executeTime);
break; break;
} }
}
if (entryCount.get() > 0) {
controller.stop(); controller.stop();
timeoutChecker.stop(); timeoutChecker.stop();
timeoutChecker.touch(); timeoutChecker.touch();
}
return true; return true;
} }
}); });
@@ -244,9 +256,11 @@ 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) {
if (entry.getEntryType() != EntryType.HEARTBEAT) {
entryCount.incrementAndGet(); entryCount.incrementAndGet();
// String logfilename = entry.getHeader().getLogfileName(); // String logfilename =
// entry.getHeader().getLogfileName();
// long logfileoffset = // long logfileoffset =
// entry.getHeader().getLogfileOffset(); // entry.getHeader().getLogfileOffset();
long executeTime = entry.getHeader().getExecuteTime(); long executeTime = entry.getHeader().getExecuteTime();
@@ -256,10 +270,13 @@ public class MysqlEventParserTest {
entryPosition.setTimestamp(executeTime); entryPosition.setTimestamp(executeTime);
break; break;
} }
}
if (entryCount.get() > 0) {
controller.stop(); controller.stop();
timeoutChecker.stop(); timeoutChecker.stop();
timeoutChecker.touch(); timeoutChecker.touch();
}
return true; return true;
} }
}); });