Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
swalrus1 committed Aug 19, 2024
1 parent b793a07 commit 75e815e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 14 deletions.
32 changes: 32 additions & 0 deletions ydb/tests/olap/scenario/helpers/tiering_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ def to_yql(self, ctx: TestContext) -> str:
f' WITH (defaultColumn = {self._default_column}, description = `{self._config.to_json()}`)'


class CreateTieringRuleIfNotExists(AlterTieringRule):
"""Create a tiering rule. If it exists, do nothing.
See {ScenarioTestHelper.IYqlble}.
"""

@override
def title(self):
return 'Create tiering rule'

@override
def to_yql(self, ctx: TestContext) -> str:
return f'CREATE OBJECT IF NOT EXISTS `{self._name}` (TYPE TIERING_RULE)' \
f' WITH (defaultColumn = {self._default_column}, description = `{self._config.to_json()}`)'


class AlterTier(ScenarioTestHelper.IYqlble):
"""Alter a tier.
Expand Down Expand Up @@ -161,6 +177,22 @@ def to_yql(self, ctx: TestContext) -> str:
return f'CREATE OBJECT `{self._name}` (TYPE TIER) WITH (tierConfig = `{self._config.to_proto_str()}`)'


class CreateTierIfNotExists(AlterTier):
"""Create a tier. If it exists, do nothing.
See {ScenarioTestHelper.IYqlble}.
"""

@override
def title(self):
return 'Create tier'

@override
def to_yql(self, ctx: TestContext) -> str:
return f'CREATE OBJECT IF NOT EXISTS `{self._name}` (TYPE TIER)' \
f' WITH (tierConfig = `{self._config.to_proto_str()}`)'


class DropObjectBase(ScenarioTestHelper.IYqlble):
"""Drop a tier.
Expand Down
22 changes: 8 additions & 14 deletions ydb/tests/olap/scenario/test_alter_tiering.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
from helpers.tiering_helper import (
ObjectStorageParams,
AlterTier,
CreateTier,
CreateTierIfNotExists,
AlterTieringRule,
CreateTieringRule,
CreateTieringRuleIfNotExists,
TierConfig,
TieringPolicy,
TieringRule,
Expand Down Expand Up @@ -118,15 +118,8 @@ def scenario_alter_tiering_rule_while_writing(self, ctx: TestContext):
tier_config = TierConfig(tiers[-1], s3_config)
tiering_config = TieringPolicy().with_rule(TieringRule(tiers[-1], '1s'))

# If the tier exists, allow CREATE to fail, then alter it
sth.execute_scheme_query(
CreateTier(tiers[-1], tier_config),
expected_status={StatusCode.SUCCESS, StatusCode.GENERIC_ERROR},
)
sth.execute_scheme_query(
CreateTieringRule(tiering_rules[-1], 'timestamp', tiering_config),
expected_status={StatusCode.SUCCESS, StatusCode.GENERIC_ERROR},
)
sth.execute_scheme_query(CreateTierIfNotExists(tiers[-1], tier_config))
sth.execute_scheme_query(CreateTieringRuleIfNotExists(tiering_rules[-1], 'timestamp', tiering_config))

sth.execute_scheme_query(AlterTier(tiers[-1], tier_config))
sth.execute_scheme_query(AlterTieringRule(tiering_rules[-1], 'timestamp', tiering_config))
Expand All @@ -140,8 +133,9 @@ def scenario_alter_tiering_rule_while_writing(self, ctx: TestContext):
target=self._change_tiering_rule,
args=[ctx, 'store/table', tiering_rules, test_duration]
))
writer_id_offset = random.randint(0, 1 << 30)
for i in range(4):
threads.append(self.TestThread(target=self._upsert, args=[ctx, 'store/table', i, test_duration]))
threads.append(self.TestThread(target=self._upsert, args=[ctx, 'store/table', writer_id_offset + i, test_duration]))

for thread in threads:
thread.start()
Expand All @@ -153,8 +147,8 @@ def scenario_alter_tiering_rule_while_writing(self, ctx: TestContext):
for tier in tiers:
sth.execute_scheme_query(DropTier(tier))

sth.execute_scheme_query(AlterTable('store/table').set_ttl('P1D'))
sth.execute_scheme_query(AlterTable('store/table').set_ttl('P1D', 'timestamp'))

while sth.execute_scan_query(f'SELECT COUNT(*) FROM `{sth.get_full_path('store/table')}`').result_set[0][0]:
while sth.execute_scan_query(f'SELECT COUNT(*) FROM `{sth.get_full_path('store/table')}`').result_set.rows[0][0]:
time.sleep(10)

0 comments on commit 75e815e

Please sign in to comment.