load-generator.td 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. $ set-arg-default default-replica-size=1
  10. $ set-arg-default single-replica-cluster=quickstart
  11. $ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  12. ALTER SYSTEM SET enable_clock_load_generator = true;
  13. > CREATE SOURCE counter_empty
  14. IN CLUSTER ${arg.single-replica-cluster}
  15. FROM LOAD GENERATOR COUNTER (AS OF 5, UP TO 5)
  16. > SELECT count(*) FROM counter_empty
  17. 0
  18. > CREATE SOURCE counter_single
  19. IN CLUSTER ${arg.single-replica-cluster}
  20. FROM LOAD GENERATOR COUNTER (AS OF 0, UP TO 1)
  21. > SELECT count(*) FROM counter_single
  22. 1
  23. > CREATE SOURCE counter_five
  24. IN CLUSTER ${arg.single-replica-cluster}
  25. FROM LOAD GENERATOR COUNTER (AS OF 4, UP TO 5)
  26. > SELECT count(*) FROM counter_five
  27. 5
  28. ! CREATE SOURCE counter
  29. IN CLUSTER ${arg.single-replica-cluster}
  30. FROM LOAD GENERATOR COUNTER (AS OF 5, UP TO 4)
  31. contains:UP TO cannot be less than AS OF
  32. ! CREATE SOURCE counter
  33. IN CLUSTER ${arg.single-replica-cluster}
  34. FROM LOAD GENERATOR COUNTER (SCALE FACTOR 1)
  35. exact:COUNTER load generators do not support SCALE FACTOR values
  36. > DROP SOURCE counter_empty, counter_single, counter_five
  37. > CREATE SOURCE auction_house
  38. IN CLUSTER ${arg.single-replica-cluster}
  39. FROM LOAD GENERATOR AUCTION (AS OF 300, UP TO 301);
  40. # Error if trying to create with subsources
  41. ! CREATE SOURCE g FROM LOAD GENERATOR COUNTER FOR ALL TABLES;
  42. contains:FOR ALL TABLES is only valid for multi-output sources
  43. ! CREATE SOURCE g FROM LOAD GENERATOR CLOCK FOR ALL TABLES;
  44. contains:FOR ALL TABLES is only valid for multi-output sources
  45. ! CREATE SOURCE g FROM LOAD GENERATOR DATUMS FOR ALL TABLES;
  46. contains:FOR ALL TABLES is only valid for multi-output sources
  47. ! CREATE SOURCE g FROM LOAD GENERATOR COUNTER FOR TABLES ("foo");
  48. regex:.*FOR TABLES.*unsupported
  49. ! CREATE SOURCE g FROM LOAD GENERATOR CLOCK FOR TABLES ("foo");
  50. regex:.*FOR TABLES.*unsupported
  51. ! CREATE SOURCE g FROM LOAD GENERATOR DATUMS FOR TABLES ("foo");
  52. regex:.*FOR TABLES.*unsupported
  53. ! CREATE SOURCE g FROM LOAD GENERATOR COUNTER FOR SCHEMAS ("foo");
  54. regex:.*FOR SCHEMAS.*unsupported
  55. ! CREATE SOURCE g FROM LOAD GENERATOR CLOCK FOR SCHEMAS ("foo");
  56. regex:.*FOR SCHEMAS.*unsupported
  57. ! CREATE SOURCE g FROM LOAD GENERATOR DATUMS FOR SCHEMAS ("foo");
  58. regex:.*FOR SCHEMAS.*unsupported
  59. > CREATE TABLE accounts FROM SOURCE auction_house (REFERENCE accounts);
  60. > CREATE TABLE auctions FROM SOURCE auction_house (REFERENCE auctions);
  61. > CREATE TABLE bids FROM SOURCE auction_house (REFERENCE bids);
  62. > CREATE TABLE organizations FROM SOURCE auction_house (REFERENCE organizations);
  63. > CREATE TABLE users FROM SOURCE auction_house (REFERENCE users);
  64. > SHOW CREATE SOURCE auction_house
  65. "materialize.public.auction_house" "CREATE SOURCE materialize.public.auction_house\nIN CLUSTER ${arg.single-replica-cluster}\nFROM LOAD GENERATOR AUCTION (AS OF = 300, UP TO = 301)\nEXPOSE PROGRESS AS materialize.public.auction_house_progress;"
  66. > SHOW CREATE TABLE accounts
  67. materialize.public.accounts "CREATE TABLE materialize.public.accounts (id pg_catalog.int8 NOT NULL, org_id pg_catalog.int8 NOT NULL, balance pg_catalog.int8 NOT NULL, UNIQUE (id)) FROM SOURCE materialize.public.auction_house (REFERENCE = mz_load_generators.auction.accounts) WITH (DETAILS = '1a040a021002');"
  68. > SHOW SOURCES
  69. auction_house load-generator ${arg.single-replica-cluster} ""
  70. auction_house_progress progress <null> ""
  71. > SHOW TABLES
  72. accounts ""
  73. auctions ""
  74. bids ""
  75. organizations ""
  76. users ""
  77. > SELECT count(*) FROM bids
  78. 255
  79. ! CREATE SOURCE auction_house
  80. IN CLUSTER ${arg.single-replica-cluster}
  81. FROM LOAD GENERATOR AUCTION FOR TABLES (user);
  82. contains:reference to user not found in source
  83. > CREATE SCHEMA another;
  84. > CREATE SOURCE another.auction_house
  85. IN CLUSTER ${arg.single-replica-cluster}
  86. FROM LOAD GENERATOR AUCTION;
  87. > CREATE TABLE another.accounts FROM SOURCE another.auction_house (REFERENCE accounts);
  88. > CREATE TABLE another.auctions FROM SOURCE another.auction_house (REFERENCE auctions);
  89. > CREATE TABLE another.bids FROM SOURCE another.auction_house (REFERENCE bids);
  90. > CREATE TABLE another.organizations FROM SOURCE another.auction_house (REFERENCE organizations);
  91. > CREATE TABLE another.users FROM SOURCE another.auction_house (REFERENCE users);
  92. > SHOW SOURCES FROM another;
  93. auction_house load-generator ${arg.single-replica-cluster} ""
  94. auction_house_progress progress <null> ""
  95. > SHOW TABLES FROM another;
  96. accounts ""
  97. auctions ""
  98. bids ""
  99. organizations ""
  100. users ""
  101. > CREATE CONNECTION IF NOT EXISTS kafka_conn TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  102. # Validate that the ID column of the load generator data is usable as a key.
  103. > CREATE SINK accounts_sink
  104. IN CLUSTER ${arg.single-replica-cluster}
  105. FROM accounts
  106. INTO KAFKA CONNECTION kafka_conn (TOPIC 'testdrive-accounts-${testdrive.seed}')
  107. KEY (id)
  108. FORMAT JSON
  109. ENVELOPE UPSERT;
  110. $ set-regex match="DETAILS = '[a-f0-9]+'" replacement=<DETAILS>
  111. > SHOW CREATE TABLE accounts
  112. materialize.public.accounts "CREATE TABLE materialize.public.accounts (id pg_catalog.int8 NOT NULL, org_id pg_catalog.int8 NOT NULL, balance pg_catalog.int8 NOT NULL, UNIQUE (id)) FROM SOURCE materialize.public.auction_house (REFERENCE = mz_load_generators.auction.accounts) WITH (<DETAILS>);"
  113. # CLOCK load generator source
  114. > CREATE SOURCE clock
  115. IN CLUSTER ${arg.single-replica-cluster}
  116. FROM LOAD GENERATOR CLOCK (TICK INTERVAL '1s')
  117. > SELECT count(*) FROM clock;
  118. 1
  119. > SELECT time < now() + INTERVAL '5s', time > now() - INTERVAL '5s' FROM clock
  120. true true
  121. # Check that non-append-only `COUNTER` sources reach the proper size
  122. > CREATE SOURCE counter
  123. IN CLUSTER ${arg.single-replica-cluster}
  124. FROM LOAD GENERATOR COUNTER (MAX CARDINALITY 8, TICK INTERVAL '0.001s')
  125. > SELECT count(*) FROM counter
  126. 8
  127. # Now make sure it doesn't change
  128. > SELECT mz_unsafe.mz_sleep(1)
  129. <null>
  130. > SELECT count(*) FROM counter
  131. 8
  132. # Check that negative max cardinalities are rejected
  133. ! CREATE SOURCE counter2
  134. IN CLUSTER ${arg.single-replica-cluster}
  135. FROM LOAD GENERATOR COUNTER (MAX CARDINALITY -1)
  136. contains:invalid MAX CARDINALITY: invalid unsigned numeric value: invalid digit found in string
  137. > CREATE SOURCE counter3
  138. IN CLUSTER ${arg.single-replica-cluster}
  139. FROM LOAD GENERATOR COUNTER (MAX CARDINALITY 0)
  140. > SELECT count(*) FROM counter3
  141. 0
  142. > SELECT mz_unsafe.mz_sleep(1)
  143. <null>
  144. > SELECT count(*) FROM counter3
  145. 0
  146. # Check that negative tick intervals are rejected
  147. ! CREATE SOURCE counter4
  148. IN CLUSTER ${arg.single-replica-cluster}
  149. FROM LOAD GENERATOR COUNTER (TICK INTERVAL '-1s')
  150. contains:invalid TICK INTERVAL: cannot convert negative interval to duration
  151. # Check that out of range tick interval values are rejected
  152. ! CREATE SOURCE counter5
  153. IN CLUSTER ${arg.single-replica-cluster}
  154. FROM LOAD GENERATOR COUNTER (TICK INTERVAL '2147483647d')
  155. contains: out of range integral type conversion
  156. # Query automatically generated progress topic
  157. $ set-regex match=\d+ replacement=<NUMBER>
  158. > SELECT "offset" FROM another.auction_house_progress
  159. <NUMBER>
  160. # Ensure we report the write frontier of the progress subsource
  161. $ set-regex match=(\s{12}0|\d{13,20}|u\d{1,5}|\(\d+-\d\d-\d\d\s\d\d:\d\d:\d\d\.\d\d\d\)|true|false) replacement=<>
  162. > EXPLAIN TIMESTAMP FOR SELECT * FROM another.auction_house_progress
  163. " query timestamp: <> <>\n oracle read timestamp: <> <>\nlargest not in advance of upper: <> <>\n upper:[<> <>]\n since:[<> <>]\n can respond immediately: <>\n timeline: Some(EpochMilliseconds)\n session wall time: <> <>\n\nsource materialize.another.auction_house_progress (<>, storage):\n read frontier:[<> <>]\n write frontier:[<> <>]\n\nbinding constraints:\nlower:\n (IsolationLevel(StrictSerializable)): [<> <>]\n"
  164. > DROP SOURCE auction_house CASCADE
  165. > DROP SOURCE another.auction_house CASCADE
  166. > DROP SOURCE counter CASCADE
  167. > DROP SOURCE counter3 CASCADE