use of com.alibaba.otter.canal.parse.CanalHASwitchable in project canal by alibaba.
the class BaseCanalServerWithEmbededTest method testSwitch.
// @Test
public void testSwitch() {
int maxEmptyCount = 10;
int emptyCount = 0;
int totalCount = 0;
int thresold = 50;
int batchSize = 11;
server.subscribe(clientIdentity);
while (emptyCount < maxEmptyCount) {
Message message = server.get(clientIdentity, batchSize);
if (CollectionUtils.isEmpty(message.getEntries())) {
emptyCount++;
try {
Thread.sleep(emptyCount * 300L);
} catch (InterruptedException e) {
Assert.fail();
}
System.out.println("empty count : " + emptyCount);
} else {
emptyCount = 0;
totalCount += message.getEntries().size();
if ((totalCount + 1) % 100 >= thresold && (totalCount + 1) % 100 <= thresold + batchSize) {
CanalEventParser eventParser = server.getCanalInstances().get(DESTINATION).getEventParser();
if (eventParser instanceof CanalHASwitchable) {
// 执行切换
((CanalHASwitchable) eventParser).doSwitch();
try {
// 等待parser启动
Thread.sleep(5 * 1000);
} catch (InterruptedException e) {
Assert.fail();
}
}
}
}
}
System.out.println("!!!!!! testGet totalCount : " + totalCount);
server.unsubscribe(clientIdentity);
}
Aggregations