mirror of
https://github.com/rustfs/rustfs.git
synced 2026-07-27 16:48:58 +00:00
73bde843d6
* refactor(common): introduce rustfs-data-usage core crate * refactor(concurrency): migrate workers crate into concurrency * refactor(crypto): migrate appauth token APIs into crypto * fix docs urls * remove unused crate * refactor(data-usage): switch consumers to rustfs-data-usage * chore(fmt): apply cargo fmt and lockfile sync * refactor(common): remove data_usage compatibility re-export * refactor(capacity): move capacity_scope to object-capacity * refactor(io-metrics): relocate internode metrics from common * refactor(common): decouple scanner report from madmin * chore(fmt): normalize import ordering after pre-commit * refactor(s3): split s3 types and ops crates * refactor(s3): centralize event version and safe parsing * refactor(s3): add op-event compatibility guardrails * refactor(s3): add runtime op-event mismatch observability * refactor(s3): extract delete event mapping helper * refactor(s3): extract put event mapping helper * refactor(s3): consolidate remaining event semantic helpers * refactor(s3): add op-event coverage checks and observability alerts * refactor(s3-ops): consolidate op-event semantic mapping * refactor(scanner): remove last_minute wrapper module * refactor(scanner): consolidate duplicated data usage models
74 lines
2.5 KiB
Rust
74 lines
2.5 KiB
Rust
// Copyright 2024 RustFS Team
|
|
//
|
|
// 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 aws_sdk_s3::primitives::ByteStream;
|
|
use rustfs_data_usage::DataUsageInfo;
|
|
use serial_test::serial;
|
|
|
|
use crate::common::{RustFSTestEnvironment, TEST_BUCKET, awscurl_get, init_logging};
|
|
|
|
/// Regression test for data usage accuracy (issue #1012).
|
|
/// Launches rustfs, writes 1000 objects, then asserts admin data usage reports the full count.
|
|
#[tokio::test(flavor = "multi_thread")]
|
|
#[serial]
|
|
#[ignore = "Starts a rustfs server and requires awscurl; enable when running full E2E"]
|
|
async fn data_usage_reports_all_objects() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
|
init_logging();
|
|
|
|
let mut env = RustFSTestEnvironment::new().await?;
|
|
env.start_rustfs_server(vec![]).await?;
|
|
|
|
let client = env.create_s3_client();
|
|
|
|
// Create bucket and upload objects
|
|
client.create_bucket().bucket(TEST_BUCKET).send().await?;
|
|
|
|
for i in 0..1000 {
|
|
let key = format!("obj-{i:04}");
|
|
client
|
|
.put_object()
|
|
.bucket(TEST_BUCKET)
|
|
.key(key)
|
|
.body(ByteStream::from_static(b"hello-world"))
|
|
.send()
|
|
.await?;
|
|
}
|
|
|
|
// Query admin data usage API
|
|
let url = format!("{}/rustfs/admin/v3/datausageinfo", env.url);
|
|
let resp = awscurl_get(&url, &env.access_key, &env.secret_key).await?;
|
|
let usage: DataUsageInfo = serde_json::from_str(&resp)?;
|
|
|
|
// Assert total object count and per-bucket count are not truncated
|
|
let bucket_usage = usage
|
|
.buckets_usage
|
|
.get(TEST_BUCKET)
|
|
.cloned()
|
|
.expect("bucket usage should exist");
|
|
|
|
assert!(
|
|
usage.objects_total_count >= 1000,
|
|
"total object count should be at least 1000, got {}",
|
|
usage.objects_total_count
|
|
);
|
|
assert!(
|
|
bucket_usage.objects_count >= 1000,
|
|
"bucket object count should be at least 1000, got {}",
|
|
bucket_usage.objects_count
|
|
);
|
|
|
|
env.stop_server();
|
|
Ok(())
|
|
}
|