Ejemplo n.º 1
0
    def test_validate_number_in_interval_double(self):
        prod, cons = app.run(Config.K_MONITOR_TEST_TOPIC,
                             Config.PS_DATABASE_NAME,
                             Config.PS_TEST_WEBSITE_TABLE_NAME,
                             "tests/t_monitor_heavy_test.yml")

        interval = File.read_time_interval("tests/t_monitor_heavy_test.yml")

        time.sleep(interval * 2)

        app.stop_monitor(prod, cons)

        admin_client = KafkaAdminClient(
            bootstrap_servers=[Config.K_HOST + ':' + Config.K_PORT],
            security_protocol=Config.K_SECURITY_PROTOCOL,
            ssl_cafile=Config.K_SSL_CAT_FILE,
            ssl_certfile=Config.K_SSL_CERT_FILE,
            ssl_keyfile=Config.K_SSL_KEY_FILE)

        admin_client.delete_topics([Config.K_MONITOR_TEST_TOPIC])

        monitors = File.read_monitors("tests/t_monitor_heavy_test.yml")

        #send messages equals total urls count in 2 cycle is double the urls size
        self.assertEqual(prod.get_message_count(), len(monitors) * 2)
Ejemplo n.º 2
0
    def test_db(self):

        aiven_results = 0
        try:

            psql_conn = Database(Config.PS_DATABASE_NAME)

            print("DB Connected!")

            query = """ CREATE TABLE IF NOT EXISTS """ + Config.PS_TEST_WEBSITE_TABLE_NAME + """ (
                        name varchar(255) NOT NULL,
                        url varchar(255) NOT NULL,
                        status_code integer NOT NULL,
                        reason varchar(255) NOT NULL,
                        response_time decimal NOT NULL,
                        checked_at timestamp NOT NULL,
                        pattern varchar(255),
                        has_pattern boolean DEFAULT FALSE,
                        PRIMARY KEY(url, checked_at)
                    )  """

            psql_conn.query(query)
            print("Table created successfully in PostgreSQL ")

            query = "DELETE FROM " + Config.PS_TEST_WEBSITE_TABLE_NAME + " WHERE url = 'https://aiven.io'"
            psql_conn.query(query)

            prod, cons = app.run(Config.K_MONITOR_TOPIC,
                                 Config.PS_DATABASE_NAME,
                                 Config.PS_TEST_WEBSITE_TABLE_NAME,
                                 "tests/t_monitor_db.yml")

            print("all 'aiven.io' is deleted from PostgreSQL ")

            interval = File.read_time_interval("tests/t_monitor_corrupted.yml")

            time.sleep(interval - 1)

            app.stop_monitor(prod, cons)

            query = "SELECT * FROM " + Config.PS_TEST_WEBSITE_TABLE_NAME + " WHERE url = 'https://aiven.io'"
            cursor = psql_conn.query(query)
            aiven_results = cursor.fetchall()

            psql_conn = Database(Config.PS_DATABASE_NAME)
            query = "DROP TABLE " + Config.PS_TEST_WEBSITE_TABLE_NAME
            psql_conn.query(query)
            psql_conn.close()

        except Exception as error:
            print("Error while connecting to PostgreSQL", error)

        self.assertEqual(len(aiven_results), 1)
Ejemplo n.º 3
0
def run(topic: str, db: str, table: str, filepath=None):
    if not filepath:
        filepath = Config.MONITERFILE

    interval = File.read_time_interval(filepath)
    monitors = File.read_monitors(filepath)

    producer = Producer(topic, interval)

    consumer = Consumer(topic, db, table)

    start_mointoring(monitors, producer, consumer)

    return producer, consumer
Ejemplo n.º 4
0
    def test_producer_equal_consumer(self):
        prod, cons = app.run(Config.K_MONITOR_TEST_TOPIC,
                             Config.PS_DATABASE_NAME,
                             Config.PS_TEST_WEBSITE_TABLE_NAME)

        interval = File.read_time_interval()

        time.sleep(interval - 1)

        app.stop_monitor(prod, cons)

        admin_client = KafkaAdminClient(
            bootstrap_servers=[Config.K_HOST + ':' + Config.K_PORT],
            security_protocol=Config.K_SECURITY_PROTOCOL,
            ssl_cafile=Config.K_SSL_CAT_FILE,
            ssl_certfile=Config.K_SSL_CERT_FILE,
            ssl_keyfile=Config.K_SSL_KEY_FILE)

        admin_client.delete_topics([Config.K_MONITOR_TEST_TOPIC])
        self.assertEqual(prod.get_message_count(), cons.get_message_count())