-
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.
- Loading branch information
1 parent
d65b74f
commit 50437fb
Showing
9 changed files
with
816 additions
and
3 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
25 changes: 25 additions & 0 deletions
25
...main/java/com/alpha/mongodb/sharding/core/client/CompositeShardedReactiveMongoClient.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,25 @@ | ||
package com.alpha.mongodb.sharding.core.client; | ||
|
||
import com.alpha.mongodb.sharding.core.configuration.CompositeShardingOptions; | ||
import com.mongodb.reactivestreams.client.MongoClient; | ||
|
||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Composite Sharded Reactive Mongo Client | ||
* | ||
* @author Shashank Sharma | ||
*/ | ||
public class CompositeShardedReactiveMongoClient extends DatabaseShardedReactiveMongoClient { | ||
|
||
public CompositeShardedReactiveMongoClient(Map<String, MongoClient> delegatedMongoClientMap, CompositeShardingOptions shardingOptions) { | ||
super(delegatedMongoClientMap.entrySet().stream().collect( | ||
Collectors.toMap(Map.Entry::getKey, v -> new CollectionShardedReactiveMongoClient( | ||
v.getValue(), shardingOptions.getDelegatedCollectionShardingOptions()))), shardingOptions); | ||
} | ||
|
||
public CompositeShardedReactiveMongoClient(MongoClient delegatedMongoClient, CompositeShardingOptions shardingOptions) { | ||
this(shardingOptions.getDefaultDatabaseHintsSet().stream().collect(Collectors.toMap(h -> h, h -> delegatedMongoClient)), shardingOptions); | ||
} | ||
} |
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
156 changes: 156 additions & 0 deletions
156
...java/com/alpha/mongodb/sharding/core/client/CollectionShardedReactiveMongoClientTest.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,156 @@ | ||
package com.alpha.mongodb.sharding.core.client; | ||
|
||
import com.alpha.mongodb.sharding.core.configuration.CollectionShardingOptions; | ||
import com.alpha.mongodb.sharding.core.database.CollectionShardedReactiveMongoDatabase; | ||
import com.alpha.mongodb.sharding.core.fixture.TestEntity1; | ||
import com.mongodb.ClientSessionOptions; | ||
import com.mongodb.reactivestreams.client.ClientSession; | ||
import com.mongodb.reactivestreams.client.MongoClient; | ||
import com.mongodb.reactivestreams.client.MongoDatabase; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import java.util.ArrayList; | ||
import java.util.stream.IntStream; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.ArgumentMatchers.anyList; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class CollectionShardedReactiveMongoClientTest { | ||
|
||
CollectionShardingOptions collectionShardingOptions = | ||
CollectionShardingOptions.withIntegerStreamHints(IntStream.range(0, 3)); | ||
|
||
MongoClient mockMongoClient = mock(MongoClient.class); | ||
|
||
ClientSessionOptions mockClientSessionOptions = mock(ClientSessionOptions.class); | ||
ClientSession mockClientSession = mock(ClientSession.class); | ||
|
||
@Test | ||
public void testGetDatabase() { | ||
MongoDatabase mockMongoDatabase = mock(MongoDatabase.class); | ||
when(mockMongoClient.getDatabase("TEST")).thenReturn(mockMongoDatabase); | ||
MongoDatabase database = getFixture().getDatabase("TEST"); | ||
verify(mockMongoClient).getDatabase("TEST"); | ||
assertTrue(database instanceof CollectionShardedReactiveMongoDatabase); | ||
} | ||
|
||
@Test | ||
public void testStartSession() { | ||
getFixture().startSession(); | ||
verify(mockMongoClient).startSession(); | ||
} | ||
|
||
@Test | ||
public void testStartSessionWithClientSessionOptions() { | ||
getFixture().startSession(mockClientSessionOptions); | ||
verify(mockMongoClient).startSession(mockClientSessionOptions); | ||
} | ||
|
||
@Test | ||
public void testClose() { | ||
getFixture().close(); | ||
verify(mockMongoClient).close(); | ||
} | ||
|
||
@Test | ||
public void testListDatabaseNames() { | ||
getFixture().listDatabaseNames(); | ||
verify(mockMongoClient).listDatabaseNames(); | ||
} | ||
|
||
@Test | ||
public void testListDatabaseNamesWithClientSession() { | ||
getFixture().listDatabaseNames(mockClientSession); | ||
verify(mockMongoClient).listDatabaseNames(mockClientSession); | ||
} | ||
|
||
@Test | ||
public void testListDatabases() { | ||
getFixture().listDatabases(); | ||
verify(mockMongoClient).listDatabases(); | ||
} | ||
|
||
@Test | ||
public void testListDatabasesWithEntity() { | ||
getFixture().listDatabases(TestEntity1.class); | ||
verify(mockMongoClient).listDatabases(TestEntity1.class); | ||
} | ||
|
||
@Test | ||
public void testListDatabasesWithClientSession() { | ||
getFixture().listDatabases(mockClientSession); | ||
verify(mockMongoClient).listDatabases(mockClientSession); | ||
|
||
} | ||
|
||
@Test | ||
public void testListDatabasesWithClientSessionAndEntityClass() { | ||
getFixture().listDatabases(mockClientSession, TestEntity1.class); | ||
verify(mockMongoClient).listDatabases(mockClientSession, TestEntity1.class); | ||
} | ||
|
||
@Test | ||
public void testWatch() { | ||
getFixture().watch(); | ||
verify(mockMongoClient).watch(); | ||
} | ||
|
||
@Test | ||
public void testWatchWithEntityClass() { | ||
getFixture().watch(TestEntity1.class); | ||
verify(mockMongoClient).watch(TestEntity1.class); | ||
} | ||
|
||
@Test | ||
public void testWatchWithClientSession() { | ||
getFixture().watch(mockClientSession); | ||
verify(mockMongoClient).watch(mockClientSession); | ||
} | ||
|
||
@Test | ||
public void testWatchWithList() { | ||
getFixture().watch(new ArrayList<>()); | ||
verify(mockMongoClient).watch(anyList()); | ||
} | ||
|
||
@Test | ||
public void testWatchWithListAndEntityCLass() { | ||
getFixture().watch(new ArrayList<>(), TestEntity1.class); | ||
verify(mockMongoClient).watch(anyList(), eq(TestEntity1.class)); | ||
} | ||
|
||
@Test | ||
public void testWatchWithClientSessionAndEntityClass() { | ||
getFixture().watch(mockClientSession, TestEntity1.class); | ||
verify(mockMongoClient).watch(mockClientSession, TestEntity1.class); | ||
} | ||
|
||
@Test | ||
public void testWatchWithClientSessionAndList() { | ||
getFixture().watch(mockClientSession, new ArrayList<>()); | ||
verify(mockMongoClient).watch(eq(mockClientSession), anyList()); | ||
} | ||
|
||
@Test | ||
public void testWatchWithCLientSessionAndListAndEntityClass() { | ||
getFixture().watch(mockClientSession, new ArrayList<>(), TestEntity1.class); | ||
verify(mockMongoClient).watch(eq(mockClientSession), anyList(), eq(TestEntity1.class)); | ||
} | ||
|
||
@Test | ||
public void getClusterDescription() { | ||
getFixture().getClusterDescription(); | ||
verify(mockMongoClient).getClusterDescription(); | ||
} | ||
|
||
public MongoClient getFixture() { | ||
return new CollectionShardedReactiveMongoClient(mockMongoClient, collectionShardingOptions); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
.../java/com/alpha/mongodb/sharding/core/client/CompositeShardedReactiveMongoClientTest.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,24 @@ | ||
package com.alpha.mongodb.sharding.core.client; | ||
|
||
import com.alpha.mongodb.sharding.core.configuration.CompositeShardingOptions; | ||
import com.mongodb.reactivestreams.client.MongoClient; | ||
import org.junit.Test; | ||
|
||
import java.util.stream.IntStream; | ||
|
||
import static org.junit.Assert.assertNotNull; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class CompositeShardedReactiveMongoClientTest { | ||
|
||
CompositeShardingOptions compositeShardingOptions = | ||
CompositeShardingOptions.withIntegerStreamHints(IntStream.range(0, 3), IntStream.range(0, 3)); | ||
|
||
MongoClient mongoClient = mock(MongoClient.class); | ||
|
||
@Test | ||
public void testConstructor() { | ||
assertNotNull(new CompositeShardedReactiveMongoClient(mongoClient, compositeShardingOptions)); | ||
} | ||
|
||
} |
Oops, something went wrong.