Search in sources :

Example 1 with MongoSourceTask

use of org.apache.connect.mongo.connector.MongoSourceTask in project rocketmq-externals by apache.

the class MongoSourceTaskTest method testEmptyContextStart.

@Test
public void testEmptyContextStart() throws NoSuchFieldException, IllegalAccessException {
    MongoSourceTask mongoSourceTask = new MongoSourceTask();
    DefaultKeyValue defaultKeyValue = new DefaultKeyValue();
    defaultKeyValue.put("mongoAddr", "test/127.0.0.1:27027");
    defaultKeyValue.put("positionTimeStamp", "11111111");
    defaultKeyValue.put("positionInc", "111");
    defaultKeyValue.put("serverSelectionTimeoutMS", "10");
    defaultKeyValue.put("dataSync", "true");
    Field context = SourceTask.class.getDeclaredField("context");
    context.setAccessible(true);
    context.set(mongoSourceTask, emptyTaskContext());
    mongoSourceTask.start(defaultKeyValue);
    Field replicaSetsContext = MongoSourceTask.class.getDeclaredField("replicaSetsContext");
    replicaSetsContext.setAccessible(true);
    ReplicaSetsContext setsContext = (ReplicaSetsContext) replicaSetsContext.get(mongoSourceTask);
    Field replicaSets = ReplicaSetsContext.class.getDeclaredField("replicaSets");
    replicaSets.setAccessible(true);
    List<ReplicaSet> replicaSetList = (List<ReplicaSet>) replicaSets.get(setsContext);
    Assert.assertTrue(replicaSetList.size() == 1);
    ReplicaSet replicaSet = replicaSetList.get(0);
    Field replicaSetConfig = ReplicaSet.class.getDeclaredField("replicaSetConfig");
    replicaSetConfig.setAccessible(true);
    ReplicaSetConfig replicaSetConfig1 = (ReplicaSetConfig) replicaSetConfig.get(replicaSet);
    Assert.assertTrue(StringUtils.equals(replicaSetConfig1.getReplicaSetName(), "test"));
    Assert.assertTrue(StringUtils.equals(replicaSetConfig1.getHost(), "127.0.0.1:27027"));
    Assert.assertTrue(replicaSetConfig1.getPosition().getTimeStamp() == 11111111);
    Assert.assertTrue(replicaSetConfig1.getPosition().getInc() == 111);
    Assert.assertTrue(replicaSetConfig1.getPosition().isInitSync());
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) Field(java.lang.reflect.Field) ReplicaSetConfig(org.apache.connect.mongo.replicator.ReplicaSetConfig) ReplicaSetsContext(org.apache.connect.mongo.replicator.ReplicaSetsContext) List(java.util.List) ReplicaSet(org.apache.connect.mongo.replicator.ReplicaSet) MongoSourceTask(org.apache.connect.mongo.connector.MongoSourceTask) Test(org.junit.Test)

Example 2 with MongoSourceTask

use of org.apache.connect.mongo.connector.MongoSourceTask in project rocketmq-externals by apache.

the class MongoSourceTaskTest method testContextStart.

@Test
public void testContextStart() throws NoSuchFieldException, IllegalAccessException {
    MongoSourceTask mongoSourceTask = new MongoSourceTask();
    DefaultKeyValue defaultKeyValue = new DefaultKeyValue();
    defaultKeyValue.put("mongoAddr", "test/127.0.0.1:27027");
    defaultKeyValue.put("serverSelectionTimeoutMS", "10");
    Field context = SourceTask.class.getDeclaredField("context");
    context.setAccessible(true);
    context.set(mongoSourceTask, TaskContext());
    mongoSourceTask.start(defaultKeyValue);
    Field replicaSetsContext = MongoSourceTask.class.getDeclaredField("replicaSetsContext");
    replicaSetsContext.setAccessible(true);
    ReplicaSetsContext setsContext = (ReplicaSetsContext) replicaSetsContext.get(mongoSourceTask);
    Field replicaSets = ReplicaSetsContext.class.getDeclaredField("replicaSets");
    replicaSets.setAccessible(true);
    List<ReplicaSet> replicaSetList = (List<ReplicaSet>) replicaSets.get(setsContext);
    Assert.assertTrue(replicaSetList.size() == 1);
    ReplicaSet replicaSet = replicaSetList.get(0);
    Field replicaSetConfig = ReplicaSet.class.getDeclaredField("replicaSetConfig");
    replicaSetConfig.setAccessible(true);
    ReplicaSetConfig replicaSetConfig1 = (ReplicaSetConfig) replicaSetConfig.get(replicaSet);
    Assert.assertTrue(StringUtils.equals(replicaSetConfig1.getReplicaSetName(), "test"));
    Assert.assertTrue(StringUtils.equals(replicaSetConfig1.getHost(), "127.0.0.1:27027"));
    Assert.assertTrue(replicaSetConfig1.getPosition().getTimeStamp() == 22222222);
    Assert.assertTrue(replicaSetConfig1.getPosition().getInc() == 222);
    Assert.assertTrue(!replicaSetConfig1.getPosition().isInitSync());
}
Also used : DefaultKeyValue(io.openmessaging.internal.DefaultKeyValue) Field(java.lang.reflect.Field) ReplicaSetConfig(org.apache.connect.mongo.replicator.ReplicaSetConfig) ReplicaSetsContext(org.apache.connect.mongo.replicator.ReplicaSetsContext) List(java.util.List) ReplicaSet(org.apache.connect.mongo.replicator.ReplicaSet) MongoSourceTask(org.apache.connect.mongo.connector.MongoSourceTask) Test(org.junit.Test)

Aggregations

DefaultKeyValue (io.openmessaging.internal.DefaultKeyValue)2 Field (java.lang.reflect.Field)2 List (java.util.List)2 MongoSourceTask (org.apache.connect.mongo.connector.MongoSourceTask)2 ReplicaSet (org.apache.connect.mongo.replicator.ReplicaSet)2 ReplicaSetConfig (org.apache.connect.mongo.replicator.ReplicaSetConfig)2 ReplicaSetsContext (org.apache.connect.mongo.replicator.ReplicaSetsContext)2 Test (org.junit.Test)2