Ejemplo n.º 1
0
    def report_summary(self):
        # Gather statistics
        summary = "\n-------------------------------------------------------------------\n"
        summary += "Summary\n"
        summary += "Histogram of number of attempts needed to successfully register:\n"
        summary += str(self.register_driver.try_histogram) + "\n"

        attempted = self.register_driver.num_attempted_registrations
        succeeded = sum([1 for record in self.register_driver.registration_data if record["success"]])
        summary += "Attempted to register %d schemas. " % attempted + "\n"
        summary += "Max registration attempts allowed: %d\n" % self.num_retries
        summary += "Retry backoff: %f seconds\n" % self.retry_wait_sec
        summary += "Successful: %d/%d = %f\n" % (succeeded, attempted, succeeded / float(attempted))

        success = True

        # Verify that all ids reported as successfully registered can be fetched
        master_id = self.schema_registry.idx(self.schema_registry.get_master_node())
        base_url = self.schema_registry.url(master_id, external=True)
        registered_ids = [record["schema_id"] for record in self.register_driver.registration_data if record["success"]]
        registered_schemas = [record["schema_string"]
                              for record in self.register_driver.registration_data if record["success"]]
        summary += "Validating that schemas reported as successful can be fetched by id...\n"
        for id in registered_ids:
            try:
                schema = get_schema_by_id(base_url, id)
            except:
                success = False
                summary += "%d was reported successful but actually failed\n" % id
        summary += "Success.\n" if success else "Failure.\n"

        # Verify that number of versions fetched matches number of registered ids
        versions = get_all_versions(base_url, self.register_driver.subject)
        summary += \
            "Validating that number of reported successful registrations matches number of versions in subject...\n"
        if len(versions) != len(registered_ids):
            success = False
        summary += "Success.\n" if success else "Failure.\n"

        results = self.validate_schema_consistency()
        summary += results["message"] + "\n"
        success = success and results["success"]

        results = self.validate_registered_vs_subjectversion()
        summary += results["message"] + "\n"
        success = success and results["success"]

        results = self.validate_registered_vs_subjectschema()
        summary += results["message"] + "\n"
        success = success and results["success"]

        summary += "-------------------------------------------------------------------\n"
        assert success, summary
        self.logger.info(summary)
Ejemplo n.º 2
0
    def report_summary(self):
        # Gather statistics
        summary = "\n-------------------------------------------------------------------\n"
        summary += "Summary\n"
        summary += "Histogram of number of attempts needed to successfully register:\n"
        summary += str(self.register_driver.try_histogram) + "\n"

        attempted = self.register_driver.num_attempted_registrations
        succeeded = sum([1 for record in self.register_driver.registration_data if record["success"]])
        summary += "Attempted to register %d schemas. " % attempted + "\n"
        summary += "Max registration attempts allowed: %d\n" % self.num_retries
        summary += "Retry backoff: %f seconds\n" % self.retry_wait_sec
        summary += "Successful: %d/%d = %f\n" % (succeeded, attempted, succeeded / float(attempted))

        success = True

        # Verify that all ids reported as successfully registered can be fetched
        master_id = self.schema_registry.idx(self.schema_registry.get_master_node())
        base_url = self.schema_registry.url(master_id, external=True)
        registered_ids = [record["schema_id"] for record in self.register_driver.registration_data if record["success"]]
        registered_schemas = [record["schema_string"]
                              for record in self.register_driver.registration_data if record["success"]]
        summary += "Validating that schemas reported as successful can be fetched by id...\n"
        for id in registered_ids:
            try:
                schema = get_schema_by_id(base_url, id)
            except:
                success = False
                summary += "%d was reported successful but actually failed\n" % id
        summary += "Success.\n" if success else "Failure.\n"

        # Verify that number of versions fetched matches number of registered ids
        versions = get_all_versions(base_url, self.register_driver.subject)
        summary += \
            "Validating that number of reported successful registrations matches number of versions in subject...\n"
        if len(versions) != len(registered_ids):
            success = False
        summary += "Success.\n" if success else "Failure.\n"

        results = self.validate_schema_consistency()
        summary += results["message"] + "\n"
        success = success and results["success"]

        results = self.validate_registered_vs_subjectversion()
        summary += results["message"] + "\n"
        success = success and results["success"]

        results = self.validate_registered_vs_subjectschema()
        summary += results["message"] + "\n"
        success = success and results["success"]

        summary += "-------------------------------------------------------------------\n"
        assert success, summary
        self.logger.info(summary)
Ejemplo n.º 3
0
    def validate_schema_consistency(self):
        """
        Much of the use case involves
        a) register a schema, get back an id
        b) sometime later, someone else fetches the schema by id

        Therefore, verify that the id we get back for registering a particular schema still gets us
        back that same particular schema.
        """
        master_id = self.schema_registry.idx(
            self.schema_registry.get_master_node())
        base_url = self.schema_registry.url(master_id, external=True)

        registration_data = self.register_driver.registration_data
        message = "Validating that registered schemas match fetched schemas...\n"
        discrepencies = []
        success = True
        for datum in registration_data:
            id = datum["schema_id"]
            schema = self.normalize_schema_string(datum["schema_string"])

            try:
                found_schema = self.normalize_schema_string(
                    get_schema_by_id(base_url, id)["schema"])
            except:
                success = False
                message += "Failed to fetch id %d. " % id

            if found_schema != schema:
                discrepencies.append((id, schema, found_schema))

        success = success and len(discrepencies) == 0
        if len(discrepencies) > 0:
            message += "Found discrepencies between registered schemas and fetched schemas (id, registered, fetched). "
            message += str(discrepencies)

        message += "Success." if success else "Failure."
        return {"success": success, "message": message}
Ejemplo n.º 4
0
    def validate_schema_consistency(self):
        """
        Much of the use case involves
        a) register a schema, get back an id
        b) sometime later, someone else fetches the schema by id

        Therefore, verify that the id we get back for registering a particular schema still gets us
        back that same particular schema.
        """
        master_id = self.schema_registry.idx(self.schema_registry.get_master_node())
        base_url = self.schema_registry.url(master_id, external=True)

        registration_data = self.register_driver.registration_data
        message = "Validating that registered schemas match fetched schemas...\n"
        discrepencies = []
        success = True
        for datum in registration_data:
            id = datum["schema_id"]
            schema = self.normalize_schema_string(datum["schema_string"])

            try:
                found_schema = self.normalize_schema_string(get_schema_by_id(base_url, id)["schema"])
            except:
                success = False
                message += "Failed to fetch id %d. " % id

            if found_schema != schema:
                discrepencies.append((id, schema, found_schema))

        success = success and len(discrepencies) == 0
        if len(discrepencies) > 0:
            message += "Found discrepencies between registered schemas and fetched schemas (id, registered, fetched). "
            message += str(discrepencies)

        message += "Success." if success else "Failure."
        return {"success": success, "message": message}