def test_compose_serialize():
    url = "url"
    username = "******"
    password = "******"
    client = ReliableHttpClient(url, {}, username, password, retry_policy)

    assert client.connection_string == get_connection_string(url, username, password)
def test_build_session_with_defaults():
    factory = LivyClientFactory()
    connection_string = get_connection_string("url", "user", "pass")
    language = "python"

    session = factory.create_session(language, connection_string)

    assert session.language == language
    assert session.id == "-1"
    assert session.started_sql_context is False
Exemplo n.º 3
0
    def _initialize_magics(self, username, password, url):
        connection_string = get_connection_string(url, username, password)

        register_magics_code = "%load_ext remotespark"
        self._execute_cell(register_magics_code, True, False, shutdown_if_error=True,
                           log_if_error="Failed to load the Spark magics library.")
        self.logger.debug("Loaded magics.")

        add_endpoint_code = "%spark add {} {} {} skip".format(
            self.client_name, self.session_language, connection_string)
        self._execute_cell(add_endpoint_code, True, False, shutdown_if_error=True,
                           log_if_error="Failed to create a Livy session.")
        self.logger.debug("Added endpoint.")

        self.already_ran_once = True
Exemplo n.º 4
0
def test_initialize_magics():
    # Set up
    usr = "******"
    pwd = "p"
    url = "url"
    conn_str = get_connection_string(url, usr, pwd)

    # Call method
    assert not kernel.already_ran_once
    kernel._initialize_magics(usr, pwd, url)

    # Assertions
    assert kernel.already_ran_once
    expected = [call("%spark add TestKernel python {} skip".format(conn_str), True, False, None, False),
                call("%load_ext remotespark", True, False, None, False)]
    for kall in expected:
        assert kall in execute_cell_mock.mock_calls
Exemplo n.º 5
0
    def test_serialize(self):
        url = "url"
        username = "******"
        password = "******"
        connection_string = get_connection_string(url, username, password)
        http_client = MagicMock()
        http_client.connection_string = connection_string
        kind = "scala"
        _t_config_hook({
            "status_sleep_seconds": 0.01,
            "statement_sleep_seconds": 0.01
        })
        session = LivySession(http_client, kind, "-1", False)
        _t_config_hook({})

        serialized = session.get_state().to_dict()

        assert serialized["connectionstring"] == connection_string
        assert serialized["id"] == "-1"
        assert serialized["language"] == kind
        assert serialized["sqlcontext"] == False
        assert serialized["version"] == "0.0.0"
        assert len(serialized.keys()) == 5
Exemplo n.º 6
0
def test_serialize():
    url = "url"
    username = "******"
    password = "******"
    connection_string = get_connection_string(url, username, password)
    http_client = MagicMock()
    http_client.connection_string = connection_string
    kind = "scala"
    session_id = "-1"
    sql_created = False
    session = MagicMock()
    session.get_state.return_value = LivySessionState(session_id, connection_string, kind, sql_created)

    client = LivyClient(session)

    serialized = client.serialize()

    assert serialized["connectionstring"] == connection_string
    assert serialized["id"] == "-1"
    assert serialized["language"] == kind
    assert serialized["sqlcontext"] == sql_created
    assert serialized["version"] == "0.0.0"
    assert len(serialized.keys()) == 5
Exemplo n.º 7
0
def test_do_execute_initializes_magics_if_not_run():
    # Set up
    usr = "******"
    pwd = "p"
    url = "url"
    conn_str = get_connection_string(url, usr, pwd)
    config_mock = MagicMock()
    config_mock.return_value = (usr, pwd, url)

    kernel._get_configuration = config_mock

    code = "code"

    # Call method
    assert not kernel.already_ran_once
    kernel.do_execute(code, False)

    # Assertions
    assert kernel.already_ran_once
    assert call("%spark add TestKernel python {} skip"
                .format(conn_str), True, False, None, False) in execute_cell_mock.mock_calls
    assert call("%load_ext remotespark", True, False, None, False) in execute_cell_mock.mock_calls
    assert call("%%spark\n{}".format(code), False, True, None, False) in execute_cell_mock.mock_calls
def test_obj_to_str():
    cs = csutil.get_connection_string(host, "user", "pass")
    assert_equals(connection_string, cs)