Skip to content

Commit

Permalink
test: add test for TTL
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Mar 22, 2024
1 parent 48ead30 commit f7acd64
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 52 deletions.
54 changes: 54 additions & 0 deletions tests/integration/adapter/clickhouse/test_clickhouse_table_ttl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import pytest
from dbt.tests.util import run_dbt
from dbt.tests.adapter.basic.test_base import BaseSimpleMaterializations
from dbt.tests.adapter.basic.files import model_base, schema_base_yml
from dbt.tests.util import (
relation_from_name,
run_dbt,
)
import time

class TestTableTTL(BaseSimpleMaterializations):
@pytest.fixture(scope="class")
def models(self):
config_materialized_table = """
{{ config(
order_by='(some_date, id, name)',
engine='MergeTree()',
materialized='table',
settings={'allow_nullable_key': 1},
ttl='some_date + INTERVAL 5 SECONDS'
query_settings={'allow_nondeterministic_mutations': 1})
}}
"""
base_table_sql = config_materialized_table + model_base
return {
"table_model.sql": base_table_sql,
"schema.yml": schema_base_yml,
}

def test_base(self, project):
# seed command
results = run_dbt(["seed"])
# seed result length
assert len(results) == 1

# run command
results = run_dbt()
# run result length
assert len(results) == 1

# base table rowcount
relation = relation_from_name(project.adapter, "table_model")
result = project.run_sql(f"select count(*) as num_rows from {relation}", fetch="one")
assert result[0] == 10

# wait for TTL to expire
time.sleep(6)

# optimize table
final = project.run_sql(f"OPTIMIZE TABLE {relation} FINAL")

# make sure is empty
result = project.run_sql(f"select count(*) as num_rows from {relation}", fetch="one")
assert result[0] == 0
14 changes: 0 additions & 14 deletions tests/integration/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,6 @@ services:
- "10743:8443"
- "10900:9000"
<<: *ch-common
ch1:
image: clickhouse/clickhouse-server:${DBT_CH_TEST_CH_VERSION:-latest}
environment:
- SERVER_INDEX=2
- SHARD_NUM=${SHARD_NUM:-2}
- REPLICA_NUM=${REPLICA_NUM:-2}
<<: *ch-common
ch2:
image: clickhouse/clickhouse-server:${DBT_CH_TEST_CH_VERSION:-latest}
environment:
- SERVER_INDEX=3
- SHARD_NUM=${SHARD_NUM:-3}
- REPLICA_NUM=${REPLICA_NUM:-3}
<<: *ch-common

networks:
default:
Expand Down
38 changes: 0 additions & 38 deletions tests/integration/test_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,6 @@
<replica from_env="REPLICA_NUM" />
<server_index from_env="SERVER_INDEX" />
</macros>
<remote_servers>
<test_shard>
<shard>
<replica>
<host>ch0</host>
<port>9000</port>
</replica>
</shard>
<shard>
<replica>
<host>ch1</host>
<port>9000</port>
</replica>
</shard>
<shard>
<replica>
<host>ch2</host>
<port>9000</port>
</replica>
</shard>
</test_shard>
<test_replica>
<shard>
<replica>
<host>ch0</host>
<port>9000</port>
</replica>
<replica>
<host>ch1</host>
<port>9000</port>
</replica>
<replica>
<host>ch2</host>
<port>9000</port>
</replica>
</shard>
</test_replica>
</remote_servers>
<keeper_server>
<tcp_port>9181</tcp_port>
<server_id from_env="SERVER_INDEX" />
Expand Down

0 comments on commit f7acd64

Please sign in to comment.