@@ -503,15 +503,6 @@ def test_prepared_metadata_generation(self):
503
503
504
504
505
505
class PreparedStatementArgTest (unittest .TestCase ):
506
-
507
- def setUp (self ):
508
- self .mock_handler = MockLoggingHandler ()
509
- self .logger = logging .getLogger (cluster .__name__ )
510
- self .logger .addHandler (self .mock_handler )
511
-
512
- def tearDown (self ):
513
- self .logger .removeHandler (self .mock_handler )
514
-
515
506
def test_prepare_on_all_hosts (self ):
516
507
"""
517
508
Test to validate prepare_on_all_hosts flag is honored.
@@ -523,14 +514,15 @@ def test_prepare_on_all_hosts(self):
523
514
@jira_ticket PYTHON-556
524
515
@expected_result queries will have to re-prepared on hosts that aren't the control connection
525
516
"""
526
- clus = TestCluster (prepare_on_all_hosts = False , reprepare_on_up = False )
527
- self .addCleanup (clus .shutdown )
517
+ with MockLoggingHandler ().set_module_name (cluster .__name__ ) as mock_handler :
518
+ clus = TestCluster (prepare_on_all_hosts = False , reprepare_on_up = False )
519
+ self .addCleanup (clus .shutdown )
528
520
529
- session = clus .connect (wait_for_all_pools = True )
530
- select_statement = session .prepare ("SELECT k FROM test3rf.test WHERE k = ?" )
531
- for host in clus .metadata .all_hosts ():
532
- session .execute (select_statement , (1 , ), host = host )
533
- self .assertEqual (2 , self . mock_handler .get_message_count ('debug' , "Re-preparing" ))
521
+ session = clus .connect (wait_for_all_pools = True )
522
+ select_statement = session .prepare ("SELECT k FROM test3rf.test WHERE k = ?" )
523
+ for host in clus .metadata .all_hosts ():
524
+ session .execute (select_statement , (1 , ), host = host )
525
+ self .assertEqual (2 , mock_handler .get_message_count ('debug' , "Re-preparing" ))
534
526
535
527
def test_prepare_batch_statement (self ):
536
528
"""
@@ -542,39 +534,40 @@ def test_prepare_batch_statement(self):
542
534
@expected_result queries will have to re-prepared on hosts that aren't the control connection
543
535
and the batch statement will be sent.
544
536
"""
545
- policy = ForcedHostIndexPolicy ()
546
- clus = TestCluster (
547
- execution_profiles = {
548
- EXEC_PROFILE_DEFAULT : ExecutionProfile (load_balancing_policy = policy ),
549
- },
550
- prepare_on_all_hosts = False ,
551
- reprepare_on_up = False ,
552
- )
553
- self .addCleanup (clus .shutdown )
537
+ with MockLoggingHandler ().set_module_name (cluster .__name__ ) as mock_handler :
538
+ policy = ForcedHostIndexPolicy ()
539
+ clus = TestCluster (
540
+ execution_profiles = {
541
+ EXEC_PROFILE_DEFAULT : ExecutionProfile (load_balancing_policy = policy ),
542
+ },
543
+ prepare_on_all_hosts = False ,
544
+ reprepare_on_up = False ,
545
+ )
546
+ self .addCleanup (clus .shutdown )
554
547
555
- table = "test3rf.%s" % self ._testMethodName .lower ()
548
+ table = "test3rf.%s" % self ._testMethodName .lower ()
556
549
557
- session = clus .connect (wait_for_all_pools = True )
550
+ session = clus .connect (wait_for_all_pools = True )
558
551
559
- session .execute ("DROP TABLE IF EXISTS %s" % table )
560
- session .execute ("CREATE TABLE %s (k int PRIMARY KEY, v int )" % table )
552
+ session .execute ("DROP TABLE IF EXISTS %s" % table )
553
+ session .execute ("CREATE TABLE %s (k int PRIMARY KEY, v int )" % table )
561
554
562
- insert_statement = session .prepare ("INSERT INTO %s (k, v) VALUES (?, ?)" % table )
555
+ insert_statement = session .prepare ("INSERT INTO %s (k, v) VALUES (?, ?)" % table )
563
556
564
- # This is going to query a host where the query
565
- # is not prepared
566
- policy .set_host (1 )
567
- batch_statement = BatchStatement (consistency_level = ConsistencyLevel .ONE )
568
- batch_statement .add (insert_statement , (1 , 2 ))
569
- session .execute (batch_statement )
557
+ # This is going to query a host where the query
558
+ # is not prepared
559
+ policy .set_host (1 )
560
+ batch_statement = BatchStatement (consistency_level = ConsistencyLevel .ONE )
561
+ batch_statement .add (insert_statement , (1 , 2 ))
562
+ session .execute (batch_statement )
570
563
571
- # To verify our test assumption that queries are getting re-prepared properly
572
- self .assertEqual (1 , self . mock_handler .get_message_count ('debug' , "Re-preparing" ))
564
+ # To verify our test assumption that queries are getting re-prepared properly
565
+ self .assertEqual (1 , mock_handler .get_message_count ('debug' , "Re-preparing" ))
573
566
574
- select_results = session .execute (SimpleStatement ("SELECT * FROM %s WHERE k = 1" % table ,
575
- consistency_level = ConsistencyLevel .ALL ))
576
- first_row = select_results [0 ][:2 ]
577
- self .assertEqual ((1 , 2 ), first_row )
567
+ select_results = session .execute (SimpleStatement ("SELECT * FROM %s WHERE k = 1" % table ,
568
+ consistency_level = ConsistencyLevel .ALL ))
569
+ first_row = select_results [0 ][:2 ]
570
+ self .assertEqual ((1 , 2 ), first_row )
578
571
579
572
def test_prepare_batch_statement_after_alter (self ):
580
573
"""
@@ -587,44 +580,45 @@ def test_prepare_batch_statement_after_alter(self):
587
580
@expected_result queries will have to re-prepared on hosts that aren't the control connection
588
581
and the batch statement will be sent.
589
582
"""
590
- clus = TestCluster (prepare_on_all_hosts = False , reprepare_on_up = False )
591
- self .addCleanup (clus .shutdown )
583
+ with MockLoggingHandler ().set_module_name (cluster .__name__ ) as mock_handler :
584
+ clus = TestCluster (prepare_on_all_hosts = False , reprepare_on_up = False )
585
+ self .addCleanup (clus .shutdown )
592
586
593
- table = "test3rf.%s" % self ._testMethodName .lower ()
587
+ table = "test3rf.%s" % self ._testMethodName .lower ()
594
588
595
- session = clus .connect (wait_for_all_pools = True )
589
+ session = clus .connect (wait_for_all_pools = True )
596
590
597
- session .execute ("DROP TABLE IF EXISTS %s" % table )
598
- session .execute ("CREATE TABLE %s (k int PRIMARY KEY, a int, b int, d int)" % table )
599
- insert_statement = session .prepare ("INSERT INTO %s (k, b, d) VALUES (?, ?, ?)" % table )
591
+ session .execute ("DROP TABLE IF EXISTS %s" % table )
592
+ session .execute ("CREATE TABLE %s (k int PRIMARY KEY, a int, b int, d int)" % table )
593
+ insert_statement = session .prepare ("INSERT INTO %s (k, b, d) VALUES (?, ?, ?)" % table )
600
594
601
- # Altering the table might trigger an update in the insert metadata
602
- session .execute ("ALTER TABLE %s ADD c int" % table )
595
+ # Altering the table might trigger an update in the insert metadata
596
+ session .execute ("ALTER TABLE %s ADD c int" % table )
603
597
604
- values_to_insert = [(1 , 2 , 3 ), (2 , 3 , 4 ), (3 , 4 , 5 ), (4 , 5 , 6 )]
598
+ values_to_insert = [(1 , 2 , 3 ), (2 , 3 , 4 ), (3 , 4 , 5 ), (4 , 5 , 6 )]
605
599
606
- # We query the three hosts in order (due to the ForcedHostIndexPolicy)
607
- # the first three queries will have to be repreapred and the rest should
608
- # work as normal batch prepared statements
609
- hosts = clus .metadata .all_hosts ()
610
- for i in range (10 ):
611
- value_to_insert = values_to_insert [i % len (values_to_insert )]
612
- batch_statement = BatchStatement (consistency_level = ConsistencyLevel .ONE )
613
- batch_statement .add (insert_statement , value_to_insert )
614
- session .execute (batch_statement , host = hosts [i % len (hosts )])
600
+ # We query the three hosts in order (due to the ForcedHostIndexPolicy)
601
+ # the first three queries will have to be repreapred and the rest should
602
+ # work as normal batch prepared statements
603
+ hosts = clus .metadata .all_hosts ()
604
+ for i in range (10 ):
605
+ value_to_insert = values_to_insert [i % len (values_to_insert )]
606
+ batch_statement = BatchStatement (consistency_level = ConsistencyLevel .ONE )
607
+ batch_statement .add (insert_statement , value_to_insert )
608
+ session .execute (batch_statement , host = hosts [i % len (hosts )])
615
609
616
- select_results = session .execute ("SELECT * FROM %s" % table )
617
- expected_results = [
618
- (1 , None , 2 , None , 3 ),
619
- (2 , None , 3 , None , 4 ),
620
- (3 , None , 4 , None , 5 ),
621
- (4 , None , 5 , None , 6 )
622
- ]
610
+ select_results = session .execute ("SELECT * FROM %s" % table )
611
+ expected_results = [
612
+ (1 , None , 2 , None , 3 ),
613
+ (2 , None , 3 , None , 4 ),
614
+ (3 , None , 4 , None , 5 ),
615
+ (4 , None , 5 , None , 6 )
616
+ ]
623
617
624
- self .assertEqual (set (expected_results ), set (select_results ._current_rows ))
618
+ self .assertEqual (set (expected_results ), set (select_results ._current_rows ))
625
619
626
- # To verify our test assumption that queries are getting re-prepared properly
627
- self .assertEqual (3 , self . mock_handler .get_message_count ('debug' , "Re-preparing" ))
620
+ # To verify our test assumption that queries are getting re-prepared properly
621
+ self .assertEqual (3 , mock_handler .get_message_count ('debug' , "Re-preparing" ))
628
622
629
623
630
624
class PrintStatementTests (unittest .TestCase ):
0 commit comments