Search in sources :

Example 6 with ReplicaSetConfig

use of org.apache.connect.mongo.replicator.ReplicaSetConfig in project rocketmq-externals by apache.

the class MongoFactoryTest method before.

@Before
public void before() {
    this.replicaSetConfig = new ReplicaSetConfig("shardName1", "rep1", "127.0.0.1:27027");
    this.sourceTaskConfig = new SourceTaskConfig();
    this.mongoClientFactory = new MongoClientFactory(sourceTaskConfig);
}
Also used : ReplicaSetConfig(org.apache.connect.mongo.replicator.ReplicaSetConfig) MongoClientFactory(org.apache.connect.mongo.replicator.MongoClientFactory) Before(org.junit.Before)

Example 7 with ReplicaSetConfig

use of org.apache.connect.mongo.replicator.ReplicaSetConfig 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)

Example 8 with ReplicaSetConfig

use of org.apache.connect.mongo.replicator.ReplicaSetConfig in project rocketmq-externals by apache.

the class ReplicaSetManagerTest method testCreatReplicaSetsMutiMongoAddr.

@Test
public void testCreatReplicaSetsMutiMongoAddr() {
    ReplicaSetManager replicaSetManager = ReplicaSetManager.create("shardName1=replicaName1/127.0.0.1:27081,127.0.0.1:27082,127.0.0.1:27083;shardName2=replicaName2/127.0.0.1:27281,127.0.0.1:27282,127.0.0.1:27283");
    Map<String, ReplicaSetConfig> replicaSetConfigMap = replicaSetManager.getReplicaConfigByName();
    Assert.assertTrue(replicaSetConfigMap.size() == 2);
    Assert.assertNotNull(replicaSetConfigMap.get("replicaName1"));
    Assert.assertEquals("127.0.0.1:27081,127.0.0.1:27082,127.0.0.1:27083", replicaSetConfigMap.get("replicaName1").getHost());
    Assert.assertEquals("replicaName1", replicaSetConfigMap.get("replicaName1").getReplicaSetName());
    Assert.assertEquals("shardName1", replicaSetConfigMap.get("replicaName1").getShardName());
    Assert.assertNotNull(replicaSetConfigMap.get("replicaName2"));
    Assert.assertEquals("127.0.0.1:27281,127.0.0.1:27282,127.0.0.1:27283", replicaSetConfigMap.get("replicaName2").getHost());
    Assert.assertEquals("replicaName2", replicaSetConfigMap.get("replicaName2").getReplicaSetName());
    Assert.assertEquals("shardName2", replicaSetConfigMap.get("replicaName2").getShardName());
}
Also used : ReplicaSetConfig(org.apache.connect.mongo.replicator.ReplicaSetConfig) ReplicaSetManager(org.apache.connect.mongo.replicator.ReplicaSetManager) Test(org.junit.Test)

Example 9 with ReplicaSetConfig

use of org.apache.connect.mongo.replicator.ReplicaSetConfig in project rocketmq-externals by apache.

the class ReplicaSetManagerTest method testCreatReplicaSetsSpecialReplicaSetName.

@Test
public void testCreatReplicaSetsSpecialReplicaSetName() {
    ReplicaSetManager replicaSetManager = ReplicaSetManager.create("replicaName1/127.0.0.1:27081,127.0.0.1:27082,127.0.0.1:27083");
    Map<String, ReplicaSetConfig> replicaSetConfigMap = replicaSetManager.getReplicaConfigByName();
    Assert.assertTrue(replicaSetConfigMap.size() == 1);
    Assert.assertNotNull(replicaSetConfigMap.get("replicaName1"));
    Assert.assertEquals("127.0.0.1:27081,127.0.0.1:27082,127.0.0.1:27083", replicaSetConfigMap.get("replicaName1").getHost());
    Assert.assertEquals("replicaName1", replicaSetConfigMap.get("replicaName1").getReplicaSetName());
}
Also used : ReplicaSetConfig(org.apache.connect.mongo.replicator.ReplicaSetConfig) ReplicaSetManager(org.apache.connect.mongo.replicator.ReplicaSetManager) Test(org.junit.Test)

Example 10 with ReplicaSetConfig

use of org.apache.connect.mongo.replicator.ReplicaSetConfig in project rocketmq-externals by apache.

the class ReplicaSetManagerTest method testCreatReplicaSetsSpecialShardNameAndReplicaSetName.

@Test
public void testCreatReplicaSetsSpecialShardNameAndReplicaSetName() {
    ReplicaSetManager replicaSetManager = ReplicaSetManager.create("shardName1=replicaName1/127.0.0.1:27081,127.0.0.1:27082,127.0.0.1:27083");
    Map<String, ReplicaSetConfig> replicaSetConfigMap = replicaSetManager.getReplicaConfigByName();
    Assert.assertTrue(replicaSetConfigMap.size() == 1);
    Assert.assertNotNull(replicaSetConfigMap.get("replicaName1"));
    Assert.assertEquals("127.0.0.1:27081,127.0.0.1:27082,127.0.0.1:27083", replicaSetConfigMap.get("replicaName1").getHost());
    Assert.assertEquals("replicaName1", replicaSetConfigMap.get("replicaName1").getReplicaSetName());
    Assert.assertEquals("shardName1", replicaSetConfigMap.get("replicaName1").getShardName());
}
Also used : ReplicaSetConfig(org.apache.connect.mongo.replicator.ReplicaSetConfig) ReplicaSetManager(org.apache.connect.mongo.replicator.ReplicaSetManager) Test(org.junit.Test)

Aggregations

ReplicaSetConfig (org.apache.connect.mongo.replicator.ReplicaSetConfig)10 Test (org.junit.Test)8 ReplicaSetsContext (org.apache.connect.mongo.replicator.ReplicaSetsContext)5 Field (java.lang.reflect.Field)4 List (java.util.List)4 ReplicaSet (org.apache.connect.mongo.replicator.ReplicaSet)4 ReplicaSetManager (org.apache.connect.mongo.replicator.ReplicaSetManager)3 JSONObject (com.alibaba.fastjson.JSONObject)2 EntryType (io.openmessaging.connector.api.data.EntryType)2 Schema (io.openmessaging.connector.api.data.Schema)2 SourceDataEntry (io.openmessaging.connector.api.data.SourceDataEntry)2 DefaultKeyValue (io.openmessaging.internal.DefaultKeyValue)2 ByteBuffer (java.nio.ByteBuffer)2 MongoSourceTask (org.apache.connect.mongo.connector.MongoSourceTask)2 Position (org.apache.connect.mongo.replicator.Position)2 Document (org.bson.Document)2 Before (org.junit.Before)2 ConnectionString (com.mongodb.ConnectionString)1 MongoClient (com.mongodb.client.MongoClient)1 ArrayList (java.util.ArrayList)1