diff --git a/src/compute/src/observer/observer_manager.rs b/src/compute/src/observer/observer_manager.rs index 8b707df73c71f..19c273f9bd4f2 100644 --- a/src/compute/src/observer/observer_manager.rs +++ b/src/compute/src/observer/observer_manager.rs @@ -61,7 +61,7 @@ impl ObserverState for ComputeObserverNode { unreachable!(); }; LocalSecretManager::global().init_secrets(snapshot.secrets); - LicenseManager::get().update_cpu_core_count(snapshot.cluster_cpu_core_count as _); + LicenseManager::get().update_cpu_core_count(snapshot.compute_node_total_cpu_count as _); } } diff --git a/src/tests/simulation/tests/integration_tests/license_cpu_limit.rs b/src/tests/simulation/tests/integration_tests/license_cpu_limit.rs new file mode 100644 index 0000000000000..ee49152cf9dba --- /dev/null +++ b/src/tests/simulation/tests/integration_tests/license_cpu_limit.rs @@ -0,0 +1,67 @@ +// Copyright 2025 RisingWave Labs +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use anyhow::Result; +use risingwave_common::error::AsReport; +use risingwave_simulation::cluster::{Cluster, Configuration}; +use risingwave_simulation::utils::AssertResult; + +const KEY_20: &str = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJwYWlkLXRlc3QtMzIiLCJpc3MiOiJ0ZXN0LnJpc2luZ3dhdmUuY29tIiwidGllciI6InBhaWQiLCJleHAiOjIxNTA0OTU5OTksImlhdCI6MTczNzYxNTI2NywiY3B1X2NvcmVfbGltaXQiOjIwfQ.V8546BDZydv1aNk8IlVaSVlCriDtMC_75nq8CIaRPKlrltcwRJYKfK-Ru3WbKj-MDFebmW_3CqA4jR77BBtmmmtj-lPHa4qrdgrMItxm9RC_qoSU1YbI8Kb_ClYkrnFug5MAbK3wGlO8CrrjqOOt-Q5ggKChtl0uFj4zgI-S80d8Hse5LYSKHv8cU-ECKvEFe451kXE9x7nN_f8MqTSOqBwfY5o17gTD8oU3XH2k1mpesdci18kDmJPK5DeLPDYht_nRt7WGbVQvx7iiol1nzj5OBjdH_eVbX7pfk9M-JNwqZKaqfOmBbwV2F-Sf7-tK33O-XqSfXjnLAzflfjkoLQ"; +const KEY_100: &str = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJwYWlkLXRlc3QtMzIiLCJpc3MiOiJ0ZXN0LnJpc2luZ3dhdmUuY29tIiwidGllciI6InBhaWQiLCJleHAiOjIxNTA0OTU5OTksImlhdCI6MTczNzYyMzc2MywiY3B1X2NvcmVfbGltaXQiOjEwMH0.ZGQjZa6t3va5MHMHKvgMgOXVLymEvvy1Yvd6teRUgCIF7en5BYaKXWuXwwtWLpLxr7LXyIQ3LQeDXag4k_fQOUTwV4oYTLTFVF8GcJ8JvGdTjBfjnM_2helLEhjZFgXSnhEy-xTOj5yM0BbqKCwanYlSODXQtp5owalt7a0JDwpId9_O8Pl24CjImZzPZLevJ_wSu4wv2IhVjK5QhkfBKBeaOxCeJaKfMVT5AzDQ-WwtJwahr1Dk0H2BxD6Hmp4KKBFRlVwGxq9-8uKBpbrmlClSuxPreBJ_xhP3SHtBFbVfcr38uaT_Bdh-gPRPgi-59tKOWPCY2FytO-Ls1U2l7w"; + +#[tokio::test] +async fn test_license_cpu_limit() -> Result<()> { + let mut cluster = Cluster::start(Configuration { + compute_nodes: 3, + compute_node_cores: 8, + ..Default::default() + }) + .await?; + + let mut session = cluster.start_session(); + + macro_rules! set_license_key { + ($key:expr) => { + session + .run(format!("ALTER SYSTEM SET license_key TO '{}';", $key)) + .await?; + }; + } + + macro_rules! test_paid_tier { + () => { + session.run("SELECT rw_test_paid_tier();").await + }; + } + + set_license_key!(""); + let error = test_paid_tier!().unwrap_err().to_report_string(); + assert!(error.contains("feature TestPaid is only available for tier Paid and above, while the current tier is Free"), "{error}"); + + set_license_key!(KEY_100); + test_paid_tier!().unwrap().assert_result_eq("true"); + + set_license_key!(KEY_20); + let error = test_paid_tier!().unwrap_err().to_report_string(); + assert!( + error.contains("the license key is currently not effective"), + "{error}" + ); + + cluster.simple_kill_nodes(["compute-2"]).await; + tokio::time::sleep(std::time::Duration::from_secs(100)).await; + test_paid_tier!().unwrap().assert_result_eq("true"); + + Ok(()) +} diff --git a/src/tests/simulation/tests/integration_tests/main.rs b/src/tests/simulation/tests/integration_tests/main.rs index ad8e854a30e5f..1bb58688192c8 100644 --- a/src/tests/simulation/tests/integration_tests/main.rs +++ b/src/tests/simulation/tests/integration_tests/main.rs @@ -22,12 +22,12 @@ mod backfill_tests; mod batch; +mod compaction; +mod default_parallelism; +mod license_cpu_limit; mod recovery; mod scale; mod sink; mod storage; mod throttle; - -mod compaction; -mod default_parallelism; mod utils;