Search in sources :

Example 6 with EntryType

use of io.openmessaging.connector.api.data.EntryType 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);
}
Also used : SourceDataEntry(io.openmessaging.connector.api.data.SourceDataEntry) Position(org.apache.connect.mongo.replicator.Position) Schema(io.openmessaging.connector.api.data.Schema) ReplicaSetsContext(org.apache.connect.mongo.replicator.ReplicaSetsContext) ReplicationEvent(org.apache.connect.mongo.replicator.event.ReplicationEvent) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Document(org.bson.Document) ByteBuffer(java.nio.ByteBuffer) BsonTimestamp(org.bson.BsonTimestamp) Field(java.lang.reflect.Field) EntryType(io.openmessaging.connector.api.data.EntryType) ReplicaSetConfig(org.apache.connect.mongo.replicator.ReplicaSetConfig) List(java.util.List) JSONObject(com.alibaba.fastjson.JSONObject) Test(org.junit.Test)

Aggregations

EntryType (io.openmessaging.connector.api.data.EntryType)6 Schema (io.openmessaging.connector.api.data.Schema)6 JSONObject (com.alibaba.fastjson.JSONObject)4 SourceDataEntry (io.openmessaging.connector.api.data.SourceDataEntry)4 Field (io.openmessaging.connector.api.data.Field)3 SinkDataEntry (io.openmessaging.connector.api.data.SinkDataEntry)3 ByteBuffer (java.nio.ByteBuffer)3 HashMap (java.util.HashMap)3 Field (java.lang.reflect.Field)2 List (java.util.List)2 Position (org.apache.connect.mongo.replicator.Position)2 ReplicaSetConfig (org.apache.connect.mongo.replicator.ReplicaSetConfig)2 ReplicaSetsContext (org.apache.connect.mongo.replicator.ReplicaSetsContext)2 RocketMQConverter (org.apache.rocketmq.connect.runtime.converter.RocketMQConverter)2 Document (org.bson.Document)2 Test (org.junit.Test)2 ConnectionString (com.mongodb.ConnectionString)1 DataEntryBuilder (io.openmessaging.connector.api.data.DataEntryBuilder)1 ArrayList (java.util.ArrayList)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1