Skip to content

Commit f3b0cf5

Browse files
committed
AsyncStreamTimeoutsSpecification fixes for the Jenkins matrix
1 parent 12ea53b commit f3b0cf5

File tree

1 file changed

+46
-19
lines changed

1 file changed

+46
-19
lines changed

driver-core/src/test/functional/com/mongodb/connection/AsyncStreamTimeoutsSpecification.groovy

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import org.bson.BsonInt32
2727
import org.bson.BsonString
2828
import org.junit.experimental.categories.Category
2929
import spock.lang.IgnoreIf
30-
import spock.lang.Unroll
3130

3231
import java.util.concurrent.TimeUnit
3332

@@ -37,35 +36,33 @@ import static com.mongodb.ClusterFixture.getSslSettings
3736
import static com.mongodb.connection.CommandHelper.executeCommand
3837

3938
@Category(Slow)
40-
@IgnoreIf({ System.getProperty('java.version').startsWith('1.6.') })
4139
class AsyncStreamTimeoutsSpecification extends OperationFunctionalSpecification {
4240

4341
static SocketSettings openSocketSettings = SocketSettings.builder().connectTimeout(1, TimeUnit.MILLISECONDS).build();
4442
static SocketSettings readSocketSettings = SocketSettings.builder().readTimeout(5, TimeUnit.SECONDS).build();
4543

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'() {
4846
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))));
5151

5252
when:
5353
connection.open()
5454

5555
then:
5656
thrown(MongoSocketOpenException)
57-
58-
where:
59-
description | streamFactory
60-
'AsynchronousSocket' | new AsynchronousSocketChannelStreamFactory(openSocketSettings, SslSettings.builder().build())
61-
'NettyStream' | new NettyStreamFactory(openSocketSettings, getSslSettings())
6257
}
6358

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'() {
6661
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()))
6966
connection.open()
7067

7168
getCollectionHelper().insertDocuments(new BsonDocument('_id', new BsonInt32(1)));
@@ -80,11 +77,41 @@ class AsyncStreamTimeoutsSpecification extends OperationFunctionalSpecification
8077

8178
cleanup:
8279
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()
8390

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()
88115
}
89116

90117
}

0 commit comments

Comments
 (0)