use of com.alibaba.otter.canal.protocol.exception.CanalClientException in project canal by alibaba.
the class ProtocolTest method testSimple.
@Test(expected = CanalClientException.class)
public void testSimple() throws IOException {
Header.Builder headerBuilder = Header.newBuilder();
headerBuilder.setLogfileName("mysql-bin.000001");
headerBuilder.setLogfileOffset(1024);
headerBuilder.setExecuteTime(1024);
Entry.Builder entryBuilder = Entry.newBuilder();
entryBuilder.setHeader(headerBuilder.build());
entryBuilder.setEntryType(EntryType.ROWDATA);
Entry entry = entryBuilder.build();
Message message = new Message(3, true, Arrays.asList(entry.toByteString()));
byte[] body = buildData(message);
Packet packet = Packet.parseFrom(body);
switch(packet.getType()) {
case MESSAGES:
{
if (!packet.getCompression().equals(Compression.NONE)) {
throw new CanalClientException("compression is not supported in this connector");
}
Messages messages = Messages.parseFrom(packet.getBody());
Message result = new Message(messages.getBatchId());
for (ByteString byteString : messages.getMessagesList()) {
result.addEntry(Entry.parseFrom(byteString));
}
System.out.println(result);
break;
}
default:
{
throw new CanalClientException("unexpected packet type: " + packet.getType());
}
}
}
Aggregations