use of org.apache.rocketmq.connect.activemq.Replicator in project rocketmq-externals by apache.
the class ActivemqSourceTaskTest method pollTest.
@Test
public void pollTest() throws Exception {
ActivemqSourceTask task = new ActivemqSourceTask();
TextMessage textMessage = new ActiveMQTextMessage();
textMessage.setText("hello rocketmq");
Replicator replicatorObject = Mockito.mock(Replicator.class);
BlockingQueue<Message> queue = new LinkedBlockingQueue<>();
Mockito.when(replicatorObject.getQueue()).thenReturn(queue);
Field replicator = ActivemqSourceTask.class.getDeclaredField("replicator");
replicator.setAccessible(true);
replicator.set(task, replicatorObject);
Field config = ActivemqSourceTask.class.getDeclaredField("config");
config.setAccessible(true);
config.set(task, new Config());
queue.put(textMessage);
Collection<SourceDataEntry> list = task.poll();
Assert.assertEquals(list.size(), 1);
list = task.poll();
Assert.assertEquals(list.size(), 0);
}
use of org.apache.rocketmq.connect.activemq.Replicator in project rocketmq-externals by apache.
the class ActivemqSourceTask method start.
@Override
public void start(KeyValue props) {
try {
this.config = new Config();
this.config.load(props);
this.sourcePartition = ByteBuffer.wrap(config.getActivemqUrl().getBytes("UTF-8"));
this.replicator = new Replicator(config);
this.replicator.start();
} catch (Exception e) {
log.error("activemq task start failed.", e);
throw new DataConnectException(ErrorCode.START_ERROR_CODE, e.getMessage(), e);
}
}
Aggregations