Skip to content

Commit

Permalink
try to fix license issue
Browse files Browse the repository at this point in the history
  • Loading branch information
v0y4g3r committed Mar 5, 2024
1 parent 181e338 commit 706c733
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 deletions.
43 changes: 29 additions & 14 deletions src/servers/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,31 +218,24 @@ mod tests {
use std::collections::{HashMap, HashSet};

use api::prom_store::remote::WriteRequest;
use api::v1::RowInsertRequests;
use bytes::Bytes;
use prost::Message;

use crate::prom_store::to_grpc_row_insert_requests;
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());

Expand Down Expand Up @@ -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,
);
}
}
}
28 changes: 14 additions & 14 deletions src/servers/src/repeated_field.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 706c733

Please sign in to comment.