Skip to content

Droppping deprecated functions #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions aw-client-rust/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,17 @@ mod test {
println!("Buckets: {buckets:?}");
let mut event = Event {
id: None,
timestamp: DateTime::from_utc(
timestamp: DateTime::from_naive_utc_and_offset(
DateTime::parse_from_rfc3339("2017-12-30T01:00:00+00:00")
.unwrap()
.naive_utc(),
Utc,
),
duration: Duration::seconds(0),
.naive_utc(), Utc),
duration: Duration::try_seconds(0).unwrap(),
data: Map::new(),
};
println!("{event:?}");
client.insert_event(&bucketname, &event).unwrap();
// Ugly way to create a UTC from timestamp, see https://github.com/chronotope/chrono/issues/263
event.timestamp = DateTime::from_utc(
event.timestamp = DateTime::from_naive_utc_and_offset(
DateTime::parse_from_rfc3339("2017-12-30T01:00:01+00:00")
.unwrap()
.naive_utc(),
Expand All @@ -108,7 +106,7 @@ mod test {

let events = client.get_events(&bucketname, None, None, None).unwrap();
println!("Events: {events:?}");
assert!(events[0].duration == Duration::seconds(1));
assert!(events[0].duration == Duration::try_seconds(1).unwrap());

client
.delete_event(&bucketname, events[0].id.unwrap())
Expand Down
2 changes: 1 addition & 1 deletion aw-datastore/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl DatastoreWorker {
response_sender.respond(response);

let now: DateTime<Utc> = Utc::now();
let commit_interval_passed: bool = (now - last_commit_time) > Duration::seconds(15);
let commit_interval_passed: bool = (now - last_commit_time) > Duration::try_seconds(15).unwrap();
if self.commit
|| commit_interval_passed
|| self.uncommitted_events > 100
Expand Down
32 changes: 16 additions & 16 deletions aw-datastore/tests/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ mod datastore_tests {
Some(created) => {
let now = Utc::now();
assert!(created <= now);
assert!(created > now - Duration::seconds(10));
assert!(created > now - Duration::try_seconds(10).unwrap());
}
};

Expand All @@ -102,7 +102,7 @@ mod datastore_tests {
Some(created) => {
let now = Utc::now();
assert!(created <= now);
assert!(created > now - Duration::seconds(10));
assert!(created > now - Duration::try_seconds(10).unwrap());
}
};

Expand All @@ -129,7 +129,7 @@ mod datastore_tests {
let e1 = Event {
id: None,
timestamp: Utc::now(),
duration: Duration::seconds(0),
duration: Duration::try_seconds(0).unwrap(),
data: json_map! {"key": json!("value")},
};
let mut e2 = e1.clone();
Expand Down Expand Up @@ -157,7 +157,7 @@ mod datastore_tests {
let e1 = Event {
id: None,
timestamp: Utc::now(),
duration: Duration::seconds(0),
duration: Duration::try_seconds(0).unwrap(),
data: json_map! {"key": json!("value")},
};
let mut e2 = e1.clone();
Expand Down Expand Up @@ -224,16 +224,16 @@ mod datastore_tests {
let e1 = Event {
id: None,
timestamp: Utc::now(),
duration: Duration::seconds(100),
duration: Duration::try_seconds(100).unwrap(),
data: json_map! {"key": json!("value")},
};

let event_list = [e1];
ds.insert_events(&bucket.id, &event_list).unwrap();

info!("Get event that covers queried timeperiod");
let query_start = now + Duration::seconds(1);
let query_end = query_start + Duration::seconds(1);
let query_start = now + Duration::try_seconds(1).unwrap();
let query_end = query_start + Duration::try_seconds(1).unwrap();
let fetched_events_limit = ds
.get_events(&bucket.id, Some(query_start), Some(query_end), Some(1))
.unwrap();
Expand All @@ -256,11 +256,11 @@ mod datastore_tests {
let e1 = Event {
id: None,
timestamp: Utc::now(),
duration: Duration::seconds(0),
duration: Duration::try_seconds(0).unwrap(),
data: json_map! {"key": json!("value")},
};
let mut e2 = e1.clone();
e2.timestamp += Duration::seconds(1);
e2.timestamp += Duration::try_seconds(1).unwrap();

let event_list = [e1.clone(), e2.clone()];

Expand Down Expand Up @@ -308,7 +308,7 @@ mod datastore_tests {
let e1 = Event {
id: None,
timestamp: Utc::now(),
duration: Duration::seconds(0),
duration: Duration::try_seconds(0).unwrap(),
data: json_map! {"key": json!("value")},
};
let mut e2 = e1.clone();
Expand All @@ -334,14 +334,14 @@ mod datastore_tests {
let e1 = Event {
id: None,
timestamp: Utc::now(),
duration: Duration::seconds(0),
duration: Duration::try_seconds(0).unwrap(),
data: json_map! {"key": json!("value")},
};
let mut e2 = e1.clone();
e2.timestamp += Duration::seconds(1);
e2.timestamp += Duration::try_seconds(1).unwrap();

let mut e_diff_data = e2.clone();
e_diff_data.timestamp += Duration::seconds(1);
e_diff_data.timestamp += Duration::try_seconds(1).unwrap();
e_diff_data.data = json_map! {"key": json!("other value")};

// First event
Expand All @@ -358,7 +358,7 @@ mod datastore_tests {
let fetched_events = ds.get_events(&bucket.id, None, None, None).unwrap();
assert_eq!(fetched_events.len(), 1);
assert_eq!(fetched_events[0].timestamp, e1.timestamp);
assert_eq!(fetched_events[0].duration, Duration::seconds(1));
assert_eq!(fetched_events[0].duration, Duration::try_seconds(1).unwrap());
assert_eq!(fetched_events[0].data, e1.data);
assert_eq!(fetched_events[0].id, e1.id);
let e2 = &fetched_events[0];
Expand All @@ -383,7 +383,7 @@ mod datastore_tests {
let e = Event {
id: None,
timestamp: Utc::now(),
duration: Duration::seconds(0),
duration: Duration::try_seconds(0).unwrap(),
data: json_map! {"key": json!("value")},
};
let mut e1 = e.clone();
Expand Down Expand Up @@ -451,7 +451,7 @@ mod datastore_tests {
let e1 = Event {
id: None,
timestamp: Utc::now(),
duration: Duration::seconds(0),
duration: Duration::try_seconds(0).unwrap(),
data: json_map! {"key": json!("value")},
};
{
Expand Down
6 changes: 3 additions & 3 deletions aw-models/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ impl Default for Event {
Event {
id: None,
timestamp: Utc::now(),
duration: Duration::seconds(0),
duration: Duration::try_seconds(0).unwrap(),
data: serde_json::Map::new(),
}
}
}

fn default_duration() -> Duration {
Duration::seconds(0)
Duration::try_seconds(0).unwrap()
}

#[test]
Expand All @@ -77,7 +77,7 @@ fn test_event() {
let e = Event {
id: None,
timestamp: Utc::now(),
duration: Duration::seconds(1),
duration: Duration::try_seconds(0).unwrap(),
data: json_map! {"test": json!(1)},
};
debug!("event: {:?}", e);
Expand Down
4 changes: 2 additions & 2 deletions aw-query/benches/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ mod query_benchmarks {
for i in 0..num_events {
let e = Event {
id: None,
timestamp: chrono::Utc::now() + Duration::seconds(i),
duration: Duration::seconds(10),
timestamp: chrono::Utc::now() + Duration::try_seconds(i).unwrap(),
duration: Duration::try_seconds(10).unwrap(),
data: possible_data[i as usize % 20].clone(),
};
event_list.push(e);
Expand Down
2 changes: 1 addition & 1 deletion aw-query/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ mod qfunctions {
validate::args_length(&args, 1)?;
let events: Vec<Event> = (&args[0]).try_into()?;
// Run flood
let mut flooded_events = aw_transform::flood(events, chrono::Duration::seconds(5));
let mut flooded_events = aw_transform::flood(events, chrono::Duration::try_seconds(5).unwrap());
// Put events back into DataType::Event container
let mut tagged_flooded_events = Vec::new();
for event in flooded_events.drain(..) {
Expand Down
4 changes: 2 additions & 2 deletions aw-query/tests/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ mod query_tests {
let e1 = Event {
id: None,
timestamp: chrono::Utc::now(),
duration: Duration::seconds(0),
duration: Duration::try_seconds(0).unwrap(),
data: json_map! {"key": json!("value")},
};
let mut e2 = e1.clone();
e2.timestamp = chrono::Utc::now();
let mut e_replace = e2.clone();
e_replace.data = json_map! {"key": json!("value2")};
e_replace.duration = Duration::seconds(2);
e_replace.duration = Duration::try_seconds(2).unwrap();

let mut event_list = Vec::new();
event_list.push(e1);
Expand Down
1 change: 1 addition & 0 deletions aw-sync/src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub fn get_config_dir() -> Result<PathBuf, Box<dyn Error>> {
Ok(dir)
}

#[allow(dead_code)]
pub fn get_server_config_path(testing: bool) -> Result<PathBuf, ()> {
let dir = aw_server::dirs::get_config_dir()?;
Ok(dir.join(if testing {
Expand Down
2 changes: 1 addition & 1 deletion aw-sync/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn sync_run(
let info = client.get_info()?;

// FIXME: Here it is assumed that the device_id for the local server is the one used by
// aw-server-rust, which is not necessarily true (aw-server-python has seperate device_id).
// aw-server-rust, which is not necessarily true (aw-server-python has separate device_id).
// Therefore, this may sometimes fail to pick up the correct local datastore.
let device_id = info.device_id.as_str();

Expand Down
2 changes: 1 addition & 1 deletion aw-sync/tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ mod sync_tests {
// Insert some testing events into the bucket
let events: Vec<Event> = (0..3)
.map(|i| {
let timestamp: DateTime<Utc> = Utc::now() + Duration::milliseconds(i * 10);
let timestamp: DateTime<Utc> = Utc::now() + Duration::try_milliseconds(i * 10).unwrap();
let event_jsonstr = format!(
r#"{{
"timestamp": "{}",
Expand Down
4 changes: 2 additions & 2 deletions aw-transform/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ fn create_events(num_events: i64) -> Vec<Event> {
for i in 0..num_events {
let e = Event {
id: None,
timestamp: chrono::Utc::now() + Duration::seconds(i),
duration: Duration::seconds(10),
timestamp: chrono::Utc::now() + Duration::try_seconds(i).unwrap(),
duration: Duration::try_seconds(10).unwrap(),
data: possible_data[i as usize % 20].clone(),
};
event_list.push(e);
Expand Down
6 changes: 3 additions & 3 deletions aw-transform/src/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ mod tests {
let e1 = Event {
id: None,
timestamp: DateTime::from_str("2000-01-01T00:00:01Z").unwrap(),
duration: Duration::seconds(1),
duration: Duration::try_seconds(1).unwrap(),
data: json_map! {"test": json!(1)},
};
let mut e2 = e1.clone();
Expand All @@ -74,7 +74,7 @@ mod tests {

let res = chunk_events_by_key(vec![e1, e2, e3, e4], "test");
assert_eq!(res.len(), 2);
assert_eq!(res[0].duration, Duration::seconds(2));
assert_eq!(res[1].duration, Duration::seconds(1));
assert_eq!(res[0].duration, Duration::try_seconds(2).unwrap());
assert_eq!(res[1].duration, Duration::try_seconds(1).unwrap());
}
}
8 changes: 4 additions & 4 deletions aw-transform/src/filter_keyvals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ mod tests {
let e1 = Event {
id: None,
timestamp: DateTime::from_str("2000-01-01T00:00:00Z").unwrap(),
duration: Duration::seconds(1),
duration: Duration::try_seconds(1).unwrap(),
data: json_map! {"test": json!(1)},
};
let mut e2 = e1.clone();
Expand All @@ -109,7 +109,7 @@ mod tests {
let e1 = Event {
id: None,
timestamp: DateTime::from_str("2000-01-01T00:00:00Z").unwrap(),
duration: Duration::seconds(1),
duration: Duration::try_seconds(1).unwrap(),
data: json_map! {"key1": json!("value1")},
};
let mut e2 = e1.clone();
Expand Down Expand Up @@ -139,7 +139,7 @@ mod tests {
let e1 = Event {
id: None,
timestamp: DateTime::from_str("2000-01-01T00:00:00Z").unwrap(),
duration: Duration::seconds(1),
duration: Duration::try_seconds(1).unwrap(),
data: json_map! {"key1": json!(100)},
};
let events = vec![e1.clone()];
Expand All @@ -153,7 +153,7 @@ mod tests {
let e1 = Event {
id: None,
timestamp: DateTime::from_str("2000-01-01T00:00:00Z").unwrap(),
duration: Duration::seconds(1),
duration: Duration::try_seconds(1).unwrap(),
data: json_map! {"test": json!(1)},
};
let mut e2 = e1.clone();
Expand Down
Loading
Loading