Moved MsgAction into action module.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 2s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 2s
This commit is contained in:
parent
ca68759c79
commit
3d19493763
@ -1,21 +1,8 @@
|
||||
mod message;
|
||||
mod query;
|
||||
mod user;
|
||||
|
||||
pub use crate::document::{definition::DocDef, field::FieldType};
|
||||
pub use message::MsgAction;
|
||||
pub use query::Query;
|
||||
|
||||
pub enum UserAction {
|
||||
CreateDocument(DocDef),
|
||||
Query(Query),
|
||||
}
|
||||
|
||||
impl From<DocDef> for UserAction {
|
||||
fn from(value: DocDef) -> Self {
|
||||
Self::CreateDocument(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Query> for UserAction {
|
||||
fn from(value: Query) -> Self {
|
||||
Self::Query(value)
|
||||
}
|
||||
}
|
||||
pub use user::UserAction;
|
||||
|
||||
148
src/action/message.rs
Normal file
148
src/action/message.rs
Normal file
@ -0,0 +1,148 @@
|
||||
use super::{DocDef, Query, UserAction};
|
||||
use crate::{
|
||||
message::wrapper::{Addition, Delete, Records, Reply, Update},
|
||||
mtterror::MTTError,
|
||||
queue::data_director::Register,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum MsgAction {
|
||||
Addition(Addition),
|
||||
Create(DocDef),
|
||||
Error(MTTError),
|
||||
OnAddition(Records),
|
||||
OnDelete(Records),
|
||||
OnQuery(Records),
|
||||
OnUpdate(Records),
|
||||
Query(Query),
|
||||
Records(Records),
|
||||
Register(Register),
|
||||
Reply(Reply),
|
||||
Show,
|
||||
Delete(Delete),
|
||||
Update(Update),
|
||||
}
|
||||
|
||||
impl From<Addition> for MsgAction {
|
||||
fn from(value: Addition) -> Self {
|
||||
MsgAction::Addition(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Delete> for MsgAction {
|
||||
fn from(value: Delete) -> Self {
|
||||
MsgAction::Delete(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DocDef> for MsgAction {
|
||||
fn from(value: DocDef) -> Self {
|
||||
MsgAction::Create(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MTTError> for MsgAction {
|
||||
fn from(value: MTTError) -> Self {
|
||||
MsgAction::Error(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Query> for MsgAction {
|
||||
fn from(value: Query) -> Self {
|
||||
MsgAction::Query(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Records> for MsgAction {
|
||||
fn from(value: Records) -> Self {
|
||||
MsgAction::Records(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Register> for MsgAction {
|
||||
fn from(value: Register) -> Self {
|
||||
MsgAction::Register(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Reply> for MsgAction {
|
||||
fn from(value: Reply) -> Self {
|
||||
MsgAction::Reply(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Update> for MsgAction {
|
||||
fn from(value: Update) -> Self {
|
||||
MsgAction::Update(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<UserAction> for MsgAction {
|
||||
fn from(value: UserAction) -> Self {
|
||||
match value {
|
||||
UserAction::CreateDocument(data) => Self::Create(data),
|
||||
UserAction::Query(data) => Self::Query(data),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod msgactions {
|
||||
use super::*;
|
||||
use crate::name::Name;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[test]
|
||||
fn turn_document_definition_into_action() {
|
||||
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||
let value = DocDef::new(name.clone());
|
||||
let result: MsgAction = value.into();
|
||||
match result {
|
||||
MsgAction::Create(def) => assert_eq!(def.get_document_names(), &[name].to_vec()),
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn turn_error_into_action() {
|
||||
let data = "data".to_string();
|
||||
let value = MTTError::DocumentAlreadyExists(data.clone());
|
||||
let result: MsgAction = value.into();
|
||||
match result {
|
||||
MsgAction::Error(result) => match result {
|
||||
MTTError::DocumentAlreadyExists(output) => assert_eq!(output, data),
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
},
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
}
|
||||
let value = MTTError::DocumentNotFound(data.clone());
|
||||
let result: MsgAction = value.into();
|
||||
match result {
|
||||
MsgAction::Error(result) => match result {
|
||||
MTTError::DocumentNotFound(output) => assert_eq!(output, data),
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
},
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn turn_query_into_action() {
|
||||
let value = Query::new();
|
||||
let result: MsgAction = value.into();
|
||||
match result {
|
||||
MsgAction::Query(_) => {}
|
||||
_ => unreachable!("Got {:?}: dhould have been query", result),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn turn_reply_into_action() {
|
||||
let value = Reply::new();
|
||||
let result: MsgAction = value.into();
|
||||
match result {
|
||||
MsgAction::Reply(_) => {}
|
||||
_ => unreachable!("Got {:?}: dhould have been reply", result),
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/action/user.rs
Normal file
19
src/action/user.rs
Normal file
@ -0,0 +1,19 @@
|
||||
use super::Query;
|
||||
use crate::document::{definition::DocDef, field::FieldType};
|
||||
|
||||
pub enum UserAction {
|
||||
CreateDocument(DocDef),
|
||||
Query(Query),
|
||||
}
|
||||
|
||||
impl From<DocDef> for UserAction {
|
||||
fn from(value: DocDef) -> Self {
|
||||
Self::CreateDocument(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Query> for UserAction {
|
||||
fn from(value: Query) -> Self {
|
||||
Self::Query(value)
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
use crate::{
|
||||
action::MsgAction,
|
||||
message::{
|
||||
action::{Action, MsgAction},
|
||||
action::Action,
|
||||
wrapper::{Message, Records},
|
||||
},
|
||||
name::{Name, NameType, Names},
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
use crate::{
|
||||
action::Query,
|
||||
action::{MsgAction, Query},
|
||||
document::{
|
||||
definition::{DocDef, DocFuncType},
|
||||
field::Field,
|
||||
},
|
||||
message::{
|
||||
action::{Action, MsgAction},
|
||||
action::Action,
|
||||
wrapper::{
|
||||
CalcValue, Calculation, InternalRecord, InternalRecords, Message, Oid, Records, Reply,
|
||||
Update,
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
use crate::{
|
||||
action::MsgAction,
|
||||
document::{
|
||||
create::IndexType,
|
||||
field::{Field, FieldType},
|
||||
},
|
||||
message::{
|
||||
action::{Action, MsgAction},
|
||||
wrapper::CalcValue,
|
||||
},
|
||||
message::{action::Action, wrapper::CalcValue},
|
||||
mtterror::MTTError,
|
||||
name::{Name, NameType, Names},
|
||||
queue::data_director::{Include, Path},
|
||||
|
||||
@ -89,16 +89,13 @@ impl Session {
|
||||
mod sessions {
|
||||
use super::*;
|
||||
use crate::{
|
||||
action::Query,
|
||||
action::{MsgAction, Query},
|
||||
document::{
|
||||
clock::{clock_test_support::gen_clock_message, Clock},
|
||||
create::CreateDoc,
|
||||
field::Field,
|
||||
},
|
||||
message::{
|
||||
action::MsgAction,
|
||||
wrapper::{Addition, Records},
|
||||
},
|
||||
message::wrapper::{Addition, Records},
|
||||
mtterror::MTTError,
|
||||
name::{Name, NameType, Names},
|
||||
queue::data_director::{Include, Path, RegMsg, Register},
|
||||
|
||||
@ -5,7 +5,7 @@ mod mtterror;
|
||||
mod name;
|
||||
mod queue;
|
||||
|
||||
use action::{DocDef, Query, UserAction};
|
||||
use action::{DocDef, MsgAction, Query, UserAction};
|
||||
use document::{
|
||||
clock::Clock,
|
||||
create::CreateDoc,
|
||||
@ -13,7 +13,7 @@ use document::{
|
||||
session::Session,
|
||||
};
|
||||
use message::{
|
||||
action::{Action, MsgAction},
|
||||
action::Action,
|
||||
wrapper::{Addition, CalcValue, Calculation, Message, Operand},
|
||||
};
|
||||
pub use mtterror::MTTError;
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
action::Query,
|
||||
action::{MsgAction, Query},
|
||||
document::definition::DocDef,
|
||||
message::wrapper::{Addition, Delete, Records, Reply, Update},
|
||||
mtterror::MTTError,
|
||||
@ -52,145 +52,3 @@ impl From<&MsgAction> for Action {
|
||||
Self::from(action)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum MsgAction {
|
||||
Addition(Addition),
|
||||
Create(DocDef),
|
||||
Error(MTTError),
|
||||
OnAddition(Records),
|
||||
OnDelete(Records),
|
||||
OnQuery(Records),
|
||||
OnUpdate(Records),
|
||||
Query(Query),
|
||||
Records(Records),
|
||||
Register(Register),
|
||||
Reply(Reply),
|
||||
Show,
|
||||
Delete(Delete),
|
||||
Update(Update),
|
||||
}
|
||||
|
||||
impl From<Addition> for MsgAction {
|
||||
fn from(value: Addition) -> Self {
|
||||
MsgAction::Addition(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Delete> for MsgAction {
|
||||
fn from(value: Delete) -> Self {
|
||||
MsgAction::Delete(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DocDef> for MsgAction {
|
||||
fn from(value: DocDef) -> Self {
|
||||
MsgAction::Create(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MTTError> for MsgAction {
|
||||
fn from(value: MTTError) -> Self {
|
||||
MsgAction::Error(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Query> for MsgAction {
|
||||
fn from(value: Query) -> Self {
|
||||
MsgAction::Query(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Records> for MsgAction {
|
||||
fn from(value: Records) -> Self {
|
||||
MsgAction::Records(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Register> for MsgAction {
|
||||
fn from(value: Register) -> Self {
|
||||
MsgAction::Register(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Reply> for MsgAction {
|
||||
fn from(value: Reply) -> Self {
|
||||
MsgAction::Reply(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Update> for MsgAction {
|
||||
fn from(value: Update) -> Self {
|
||||
MsgAction::Update(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<UserAction> for MsgAction {
|
||||
fn from(value: UserAction) -> Self {
|
||||
match value {
|
||||
UserAction::CreateDocument(data) => Self::Create(data),
|
||||
UserAction::Query(data) => Self::Query(data),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod msgactions {
|
||||
use super::*;
|
||||
use crate::name::Name;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[test]
|
||||
fn turn_document_definition_into_action() {
|
||||
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||
let value = DocDef::new(name.clone());
|
||||
let result: MsgAction = value.into();
|
||||
match result {
|
||||
MsgAction::Create(def) => assert_eq!(def.get_document_names(), &[name].to_vec()),
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn turn_error_into_action() {
|
||||
let data = "data".to_string();
|
||||
let value = MTTError::DocumentAlreadyExists(data.clone());
|
||||
let result: MsgAction = value.into();
|
||||
match result {
|
||||
MsgAction::Error(result) => match result {
|
||||
MTTError::DocumentAlreadyExists(output) => assert_eq!(output, data),
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
},
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
}
|
||||
let value = MTTError::DocumentNotFound(data.clone());
|
||||
let result: MsgAction = value.into();
|
||||
match result {
|
||||
MsgAction::Error(result) => match result {
|
||||
MTTError::DocumentNotFound(output) => assert_eq!(output, data),
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
},
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn turn_query_into_action() {
|
||||
let value = Query::new();
|
||||
let result: MsgAction = value.into();
|
||||
match result {
|
||||
MsgAction::Query(_) => {}
|
||||
_ => unreachable!("Got {:?}: dhould have been query", result),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn turn_reply_into_action() {
|
||||
let value = Reply::new();
|
||||
let result: MsgAction = value.into();
|
||||
match result {
|
||||
MsgAction::Reply(_) => {}
|
||||
_ => unreachable!("Got {:?}: dhould have been reply", result),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
use crate::{
|
||||
action::Query,
|
||||
action::{MsgAction, Query},
|
||||
document::field::{Field, FieldType},
|
||||
message::action::MsgAction,
|
||||
mtterror::MTTError,
|
||||
name::{NameType, Names},
|
||||
queue::data_director::{Include, Path, Route},
|
||||
|
||||
@ -1,8 +1,6 @@
|
||||
use crate::{
|
||||
message::{
|
||||
action::{Action, MsgAction},
|
||||
wrapper::Message,
|
||||
},
|
||||
action::MsgAction,
|
||||
message::{action::Action, wrapper::Message},
|
||||
mtterror::MTTError,
|
||||
name::{Name, NameType, Names},
|
||||
queue::router::Queue,
|
||||
@ -123,7 +121,7 @@ impl Path {
|
||||
mod paths {
|
||||
use super::*;
|
||||
use crate::{
|
||||
message::{action::MsgAction, wrapper::Records},
|
||||
message::wrapper::Records,
|
||||
name::{Name, Names},
|
||||
};
|
||||
|
||||
|
||||
@ -96,7 +96,11 @@ impl Queue {
|
||||
#[cfg(test)]
|
||||
mod routers {
|
||||
use super::*;
|
||||
use crate::{action::Query, message::action::MsgAction, name::Name, support_tests::TIMEOUT};
|
||||
use crate::{
|
||||
action::{MsgAction, Query},
|
||||
name::Name,
|
||||
support_tests::TIMEOUT,
|
||||
};
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
sync::mpsc::{Receiver, RecvTimeoutError},
|
||||
@ -238,7 +242,7 @@ mod routers {
|
||||
mod queues {
|
||||
use super::*;
|
||||
use crate::{
|
||||
message::action::MsgAction,
|
||||
action::MsgAction,
|
||||
mtterror::MTTError,
|
||||
name::Name,
|
||||
queue::data_director::{Include, Path},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user