Got addition working with field name types.
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
5fb6035069
commit
027fc322e6
197
src/message.rs
197
src/message.rs
@ -43,6 +43,7 @@ enum Action {
|
|||||||
Delete,
|
Delete,
|
||||||
Error,
|
Error,
|
||||||
Query,
|
Query,
|
||||||
|
Records,
|
||||||
Register,
|
Register,
|
||||||
Reply,
|
Reply,
|
||||||
Show,
|
Show,
|
||||||
@ -57,6 +58,7 @@ impl From<MsgAction> for Action {
|
|||||||
MsgAction::Delete(_) => Action::Delete,
|
MsgAction::Delete(_) => Action::Delete,
|
||||||
MsgAction::Error(_) => Action::Error,
|
MsgAction::Error(_) => Action::Error,
|
||||||
MsgAction::Query(_) => Action::Query,
|
MsgAction::Query(_) => Action::Query,
|
||||||
|
MsgAction::Records(_) => Action::Records,
|
||||||
MsgAction::Register(_) => Action::Register,
|
MsgAction::Register(_) => Action::Register,
|
||||||
MsgAction::Reply(_) => Action::Reply,
|
MsgAction::Reply(_) => Action::Reply,
|
||||||
MsgAction::Show => Action::Show,
|
MsgAction::Show => Action::Show,
|
||||||
@ -120,6 +122,7 @@ enum MsgAction {
|
|||||||
// Remove
|
// Remove
|
||||||
Error(MTTError),
|
Error(MTTError),
|
||||||
Query(Query),
|
Query(Query),
|
||||||
|
Records(RecordIter),
|
||||||
Register(Register),
|
Register(Register),
|
||||||
Reply(Reply),
|
Reply(Reply),
|
||||||
Show,
|
Show,
|
||||||
@ -157,6 +160,12 @@ impl From<Query> for MsgAction {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<RecordIter> for MsgAction {
|
||||||
|
fn from(value: RecordIter) -> Self {
|
||||||
|
MsgAction::Records(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<Register> for MsgAction {
|
impl From<Register> for MsgAction {
|
||||||
fn from(value: Register) -> Self {
|
fn from(value: Register) -> Self {
|
||||||
MsgAction::Register(value)
|
MsgAction::Register(value)
|
||||||
@ -4220,6 +4229,25 @@ impl DocumentFile {
|
|||||||
Err(err) => return MsgAction::Error(err),
|
Err(err) => return MsgAction::Error(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let mut records = RecordIter::new();
|
||||||
|
if !holder.is_empty() {
|
||||||
|
let mut oid = Oid::new();
|
||||||
|
while self.docs.contains_key(&oid) {
|
||||||
|
oid = Oid::new();
|
||||||
|
}
|
||||||
|
self.docs.insert(oid, holder.clone());
|
||||||
|
let mut rec = Record::new(self.docdef.get_field_names().clone());
|
||||||
|
for (name_id, field) in holder.iter() {
|
||||||
|
rec.insert(name_id, field.clone());
|
||||||
|
}
|
||||||
|
records.push(rec);
|
||||||
|
}
|
||||||
|
records.into()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
let mut reply = Reply::new();
|
let mut reply = Reply::new();
|
||||||
if !holder.is_empty() {
|
if !holder.is_empty() {
|
||||||
let mut oid = Oid::new();
|
let mut oid = Oid::new();
|
||||||
@ -4228,17 +4256,14 @@ impl DocumentFile {
|
|||||||
}
|
}
|
||||||
self.docs.insert(oid, holder);
|
self.docs.insert(oid, holder);
|
||||||
|
|
||||||
/*
|
|
||||||
self.docs.insert(oid.clone(), holder.clone());
|
self.docs.insert(oid.clone(), holder.clone());
|
||||||
for (key, value) in holder.iter() {
|
for (key, value) in holder.iter() {
|
||||||
self.add_to_index(&key, value.clone(), oid.clone());
|
self.add_to_index(&key, value.clone(), oid.clone());
|
||||||
}
|
}
|
||||||
reply.add(holder);
|
reply.add(holder);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
reply.into()
|
reply.into()
|
||||||
|
|
||||||
/*
|
|
||||||
let mut holder = Document::new();
|
let mut holder = Document::new();
|
||||||
let doc = addition.get_document();
|
let doc = addition.get_document();
|
||||||
for (key, value) in doc.iter() {
|
for (key, value) in doc.iter() {
|
||||||
@ -4385,6 +4410,16 @@ impl DocumentFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn query(&self, query: &Query) -> MsgAction {
|
fn query(&self, query: &Query) -> MsgAction {
|
||||||
|
let mut records = RecordIter::new();
|
||||||
|
for rec in self.docs.values() {
|
||||||
|
let mut record = Record::new(self.docdef.get_field_names().clone());
|
||||||
|
for (key, value) in rec.iter() {
|
||||||
|
record.insert(key, value.clone());
|
||||||
|
}
|
||||||
|
records.push(record);
|
||||||
|
}
|
||||||
|
records.into()
|
||||||
|
/*
|
||||||
match self.run_query(query) {
|
match self.run_query(query) {
|
||||||
Ok(result) => {
|
Ok(result) => {
|
||||||
let mut reply = Reply::new();
|
let mut reply = Reply::new();
|
||||||
@ -4395,6 +4430,7 @@ impl DocumentFile {
|
|||||||
}
|
}
|
||||||
Err(err) => err.into(),
|
Err(err) => err.into(),
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, update: &Update) -> MsgAction {
|
fn update(&mut self, update: &Update) -> MsgAction {
|
||||||
@ -4448,6 +4484,14 @@ mod document_files {
|
|||||||
use super::{support_test::TIMEOUT, *};
|
use super::{support_test::TIMEOUT, *};
|
||||||
use std::sync::mpsc::RecvTimeoutError;
|
use std::sync::mpsc::RecvTimeoutError;
|
||||||
|
|
||||||
|
fn standard_paths() -> Vec<Path> {
|
||||||
|
[
|
||||||
|
Path::new(Include::All, Include::All, Include::Some(Action::Records)),
|
||||||
|
Path::new(Include::All, Include::All, Include::Some(Action::Reply)),
|
||||||
|
Path::new(Include::All, Include::All, Include::Some(Action::Error)),
|
||||||
|
].to_vec()
|
||||||
|
}
|
||||||
|
|
||||||
struct TestDocument {
|
struct TestDocument {
|
||||||
docdef: DocDef,
|
docdef: DocDef,
|
||||||
queue: Queue,
|
queue: Queue,
|
||||||
@ -4471,11 +4515,7 @@ mod document_files {
|
|||||||
Self {
|
Self {
|
||||||
docdef: docdef,
|
docdef: docdef,
|
||||||
queue: queue,
|
queue: queue,
|
||||||
routes: [
|
routes: standard_paths(),
|
||||||
Path::new(Include::All, Include::All, Include::Some(Action::Reply)),
|
|
||||||
Path::new(Include::All, Include::All, Include::Some(Action::Error)),
|
|
||||||
]
|
|
||||||
.to_vec(),
|
|
||||||
sender_id: id,
|
sender_id: id,
|
||||||
rx: rx,
|
rx: rx,
|
||||||
}
|
}
|
||||||
@ -4541,52 +4581,13 @@ mod document_files {
|
|||||||
Self {
|
Self {
|
||||||
docdef: value,
|
docdef: value,
|
||||||
queue: queue,
|
queue: queue,
|
||||||
routes: [
|
routes: standard_paths(),
|
||||||
Path::new(Include::All, Include::All, Include::Some(Action::Reply)),
|
|
||||||
Path::new(Include::All, Include::All, Include::Some(Action::Error)),
|
|
||||||
]
|
|
||||||
.to_vec(),
|
|
||||||
sender_id: id,
|
sender_id: id,
|
||||||
rx: rx,
|
rx: rx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
fn standard_routes() -> Vec<RouteRequest> {
|
|
||||||
[
|
|
||||||
RouteRequest::new(Include::All, Include::All, Include::Some(Action::Reply)),
|
|
||||||
RouteRequest::new(Include::All, Include::All, Include::Some(Action::Error)),
|
|
||||||
]
|
|
||||||
.to_vec()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn create_docdef(field_types: Vec<FieldType>) -> (DocDef, String) {
|
|
||||||
let mut output = DocDef::new();
|
|
||||||
let mut count = 0;
|
|
||||||
for field_type in field_types.iter() {
|
|
||||||
output.add_field(format!("field{}", count), field_type.clone());
|
|
||||||
count += 1;
|
|
||||||
}
|
|
||||||
(output, format!("name-{}", Uuid::new_v4()))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn test_doc(
|
|
||||||
name: &str,
|
|
||||||
docdef: DocDef,
|
|
||||||
routes: Vec<RouteRequest>,
|
|
||||||
) -> (Queue, Receiver<Message>) {
|
|
||||||
let (tx, rx) = channel();
|
|
||||||
let mut queue = Queue::new();
|
|
||||||
let msg = Message::new(name, docdef);
|
|
||||||
DocumentFile::start(queue.clone(), msg);
|
|
||||||
queue
|
|
||||||
.register(tx, Uuid::new_v4().to_string(), routes)
|
|
||||||
.unwrap();
|
|
||||||
(queue, rx)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn does_not_respond_to_create() {
|
fn does_not_respond_to_create() {
|
||||||
let name = Name::english("quiet".to_string());
|
let name = Name::english("quiet".to_string());
|
||||||
@ -4637,6 +4638,9 @@ mod document_files {
|
|||||||
MsgAction::Reply(data) => {
|
MsgAction::Reply(data) => {
|
||||||
assert_eq!(data.len(), 0, "for {:?} got {:?}", msg_action, result)
|
assert_eq!(data.len(), 0, "for {:?} got {:?}", msg_action, result)
|
||||||
}
|
}
|
||||||
|
MsgAction::Records(data) => {
|
||||||
|
assert_eq!(data.len(), 0, "for {:?} got {:?}", msg_action, result)
|
||||||
|
}
|
||||||
_ => unreachable!(
|
_ => unreachable!(
|
||||||
"for {:?} got {:?}: should have received a reply",
|
"for {:?} got {:?}: should have received a reply",
|
||||||
msg_action,
|
msg_action,
|
||||||
@ -4679,7 +4683,6 @@ mod document_files {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
#[ignore]
|
|
||||||
fn can_document_be_added() {
|
fn can_document_be_added() {
|
||||||
let doc_name = Name::english("document".to_string());
|
let doc_name = Name::english("document".to_string());
|
||||||
let mut docdef = DocDef::new(doc_name.clone());
|
let mut docdef = DocDef::new(doc_name.clone());
|
||||||
@ -4691,100 +4694,32 @@ mod document_files {
|
|||||||
let queue = test_doc.get_queue();
|
let queue = test_doc.get_queue();
|
||||||
let mut new_doc = Addition::new();
|
let mut new_doc = Addition::new();
|
||||||
new_doc.add_field(name.clone(), data.clone());
|
new_doc.add_field(name.clone(), data.clone());
|
||||||
let msg = Message::new(doc_name, new_doc);
|
let testing = |msg: Message| {
|
||||||
queue.send(msg.clone()).unwrap();
|
queue.send(msg.clone()).unwrap();
|
||||||
let result = test_doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
|
let result = test_doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
|
||||||
assert_eq!(result.get_message_id(), msg.get_message_id());
|
assert_eq!(result.get_message_id(), msg.get_message_id());
|
||||||
match result.get_action() {
|
match result.get_action() {
|
||||||
MsgAction::Reply(output) => {
|
MsgAction::Records(output) => {
|
||||||
assert_eq!(output.len(), 1);
|
assert_eq!(output.len(), 1);
|
||||||
let holder = output.iter().next().unwrap();
|
for rec in output.clone() {
|
||||||
match holder.get_field(name.clone()) {
|
let holder = rec.get(&name).unwrap();
|
||||||
Some(field) => match field {
|
match holder {
|
||||||
Field::Uuid(store) => assert_eq!(store, data),
|
Field::Uuid(field_data) => assert_eq!(field_data, data),
|
||||||
_ => unreachable!(
|
_ => unreachable!("got {:?}, should have been uuid", holder),
|
||||||
"got {:?}: should have received uuid",
|
}
|
||||||
holder.get_field(name).unwrap()
|
|
||||||
),
|
|
||||||
},
|
|
||||||
None => unreachable!("{:?} did not contain field '{:?}'", holder, name),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => unreachable!(
|
_ => unreachable!(
|
||||||
"\n\ngot {:?}\n\nfor {:?}\n\nshould have been a reply",
|
"\n\ngot {:?}\n\nfor {:?}\n\nshould have been records",
|
||||||
result, docdef
|
result, msg
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
testing(Message::new(doc_name.clone(), new_doc));
|
||||||
|
testing(Message::new(doc_name.clone(), Query::new()));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
let (queue, rx) = test_doc(doc_name, docdef, standard_routes());
|
|
||||||
let mut new_doc = Addition::new();
|
|
||||||
new_doc.add_field(name.to_string(), data.clone());
|
|
||||||
let msg = Message::new(doc_name, new_doc);
|
|
||||||
queue.send(msg.clone()).unwrap();
|
|
||||||
let result = rx.recv_timeout(TIMEOUT).unwrap();
|
|
||||||
assert_eq!(result.get_message_id(), msg.get_message_id());
|
|
||||||
match result.get_action() {
|
|
||||||
MsgAction::Reply(output) => {
|
|
||||||
assert_eq!(output.len(), 1);
|
|
||||||
let holder = output.iter().next().unwrap();
|
|
||||||
match holder.get_field(name) {
|
|
||||||
Some(field) => match field {
|
|
||||||
Field::Uuid(store) => assert_eq!(store, data),
|
|
||||||
_ => unreachable!(
|
|
||||||
"got {:?}: should have received uuid",
|
|
||||||
holder.get_field(name).unwrap()
|
|
||||||
),
|
|
||||||
},
|
|
||||||
None => unreachable!("{:?} did not contain field '{}'", holder, name),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => unreachable!("got {:?}: should have been a reply", result),
|
|
||||||
}
|
|
||||||
let msg = Message::new(doc_name, Query::new());
|
|
||||||
queue.send(msg.clone()).unwrap();
|
|
||||||
let result = rx.recv_timeout(TIMEOUT).unwrap();
|
|
||||||
assert_eq!(result.get_message_id(), msg.get_message_id());
|
|
||||||
match result.get_action() {
|
|
||||||
MsgAction::Reply(output) => {
|
|
||||||
assert_eq!(output.len(), 1);
|
|
||||||
let holder = output.iter().next().unwrap();
|
|
||||||
match holder.get_field(name) {
|
|
||||||
Some(field) => match field {
|
|
||||||
Field::Uuid(store) => assert_eq!(store, data),
|
|
||||||
_ => unreachable!(
|
|
||||||
"got {:?}: should have received uuid",
|
|
||||||
holder.get_field(name).unwrap()
|
|
||||||
),
|
|
||||||
},
|
|
||||||
None => unreachable!("{:?} did not contain field '{}'", holder, name),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => unreachable!("got {:?}: should have been a reply", result),
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
#[test]
|
|
||||||
fn only_responses_to_its_additions() {
|
|
||||||
let docdef = DocDef::new();
|
|
||||||
let name = "quiet";
|
|
||||||
let (mut queue, rx) = test_doc(name, docdef, standard_routes());
|
|
||||||
let other = "alternate";
|
|
||||||
let (tx, _) = channel();
|
|
||||||
queue.register(tx, other.to_string(), Vec::new()).unwrap();
|
|
||||||
let msg = Message::new(other, Addition::new());
|
|
||||||
queue.send(msg).unwrap();
|
|
||||||
match rx.recv_timeout(TIMEOUT) {
|
|
||||||
Ok(msg) => unreachable!("should not receive: {:?}", msg),
|
|
||||||
Err(err) => match err {
|
|
||||||
RecvTimeoutError::Timeout => {}
|
|
||||||
_ => unreachable!("should have timed out"),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_add_multiple_documents() {
|
fn can_add_multiple_documents() {
|
||||||
let count = 4;
|
let count = 4;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user