1616package com .datastax .driver .core ;
1717
1818import com .datastax .driver .core .exceptions .*;
19+ import com .datastax .driver .core .policies .FallthroughRetryPolicy ;
1920import com .google .common .util .concurrent .Uninterruptibles ;
2021import org .apache .log4j .Level ;
2122import org .apache .log4j .Logger ;
@@ -66,7 +67,7 @@ public void setUp() {
6667
6768 queryLogger = null ;
6869
69- cluster = createClusterBuilder ().build ();
70+ cluster = createClusterBuilder ().withRetryPolicy ( FallthroughRetryPolicy . INSTANCE ). build ();
7071 session = cluster .connect ();
7172 }
7273
@@ -175,8 +176,8 @@ public void should_log_timed_out_queries() throws Exception {
175176 // when
176177 try {
177178 session .execute (query );
178- fail ("Should have thrown NoHostAvailableException " );
179- } catch (NoHostAvailableException e ) {
179+ fail ("Should have thrown OperationTimedOutException " );
180+ } catch (OperationTimedOutException e ) {
180181 // ok
181182 }
182183 // then
@@ -192,25 +193,25 @@ public void should_log_timed_out_queries() throws Exception {
192193 @ DataProvider (name = "errors" )
193194 public static Object [][] createErrors () {
194195 return new Object [][]{
195- {unavailable , NoHostAvailableException . class , UnavailableException .class },
196- {write_request_timeout , WriteTimeoutException .class , WriteTimeoutException . class },
197- {read_request_timeout , ReadTimeoutException .class , ReadTimeoutException . class },
198- {server_error , NoHostAvailableException . class , ServerError .class },
199- {protocol_error , ProtocolError .class , ProtocolError . class },
200- {bad_credentials , AuthenticationException .class , AuthenticationException . class },
201- {overloaded , NoHostAvailableException . class , OverloadedException .class },
202- {is_bootstrapping , NoHostAvailableException . class , BootstrappingException .class },
203- {truncate_error , TruncateException .class , TruncateException . class },
204- {syntax_error , SyntaxError .class , SyntaxError . class },
205- {invalid , InvalidQueryException .class , InvalidQueryException . class },
206- {config_error , InvalidConfigurationInQueryException .class , InvalidConfigurationInQueryException . class },
207- {already_exists , AlreadyExistsException .class , AlreadyExistsException . class },
208- {unprepared , DriverInternalError . class , UnpreparedException .class }
196+ {unavailable , UnavailableException .class },
197+ {write_request_timeout , WriteTimeoutException .class },
198+ {read_request_timeout , ReadTimeoutException .class },
199+ {server_error , ServerError .class },
200+ {protocol_error , ProtocolError .class },
201+ {bad_credentials , AuthenticationException .class },
202+ {overloaded , OverloadedException .class },
203+ {is_bootstrapping , BootstrappingException .class },
204+ {truncate_error , TruncateException .class },
205+ {syntax_error , SyntaxError .class },
206+ {invalid , InvalidQueryException .class },
207+ {config_error , InvalidConfigurationInQueryException .class },
208+ {already_exists , AlreadyExistsException .class },
209+ {unprepared , UnpreparedException .class }
209210 };
210211 }
211212
212213 @ Test (groups = "short" , dataProvider = "errors" )
213- public void should_log_exception_from_the_given_result (Result result , Class <? extends Exception > expectedException , Class <? extends Exception > loggedException ) throws Exception {
214+ public void should_log_exception_from_the_given_result (Result result , Class <? extends Exception > expectedException ) throws Exception {
214215 // given
215216 error .setLevel (DEBUG );
216217 queryLogger = builder ().build ();
@@ -225,12 +226,15 @@ public void should_log_exception_from_the_given_result(Result result, Class<? ex
225226 // when
226227 try {
227228 session .execute (query );
228- fail ("Should have thrown NoHostAvailableException " );
229+ fail ("Should have thrown Exception " );
229230 } catch (Exception e ) {
230- if (e instanceof NoHostAvailableException ) {
231- assertThat (expectedException ).isEqualTo (NoHostAvailableException .class );
232- Throwable error = ((NoHostAvailableException ) e ).getErrors ().get (hostAddress );
233- assertThat (error ).isNotNull ().isOfAnyClassIn (loggedException );
231+ if (expectedException == UnpreparedException .class ) {
232+ // Special case UnpreparedException, it raises DriverInternalError instead.
233+ assertThat (e ).isInstanceOf (DriverInternalError .class );
234+ } else if (expectedException == BootstrappingException .class ) {
235+ // Special case BootstrappingException, it's wrapped in NHAE since it's always retried.
236+ assertThat (e ).isInstanceOf (NoHostAvailableException .class );
237+ assertThat (((NoHostAvailableException ) e ).getErrors ().get (hostAddress )).isInstanceOf (expectedException );
234238 } else {
235239 assertThat (e ).isInstanceOf (expectedException );
236240 }
@@ -242,7 +246,7 @@ public void should_log_exception_from_the_given_result(Result result, Class<? ex
242246 .contains (ip )
243247 .contains (Integer .toString (scassandra .getBinaryPort ()))
244248 .contains (query )
245- .contains (loggedException .getName ());
249+ .contains (expectedException .getName ());
246250 }
247251
248252}
0 commit comments