use of com.linkedin.databus.bootstrap.api.BootstrapEventCallback in project databus by linkedin.
the class TestBootstrapProcessor method testCkptWriteLogic.
@Test
public void testCkptWriteLogic() throws Exception {
BootstrapProcessor bp = new BootstrapProcessor();
long processedRowCount = 1;
// order of args : processedRowCount, isLimitExceeded, isDropped, isError
BootstrapEventProcessResult result_ok = new BootstrapEventProcessResult(processedRowCount, false, false, false);
BootstrapEventProcessResult result_zero_ok = new BootstrapEventProcessResult(0, false, false, false);
BootstrapEventProcessResult result_err = new BootstrapEventProcessResult(processedRowCount, false, false, true);
BootstrapEventProcessResult result_zero_ile = new BootstrapEventProcessResult(0, true, false, false);
Checkpoint ckpt_ss = new Checkpoint("{\"consumption_mode\":\"BOOTSTRAP_SNAPSHOT\", \"bootstrap_since_scn\":0," + "\"bootstrap_start_scn\":1000,\"bootstrap_target_scn\":2000,\"bootstrap_catchup_source_index\":0," + "\"bootstrap_snapshot_source_index\":1}");
ckpt_ss.assertCheckpoint();
long numRowsReadFromDb = 1;
BootstrapEventCallback callback1 = EasyMock.createMock(BootstrapEventCallback.class);
EasyMock.replay(callback1);
BootstrapEventCallback callback2 = EasyMock.createMock(BootstrapEventCallback.class);
callback2.onCheckpointEvent(ckpt_ss, null);
EasyMock.replay(callback2);
BootstrapEventCallback callback3 = EasyMock.createMock(BootstrapEventCallback.class);
callback3.onCheckpointEvent(ckpt_ss, null);
EasyMock.replay(callback3);
// No checkpoint when result is null
bp.writeCkptIfAppropriate(null, callback1, numRowsReadFromDb, ckpt_ss, "test");
// No checkpoint when result is error
bp.writeCkptIfAppropriate(result_err, callback1, numRowsReadFromDb, ckpt_ss, "test");
// numRowsWritten == 1, must checkpoint
bp.writeCkptIfAppropriate(result_ok, callback2, numRowsReadFromDb, ckpt_ss, "test");
// numRowsWritten == 0, must checkpoint as numRowsReadFromDb > 0
bp.writeCkptIfAppropriate(result_zero_ok, callback3, numRowsReadFromDb, ckpt_ss, "test");
// numRowsWritten == 0, must have checkpointed as numRowsReadFromDb > 0. However result is client buffer exceeded
// So .. sorry to disappoint but no checkpoint as we want that pending_event_header
bp.writeCkptIfAppropriate(result_zero_ile, callback1, numRowsReadFromDb, ckpt_ss, "test");
// result != null, numRowsWritten == 0, numRowsReadFromDb == 0. We expect a RuntimeException here
try {
bp.writeCkptIfAppropriate(result_zero_ok, callback2, 0, ckpt_ss, "test");
Assert.fail();
} catch (RuntimeException e) {
}
}
Aggregations