def test_data_validator_event_msgfmt(self):
        critical_event = DataValidatorEvent.DataValidator(
            severity=Severity.ERROR, error="e1")
        self.assertEqual(
            str(critical_event),
            "(DataValidatorEvent Severity.ERROR): type=DataValidator error=e1")
        self.assertEqual(critical_event,
                         pickle.loads(pickle.dumps(critical_event)))

        error_event = DataValidatorEvent.ImmutableRowsValidator(
            severity=Severity.ERROR, error="e2")
        self.assertEqual(
            str(error_event),
            "(DataValidatorEvent Severity.ERROR): type=ImmutableRowsValidator error=e2"
        )
        self.assertEqual(error_event, pickle.loads(pickle.dumps(error_event)))

        warning_event = DataValidatorEvent.UpdatedRowsValidator(
            severity=Severity.WARNING, message="m3")
        self.assertEqual(
            str(warning_event),
            "(DataValidatorEvent Severity.WARNING): type=UpdatedRowsValidator message=m3"
        )
        self.assertEqual(warning_event,
                         pickle.loads(pickle.dumps(warning_event)))

        info_event = DataValidatorEvent.DeletedRowsValidator(
            severity=Severity.NORMAL, message="m4")
        self.assertEqual(
            str(info_event),
            "(DataValidatorEvent Severity.NORMAL): type=DeletedRowsValidator message=m4"
        )
        self.assertEqual(info_event, pickle.loads(pickle.dumps(info_event)))
Beispiel #2
0
    def test_data_validator_event_msgfmt(self):
        critical_event = DataValidatorEvent.DataValidator(
            severity=Severity.ERROR, error="e1")
        critical_event.event_id = "3916da00-643c-4886-bdd0-963d3ebac536"
        self.assertEqual(
            str(critical_event),
            "(DataValidatorEvent Severity.ERROR) period_type=one-time "
            "event_id=3916da00-643c-4886-bdd0-963d3ebac536: type=DataValidator error=e1"
        )
        self.assertEqual(critical_event,
                         pickle.loads(pickle.dumps(critical_event)))

        error_event = DataValidatorEvent.ImmutableRowsValidator(
            severity=Severity.ERROR, error="e2")
        error_event.event_id = "3916da00-643c-4886-bdd0-963d3ebac536"
        self.assertEqual(
            str(error_event),
            "(DataValidatorEvent Severity.ERROR) period_type=one-time "
            "event_id=3916da00-643c-4886-bdd0-963d3ebac536: type=ImmutableRowsValidator error=e2"
        )
        self.assertEqual(error_event, pickle.loads(pickle.dumps(error_event)))

        warning_event = DataValidatorEvent.UpdatedRowsValidator(
            severity=Severity.WARNING, message="m3")
        warning_event.event_id = "3916da00-643c-4886-bdd0-963d3ebac536"
        self.assertEqual(
            str(warning_event),
            "(DataValidatorEvent Severity.WARNING) period_type=one-time "
            "event_id=3916da00-643c-4886-bdd0-963d3ebac536: type=UpdatedRowsValidator message=m3"
        )
        self.assertEqual(warning_event,
                         pickle.loads(pickle.dumps(warning_event)))

        info_event = DataValidatorEvent.DeletedRowsValidator(
            severity=Severity.NORMAL, message="m4")
        info_event.event_id = "3916da00-643c-4886-bdd0-963d3ebac536"
        self.assertEqual(
            str(info_event),
            "(DataValidatorEvent Severity.NORMAL) period_type=one-time "
            "event_id=3916da00-643c-4886-bdd0-963d3ebac536: type=DeletedRowsValidator message=m4"
        )
        self.assertEqual(info_event, pickle.loads(pickle.dumps(info_event)))
Beispiel #3
0
    def validate_range_not_expected_to_change(self,
                                              session,
                                              during_nemesis=False):
        """
        Part of data in the user profile table shouldn't be updated using LWT.
        This data will be saved in the materialized view with "not_updated" substring in the name
        After prepare write all data from this materialized view will be saved in the separate table as expected result.
        During stress (after prepare) LWT update statements will be run for a few hours.
        When updates will be finished this function verifies that data in "not_updated" MV and expected result table
        is same
        """

        if not (self._validate_not_updated_data
                and self.view_name_for_not_updated_data
                and self.expected_data_table_name):
            LOGGER.debug(
                'Verify immutable rows can\'t be performed as expected data has not been saved. '
                'See error above in the sct.log')
            return

        if not during_nemesis:
            LOGGER.debug('Verify immutable rows')

        actual_result = self.longevity_self_object.fetch_all_rows(
            session=session,
            default_fetch_size=self.DEFAULT_FETCH_SIZE,
            statement=f"SELECT * FROM {self.view_name_for_not_updated_data}",
            verbose=not during_nemesis)
        if not actual_result:
            DataValidatorEvent.ImmutableRowsValidator(
                severity=Severity.WARNING,
                message=f"Can't validate immutable rows. "
                f"Fetch all rows from {self.view_name_for_not_updated_data} failed. "
                f"See error above in the sct.log").publish()
            return

        expected_result = self.longevity_self_object.fetch_all_rows(
            session=session,
            default_fetch_size=self.DEFAULT_FETCH_SIZE,
            statement=f"SELECT * FROM {self.expected_data_table_name}",
            verbose=not during_nemesis)
        if not expected_result:
            DataValidatorEvent.ImmutableRowsValidator(
                severity=Severity.WARNING,
                message=
                f"Can't validate immutable rows. Fetch all rows from {self.expected_data_table_name} failed. "
                f"See error above in the sct.log").publish()
            return

        # Issue https://github.com/scylladb/scylla/issues/6181
        # Not fail the test if unexpected additional rows where found in actual result table
        if len(actual_result) > len(expected_result):
            DataValidatorEvent.ImmutableRowsValidator(
                severity=Severity.WARNING,
                message=
                f"Actual dataset length more then expected ({len(actual_result)} > {len(expected_result)}). "
                f"Issue #6181").publish()
        else:
            if not during_nemesis:
                assert len(actual_result) == len(expected_result), \
                    'One or more rows are not as expected, suspected LWT wrong update. ' \
                    'Actual dataset length: {}, Expected dataset length: {}'.format(len(actual_result),
                                                                                    len(expected_result))

                assert actual_result == expected_result, \
                    'One or more rows are not as expected, suspected LWT wrong update'

                # Raise info event at the end of the test only.
                DataValidatorEvent.ImmutableRowsValidator(
                    severity=Severity.NORMAL,
                    message="Validation immutable rows finished successfully"
                ).publish()
            else:
                if len(actual_result) < len(expected_result):
                    DataValidatorEvent.ImmutableRowsValidator(
                        severity=Severity.ERROR,
                        error=f"Verify immutable rows. "
                        f"One or more rows not found as expected, suspected LWT wrong update. "
                        f"Actual dataset length: {len(actual_result)}, "
                        f"Expected dataset length: {len(expected_result)}"
                    ).publish()
                else:
                    LOGGER.debug(
                        'Verify immutable rows. Actual dataset length: %s, Expected dataset length: %s',
                        len(actual_result), len(expected_result))