From 706c7334dee5befff08db6795cb7d7df99dff1f3 Mon Sep 17 00:00:00 2001 From: "Lei, HUANG" Date: Tue, 5 Mar 2024 06:40:06 +0000 Subject: [PATCH] try to fix license issue --- src/servers/src/proto.rs | 43 +++++++++++++++++++++---------- src/servers/src/repeated_field.rs | 28 ++++++++++---------- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/src/servers/src/proto.rs b/src/servers/src/proto.rs index 8587c76d8df3..f2c17c37c9d9 100644 --- a/src/servers/src/proto.rs +++ b/src/servers/src/proto.rs @@ -218,6 +218,7 @@ mod tests { use std::collections::{HashMap, HashSet}; use api::prom_store::remote::WriteRequest; + use api::v1::RowInsertRequests; use bytes::Bytes; use prost::Message; @@ -225,24 +226,16 @@ mod tests { use crate::proto::PromWriteRequest; use crate::repeated_field::Clear; - // Ensures `WriteRequest` and `PromWriteRequest` produce the same gRPC request. - #[test] - fn test_decode_write_request() { - let mut d = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); - d.push("benches"); - d.push("write_request.pb.data"); - - let data = Bytes::from(std::fs::read(d).unwrap()); - - let mut prom_write_request = PromWriteRequest::default(); + fn check_deserialized( + prom_write_request: &mut PromWriteRequest, + data: &Bytes, + expected_samples: usize, + expected_rows: &RowInsertRequests, + ) { prom_write_request.clear(); prom_write_request.merge(data.clone()).unwrap(); let (prom_rows, samples) = prom_write_request.as_row_insert_requests(); - let expected_request = WriteRequest::decode(data).unwrap(); - let (expected_rows, expected_samples) = - to_grpc_row_insert_requests(&expected_request).unwrap(); - assert_eq!(expected_samples, samples); assert_eq!(expected_rows.inserts.len(), prom_rows.inserts.len()); @@ -277,4 +270,26 @@ mod tests { ); } } + + // Ensures `WriteRequest` and `PromWriteRequest` produce the same gRPC request. + #[test] + fn test_decode_write_request() { + let mut d = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); + d.push("benches"); + d.push("write_request.pb.data"); + let data = Bytes::from(std::fs::read(d).unwrap()); + + let (expected_rows, expected_samples) = + to_grpc_row_insert_requests(&WriteRequest::decode(data.clone()).unwrap()).unwrap(); + + let mut prom_write_request = PromWriteRequest::default(); + for _ in 0..3 { + check_deserialized( + &mut prom_write_request, + &data, + expected_samples, + &expected_rows, + ); + } + } } diff --git a/src/servers/src/repeated_field.rs b/src/servers/src/repeated_field.rs index 9875b291aa92..0e3baf16a576 100644 --- a/src/servers/src/repeated_field.rs +++ b/src/servers/src/repeated_field.rs @@ -1,3 +1,17 @@ +// Copyright 2023 Greptime 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. + // Copyright (c) 2019 Stepan Koltsov // // Permission is hereby granted, free of charge, to any person obtaining a copy @@ -18,20 +32,6 @@ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE // OR OTHER DEALINGS IN THE SOFTWARE. -// Copyright 2023 Greptime 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. - /// ! The [Clear] trait and [RepeatedField] are taken from [rust-protobuf](https://github.com/stepancheg/rust-protobuf/tree/master/protobuf-examples/vs-prost) /// to leverage the pooling mechanism to avoid frequent heap allocation/deallocation when decoding deeply nested structs. use std::borrow::Borrow;