1
1
package resilience .connection ;
2
2
3
- import com .arangodb .ArangoDB ;
4
- import com .arangodb .ArangoDBException ;
5
- import com .arangodb .ArangoDBMultipleException ;
6
- import com .arangodb .Protocol ;
3
+ import com .arangodb .*;
7
4
import resilience .SingleServerTest ;
8
5
import org .junit .jupiter .params .ParameterizedTest ;
9
6
import org .junit .jupiter .params .provider .MethodSource ;
@@ -36,9 +33,13 @@ static Stream<ArangoDB> arangoProvider() {
36
33
);
37
34
}
38
35
36
+ static Stream <ArangoDBAsync > asyncArangoProvider () {
37
+ return arangoProvider ().map (ArangoDB ::async );
38
+ }
39
+
39
40
@ ParameterizedTest
40
41
@ MethodSource ("protocolProvider" )
41
- void nameResolutionFailTest (Protocol protocol ) {
42
+ void nameResolutionFail (Protocol protocol ) {
42
43
ArangoDB arangoDB = new ArangoDB .Builder ()
43
44
.host ("wrongHost" , 8529 )
44
45
.protocol (protocol )
@@ -57,8 +58,29 @@ void nameResolutionFailTest(Protocol protocol) {
57
58
}
58
59
59
60
@ ParameterizedTest
61
+ @ MethodSource ("protocolProvider" )
62
+ void nameResolutionFailAsync (Protocol protocol ) {
63
+ ArangoDBAsync arangoDB = new ArangoDB .Builder ()
64
+ .host ("wrongHost" , 8529 )
65
+ .protocol (protocol )
66
+ .build ()
67
+ .async ();
68
+
69
+ Throwable thrown = catchThrowable (() -> arangoDB .getVersion ().get ()).getCause ();
70
+ assertThat (thrown ).isInstanceOf (ArangoDBException .class );
71
+ assertThat (thrown .getMessage ()).contains ("Cannot contact any host!" );
72
+ assertThat (thrown .getCause ()).isNotNull ();
73
+ assertThat (thrown .getCause ()).isInstanceOf (ArangoDBMultipleException .class );
74
+ ((ArangoDBMultipleException ) thrown .getCause ()).getExceptions ().forEach (e -> {
75
+ assertThat (e ).isInstanceOf (UnknownHostException .class );
76
+ assertThat (e .getMessage ()).contains ("wrongHost" );
77
+ });
78
+ arangoDB .shutdown ();
79
+ }
80
+
81
+ @ ParameterizedTest (name = "{index}" )
60
82
@ MethodSource ("arangoProvider" )
61
- void connectionFailTest (ArangoDB arangoDB ) {
83
+ void connectionFail (ArangoDB arangoDB ) {
62
84
disableEndpoint ();
63
85
64
86
Throwable thrown = catchThrowable (arangoDB ::getVersion );
@@ -72,4 +94,20 @@ void connectionFailTest(ArangoDB arangoDB) {
72
94
enableEndpoint ();
73
95
}
74
96
97
+ @ ParameterizedTest (name = "{index}" )
98
+ @ MethodSource ("asyncArangoProvider" )
99
+ void connectionFailAsync (ArangoDBAsync arangoDB ) {
100
+ disableEndpoint ();
101
+
102
+ Throwable thrown = catchThrowable (() -> arangoDB .getVersion ().get ()).getCause ();
103
+ assertThat (thrown ).isInstanceOf (ArangoDBException .class );
104
+ assertThat (thrown .getMessage ()).contains ("Cannot contact any host" );
105
+ assertThat (thrown .getCause ()).isNotNull ();
106
+ assertThat (thrown .getCause ()).isInstanceOf (ArangoDBMultipleException .class );
107
+ ((ArangoDBMultipleException ) thrown .getCause ()).getExceptions ().forEach (e ->
108
+ assertThat (e ).isInstanceOf (ConnectException .class ));
109
+ arangoDB .shutdown ();
110
+ enableEndpoint ();
111
+ }
112
+
75
113
}
0 commit comments