@@ -561,15 +561,15 @@ def test_with_no_state(self):
561
561
562
562
(message_types , versions ) = message_types_and_versions (SINGER_MESSAGES )
563
563
564
- self .assertEqual (
565
- [
566
- "ActivateVersionMessage" ,
567
- "RecordMessage" ,
568
- ],
569
- sorted (list (set (message_types ))),
570
- )
564
+
571
565
self .assertTrue (isinstance (versions [0 ], int ))
572
566
self .assertEqual (versions [0 ], versions [1 ])
567
+ record_messages = [message for message in SINGER_MESSAGES if isinstance (message ,singer .RecordMessage )]
568
+ incremental_record_messages = [m for m in record_messages if m .stream == 'dbo-incremental' ]
569
+ integer_incremental_record_messages = [m for m in record_messages if m .stream == 'dbo-integer_incremental' ]
570
+
571
+ self .assertEqual (len (incremental_record_messages ),3 )
572
+ self .assertEqual (len (integer_incremental_record_messages ),3 )
573
573
574
574
def test_with_state (self ):
575
575
state = {
@@ -602,7 +602,14 @@ def test_with_state(self):
602
602
)
603
603
self .assertTrue (isinstance (versions [0 ], int ))
604
604
self .assertEqual (versions [0 ], versions [1 ])
605
- self .assertEqual (versions [1 ], 12345 )
605
+
606
+ # Based on state values provided check the number of record messages emitted
607
+ record_messages = [message for message in SINGER_MESSAGES if isinstance (message ,singer .RecordMessage )]
608
+ incremental_record_messages = [m for m in record_messages if m .stream == 'dbo-incremental' ]
609
+ integer_incremental_record_messages = [m for m in record_messages if m .stream == 'dbo-integer_incremental' ]
610
+
611
+ self .assertEqual (len (incremental_record_messages ),2 )
612
+ self .assertEqual (len (integer_incremental_record_messages ),1 )
606
613
607
614
608
615
class TestViews (unittest .TestCase ):
@@ -650,6 +657,76 @@ def test_do_not_discover_key_properties_for_view(self):
650
657
651
658
self .assertEqual (primary_keys , {"a_table" : ["id" ], "a_view" : []})
652
659
660
+ class TestTimestampIncrementalReplication (unittest .TestCase ):
661
+ def setUp (self ):
662
+ self .conn = test_utils .get_test_connection ()
663
+
664
+ with connect_with_backoff (self .conn ) as open_conn :
665
+ with open_conn .cursor () as cursor :
666
+ try :
667
+ cursor .execute ("drop table incremental" )
668
+ except :
669
+ pass
670
+ cursor .execute ("CREATE TABLE incremental (val int, updated timestamp)" )
671
+ cursor .execute ("INSERT INTO incremental (val) VALUES (1)" ) #00000000000007d1
672
+ cursor .execute ("INSERT INTO incremental (val) VALUES (2)" ) #00000000000007d2
673
+ cursor .execute ("INSERT INTO incremental (val) VALUES (3)" ) #00000000000007d3
674
+
675
+ self .catalog = test_utils .discover_catalog (self .conn , {})
676
+
677
+ for stream in self .catalog .streams :
678
+ stream .metadata = [
679
+ {
680
+ "breadcrumb" : (),
681
+ "metadata" : {
682
+ "selected" : True ,
683
+ "table-key-properties" : [],
684
+ "database-name" : "dbo" ,
685
+ },
686
+ },
687
+ {"breadcrumb" : ("properties" , "val" ), "metadata" : {"selected" : True }},
688
+ ]
689
+
690
+ stream .stream = stream .table
691
+ test_utils .set_replication_method_and_key (stream , "INCREMENTAL" , "updated" )
692
+
693
+ def test_with_no_state (self ):
694
+ state = {}
695
+
696
+ global SINGER_MESSAGES
697
+ SINGER_MESSAGES .clear ()
698
+
699
+ tap_mssql .do_sync (self .conn , test_utils .get_db_config (), self .catalog , state )
700
+
701
+ (message_types , versions ) = message_types_and_versions (SINGER_MESSAGES )
702
+
703
+ record_messages = [message for message in SINGER_MESSAGES if isinstance (message ,singer .RecordMessage )]
704
+
705
+ self .assertEqual (len (record_messages ),3 )
706
+
707
+
708
+ def test_with_state (self ):
709
+ state = {
710
+ "bookmarks" : {
711
+ "dbo-incremental" : {
712
+ "version" : 1 ,
713
+ "replication_key_value" : '00000000000007d2' ,
714
+ "replication_key" : "updated" ,
715
+ },
716
+ }
717
+ }
718
+
719
+ global SINGER_MESSAGES
720
+ SINGER_MESSAGES .clear ()
721
+ tap_mssql .do_sync (self .conn , test_utils .get_db_config (), self .catalog , state )
722
+
723
+ (message_types , versions ) = message_types_and_versions (SINGER_MESSAGES )
724
+
725
+ # Given the state value supplied, there should only be two RECORD messages
726
+ record_messages = [message for message in SINGER_MESSAGES if isinstance (message ,singer .RecordMessage )]
727
+
728
+ self .assertEqual (len (record_messages ),2 )
729
+
653
730
class TestPrimaryKeyUniqueKey (unittest .TestCase ):
654
731
def setUp (self ):
655
732
self .conn = test_utils .get_test_connection ()
@@ -708,6 +785,7 @@ def test_only_primary_key(self):
708
785
self .assertEqual (primary_keys ["pk_only_table" ], ["pk" ])
709
786
self .assertEqual (primary_keys ["pk_uc_table" ], ["pk" ])
710
787
788
+
711
789
if __name__ == "__main__" :
712
790
# test1 = TestBinlogReplication()
713
791
# test1.setUp()
0 commit comments