File tree Expand file tree Collapse file tree 3 files changed +28
-18
lines changed
driver-async/src/test/functional/com/mongodb/async/client
driver-core/src/main/com/mongodb/internal/connection
driver-sync/src/test/functional/com/mongodb/client Expand file tree Collapse file tree 3 files changed +28
-18
lines changed Original file line number Diff line number Diff line change @@ -33,12 +33,23 @@ public TransactionFailureTest() {
3333
3434 @ Before
3535 public void setUp () {
36- assumeTrue (canRunTests ());
3736 super .setUp ();
3837 }
3938
4039 @ Test (expected = MongoClientException .class )
41- public void testTransactionFails () throws InterruptedException {
40+ public void testTransactionFailsOn40Cluster () throws InterruptedException {
41+ assumeTrue (serverVersionLessThan ("4.0" ));
42+ doTransaction ();
43+ }
44+
45+ @ Test (expected = MongoClientException .class )
46+ public void testTransactionFailsOnShardedCluster () throws InterruptedException {
47+ assumeTrue (isSharded ());
48+ doTransaction ();
49+ }
50+
51+
52+ private void doTransaction () throws InterruptedException {
4253 final ClientSession clientSession = createSession ();
4354
4455 try {
@@ -61,10 +72,4 @@ public void execute() {
6172 }
6273 }.get ();
6374 }
64-
65-
66- private boolean canRunTests () {
67- return serverVersionLessThan ("4.0" )
68- || (serverVersionLessThan ("4.1.0" ) && isSharded ());
69- }
7075}
Original file line number Diff line number Diff line change 5050import static com .mongodb .connection .ServerType .SHARD_ROUTER ;
5151import static com .mongodb .internal .connection .BsonWriterHelper .writePayload ;
5252import static com .mongodb .internal .connection .ReadConcernHelper .getReadConcernDocument ;
53- import static com .mongodb .internal .operation .ServerVersionHelper .FOUR_DOT_TWO_WIRE_VERSION ;
5453import static com .mongodb .internal .operation .ServerVersionHelper .FOUR_DOT_ZERO_WIRE_VERSION ;
5554import static com .mongodb .internal .operation .ServerVersionHelper .THREE_DOT_SIX_WIRE_VERSION ;
5655
@@ -265,9 +264,10 @@ private List<BsonElement> getExtraElements(final SessionContext sessionContext)
265264
266265 private void checkServerVersionForTransactionSupport () {
267266 int wireVersion = getSettings ().getMaxWireVersion ();
268- if (wireVersion < FOUR_DOT_ZERO_WIRE_VERSION
269- || (wireVersion < FOUR_DOT_TWO_WIRE_VERSION && getSettings ().getServerType () == SHARD_ROUTER )) {
267+ if (wireVersion < FOUR_DOT_ZERO_WIRE_VERSION ) {
270268 throw new MongoClientException ("Transactions are not supported by the MongoDB cluster to which this client is connected." );
269+ } else if (getSettings ().getServerType () == SHARD_ROUTER ) {
270+ throw new MongoClientException ("This version of the driver does not support transactions on a sharded cluster." );
271271 }
272272 }
273273
Original file line number Diff line number Diff line change @@ -31,12 +31,22 @@ public TransactionFailureTest() {
3131
3232 @ Before
3333 public void setUp () {
34- assumeTrue (canRunTests ());
3534 super .setUp ();
3635 }
3736
3837 @ Test (expected = MongoClientException .class )
39- public void testTransactionFails () {
38+ public void testTransactionFailsOn40Cluster () {
39+ assumeTrue (serverVersionLessThan ("4.0" ));
40+ doTransaction ();
41+ }
42+
43+ @ Test (expected = MongoClientException .class )
44+ public void testTransactionFailsOnShardedCluster () {
45+ assumeTrue (isSharded ());
46+ doTransaction ();
47+ }
48+
49+ private void doTransaction () {
4050 ClientSession clientSession = client .startSession ();
4151 try {
4252 clientSession .startTransaction ();
@@ -45,9 +55,4 @@ public void testTransactionFails() {
4555 clientSession .close ();
4656 }
4757 }
48-
49- private boolean canRunTests () {
50- return serverVersionLessThan ("4.0" )
51- || (serverVersionLessThan ("4.1.0" ) && isSharded ());
52- }
5358}
You can’t perform that action at this time.
0 commit comments