|
| 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. |
| 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 | + |
| 10 | +import { parseAutoScaling } from "~/platform/clusters/ClusterPage/Configuration/clusterConfigurationModel"; |
| 11 | +import { |
| 12 | + executeSqlHttp, |
| 13 | + getMaterializeClient, |
| 14 | +} from "~/test/sql/materializeSqlClient"; |
| 15 | +import { testdrive } from "~/test/sql/mzcompose"; |
| 16 | + |
| 17 | +import { buildClusterAutoScalingQuery } from "./clusterConfiguration"; |
| 18 | +import { buildObjectCreationTimesQuery } from "./objectCreationTimes"; |
| 19 | + |
| 20 | +const OPTIONS = { sessionVariables: { transaction_isolation: "serializable" } }; |
| 21 | + |
| 22 | +async function clusterIdByName(name: string) { |
| 23 | + const client = await getMaterializeClient(); |
| 24 | + const { |
| 25 | + rows: [cluster], |
| 26 | + } = await client.query("SELECT id FROM mz_clusters WHERE name = $1", [name]); |
| 27 | + return cluster.id as string; |
| 28 | +} |
| 29 | + |
| 30 | +describe("cluster configuration queries", () => { |
| 31 | + it("tells a cluster's creation from a replica's with the same id", async () => { |
| 32 | + await testdrive(`> SET cluster to quickstart;`); |
| 33 | + const client = await getMaterializeClient(); |
| 34 | + // Clusters and replicas take ids from separate counters, so the first of |
| 35 | + // each share an id. |
| 36 | + const { |
| 37 | + rows: [shared], |
| 38 | + } = await client.query( |
| 39 | + `SELECT c.id FROM mz_clusters c JOIN mz_cluster_replicas r ON r.id = c.id LIMIT 1`, |
| 40 | + ); |
| 41 | + expect(shared?.id).toBeDefined(); |
| 42 | + |
| 43 | + const { rows } = await executeSqlHttp( |
| 44 | + buildObjectCreationTimesQuery({ |
| 45 | + objectIds: [shared.id], |
| 46 | + objectTypes: ["cluster", "cluster-replica"], |
| 47 | + }).compile(), |
| 48 | + OPTIONS, |
| 49 | + ); |
| 50 | + |
| 51 | + expect(rows.map(({ id, objectType }) => [id, objectType]).sort()).toEqual([ |
| 52 | + [shared.id, "cluster"], |
| 53 | + [shared.id, "cluster-replica"], |
| 54 | + ]); |
| 55 | + expect(rows.every(({ occurredAt }) => occurredAt instanceof Date)).toBe( |
| 56 | + true, |
| 57 | + ); |
| 58 | + }); |
| 59 | + |
| 60 | + it("reads a cluster's autoscaling policy as the drawer parses it", async () => { |
| 61 | + await testdrive(` |
| 62 | + $ postgres-execute connection=postgres://mz_system@\${testdrive.materialize-internal-sql-addr}/materialize |
| 63 | + ALTER SYSTEM SET enable_auto_scaling_strategy = true |
| 64 | +
|
| 65 | + > CREATE CLUSTER lingering (SIZE 'scale=1,workers=1', AUTO SCALING STRATEGY = (ON HYDRATION (HYDRATION SIZE = 'scale=1,workers=2', LINGER DURATION = '120s'))); |
| 66 | + > CREATE CLUSTER defaulted (SIZE 'scale=1,workers=1', AUTO SCALING STRATEGY = (ON HYDRATION (HYDRATION SIZE = 'scale=1,workers=2'))); |
| 67 | + > CREATE CLUSTER steady (SIZE 'scale=1,workers=1'); |
| 68 | + `); |
| 69 | + |
| 70 | + const policy = async (name: string) => { |
| 71 | + const { rows } = await executeSqlHttp( |
| 72 | + buildClusterAutoScalingQuery(await clusterIdByName(name)).compile(), |
| 73 | + OPTIONS, |
| 74 | + ); |
| 75 | + return parseAutoScaling(rows.at(0) ?? null).policy; |
| 76 | + }; |
| 77 | + |
| 78 | + expect(await policy("lingering")).toEqual({ |
| 79 | + hydrationSize: "scale=1,workers=2", |
| 80 | + lingerMs: 120_000, |
| 81 | + }); |
| 82 | + // An omitted linger arrives as a null duration, the server's default. |
| 83 | + expect(await policy("defaulted")).toEqual({ |
| 84 | + hydrationSize: "scale=1,workers=2", |
| 85 | + lingerMs: undefined, |
| 86 | + }); |
| 87 | + expect(await policy("steady")).toBeNull(); |
| 88 | + }); |
| 89 | +}); |
0 commit comments