Exemple #1
0
def test_cache_connections() -> None:
    cluster_1 = cluster.ClickhouseCluster(
        "localhost", 8000, "default", "", "default", 8001, {"events"}, True
    )

    cluster_2 = cluster.ClickhouseCluster(
        "localhost", 8000, "default", "", "default", 8001, {"transactions"}, True
    )

    # Same node but different user
    cluster_3 = cluster.ClickhouseCluster(
        "localhost", 8000, "readonly", "", "default", 8001, {"metrics"}, True
    )

    assert cluster_1.get_query_connection(
        cluster.ClickhouseClientSettings.QUERY
    ) == cluster_1.get_query_connection(cluster.ClickhouseClientSettings.QUERY)

    assert cluster_1.get_node_connection(
        cluster.ClickhouseClientSettings.OPTIMIZE,
        cluster.ClickhouseNode("localhost", 8002),
    ) == cluster_1.get_node_connection(
        cluster.ClickhouseClientSettings.OPTIMIZE,
        cluster.ClickhouseNode("localhost", 8002),
    )

    assert cluster_1.get_query_connection(
        cluster.ClickhouseClientSettings.QUERY
    ) == cluster_2.get_query_connection(cluster.ClickhouseClientSettings.QUERY)

    # Does not share a connection since user is different
    assert cluster_1.get_query_connection(
        cluster.ClickhouseClientSettings.QUERY
    ) != cluster_3.get_query_connection(cluster.ClickhouseClientSettings.QUERY)
Exemple #2
0
def test_cache_connections() -> None:
    cluster_1 = cluster.ClickhouseCluster("localhost", 8000, "default", "",
                                          "default", 8001, {"events"}, True)

    assert cluster_1.get_query_connection(
        cluster.ClickhouseClientSettings.QUERY
    ) == cluster_1.get_query_connection(cluster.ClickhouseClientSettings.QUERY)

    assert cluster_1.get_node_connection(
        cluster.ClickhouseClientSettings.OPTIMIZE,
        cluster.ClickhouseNode("localhost", 8002),
    ) == cluster_1.get_node_connection(
        cluster.ClickhouseClientSettings.OPTIMIZE,
        cluster.ClickhouseNode("localhost", 8002),
    )