forked from opensearch-project/data-prepper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Haidong <[email protected]>
- Loading branch information
Haidong
committed
Nov 6, 2023
1 parent
04a8ec2
commit 3f7d26f
Showing
4 changed files
with
144 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...va/org/opensearch/dataprepper/plugins/kafkaconnect/source/mongoDB/MongoDBServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.kafkaconnect.source.mongoDB; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.MockedConstruction; | ||
import org.mockito.MockedStatic; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.opensearch.dataprepper.metrics.PluginMetrics; | ||
import org.opensearch.dataprepper.model.acknowledgements.AcknowledgementSetManager; | ||
import org.opensearch.dataprepper.model.buffer.Buffer; | ||
import org.opensearch.dataprepper.model.record.Record; | ||
import org.opensearch.dataprepper.model.source.coordinator.SourceCoordinator; | ||
import org.opensearch.dataprepper.plugins.kafkaconnect.configuration.MongoDBConfig; | ||
|
||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.mockConstruction; | ||
import static org.mockito.Mockito.mockStatic; | ||
import static org.mockito.Mockito.verify; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class MongoDBServiceTest { | ||
@Mock | ||
private MongoDBConfig mongoDBConfig; | ||
|
||
@Mock | ||
private Buffer<Record<Object>> buffer; | ||
|
||
@Mock | ||
private AcknowledgementSetManager acknowledgementSetManager; | ||
|
||
@Mock | ||
private ScheduledExecutorService scheduledExecutorService; | ||
|
||
@Mock | ||
private SourceCoordinator<MongoDBSnapshotProgressState> sourceCoordinator; | ||
|
||
@Mock | ||
private MongoDBPartitionCreationSupplier mongoDBPartitionCreationSupplier; | ||
|
||
@Mock | ||
private PluginMetrics pluginMetrics; | ||
|
||
@Test | ||
public void testConstructor() { | ||
createObjectUnderTest(); | ||
verify(sourceCoordinator).initialize(); | ||
} | ||
|
||
@Test | ||
public void testStart() { | ||
createObjectUnderTest().start(); | ||
verify(scheduledExecutorService).schedule(any(Runnable.class), eq(0L), eq(TimeUnit.MILLISECONDS)); | ||
} | ||
|
||
private MongoDBService createObjectUnderTest() { | ||
try (final MockedStatic<Executors> executorsMockedStatic = mockStatic(Executors.class); | ||
final MockedConstruction<MongoDBPartitionCreationSupplier> mockedConstruction = mockConstruction(MongoDBPartitionCreationSupplier.class, (mock, context) -> { | ||
mongoDBPartitionCreationSupplier = mock; | ||
})) { | ||
executorsMockedStatic.when(Executors::newSingleThreadScheduledExecutor).thenReturn(scheduledExecutorService); | ||
return MongoDBService.create(mongoDBConfig, sourceCoordinator, buffer, acknowledgementSetManager, pluginMetrics); | ||
} | ||
} | ||
} |