Generate and read channel config for test case
This commit is contained in:
@@ -51,11 +51,41 @@ impl Query {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn binned_bytes_for_http(node_config: Arc<NodeConfig>, query: &Query) -> Result<BinnedBytesForHttpStream, Error> {
|
||||
pub async fn binned_bytes_for_http(
|
||||
node_config: Arc<NodeConfig>,
|
||||
query: &Query,
|
||||
) -> Result<BinnedBytesForHttpStream, Error> {
|
||||
let agg_kind = AggKind::DimXBins1;
|
||||
|
||||
// TODO
|
||||
// Translate the Query TimeRange + AggKind into an iterator over the pre-binned patches.
|
||||
let channel_config = super::channelconfig::read_local_config(&query.channel, node_config.clone()).await?;
|
||||
let entry;
|
||||
{
|
||||
let mut ixs = vec![];
|
||||
for i1 in 0..channel_config.entries.len() {
|
||||
let e1 = &channel_config.entries[i1];
|
||||
if i1 + 1 < channel_config.entries.len() {
|
||||
let e2 = &channel_config.entries[i1 + 1];
|
||||
if e1.ts < query.range.end && e2.ts >= query.range.beg {
|
||||
ixs.push(i1);
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
if e1.ts < query.range.end {
|
||||
ixs.push(i1);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
if ixs.len() == 0 {
|
||||
return Err(Error::with_msg(format!("no config entries found")));
|
||||
} else if ixs.len() > 1 {
|
||||
return Err(Error::with_msg(format!("too many config entries found: {}", ixs.len())));
|
||||
}
|
||||
entry = &channel_config.entries[ixs[0]];
|
||||
}
|
||||
|
||||
info!("found config entry {:?}", entry);
|
||||
|
||||
let grid = PreBinnedPatchRange::covering_range(query.range.clone(), query.count);
|
||||
match grid {
|
||||
Some(spec) => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use err::Error;
|
||||
use netpod::{Channel, NodeConfig};
|
||||
use nom::number::complete::{be_i16, be_i32, be_i64, be_i8, be_u8};
|
||||
use nom::Needed;
|
||||
#[allow(unused_imports)]
|
||||
@@ -10,6 +11,7 @@ use nom::{
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use num_traits::ToPrimitive;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
#[allow(unused_imports)]
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
|
||||
@@ -60,7 +62,7 @@ impl CompressionMethod {
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct ConfigEntry {
|
||||
pub ts: i64,
|
||||
pub ts: u64,
|
||||
pub pulse: i64,
|
||||
pub ks: i32,
|
||||
pub bs: i64,
|
||||
@@ -198,7 +200,7 @@ pub fn parse_entry(inp: &[u8]) -> NRes<Option<ConfigEntry>> {
|
||||
Ok((
|
||||
inp_e,
|
||||
Some(ConfigEntry {
|
||||
ts,
|
||||
ts: ts as u64,
|
||||
pulse,
|
||||
ks,
|
||||
bs,
|
||||
@@ -262,31 +264,49 @@ pub fn parse_config(inp: &[u8]) -> NRes<Config> {
|
||||
Ok((inp, ret))
|
||||
}
|
||||
|
||||
pub async fn read_local_config(channel: &Channel, node_config: Arc<NodeConfig>) -> Result<Config, Error> {
|
||||
let path = node_config
|
||||
.node
|
||||
.data_base_path
|
||||
.join("config")
|
||||
.join(&channel.name)
|
||||
.join("latest")
|
||||
.join("00000_Config");
|
||||
let buf = tokio::fs::read(&path).await?;
|
||||
info!("try to parse config {} bytes", buf.len());
|
||||
let config = parse_config(&buf)?;
|
||||
Ok(config.1)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn read_data() -> Vec<u8> {
|
||||
use std::io::Read;
|
||||
let path = "ks/config/S10CB01-RLOD100-PUP10:SIG-AMPLT/latest/00000_Config";
|
||||
let mut f1 = std::fs::File::open(path).unwrap();
|
||||
let mut buf = vec![];
|
||||
f1.read_to_end(&mut buf).unwrap();
|
||||
buf
|
||||
}
|
||||
mod test {
|
||||
use super::parse_config;
|
||||
|
||||
#[test]
|
||||
fn parse_dummy() {
|
||||
let config = parse_config(&[0, 0, 0, 0, 0, 11, 0x61, 0x62, 0x63, 0, 0, 0, 11, 0, 0, 0, 1]).unwrap();
|
||||
assert_eq!(0, config.1.format_version);
|
||||
assert_eq!("abc", config.1.channel_name);
|
||||
}
|
||||
fn read_data() -> Vec<u8> {
|
||||
use std::io::Read;
|
||||
let path = "ks/config/S10CB01-RLOD100-PUP10:SIG-AMPLT/latest/00000_Config";
|
||||
let mut f1 = std::fs::File::open(path).unwrap();
|
||||
let mut buf = vec![];
|
||||
f1.read_to_end(&mut buf).unwrap();
|
||||
buf
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_file() {
|
||||
let config = parse_config(&read_data()).unwrap().1;
|
||||
assert_eq!(0, config.format_version);
|
||||
assert_eq!(9, config.entries.len());
|
||||
for e in &config.entries {
|
||||
assert!(e.ts >= 631152000000000000);
|
||||
assert!(e.ts <= 1591106812800073974);
|
||||
assert!(e.shape.is_some());
|
||||
#[test]
|
||||
fn parse_dummy() {
|
||||
let config = parse_config(&[0, 0, 0, 0, 0, 11, 0x61, 0x62, 0x63, 0, 0, 0, 11, 0, 0, 0, 1]).unwrap();
|
||||
assert_eq!(0, config.1.format_version);
|
||||
assert_eq!("abc", config.1.channel_name);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_file() {
|
||||
let config = parse_config(&read_data()).unwrap().1;
|
||||
assert_eq!(0, config.format_version);
|
||||
assert_eq!(9, config.entries.len());
|
||||
for e in &config.entries {
|
||||
assert!(e.ts >= 631152000000000000);
|
||||
assert!(e.ts <= 1591106812800073974);
|
||||
assert!(e.shape.is_some());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ pub async fn gen_test_data() -> Result<(), Error> {
|
||||
big_endian: true,
|
||||
compression: true,
|
||||
},
|
||||
time_spacing: MS * 10,
|
||||
time_spacing: MS * 2000,
|
||||
};
|
||||
ensemble.channels.push(chn);
|
||||
}
|
||||
@@ -150,8 +150,8 @@ async fn gen_config(
|
||||
|
||||
{
|
||||
// this len does not include itself and there seems to be no copy of it afterwards.
|
||||
buf.put_i32(0x20202020);
|
||||
let p3 = buf.len();
|
||||
buf.put_i32(404040);
|
||||
buf.put_u8(config.dtflags());
|
||||
buf.put_u8(config.scalar_type.index());
|
||||
if config.compression {
|
||||
@@ -161,13 +161,25 @@ async fn gen_config(
|
||||
match config.shape {
|
||||
Shape::Scalar => {}
|
||||
Shape::Wave(k) => {
|
||||
buf.put_i8(1);
|
||||
buf.put_i32(k as i32);
|
||||
}
|
||||
}
|
||||
let len = buf.len() - p3;
|
||||
let len = buf.len() - p3 - 4;
|
||||
buf.as_mut()[p3..].as_mut().put_i32(len as i32);
|
||||
}
|
||||
|
||||
// source name
|
||||
buf.put_i32(-1);
|
||||
// unit
|
||||
buf.put_i32(-1);
|
||||
// description
|
||||
buf.put_i32(-1);
|
||||
// optional fields
|
||||
buf.put_i32(-1);
|
||||
// value converter
|
||||
buf.put_i32(-1);
|
||||
|
||||
let p2 = buf.len();
|
||||
let len = p2 - p1 + 4;
|
||||
buf.put_i32(len as i32);
|
||||
|
||||
Reference in New Issue
Block a user