Moved include and path to data.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
This commit is contained in:
parent
0bbcf7a1d7
commit
9e88f84166
114
src/data_director.rs
Normal file
114
src/data_director.rs
Normal file
@ -0,0 +1,114 @@
|
||||
use crate::{
|
||||
message::{Action, MsgAction},
|
||||
name::NameType,
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash)]
|
||||
pub enum Include<T> {
|
||||
All,
|
||||
Just(T),
|
||||
}
|
||||
|
||||
impl<T: PartialEq> PartialEq for Include<T> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match self {
|
||||
Include::All => true,
|
||||
Include::Just(data) => match other {
|
||||
Include::All => true,
|
||||
Include::Just(other_data) => data == other_data,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod includes {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn does_all_equal_evberything() {
|
||||
let a: Include<isize> = Include::All;
|
||||
let b: Include<isize> = Include::Just(5);
|
||||
let c: Include<isize> = Include::Just(7);
|
||||
assert!(a == a, "all should equal all");
|
||||
assert!(a == b, "all should equal just");
|
||||
assert!(b == a, "just should equal all");
|
||||
assert!(b == b, "same just should equal");
|
||||
assert!(b != c, "different justs do not equal");
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Path {
|
||||
pub msg_id: Include<Uuid>,
|
||||
pub doc: Include<NameType>,
|
||||
pub action: Include<Action>,
|
||||
}
|
||||
|
||||
impl Path {
|
||||
pub fn new(id: Include<Uuid>, doc: Include<NameType>, action: Include<Action>) -> Self {
|
||||
Self {
|
||||
msg_id: id,
|
||||
doc: doc,
|
||||
action: action,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn for_message<NT>(name: NT, action: &MsgAction) -> Self
|
||||
where
|
||||
NT: Into<NameType>,
|
||||
{
|
||||
Self {
|
||||
msg_id: Include::Just(Uuid::new_v4()),
|
||||
doc: Include::Just(name.into()),
|
||||
action: Include::Just(action.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod paths {
|
||||
use super::*;
|
||||
use crate::{
|
||||
message::{MsgAction, Records},
|
||||
name::{Name, Names},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn can_create_for_message() {
|
||||
let input = [
|
||||
(Name::english("one"), MsgAction::Show),
|
||||
(
|
||||
Name::english("two"),
|
||||
MsgAction::Records(Records::new(Names::new())),
|
||||
),
|
||||
];
|
||||
for item in input.iter() {
|
||||
let path = Path::for_message(item.0.clone(), &item.1);
|
||||
match path.doc {
|
||||
Include::Just(name) => assert_eq!(name, item.0.clone().into()),
|
||||
_ => unreachable!("should have returned document name"),
|
||||
}
|
||||
match path.action {
|
||||
Include::Just(action) => assert_eq!(action, item.1.clone().into()),
|
||||
_ => unreachable!("should have returned action type"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn message_ids_are_unique_for_message_paths() {
|
||||
let count = 10;
|
||||
let mut ids: Vec<Uuid> = Vec::new();
|
||||
for _ in 0..count {
|
||||
let path = Path::for_message(NameType::None, &MsgAction::Show);
|
||||
let id = match path.msg_id {
|
||||
Include::Just(data) => data.clone(),
|
||||
Include::All => unreachable!("should have been a message id"),
|
||||
};
|
||||
assert!(!ids.contains(&id), "{:?} is duplicated in {:?}", id, ids);
|
||||
ids.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,10 @@
|
||||
mod data_director;
|
||||
mod message;
|
||||
mod mtterror;
|
||||
mod name;
|
||||
mod router;
|
||||
|
||||
use data_director::{Include, Path};
|
||||
use message::{
|
||||
Action, Addition, CalcValue, Calculation, Clock, CreateDoc, Field, FieldType, Message, Operand,
|
||||
RegMsg, Register, Session,
|
||||
@ -10,7 +12,7 @@ use message::{
|
||||
pub use message::{MsgAction, Query};
|
||||
use mtterror::MTTError;
|
||||
use name::{Name, NameType};
|
||||
use router::{Include, Path, Queue};
|
||||
use router::Queue;
|
||||
use std::sync::mpsc::{channel, Receiver};
|
||||
use uuid::Uuid;
|
||||
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
use super::MTTError;
|
||||
use crate::{
|
||||
data_director::{Include, Path},
|
||||
name::{Name, NameType, Names},
|
||||
router::{Include, Path, Queue},
|
||||
router::Queue,
|
||||
};
|
||||
use chrono::prelude::*;
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
ops::{Add, AddAssign},
|
||||
sync::{
|
||||
mpsc::{channel, Receiver},
|
||||
},
|
||||
sync::mpsc::{channel, Receiver},
|
||||
thread::{sleep, spawn},
|
||||
time::Duration,
|
||||
};
|
||||
@ -3691,7 +3690,7 @@ pub struct Records {
|
||||
}
|
||||
|
||||
impl Records {
|
||||
fn new(names: Names) -> Self {
|
||||
pub fn new(names: Names) -> Self {
|
||||
Self {
|
||||
names: names,
|
||||
data: InternalRecords::new(),
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
data_director::{Include, Path},
|
||||
message::Route,
|
||||
mtterror::MTTError,
|
||||
router::{Include, Path},
|
||||
};
|
||||
use isolang::Language;
|
||||
use std::collections::HashMap;
|
||||
|
||||
@ -1,58 +1,16 @@
|
||||
use crate::{mtterror::MTTError, message::{Action, DocRegistry, Message, RegMsg, Register}, name::NameType};
|
||||
use crate::{
|
||||
message::{DocRegistry, Message, RegMsg, Register},
|
||||
mtterror::MTTError,
|
||||
name::NameType,
|
||||
};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
sync::{
|
||||
mpsc::{channel, Sender},
|
||||
Arc, RwLock,
|
||||
},
|
||||
};
|
||||
use uuid::Uuid;
|
||||
use std::{collections::HashMap, sync::{mpsc::{Sender, channel}, Arc, RwLock}};
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash)]
|
||||
pub enum Include<T> {
|
||||
All,
|
||||
Just(T),
|
||||
}
|
||||
|
||||
impl<T: PartialEq> PartialEq for Include<T> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
match self {
|
||||
Include::All => true,
|
||||
Include::Just(data) => match other {
|
||||
Include::All => true,
|
||||
Include::Just(other_data) => data == other_data,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod includes {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn does_all_equal_evberything() {
|
||||
let a: Include<isize> = Include::All;
|
||||
let b: Include<isize> = Include::Just(5);
|
||||
let c: Include<isize> = Include::Just(7);
|
||||
assert!(a == a, "all should equal all");
|
||||
assert!(a == b, "all should equal just");
|
||||
assert!(b == a, "just should equal all");
|
||||
assert!(b == b, "same just should equal");
|
||||
assert!(b != c, "different justs do not equal");
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Path {
|
||||
pub msg_id: Include<Uuid>,
|
||||
pub doc: Include<NameType>,
|
||||
pub action: Include<Action>,
|
||||
}
|
||||
|
||||
impl Path {
|
||||
pub fn new(id: Include<Uuid>, doc: Include<NameType>, action: Include<Action>) -> Self {
|
||||
Self {
|
||||
msg_id: id,
|
||||
doc: doc,
|
||||
action: action,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Router {
|
||||
doc_registry: Sender<Message>,
|
||||
@ -135,9 +93,13 @@ impl Queue {
|
||||
|
||||
#[cfg(test)]
|
||||
mod routers {
|
||||
use crate::{message::{MsgAction, Query}, name::Name, support_tests::TIMEOUT};
|
||||
use std::collections::HashSet;
|
||||
use super::*;
|
||||
use crate::{
|
||||
message::{MsgAction, Query},
|
||||
name::Name,
|
||||
support_tests::TIMEOUT,
|
||||
};
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[test]
|
||||
fn can_pass_message() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user