use of org.apache.connect.mongo.replicator.event.ReplicationEvent in project rocketmq-externals by apache.
the class ReplicatorTask method executorCursor.
private void executorCursor(MongoCursor<Document> cursor) {
while (cursor.hasNext() && !replicaSet.isPause()) {
Document document = cursor.next();
ReplicationEvent event = Document2EventConverter.convert(document, replicaSetConfig.getReplicaSetName());
if (replicaSetsContext.filterEvent(event)) {
replicaSetsContext.publishEvent(event, replicaSetConfig);
}
}
}
use of org.apache.connect.mongo.replicator.event.ReplicationEvent in project rocketmq-externals by apache.
the class FilterTest method testFilterEvent.
@Test
public void testFilterEvent() {
OperationFilter operationFilter = new OperationFilter(sourceTaskConfig);
ReplicationEvent replicationEvent = new ReplicationEvent();
replicationEvent.setOperationType(OperationType.NOOP);
Assert.assertFalse(operationFilter.filterEvent(replicationEvent));
replicationEvent.setOperationType(OperationType.DB_COMMAND);
Assert.assertTrue(operationFilter.filterEvent(replicationEvent));
}
use of org.apache.connect.mongo.replicator.event.ReplicationEvent in project rocketmq-externals by apache.
the class MongoSourceConnectorTest method testPoll.
@Test
public void testPoll() throws Exception {
LinkedBlockingQueue<SourceDataEntry> entries = new LinkedBlockingQueue<>();
ReplicaSetsContext context = new ReplicaSetsContext(sourceTaskConfig);
Field dataEntryQueue = ReplicaSetsContext.class.getDeclaredField("dataEntryQueue");
dataEntryQueue.setAccessible(true);
dataEntryQueue.set(context, entries);
ReplicationEvent event = new ReplicationEvent();
event.setOperationType(OperationType.INSERT);
event.setNamespace("test.person");
event.setTimestamp(new BsonTimestamp(1565609506, 1));
event.setDocument(new Document("testKey", "testValue"));
event.setH(324243242L);
event.setEventData(Optional.ofNullable(new Document("testEventKey", "testEventValue")));
event.setObjectId(Optional.empty());
context.publishEvent(event, new ReplicaSetConfig("", "testReplicaName", "localhost:27027"));
List<SourceDataEntry> sourceDataEntries = (List<SourceDataEntry>) context.poll();
Assert.assertTrue(sourceDataEntries.size() == 1);
SourceDataEntry sourceDataEntry = sourceDataEntries.get(0);
Assert.assertEquals("test-person", sourceDataEntry.getQueueName());
ByteBuffer sourcePartition = sourceDataEntry.getSourcePartition();
Assert.assertEquals("testReplicaName", new String(sourcePartition.array()));
ByteBuffer sourcePosition = sourceDataEntry.getSourcePosition();
Position position = JSONObject.parseObject(new String(sourcePosition.array()), Position.class);
Assert.assertEquals(position.getTimeStamp(), 1565609506);
Assert.assertEquals(position.getInc(), 1);
Assert.assertEquals(position.isInitSync(), false);
EntryType entryType = sourceDataEntry.getEntryType();
Assert.assertEquals(EntryType.CREATE, entryType);
String queueName = sourceDataEntry.getQueueName();
Assert.assertEquals("test-person", queueName);
Schema schema = sourceDataEntry.getSchema();
Assert.assertTrue(schema.getFields().size() == 6);
Object[] payload = sourceDataEntry.getPayload();
Assert.assertTrue(payload.length == 6);
}
use of org.apache.connect.mongo.replicator.event.ReplicationEvent in project rocketmq-externals by apache.
the class MongoTest method testConvertEvent.
@Test
public void testConvertEvent() {
Document oplog = new Document();
BsonTimestamp timestamp = new BsonTimestamp(1565074665, 10);
oplog.put(Constants.TIMESTAMP, timestamp);
oplog.put(Constants.NAMESPACE, "test.person");
oplog.put(Constants.HASH, 11111L);
oplog.put(Constants.OPERATION_TYPE, "i");
Document document = new Document();
document.put("test", "test");
oplog.put(Constants.OPERATION, document);
ReplicationEvent event = Document2EventConverter.convert(oplog, "testR");
Assert.assertEquals(timestamp, event.getTimestamp());
Assert.assertEquals("test.person", event.getNamespace());
Assert.assertTrue(11111L == event.getH());
Assert.assertEquals(OperationType.INSERT, event.getOperationType());
Assert.assertEquals(EntryType.CREATE, event.getEntryType());
Assert.assertEquals(document, event.getEventData().get());
Assert.assertEquals("testR", event.getReplicaSetName());
}
Aggregations