Jiabao-Sun commented on code in PR #1: URL: https://github.com/apache/flink-connector-mongodb/pull/1#discussion_r1028782035
########## flink-connector-mongodb/src/test/java/org/apache/flink/connector/mongodb/source/splitter/MongoShardedSplitterTest.java: ########## @@ -0,0 +1,145 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.connector.mongodb.source.splitter; + +import org.apache.flink.connector.mongodb.common.utils.MongoUtils; +import org.apache.flink.connector.mongodb.source.config.MongoReadOptions; +import org.apache.flink.connector.mongodb.source.enumerator.splitter.MongoShardedSplitter; +import org.apache.flink.connector.mongodb.source.enumerator.splitter.MongoSplitContext; +import org.apache.flink.connector.mongodb.source.split.MongoScanSourceSplit; +import org.apache.flink.util.TestLoggerExtension; + +import com.mongodb.MongoNamespace; +import com.mongodb.client.MongoClient; +import org.bson.BsonBinary; +import org.bson.BsonBoolean; +import org.bson.BsonDocument; +import org.bson.BsonInt32; +import org.bson.BsonInt64; +import org.bson.BsonObjectId; +import org.bson.BsonString; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.MockedStatic; +import org.mockito.MockitoAnnotations; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.UUID; + +import static org.apache.flink.connector.mongodb.common.utils.MongoConstants.AVG_OBJ_SIZE_FIELD; +import static org.apache.flink.connector.mongodb.common.utils.MongoConstants.COUNT_FIELD; +import static org.apache.flink.connector.mongodb.common.utils.MongoConstants.DROPPED_FIELD; +import static org.apache.flink.connector.mongodb.common.utils.MongoConstants.ID_FIELD; +import static org.apache.flink.connector.mongodb.common.utils.MongoConstants.ID_HINT; +import static org.apache.flink.connector.mongodb.common.utils.MongoConstants.KEY_FIELD; +import static org.apache.flink.connector.mongodb.common.utils.MongoConstants.MAX_FIELD; +import static org.apache.flink.connector.mongodb.common.utils.MongoConstants.MIN_FIELD; +import static org.apache.flink.connector.mongodb.common.utils.MongoConstants.SHARD_FIELD; +import static org.apache.flink.connector.mongodb.common.utils.MongoConstants.SIZE_FIELD; +import static org.apache.flink.connector.mongodb.common.utils.MongoConstants.UUID_FIELD; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mockStatic; + +/** Unit tests for {@link MongoShardedSplitter}. */ +@ExtendWith(TestLoggerExtension.class) +public class MongoShardedSplitterTest { + + @Mock private MongoClient mongoClient; + + @BeforeEach + public void setUp() { + MockitoAnnotations.initMocks(this); Review Comment: Hi @zentol, The [MongoDB test container](https://www.testcontainers.org/modules/databases/mongodb/) only supports [replica set](https://www.mongodb.com/docs/manual/replication/#replication-in-mongodb) mode, while the sharded split strategy requires MongoDB to run in [sharded cluster](https://www.mongodb.com/docs/manual/sharding/#sharded-cluster) mode. So here mocks some result of [config.collections](https://www.mongodb.com/docs/manual/reference/config-database/#mongodb-data-config.collections) and [config.chunks](https://www.mongodb.com/docs/manual/reference/config-database/#mongodb-data-config.chunks) to simulate the scenario of sharded cluster. Also, I'm a bit confused about these functional wrappers, using them we might still need to mock their results. Is there something wrong with my understanding? BTW, We can also do some extra work to start 3 mongo containers and have them run in sharded mode. Do we need to take this approach? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
