Exemple #1
0
def run(endpoint, database, path):
    driver_config = ydb.DriverConfig(
        endpoint,
        database,
        credentials=ydb.construct_credentials_from_environ())
    with ydb.Driver(driver_config) as driver:
        try:
            driver.wait(timeout=5)
        except TimeoutError:
            print("Connect failed to YDB")
            print("Last reported errors by discovery:")
            print(driver.discovery_debug_details())
            exit(1)

        with ydb.SessionPool(driver, size=10) as session_pool:
            ensure_path_exists(driver, database, path)

            full_path = os.path.join(database, path)

            create_tables(session_pool, full_path)

            describe_table(session_pool, full_path, "series")

            fill_tables_with_data(session_pool, full_path)

            select_simple(session_pool, full_path)

            upsert_simple(session_pool, full_path)

            select_prepared(session_pool, full_path, 2, 3, 7)
            select_prepared(session_pool, full_path, 2, 3, 8)

            explicit_tcl(session_pool, full_path, 2, 6, 1)
            select_prepared(session_pool, full_path, 2, 6, 1)
def run(endpoint, database, path):
    driver_config = ydb.DriverConfig(endpoint, database, credentials=ydb.construct_credentials_from_environ())
    with ydb.Driver(driver_config) as driver:
        try:
            driver.wait(timeout=5)
        except TimeoutError:
            print("Connect failed to YDB")
            print("Last reported errors by discovery:")
            print(driver.discovery_debug_details())
            exit(1)

        with ydb.SessionPool(driver, size=10) as session_pool:
            ensure_path_exists(driver, database, path)

            create_tables(session_pool, path)

            fill_data(session_pool, path)

            peter_series = select_by_username(session_pool, path, "Peter Dinklage")

            assert len(peter_series) == 2

            emilia_series = select_by_username(session_pool, path, "Emilia Clarke")

            assert len(emilia_series) == 3
def run(endpoint, database, path):
    driver_config = ydb.DriverConfig(endpoint,
                                     database=database,
                                     credentials=credentials_from_environ())

    try:
        driver = ydb.Driver(driver_config)
        driver.wait(timeout=5)
        session_pool = ydb.SessionPool(driver, size=10)
    except TimeoutError:
        raise RuntimeError("Connect failed to YDB")

    try:
        ensure_path_exists(driver, database, path)

        create_tables(session_pool, database)

        describe_table(session_pool, database, "series")

        fill_tables_with_data(session_pool, database)

        select_simple(session_pool, database)

        upsert_simple(session_pool, database)

        select_prepared(session_pool, database, 2, 3, 7)
        select_prepared(session_pool, database, 2, 3, 8)

        explicit_tcl(session_pool, database, 2, 6, 1)
        select_prepared(session_pool, database, 2, 6, 1)

    finally:

        session_pool.stop()
        driver.stop()
Exemple #4
0
def run(endpoint, database, path):
    driver_config = ydb.DriverConfig(
        endpoint,
        database,
        credentials=ydb.construct_credentials_from_environ())
    with ydb.Driver(driver_config) as driver:
        try:
            driver.wait(timeout=5)
        except TimeoutError:
            raise RuntimeError("Connect failed to YDB")

        with ydb.SessionPool(driver, size=10) as session_pool:
            _run(driver, session_pool, database, path)
Exemple #5
0
def run(endpoint, database, path, auth_token):
    driver_config = ydb.DriverConfig(endpoint,
                                     database=database,
                                     auth_token=auth_token)
    try:
        driver = ydb.Driver(driver_config)
        driver.wait(timeout=5)
        session_pool = ydb.SessionPool(driver, size=10)
    except TimeoutError:
        raise RuntimeError("Connect failed to YDB")

    try:

        _run(driver, session_pool, database, path)
    finally:

        session_pool.stop()
        driver.stop()
Exemple #6
0
def session_pool_context(driver_config: ydb.DriverConfig,
                         size=1,
                         workers_threads_count=1):
    with ydb.Driver(driver_config) as driver:
        try:
            logging.info("connecting to the database")
            driver.wait(timeout=15)
        except TimeoutError:
            logging.critical(
                f"connection failed\n"
                f"last reported errors by discovery: {driver.discovery_debug_details()}"
            )
            raise
        with ydb.SessionPool(
                driver, size=size,
                workers_threads_count=workers_threads_count) as session_pool:
            try:
                yield session_pool
            except Exception as e:
                logging.critical(
                    f"failed to create session pool due to {repr(e)}")