def test_for_sorting_based_on_context_and_dbid_with_file_compare_option_succeeds( self): self.subject = GucCollection() row = ['-1', 'guc_name', 'coordinator_value', 'dbid1'] self.subject.update(FileSegmentGuc(row)) row = ['0', 'guc_name', 'value', 'dbid2'] self.subject.update(FileSegmentGuc(row)) row = ['-1', 'guc_name', 'coordinator_value'] self.subject.update(DatabaseSegmentGuc(row)) row = ['0', 'guc_name', 'value'] self.subject.update(DatabaseSegmentGuc(row)) row = ['1', 'guc_name', 'value', 'dbid5'] self.subject.update(FileSegmentGuc(row)) row = ['1', 'guc_name', 'wrong_value', 'dbid4'] self.subject.update(FileSegmentGuc(row)) row = ['1', 'guc_name', 'value'] self.subject.update(DatabaseSegmentGuc(row)) row = ['0', 'guc_name', 'value', 'dbid3'] self.subject.update(FileSegmentGuc(row)) self.assertEqual( "[context: -1] [dbid: dbid1] [name: guc_name] [value: coordinator_value | file: coordinator_value]\n" "[context: 0] [dbid: dbid2] [name: guc_name] [value: value | file: value]\n" "[context: 0] [dbid: dbid3] [name: guc_name] [value: value | file: value]\n" "[context: 1] [dbid: dbid4] [name: guc_name] [value: value | file: wrong_value]\n" "[context: 1] [dbid: dbid5] [name: guc_name] [value: value | file: value]", self.subject.report())
class DatabaseSegmentGucTest(GpTestCase): def setUp(self): row = ['contentid', 'guc_name', 'sql_value'] self.subject = DatabaseSegmentGuc(row) def test_when_segment_report_success_format_database(self): self.subject.context = '0' self.assertEqual(self.subject.report_success_format(), "Segment value: sql_value") def test_when_coordinator_report_success_format_database(self): self.subject.context = '-1' self.assertEqual(self.subject.report_success_format(), "Coordinator value: sql_value") def test_report_fail_format_database(self): self.assertEqual( self.subject.report_fail_format(), ["[context: contentid] [name: guc_name] [value: sql_value]"]) def test_init_with_insufficient_database_values_raises(self): row = ['contentid', 'guc_name'] with self.assertRaisesRegex( Exception, "must provide \['context', 'guc name', 'value'\]"): DatabaseSegmentGuc(row)
def setUp(self): self.subject = GucCollection() row = ['-1', 'guc_name', 'coordinator_value'] self.db_seg_guc_1 = DatabaseSegmentGuc(row) self.subject.update(self.db_seg_guc_1) row = ['0', 'guc_name', 'value'] self.db_seg_guc_2 = DatabaseSegmentGuc(row) self.subject.update(self.db_seg_guc_2)
def test_update_when_only_database_segments_succeeds(self): row = ['-1', 'guc_name', 'master_value'] self.subject.update(DatabaseSegmentGuc(row)) row = ['0', 'guc_name', 'value'] self.subject.update(DatabaseSegmentGuc(row)) self.assertIn("Master value: master_value", self.subject.report()) self.assertIn("Segment value: value", self.subject.report())
def test_update_when_file_segments_first_succeeds(self): row = ['-1', 'guc_name', 'master_value', 'dbid1'] self.subject.update(FileSegmentGuc(row)) row = ['0', 'guc_name', 'value', 'dbid2'] self.subject.update(FileSegmentGuc(row)) primary_file_seg = FileSegmentGuc(row) self.subject.update(primary_file_seg) row = ['-1', 'guc_name', 'master_value'] self.subject.update(DatabaseSegmentGuc(row)) row = ['0', 'guc_name', 'value'] self.subject.update(DatabaseSegmentGuc(row)) self.assertIn("Master value: master_value | file: master_value", self.subject.report()) self.assertIn("Segment value: value | file: value", self.subject.report())
def setUp(self): row = ['contentid', 'guc_name', 'file_value', "dbid"] self.file_seg_guc = FileSegmentGuc(row) row = ['contentid', 'guc_name', 'sql_value'] self.db_seg_guc = DatabaseSegmentGuc(row) self.subject = MultiValueGuc(self.file_seg_guc, self.db_seg_guc)
def test_init_with_wrong_content_id_raises(self): row = ['contentid', 'guc_name', 'file_value', "dbid"] file_seg_guc = FileSegmentGuc(row) row = ['different', 'guc_name', 'sql_value'] db_seg_guc = DatabaseSegmentGuc(row) with self.assertRaisesRegex(Exception, "Not the same context"): MultiValueGuc(file_seg_guc, db_seg_guc)
def test_is_internally_consistent_when_gucs_are_different_returns_false( self): file_seg_guc = FileSegmentGuc( ['contentid', 'guc_name', "'hello", "dbid"]) db_seg_guc = DatabaseSegmentGuc(['contentid', 'guc_name', "hello"]) subject = MultiValueGuc(file_seg_guc, db_seg_guc) self.assertFalse(subject.is_internally_consistent())
class DatabaseSegmentGucTest(GpTestCase): def setUp(self): row = ['contentid', 'guc_name', 'sql_value'] self.subject = DatabaseSegmentGuc(row) def test_when_segment_report_success_format_database(self): self.subject.context = '0' self.assertEquals(self.subject.report_success_format(), "Segment value: sql_value") def test_when_master_report_success_format_database(self): self.subject.context = '-1' self.assertEquals(self.subject.report_success_format(), "Master value: sql_value") def test_report_fail_format_database(self): self.assertEquals(self.subject.report_fail_format(), ["[context: contentid] [name: guc_name] [value: sql_value]"]) def test_init_with_insufficient_database_values_raises(self): row = ['contentid', 'guc_name'] with self.assertRaisesRegexp(Exception, "must provide \['context', 'guc name', 'value'\]"): DatabaseSegmentGuc(row)
def test_when_three_segments_match_success_format(self): row = ['-1', 'guc_name', 'master_value', 'dbid1'] self.subject.update(FileSegmentGuc(row)) row = ['0', 'guc_name', 'value', 'dbid2'] self.subject.update(FileSegmentGuc(row)) row = ['1', 'guc_name', 'value'] self.subject.update(DatabaseSegmentGuc(row)) row = ['1', 'guc_name', 'value', 'dbid3'] self.subject.update(FileSegmentGuc(row)) self.assertIn("Master value: master_value | file: master_value", self.subject.report()) self.assertIn("Segment value: value | file: value", self.subject.report())
def test_when_multiple_dbids_per_contentid_reports_failure(self): row = ['-1', 'guc_name', 'master_value', '1'] self.subject.update(FileSegmentGuc(row)) row = ['-1', 'guc_name', 'master_value', '2'] self.subject.update(FileSegmentGuc(row)) row = ['0', 'guc_name', 'value', '3'] self.subject.update(FileSegmentGuc(row)) row = ['0', 'guc_name', 'value', '4'] self.subject.update(FileSegmentGuc(row)) row = ['1', 'guc_name', 'value'] self.subject.update(DatabaseSegmentGuc(row)) row = ['1', 'guc_name', 'different', '5'] self.subject.update(FileSegmentGuc(row)) row = ['1', 'guc_name', 'different', '6'] self.subject.update(FileSegmentGuc(row)) self.assertIn("" "[context: -1] [dbid: 1] [name: guc_name] [value: master_value | file: master_value]" "\n[context: -1] [dbid: 2] [name: guc_name] [value: master_value | file: master_value]", # "\n[context: 0] [dbid: dbid] [name: guc_name] [value: value | file: file_value]", self.subject.report())
def setUp(self): row = ['contentid', 'guc_name', 'sql_value'] self.subject = DatabaseSegmentGuc(row)
def test_init_with_insufficient_database_values_raises(self): row = ['contentid', 'guc_name'] with self.assertRaisesRegex(Exception, "must provide \['context', 'guc name', 'value'\]"): DatabaseSegmentGuc(row)
def test_update_when_same_database_segment_guc_type_overrides_existing( self): row = ['-1', 'guc_name', 'new_value', 'dbid'] self.subject.update(DatabaseSegmentGuc(row)) self.assertEqual(len(self.subject.gucs), 2)
def setUp(self): row = ['contentid', 'guc_name', 'sql_value'] self.subject = DatabaseSegmentGuc(row)