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);
}
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());
}
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());
}
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());
}
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());
}
Aggregations