123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- # Copyright Materialize, Inc. and contributors. All rights reserved.
- #
- # Use of this software is governed by the Business Source License
- # included in the LICENSE file at the root of this repository.
- #
- # As of the Change Date specified in that file, in accordance with
- # the Business Source License, use of this software will be governed
- # by the Apache License, Version 2.0.
- from textwrap import dedent
- from materialize.checks.actions import Testdrive
- from materialize.checks.checks import Check
- class CreateCluster(Check):
- def manipulate(self) -> list[Testdrive]:
- # This list MUST be of length 2.
- return [
- Testdrive(dedent(s))
- for s in [
- """
- $ postgres-execute connection=postgres://mz_system@${testdrive.materialize-internal-sql-addr}
- GRANT CREATECLUSTER ON SYSTEM TO materialize
- > CREATE CLUSTER create_cluster1 REPLICAS (replica1 (SIZE '2-2'));
- """,
- """
- $ postgres-execute connection=postgres://mz_system@${testdrive.materialize-internal-sql-addr}
- GRANT CREATECLUSTER ON SYSTEM TO materialize
- > CREATE CLUSTER create_cluster2 (SIZE '2-2', REPLICATION FACTOR 1);
- """,
- ]
- ]
- def validate(self) -> Testdrive:
- return Testdrive(
- dedent(
- """
- $ set-sql-timeout duration=240s
- > CREATE TABLE create_cluster1_table (f1 INTEGER);
- > CREATE TABLE create_cluster2_table (f1 INTEGER);
- > INSERT INTO create_cluster1_table VALUES (123);
- > INSERT INTO create_cluster2_table VALUES (234);
- > SET cluster=create_cluster1
- > CREATE DEFAULT INDEX ON create_cluster1_table;
- > CREATE MATERIALIZED VIEW create_cluster1_view AS SELECT SUM(f1) FROM create_cluster1_table;
- > SELECT * FROM create_cluster1_table;
- 123
- > SELECT * FROM create_cluster1_view;
- 123
- > SET cluster=create_cluster2
- > CREATE DEFAULT INDEX ON create_cluster2_table;
- > CREATE MATERIALIZED VIEW create_cluster2_view AS SELECT SUM(f1) FROM create_cluster2_table;
- > SELECT * FROM create_cluster2_table;
- 234
- > SELECT * FROM create_cluster2_view;
- 234
- ! SHOW CREATE CLUSTER create_cluster1;
- contains: SHOW CREATE for unmanaged clusters not yet supported
- > SHOW CREATE CLUSTER create_cluster2;
- create_cluster2 "CREATE CLUSTER \\"create_cluster2\\" (DISK = true, INTROSPECTION DEBUGGING = false, INTROSPECTION INTERVAL = INTERVAL '00:00:01', MANAGED = true, REPLICATION FACTOR = 1, SIZE = '2-2', SCHEDULE = MANUAL)"
- > DROP TABLE create_cluster1_table CASCADE;
- > DROP TABLE create_cluster2_table CASCADE;
- """
- )
- )
- class AlterCluster(Check):
- def manipulate(self) -> list[Testdrive]:
- return [
- Testdrive(dedent(s))
- for s in [
- """
- > CREATE CLUSTER alter_cluster1 REPLICAS (r1 (SIZE '2-2'));
- > CREATE TABLE alter_cluster1_table (f1 INTEGER);
- > INSERT INTO alter_cluster1_table VALUES (123);
- > SET cluster=alter_cluster1
- > CREATE DEFAULT INDEX ON alter_cluster1_table;
- > CREATE MATERIALIZED VIEW alter_cluster1_view AS SELECT SUM(f1) FROM alter_cluster1_table;
- """,
- """
- > ALTER CLUSTER alter_cluster1 SET (MANAGED);
- > ALTER CLUSTER alter_cluster1 SET (introspection debugging = TRUE, introspection interval = '45s');
- """,
- ]
- ]
- def validate(self) -> Testdrive:
- return Testdrive(
- dedent(
- """
- > SET cluster=default
- > SELECT * FROM alter_cluster1_table;
- 123
- > SELECT * FROM alter_cluster1_view;
- 123
- > SET cluster=alter_cluster1
- > SELECT * FROM alter_cluster1_table;
- 123
- > SELECT * FROM alter_cluster1_view;
- 123
- > SHOW CREATE CLUSTER alter_cluster1;
- alter_cluster1 "CREATE CLUSTER \\"alter_cluster1\\" (DISK = true, INTROSPECTION DEBUGGING = true, INTROSPECTION INTERVAL = INTERVAL '00:00:45', MANAGED = true, REPLICATION FACTOR = 1, SIZE = '2-2', SCHEDULE = MANUAL)"
- > SELECT name, introspection_debugging, introspection_interval FROM mz_catalog.mz_clusters WHERE name = 'alter_cluster1';
- alter_cluster1 true "00:00:45"
- """
- )
- )
- class DropCluster(Check):
- def manipulate(self) -> list[Testdrive]:
- return [
- Testdrive(dedent(s))
- for s in [
- """
- > CREATE TABLE drop_cluster1_table (f1 INTEGER);
- > CREATE TABLE drop_cluster2_table (f1 INTEGER);
- > INSERT INTO drop_cluster1_table VALUES (123);
- > INSERT INTO drop_cluster2_table VALUES (234);
- > CREATE CLUSTER drop_cluster1 REPLICAS (replica1 (SIZE '2-2'));
- > CREATE CLUSTER drop_cluster2 REPLICAS (replica1 (SIZE '2-2'));
- > SET cluster=drop_cluster1
- > CREATE DEFAULT INDEX ON drop_cluster1_table;
- > CREATE MATERIALIZED VIEW drop_cluster1_view AS SELECT SUM(f1) FROM drop_cluster1_table;
- > SET cluster=drop_cluster2
- > CREATE DEFAULT INDEX ON drop_cluster2_table;
- > CREATE MATERIALIZED VIEW drop_cluster2_view AS SELECT SUM(f1) FROM drop_cluster2_table;
- > DROP CLUSTER drop_cluster1 CASCADE;
- """,
- """
- > DROP CLUSTER drop_cluster2 CASCADE;
- """,
- ]
- ]
- def validate(self) -> Testdrive:
- return Testdrive(
- dedent(
- """
- > SET cluster=drop_cluster1
- > SET cluster=drop_cluster2
- > SET cluster=default
- > SELECT * FROM drop_cluster1_table;
- 123
- ! SELECT * FROM drop_cluster1_view;
- contains: unknown catalog item 'drop_cluster1_view'
- > SELECT * FROM drop_cluster2_table;
- 234
- ! SELECT * FROM drop_cluster2_view;
- contains: unknown catalog item 'drop_cluster2_view'
- """
- )
- )
|