Skip to content

Commit

Permalink
add sim test
Browse files Browse the repository at this point in the history
Signed-off-by: Bugen Zhao <[email protected]>
  • Loading branch information
BugenZhao committed Jan 23, 2025
1 parent f43a615 commit 564d163
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/compute/src/observer/observer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _);
}
}

Expand Down
67 changes: 67 additions & 0 deletions src/tests/simulation/tests/integration_tests/license_cpu_limit.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
6 changes: 3 additions & 3 deletions src/tests/simulation/tests/integration_tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 564d163

Please sign in to comment.