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
211
src/message.rs
211
src/message.rs
@ -43,6 +43,7 @@ enum Action {
|
||||
Delete,
|
||||
Error,
|
||||
Query,
|
||||
Records,
|
||||
Register,
|
||||
Reply,
|
||||
Show,
|
||||
@ -57,6 +58,7 @@ impl From<MsgAction> for Action {
|
||||
MsgAction::Delete(_) => Action::Delete,
|
||||
MsgAction::Error(_) => Action::Error,
|
||||
MsgAction::Query(_) => Action::Query,
|
||||
MsgAction::Records(_) => Action::Records,
|
||||
MsgAction::Register(_) => Action::Register,
|
||||
MsgAction::Reply(_) => Action::Reply,
|
||||
MsgAction::Show => Action::Show,
|
||||
@ -120,6 +122,7 @@ enum MsgAction {
|
||||
// Remove
|
||||
Error(MTTError),
|
||||
Query(Query),
|
||||
Records(RecordIter),
|
||||
Register(Register),
|
||||
Reply(Reply),
|
||||
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 {
|
||||
fn from(value: Register) -> Self {
|
||||
MsgAction::Register(value)
|
||||
@ -4220,6 +4229,25 @@ impl DocumentFile {
|
||||
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();
|
||||
if !holder.is_empty() {
|
||||
let mut oid = Oid::new();
|
||||
@ -4228,17 +4256,14 @@ impl DocumentFile {
|
||||
}
|
||||
self.docs.insert(oid, holder);
|
||||
|
||||
/*
|
||||
self.docs.insert(oid.clone(), holder.clone());
|
||||
for (key, value) in holder.iter() {
|
||||
self.add_to_index(&key, value.clone(), oid.clone());
|
||||
}
|
||||
reply.add(holder);
|
||||
*/
|
||||
}
|
||||
reply.into()
|
||||
|
||||
/*
|
||||
let mut holder = Document::new();
|
||||
let doc = addition.get_document();
|
||||
for (key, value) in doc.iter() {
|
||||
@ -4385,6 +4410,16 @@ impl DocumentFile {
|
||||
}
|
||||
|
||||
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) {
|
||||
Ok(result) => {
|
||||
let mut reply = Reply::new();
|
||||
@ -4395,6 +4430,7 @@ impl DocumentFile {
|
||||
}
|
||||
Err(err) => err.into(),
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
fn update(&mut self, update: &Update) -> MsgAction {
|
||||
@ -4448,6 +4484,14 @@ mod document_files {
|
||||
use super::{support_test::TIMEOUT, *};
|
||||
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 {
|
||||
docdef: DocDef,
|
||||
queue: Queue,
|
||||
@ -4471,11 +4515,7 @@ mod document_files {
|
||||
Self {
|
||||
docdef: docdef,
|
||||
queue: queue,
|
||||
routes: [
|
||||
Path::new(Include::All, Include::All, Include::Some(Action::Reply)),
|
||||
Path::new(Include::All, Include::All, Include::Some(Action::Error)),
|
||||
]
|
||||
.to_vec(),
|
||||
routes: standard_paths(),
|
||||
sender_id: id,
|
||||
rx: rx,
|
||||
}
|
||||
@ -4541,52 +4581,13 @@ mod document_files {
|
||||
Self {
|
||||
docdef: value,
|
||||
queue: queue,
|
||||
routes: [
|
||||
Path::new(Include::All, Include::All, Include::Some(Action::Reply)),
|
||||
Path::new(Include::All, Include::All, Include::Some(Action::Error)),
|
||||
]
|
||||
.to_vec(),
|
||||
routes: standard_paths(),
|
||||
sender_id: id,
|
||||
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]
|
||||
fn does_not_respond_to_create() {
|
||||
let name = Name::english("quiet".to_string());
|
||||
@ -4637,6 +4638,9 @@ mod document_files {
|
||||
MsgAction::Reply(data) => {
|
||||
assert_eq!(data.len(), 0, "for {:?} got {:?}", msg_action, result)
|
||||
}
|
||||
MsgAction::Records(data) => {
|
||||
assert_eq!(data.len(), 0, "for {:?} got {:?}", msg_action, result)
|
||||
}
|
||||
_ => unreachable!(
|
||||
"for {:?} got {:?}: should have received a reply",
|
||||
msg_action,
|
||||
@ -4679,7 +4683,6 @@ mod document_files {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn can_document_be_added() {
|
||||
let doc_name = Name::english("document".to_string());
|
||||
let mut docdef = DocDef::new(doc_name.clone());
|
||||
@ -4691,100 +4694,32 @@ mod document_files {
|
||||
let queue = test_doc.get_queue();
|
||||
let mut new_doc = Addition::new();
|
||||
new_doc.add_field(name.clone(), data.clone());
|
||||
let msg = Message::new(doc_name, new_doc);
|
||||
queue.send(msg.clone()).unwrap();
|
||||
let result = test_doc.get_receiver().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.clone()) {
|
||||
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),
|
||||
let testing = |msg: Message| {
|
||||
queue.send(msg.clone()).unwrap();
|
||||
let result = test_doc.get_receiver().recv_timeout(TIMEOUT).unwrap();
|
||||
assert_eq!(result.get_message_id(), msg.get_message_id());
|
||||
match result.get_action() {
|
||||
MsgAction::Records(output) => {
|
||||
assert_eq!(output.len(), 1);
|
||||
for rec in output.clone() {
|
||||
let holder = rec.get(&name).unwrap();
|
||||
match holder {
|
||||
Field::Uuid(field_data) => assert_eq!(field_data, data),
|
||||
_ => unreachable!("got {:?}, should have been uuid", holder),
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => unreachable!(
|
||||
"\n\ngot {:?}\n\nfor {:?}\n\nshould have been records",
|
||||
result, msg
|
||||
),
|
||||
}
|
||||
_ => unreachable!(
|
||||
"\n\ngot {:?}\n\nfor {:?}\n\nshould have been a reply",
|
||||
result, docdef
|
||||
),
|
||||
}
|
||||
|
||||
/*
|
||||
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),
|
||||
}
|
||||
*/
|
||||
};
|
||||
testing(Message::new(doc_name.clone(), new_doc));
|
||||
testing(Message::new(doc_name.clone(), Query::new()));
|
||||
}
|
||||
|
||||
/*
|
||||
#[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]
|
||||
fn can_add_multiple_documents() {
|
||||
let count = 4;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user