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() {
33
33
34
34
@ Before
35
35
public void setUp () {
36
- assumeTrue (canRunTests ());
37
36
super .setUp ();
38
37
}
39
38
40
39
@ 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 {
42
53
final ClientSession clientSession = createSession ();
43
54
44
55
try {
@@ -61,10 +72,4 @@ public void execute() {
61
72
}
62
73
}.get ();
63
74
}
64
-
65
-
66
- private boolean canRunTests () {
67
- return serverVersionLessThan ("4.0" )
68
- || (serverVersionLessThan ("4.1.0" ) && isSharded ());
69
- }
70
75
}
Original file line number Diff line number Diff line change 50
50
import static com .mongodb .connection .ServerType .SHARD_ROUTER ;
51
51
import static com .mongodb .internal .connection .BsonWriterHelper .writePayload ;
52
52
import static com .mongodb .internal .connection .ReadConcernHelper .getReadConcernDocument ;
53
- import static com .mongodb .internal .operation .ServerVersionHelper .FOUR_DOT_TWO_WIRE_VERSION ;
54
53
import static com .mongodb .internal .operation .ServerVersionHelper .FOUR_DOT_ZERO_WIRE_VERSION ;
55
54
import static com .mongodb .internal .operation .ServerVersionHelper .THREE_DOT_SIX_WIRE_VERSION ;
56
55
@@ -265,9 +264,10 @@ private List<BsonElement> getExtraElements(final SessionContext sessionContext)
265
264
266
265
private void checkServerVersionForTransactionSupport () {
267
266
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 ) {
270
268
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." );
271
271
}
272
272
}
273
273
Original file line number Diff line number Diff line change @@ -31,12 +31,22 @@ public TransactionFailureTest() {
31
31
32
32
@ Before
33
33
public void setUp () {
34
- assumeTrue (canRunTests ());
35
34
super .setUp ();
36
35
}
37
36
38
37
@ 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 () {
40
50
ClientSession clientSession = client .startSession ();
41
51
try {
42
52
clientSession .startTransaction ();
@@ -45,9 +55,4 @@ public void testTransactionFails() {
45
55
clientSession .close ();
46
56
}
47
57
}
48
-
49
- private boolean canRunTests () {
50
- return serverVersionLessThan ("4.0" )
51
- || (serverVersionLessThan ("4.1.0" ) && isSharded ());
52
- }
53
58
}
You can’t perform that action at this time.
0 commit comments