From 1a3f7da81c5caadefd4e12a05878a383bf55ffe3 Mon Sep 17 00:00:00 2001 From: Janne Valkealahti Date: Fri, 10 Feb 2017 16:12:03 +0000 Subject: [PATCH] Make mongo tests faster - There is a newer mongo client with changed behaviour as junit rule skipping tests if mongo is not running waits 30s for a connect failure. Add new server select timeout. - Fixes #314 --- .../statemachine/buildtests/tck/mongodb/MongoDbRule.java | 5 +++-- .../statemachine/data/mongodb/MongoDbRule.java | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/MongoDbRule.java b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/MongoDbRule.java index b1cf8233..9fac2a14 100644 --- a/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/MongoDbRule.java +++ b/spring-statemachine-build-tests/src/test/java/org/springframework/statemachine/buildtests/tck/mongodb/MongoDbRule.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,8 @@ public class MongoDbRule extends TestWatcher implements TestRule { public Statement apply(Statement base, Description description) { MongoClient client = null; try { - client = new MongoClient(new ServerAddress(), MongoClientOptions.builder().connectTimeout(50).build()); + client = new MongoClient(new ServerAddress(), + MongoClientOptions.builder().connectTimeout(50).serverSelectionTimeout(50).build()); client.getAddress(); } catch (Exception e) { return super.apply(new Statement() { diff --git a/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/MongoDbRule.java b/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/MongoDbRule.java index 8709ba05..d56a255b 100644 --- a/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/MongoDbRule.java +++ b/spring-statemachine-data/mongodb/src/test/java/org/springframework/statemachine/data/mongodb/MongoDbRule.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 the original author or authors. + * Copyright 2016-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +35,8 @@ public class MongoDbRule extends TestWatcher implements TestRule { public Statement apply(Statement base, Description description) { MongoClient client = null; try { - client = new MongoClient(new ServerAddress(), MongoClientOptions.builder().connectTimeout(50).build()); + client = new MongoClient(new ServerAddress(), + MongoClientOptions.builder().connectTimeout(50).serverSelectionTimeout(50).build()); client.getAddress(); } catch (Exception e) { return super.apply(new Statement() {