@@ -27,7 +27,6 @@ import org.bson.BsonInt32
27
27
import org.bson.BsonString
28
28
import org.junit.experimental.categories.Category
29
29
import spock.lang.IgnoreIf
30
- import spock.lang.Unroll
31
30
32
31
import java.util.concurrent.TimeUnit
33
32
@@ -37,35 +36,33 @@ import static com.mongodb.ClusterFixture.getSslSettings
37
36
import static com.mongodb.connection.CommandHelper.executeCommand
38
37
39
38
@Category (Slow )
40
- @IgnoreIf ({ System .getProperty(' java.version' ).startsWith(' 1.6.' ) })
41
39
class AsyncStreamTimeoutsSpecification extends OperationFunctionalSpecification {
42
40
43
41
static SocketSettings openSocketSettings = SocketSettings . builder(). connectTimeout(1 , TimeUnit . MILLISECONDS ). build();
44
42
static SocketSettings readSocketSettings = SocketSettings . builder(). readTimeout(5 , TimeUnit . SECONDS ). build();
45
43
46
- @Unroll
47
- def ' should throw a MongoSocketOpenException when the #description Stream fails to open' () {
44
+ @IgnoreIf ({ System .getProperty( ' java.version ' ).startsWith( ' 1.6. ' ) || getSslSettings().isEnabled() })
45
+ def ' should throw a MongoSocketOpenException when the AsynchronousSocket Stream fails to open' () {
48
46
given :
49
- def connection = new InternalStreamConnectionFactory (streamFactory, getCredentialList(), new NoOpConnectionListener ())
50
- .create(new ServerId (new ClusterId (), new ServerAddress (new InetSocketAddress (' 192.168.255.255' , 27017 ))));
47
+ def connection = new InternalStreamConnectionFactory (
48
+ new AsynchronousSocketChannelStreamFactory (openSocketSettings, getSslSettings()), getCredentialList(),
49
+ new NoOpConnectionListener ()
50
+ ). create(new ServerId (new ClusterId (), new ServerAddress (new InetSocketAddress (' 192.168.255.255' , 27017 ))));
51
51
52
52
when :
53
53
connection. open()
54
54
55
55
then :
56
56
thrown(MongoSocketOpenException )
57
-
58
- where :
59
- description | streamFactory
60
- ' AsynchronousSocket' | new AsynchronousSocketChannelStreamFactory (openSocketSettings, SslSettings . builder(). build())
61
- ' NettyStream' | new NettyStreamFactory (openSocketSettings, getSslSettings())
62
57
}
63
58
64
- @Unroll
65
- def ' should throw a MongoSocketReadTimeoutException with the #description stream' () {
59
+ @IgnoreIf ({ System .getProperty( ' java.version ' ).startsWith( ' 1.6. ' ) || getSslSettings().isEnabled() })
60
+ def ' should throw a MongoSocketReadTimeoutException with the AsynchronousSocket stream' () {
66
61
given :
67
- def connection = new InternalStreamConnectionFactory (streamFactory, getCredentialList(), new NoOpConnectionListener ())
68
- .create(new ServerId (new ClusterId (), getPrimary()))
62
+ def connection = new InternalStreamConnectionFactory (
63
+ new AsynchronousSocketChannelStreamFactory (readSocketSettings, getSslSettings()), getCredentialList(),
64
+ new NoOpConnectionListener ()
65
+ ). create(new ServerId (new ClusterId (), getPrimary()))
69
66
connection. open()
70
67
71
68
getCollectionHelper(). insertDocuments(new BsonDocument (' _id' , new BsonInt32 (1 )));
@@ -80,11 +77,41 @@ class AsyncStreamTimeoutsSpecification extends OperationFunctionalSpecification
80
77
81
78
cleanup :
82
79
connection?. close()
80
+ }
81
+
82
+ def ' should throw a MongoSocketOpenException when the Netty Stream fails to open' () {
83
+ given :
84
+ def connection = new InternalStreamConnectionFactory (
85
+ new NettyStreamFactory (openSocketSettings, getSslSettings()), getCredentialList(), new NoOpConnectionListener ()
86
+ ). create(new ServerId (new ClusterId (), new ServerAddress (new InetSocketAddress (' 192.168.255.255' , 27017 ))));
87
+
88
+ when :
89
+ connection. open()
83
90
84
- where :
85
- description | streamFactory
86
- ' AsynchronousSocket' | new AsynchronousSocketChannelStreamFactory (readSocketSettings, SslSettings . builder(). build())
87
- ' NettyStream' | new NettyStreamFactory (readSocketSettings, getSslSettings())
91
+ then :
92
+ thrown(MongoSocketOpenException )
93
+ }
94
+
95
+
96
+ def ' should throw a MongoSocketReadTimeoutException with the Netty stream' () {
97
+ given :
98
+ def connection = new InternalStreamConnectionFactory (
99
+ new NettyStreamFactory (readSocketSettings, getSslSettings()), getCredentialList(), new NoOpConnectionListener ()
100
+ ). create(new ServerId (new ClusterId (), getPrimary()))
101
+ connection. open()
102
+
103
+ getCollectionHelper(). insertDocuments(new BsonDocument (' _id' , new BsonInt32 (1 )));
104
+ def countCommand = new BsonDocument (' count' , new BsonString (getCollectionName()))
105
+ countCommand. put(' query' , new BsonDocument (' $where' , new BsonString (' sleep(5050); return true;' )))
106
+
107
+ when :
108
+ executeCommand(getDatabaseName(), countCommand, connection)
109
+
110
+ then :
111
+ thrown(MongoSocketReadTimeoutException )
112
+
113
+ cleanup :
114
+ connection?. close()
88
115
}
89
116
90
117
}
0 commit comments