cluster.py 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. from textwrap import dedent
  10. from materialize.checks.actions import Testdrive
  11. from materialize.checks.checks import Check
  12. class CreateCluster(Check):
  13. def manipulate(self) -> list[Testdrive]:
  14. # This list MUST be of length 2.
  15. return [
  16. Testdrive(dedent(s))
  17. for s in [
  18. """
  19. $ postgres-execute connection=postgres://mz_system@${testdrive.materialize-internal-sql-addr}
  20. GRANT CREATECLUSTER ON SYSTEM TO materialize
  21. > CREATE CLUSTER create_cluster1 REPLICAS (replica1 (SIZE '2-2'));
  22. """,
  23. """
  24. $ postgres-execute connection=postgres://mz_system@${testdrive.materialize-internal-sql-addr}
  25. GRANT CREATECLUSTER ON SYSTEM TO materialize
  26. > CREATE CLUSTER create_cluster2 (SIZE '2-2', REPLICATION FACTOR 1);
  27. """,
  28. ]
  29. ]
  30. def validate(self) -> Testdrive:
  31. return Testdrive(
  32. dedent(
  33. """
  34. $ set-sql-timeout duration=240s
  35. > CREATE TABLE create_cluster1_table (f1 INTEGER);
  36. > CREATE TABLE create_cluster2_table (f1 INTEGER);
  37. > INSERT INTO create_cluster1_table VALUES (123);
  38. > INSERT INTO create_cluster2_table VALUES (234);
  39. > SET cluster=create_cluster1
  40. > CREATE DEFAULT INDEX ON create_cluster1_table;
  41. > CREATE MATERIALIZED VIEW create_cluster1_view AS SELECT SUM(f1) FROM create_cluster1_table;
  42. > SELECT * FROM create_cluster1_table;
  43. 123
  44. > SELECT * FROM create_cluster1_view;
  45. 123
  46. > SET cluster=create_cluster2
  47. > CREATE DEFAULT INDEX ON create_cluster2_table;
  48. > CREATE MATERIALIZED VIEW create_cluster2_view AS SELECT SUM(f1) FROM create_cluster2_table;
  49. > SELECT * FROM create_cluster2_table;
  50. 234
  51. > SELECT * FROM create_cluster2_view;
  52. 234
  53. ! SHOW CREATE CLUSTER create_cluster1;
  54. contains: SHOW CREATE for unmanaged clusters not yet supported
  55. > SHOW CREATE CLUSTER create_cluster2;
  56. 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)"
  57. > DROP TABLE create_cluster1_table CASCADE;
  58. > DROP TABLE create_cluster2_table CASCADE;
  59. """
  60. )
  61. )
  62. class AlterCluster(Check):
  63. def manipulate(self) -> list[Testdrive]:
  64. return [
  65. Testdrive(dedent(s))
  66. for s in [
  67. """
  68. > CREATE CLUSTER alter_cluster1 REPLICAS (r1 (SIZE '2-2'));
  69. > CREATE TABLE alter_cluster1_table (f1 INTEGER);
  70. > INSERT INTO alter_cluster1_table VALUES (123);
  71. > SET cluster=alter_cluster1
  72. > CREATE DEFAULT INDEX ON alter_cluster1_table;
  73. > CREATE MATERIALIZED VIEW alter_cluster1_view AS SELECT SUM(f1) FROM alter_cluster1_table;
  74. """,
  75. """
  76. > ALTER CLUSTER alter_cluster1 SET (MANAGED);
  77. > ALTER CLUSTER alter_cluster1 SET (introspection debugging = TRUE, introspection interval = '45s');
  78. """,
  79. ]
  80. ]
  81. def validate(self) -> Testdrive:
  82. return Testdrive(
  83. dedent(
  84. """
  85. > SET cluster=default
  86. > SELECT * FROM alter_cluster1_table;
  87. 123
  88. > SELECT * FROM alter_cluster1_view;
  89. 123
  90. > SET cluster=alter_cluster1
  91. > SELECT * FROM alter_cluster1_table;
  92. 123
  93. > SELECT * FROM alter_cluster1_view;
  94. 123
  95. > SHOW CREATE CLUSTER alter_cluster1;
  96. 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)"
  97. > SELECT name, introspection_debugging, introspection_interval FROM mz_catalog.mz_clusters WHERE name = 'alter_cluster1';
  98. alter_cluster1 true "00:00:45"
  99. """
  100. )
  101. )
  102. class DropCluster(Check):
  103. def manipulate(self) -> list[Testdrive]:
  104. return [
  105. Testdrive(dedent(s))
  106. for s in [
  107. """
  108. > CREATE TABLE drop_cluster1_table (f1 INTEGER);
  109. > CREATE TABLE drop_cluster2_table (f1 INTEGER);
  110. > INSERT INTO drop_cluster1_table VALUES (123);
  111. > INSERT INTO drop_cluster2_table VALUES (234);
  112. > CREATE CLUSTER drop_cluster1 REPLICAS (replica1 (SIZE '2-2'));
  113. > CREATE CLUSTER drop_cluster2 REPLICAS (replica1 (SIZE '2-2'));
  114. > SET cluster=drop_cluster1
  115. > CREATE DEFAULT INDEX ON drop_cluster1_table;
  116. > CREATE MATERIALIZED VIEW drop_cluster1_view AS SELECT SUM(f1) FROM drop_cluster1_table;
  117. > SET cluster=drop_cluster2
  118. > CREATE DEFAULT INDEX ON drop_cluster2_table;
  119. > CREATE MATERIALIZED VIEW drop_cluster2_view AS SELECT SUM(f1) FROM drop_cluster2_table;
  120. > DROP CLUSTER drop_cluster1 CASCADE;
  121. """,
  122. """
  123. > DROP CLUSTER drop_cluster2 CASCADE;
  124. """,
  125. ]
  126. ]
  127. def validate(self) -> Testdrive:
  128. return Testdrive(
  129. dedent(
  130. """
  131. > SET cluster=drop_cluster1
  132. > SET cluster=drop_cluster2
  133. > SET cluster=default
  134. > SELECT * FROM drop_cluster1_table;
  135. 123
  136. ! SELECT * FROM drop_cluster1_view;
  137. contains: unknown catalog item 'drop_cluster1_view'
  138. > SELECT * FROM drop_cluster2_table;
  139. 234
  140. ! SELECT * FROM drop_cluster2_view;
  141. contains: unknown catalog item 'drop_cluster2_view'
  142. """
  143. )
  144. )