managed_cluster.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 CreateManagedCluster(Check):
  13. def manipulate(self) -> list[Testdrive]:
  14. return [
  15. Testdrive(dedent(s))
  16. for s in [
  17. """
  18. >[version>=13800] CREATE CLUSTER create_managed_cluster1 SIZE '2-2', REPLICATION FACTOR 2;
  19. >[version<13800] CREATE CLUSTER create_managed_cluster1 SIZE '2-2', REPLICATION FACTOR 1;
  20. """,
  21. """
  22. >[version>=13800] CREATE CLUSTER create_managed_cluster2 SIZE '2-2', REPLICATION FACTOR 2;
  23. >[version<13800] CREATE CLUSTER create_managed_cluster2 SIZE '2-2', REPLICATION FACTOR 1;
  24. """,
  25. ]
  26. ]
  27. def validate(self) -> Testdrive:
  28. return Testdrive(
  29. dedent(
  30. """
  31. > CREATE TABLE create_managed_cluster1_table (f1 INTEGER);
  32. > CREATE TABLE create_managed_cluster2_table (f1 INTEGER);
  33. > INSERT INTO create_managed_cluster1_table VALUES (123);
  34. > INSERT INTO create_managed_cluster2_table VALUES (234);
  35. > SET cluster=create_managed_cluster1
  36. > CREATE DEFAULT INDEX ON create_managed_cluster1_table;
  37. > CREATE MATERIALIZED VIEW create_managed_cluster1_view AS SELECT SUM(f1) FROM create_managed_cluster1_table;
  38. > SELECT * FROM create_managed_cluster1_table;
  39. 123
  40. > SELECT * FROM create_managed_cluster1_view;
  41. 123
  42. > SET cluster=create_managed_cluster2
  43. > CREATE DEFAULT INDEX ON create_managed_cluster2_table;
  44. > CREATE MATERIALIZED VIEW create_managed_cluster2_view AS SELECT SUM(f1) FROM create_managed_cluster2_table;
  45. > SELECT * FROM create_managed_cluster2_table;
  46. 234
  47. > SELECT * FROM create_managed_cluster2_view;
  48. 234
  49. > DROP TABLE create_managed_cluster1_table CASCADE;
  50. > DROP TABLE create_managed_cluster2_table CASCADE;
  51. """
  52. )
  53. )
  54. class DropManagedCluster(Check):
  55. def manipulate(self) -> list[Testdrive]:
  56. return [
  57. Testdrive(dedent(s))
  58. for s in [
  59. """
  60. > CREATE TABLE drop_managed_cluster1_table (f1 INTEGER);
  61. > CREATE TABLE drop_managed_cluster2_table (f1 INTEGER);
  62. > INSERT INTO drop_managed_cluster1_table VALUES (123);
  63. > INSERT INTO drop_managed_cluster2_table VALUES (234);
  64. >[version>=13800] CREATE CLUSTER drop_managed_cluster1 SIZE '2-2', REPLICATION FACTOR 2;
  65. >[version<13800] CREATE CLUSTER drop_managed_cluster1 SIZE '2-2', REPLICATION FACTOR 1;
  66. >[version>=13800] CREATE CLUSTER drop_managed_cluster2 SIZE '2-2', REPLICATION FACTOR 2;
  67. >[version<13800] CREATE CLUSTER drop_managed_cluster2 SIZE '2-2', REPLICATION FACTOR 1;
  68. > SET cluster=drop_managed_cluster1
  69. > CREATE DEFAULT INDEX ON drop_managed_cluster1_table;
  70. > CREATE MATERIALIZED VIEW drop_managed_cluster1_view AS SELECT SUM(f1) FROM drop_managed_cluster1_table;
  71. > SET cluster=drop_managed_cluster2
  72. > CREATE DEFAULT INDEX ON drop_managed_cluster2_table;
  73. > CREATE MATERIALIZED VIEW drop_managed_cluster2_view AS SELECT SUM(f1) FROM drop_managed_cluster2_table;
  74. > DROP CLUSTER drop_managed_cluster1 CASCADE;
  75. """,
  76. """
  77. > DROP CLUSTER drop_managed_cluster2 CASCADE;
  78. """,
  79. ]
  80. ]
  81. def validate(self) -> Testdrive:
  82. return Testdrive(
  83. dedent(
  84. """
  85. > SET cluster=drop_managed_cluster1
  86. > SET cluster=drop_managed_cluster2
  87. > SET cluster=default
  88. > SELECT * FROM drop_managed_cluster1_table;
  89. 123
  90. ! SELECT * FROM drop_managed_cluster1_view;
  91. contains: unknown catalog item 'drop_managed_cluster1_view'
  92. > SELECT * FROM drop_managed_cluster2_table;
  93. 234
  94. ! SELECT * FROM drop_managed_cluster2_view;
  95. contains: unknown catalog item 'drop_managed_cluster2_view'
  96. """
  97. )
  98. )