@@ -458,7 +458,7 @@ class Cluster
458458 attempts << connection . host
459459 if count == 0
460460 count += 1
461- raise Cassandra ::Errors ::ClientError . new
461+ raise Cassandra ::Errors ::InternalError . new
462462 else
463463 Cassandra ::Protocol ::RowsResultResponse . new ( nil , nil , [ ] , [ ] , nil , nil )
464464 end
@@ -474,6 +474,72 @@ class Cluster
474474 expect ( attempts ) . to eq ( hosts )
475475 end
476476
477+ it 'does not retry on client timeout error if statement is not idempotent' do
478+ attempts = [ ]
479+ io_reactor . on_connection do |connection |
480+ connection . handle_request do |request |
481+ case request
482+ when Cassandra ::Protocol ::OptionsRequest
483+ Cassandra ::Protocol ::SupportedResponse . new ( { } )
484+ when Cassandra ::Protocol ::StartupRequest
485+ Cassandra ::Protocol ::ReadyResponse . new
486+ when Cassandra ::Protocol ::QueryRequest
487+ case request . cql
488+ when 'SELECT * FROM songs'
489+ attempts << connection . host
490+ raise Cassandra ::Errors ::TimeoutError . new
491+ else
492+ Cassandra ::Protocol ::RowsResultResponse . new ( nil , nil , [ ] , [ ] , nil , nil )
493+ end
494+ end
495+ end
496+ end
497+ client . connect . value
498+ future = client . query ( Statements ::Simple . new ( 'SELECT * FROM songs' ) ,
499+ Execution ::Options . new ( :consistency => :one ) )
500+ got_excp = false
501+ future . on_failure do |ex |
502+ got_excp = true
503+ expect ( ex ) . to be_a ( Cassandra ::Errors ::TimeoutError )
504+ end
505+ expect ( got_excp )
506+ expect ( attempts ) . to have ( 1 ) . items
507+ expect ( attempts . first ) . to eq ( hosts . first )
508+ end
509+
510+ it 'retries on client timeout error if statement is idempotent' do
511+ count = 0
512+ attempts = [ ]
513+ io_reactor . on_connection do |connection |
514+ connection . handle_request do |request |
515+ case request
516+ when Cassandra ::Protocol ::OptionsRequest
517+ Cassandra ::Protocol ::SupportedResponse . new ( { } )
518+ when Cassandra ::Protocol ::StartupRequest
519+ Cassandra ::Protocol ::ReadyResponse . new
520+ when Cassandra ::Protocol ::QueryRequest
521+ case request . cql
522+ when 'SELECT * FROM songs'
523+ attempts << connection . host
524+ if count == 0
525+ count += 1
526+ raise raise Cassandra ::Errors ::TimeoutError . new
527+ else
528+ Cassandra ::Protocol ::RowsResultResponse . new ( nil , nil , [ ] , [ ] , nil , nil )
529+ end
530+ else
531+ Cassandra ::Protocol ::RowsResultResponse . new ( nil , nil , [ ] , [ ] , nil , nil )
532+ end
533+ end
534+ end
535+ end
536+ client . connect . value
537+ client . query ( Statements ::Simple . new ( 'SELECT * FROM songs' , nil , nil , true ) ,
538+ Execution ::Options . new ( :consistency => :one ) ) . get
539+ expect ( attempts ) . to have ( 2 ) . items
540+ expect ( attempts ) . to eq ( hosts )
541+ end
542+
477543 it 'raises if all hosts failed' do
478544 io_reactor . on_connection do |connection |
479545 connection . handle_request do |request |
@@ -485,7 +551,7 @@ class Cluster
485551 when Cassandra ::Protocol ::QueryRequest
486552 case request . cql
487553 when 'SELECT * FROM songs'
488- raise Cassandra ::Errors ::ClientError . new
554+ raise Cassandra ::Errors ::InternalError . new
489555 else
490556 Cassandra ::Protocol ::RowsResultResponse . new ( nil , nil , [ ] , [ ] , nil , nil )
491557 end
@@ -692,7 +758,7 @@ class Cluster
692758 attempts << connection . host
693759 if count == 0
694760 count += 1
695- raise Cassandra ::Errors ::ClientError . new
761+ raise Cassandra ::Errors ::InternalError . new
696762 end
697763 Cassandra ::Protocol ::RowsResultResponse . new ( nil , nil , [ ] , [ ] , nil , nil )
698764 end
@@ -769,7 +835,7 @@ class Cluster
769835 when Cassandra ::Protocol ::PrepareRequest
770836 Protocol ::PreparedResultResponse . new ( nil , nil , 123 , [ ] , [ ] , nil , nil )
771837 when Cassandra ::Protocol ::ExecuteRequest
772- raise Cassandra ::Errors ::ClientError . new
838+ raise Cassandra ::Errors ::InternalError . new
773839 end
774840 end
775841 end
@@ -918,7 +984,7 @@ class Cluster
918984 attempts << connection . host
919985 if count == 0
920986 count += 1
921- raise Cassandra ::Errors ::ClientError . new
987+ raise Cassandra ::Errors ::InternalError . new
922988 end
923989 Cassandra ::Protocol ::RowsResultResponse . new ( nil , nil , [ ] , [ ] , nil , nil )
924990 end
@@ -943,7 +1009,7 @@ class Cluster
9431009 when Cassandra ::Protocol ::StartupRequest
9441010 Cassandra ::Protocol ::ReadyResponse . new
9451011 when Cassandra ::Protocol ::BatchRequest
946- raise Cassandra ::Errors ::ClientError . new
1012+ raise Cassandra ::Errors ::InternalError . new
9471013 end
9481014 end
9491015 end
0 commit comments