mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-20 05:37:57 +00:00
Make sure all restful newsince responses can be sorted by the front end
This commit is contained in:
parent
84caa24d0f
commit
f4210e06d8
@ -3,13 +3,14 @@ package org.servalproject.servaldna.meshmb;
|
||||
/**
|
||||
* Created by jeremy on 10/10/16.
|
||||
*/
|
||||
public class PlyMessage {
|
||||
public class PlyMessage implements Comparable<PlyMessage>{
|
||||
|
||||
public final long _row;
|
||||
public final long offset;
|
||||
public final String token;
|
||||
public final long timestamp;
|
||||
public final String text;
|
||||
|
||||
public PlyMessage(long _row, long offset, String token, long timestamp, String text){
|
||||
this._row = _row;
|
||||
this.offset = offset;
|
||||
@ -17,4 +18,9 @@ public class PlyMessage {
|
||||
this.timestamp = timestamp;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(PlyMessage plyMessage) {
|
||||
return (this.offset < plyMessage.offset) ? -1 : 0;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import org.servalproject.servaldna.Subscriber;
|
||||
import org.servalproject.servaldna.SubscriberId;
|
||||
import org.servalproject.servaldna.ServalDInterfaceException;
|
||||
|
||||
public class MeshMSMessage {
|
||||
public class MeshMSMessage implements Comparable<MeshMSMessage>{
|
||||
|
||||
public enum Type {
|
||||
MESSAGE_SENT,
|
||||
@ -40,7 +40,8 @@ public class MeshMSMessage {
|
||||
public final Subscriber them;
|
||||
@Deprecated
|
||||
public final SubscriberId theirSid;
|
||||
public final long offset;
|
||||
public final long myOffset;
|
||||
public final long theirOffset;
|
||||
public final String token;
|
||||
public final String text;
|
||||
public final boolean isDelivered;
|
||||
@ -52,7 +53,8 @@ public class MeshMSMessage {
|
||||
Type type,
|
||||
Subscriber me,
|
||||
Subscriber them,
|
||||
long offset,
|
||||
long myOffset,
|
||||
long theirOffset,
|
||||
String token,
|
||||
String text,
|
||||
boolean delivered,
|
||||
@ -78,7 +80,8 @@ public class MeshMSMessage {
|
||||
this.mySid = me.sid;
|
||||
this.them = them;
|
||||
this.theirSid = them.sid;
|
||||
this.offset = offset;
|
||||
this.myOffset = myOffset;
|
||||
this.theirOffset = theirOffset;
|
||||
this.token = token;
|
||||
this.text = text;
|
||||
this.isDelivered = delivered;
|
||||
@ -90,11 +93,24 @@ public class MeshMSMessage {
|
||||
public long getId(){
|
||||
switch (type){
|
||||
default:
|
||||
return offset;
|
||||
return myOffset;
|
||||
case MESSAGE_RECEIVED:
|
||||
return -offset;
|
||||
return -theirOffset;
|
||||
case ACK_RECEIVED:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(MeshMSMessage meshMSMessage) {
|
||||
if (this.myOffset < meshMSMessage.myOffset)
|
||||
return -1;
|
||||
if (this.myOffset > meshMSMessage.myOffset)
|
||||
return 1;
|
||||
if (this.theirOffset < meshMSMessage.theirOffset)
|
||||
return -1;
|
||||
if (this.theirOffset > meshMSMessage.theirOffset)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,8 @@ public class MeshMSMessageList extends AbstractJsonList<MeshMSMessage, MeshMSExc
|
||||
.addColumn("type", String.class)
|
||||
.addColumn("my_sid", SubscriberId.class)
|
||||
.addColumn("their_sid", SubscriberId.class)
|
||||
.addColumn("offset", Long.class)
|
||||
.addColumn("my_offset", Long.class)
|
||||
.addColumn("their_offset", Long.class)
|
||||
.addColumn("token", String.class)
|
||||
.addColumn("text", String.class, JSONTokeniser.Narrow.ALLOW_NULL)
|
||||
.addColumn("delivered", Boolean.class)
|
||||
@ -113,7 +114,8 @@ public class MeshMSMessageList extends AbstractJsonList<MeshMSMessage, MeshMSExc
|
||||
type,
|
||||
new Subscriber((SubscriberId)row.get("my_sid")),
|
||||
new Subscriber((SubscriberId)row.get("their_sid")),
|
||||
(Long)row.get("offset"),
|
||||
(Long)row.get("my_offset"),
|
||||
(Long)row.get("their_offset"),
|
||||
(String)row.get("token"),
|
||||
(String)row.get("text"),
|
||||
(Boolean)row.get("delivered"),
|
||||
|
@ -22,7 +22,7 @@ package org.servalproject.servaldna.rhizome;
|
||||
|
||||
import org.servalproject.servaldna.SubscriberId;
|
||||
|
||||
public class RhizomeListBundle {
|
||||
public class RhizomeListBundle implements Comparable<RhizomeListBundle>{
|
||||
|
||||
public final int rowNumber;
|
||||
public final int rowId;
|
||||
@ -49,4 +49,8 @@ public class RhizomeListBundle {
|
||||
this.fromHere = fromHere;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(RhizomeListBundle rhizomeListBundle) {
|
||||
return (this.rowId < rhizomeListBundle.rowId) ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,8 @@ public class Meshms {
|
||||
System.out.println("type=" + msg.type
|
||||
+ ", my_sid=" + msg.mySid
|
||||
+ ", their_sid=" + msg.theirSid
|
||||
+ ", offset=" + msg.offset
|
||||
+ ", my_offset=" + msg.myOffset
|
||||
+ ", their_offset=" + msg.theirOffset
|
||||
+ ", token=" + msg.token
|
||||
+ ", text=" + (msg.text == null ? null : msg.text.replace('\n', '.').replace(' ', '.'))
|
||||
+ ", delivered=" + msg.isDelivered
|
||||
@ -107,7 +108,8 @@ public class Meshms {
|
||||
System.out.println("type=" + msg.type
|
||||
+ ", my_sid=" + msg.mySid
|
||||
+ ", their_sid=" + msg.theirSid
|
||||
+ ", offset=" + msg.offset
|
||||
+ ", my_offset=" + msg.myOffset
|
||||
+ ", their_offset=" + msg.theirOffset
|
||||
+ ", token=" + msg.token
|
||||
+ ", text=" + (msg.text == null ? null : msg.text.replace('\n', '.').replace(' ', '.'))
|
||||
+ ", delivered=" + msg.isDelivered
|
||||
|
8
meshms.c
8
meshms.c
@ -786,7 +786,7 @@ enum meshms_status meshms_message_iterator_prev(struct meshms_message_iterator *
|
||||
switch (iter->_their_reader.type) {
|
||||
case MESSAGE_BLOCK_TYPE_ACK:
|
||||
iter->type = ACK_RECEIVED;
|
||||
iter->offset = iter->_their_reader.record_end_offset;
|
||||
iter->their_offset = iter->_their_reader.record_end_offset;
|
||||
iter->text = NULL;
|
||||
iter->text_length = 0;
|
||||
if (unpack_uint(iter->_their_reader.record, iter->_their_reader.record_length, &iter->ack_offset) == -1)
|
||||
@ -795,7 +795,7 @@ enum meshms_status meshms_message_iterator_prev(struct meshms_message_iterator *
|
||||
return MESHMS_STATUS_UPDATED;
|
||||
case MESSAGE_BLOCK_TYPE_MESSAGE:
|
||||
iter->type = MESSAGE_RECEIVED;
|
||||
iter->offset = iter->_their_reader.record_end_offset;
|
||||
iter->their_offset = iter->_their_reader.record_end_offset;
|
||||
iter->text = (const char *)iter->_their_reader.record;
|
||||
iter->text_length = iter->_their_reader.record_length;
|
||||
if ( iter->_their_reader.record_length != 0
|
||||
@ -830,6 +830,7 @@ enum meshms_status meshms_message_iterator_prev(struct meshms_message_iterator *
|
||||
case MESSAGE_BLOCK_TYPE_ACK:
|
||||
// Read the received messages up to the ack'ed offset
|
||||
if (iter->their_ply.found) {
|
||||
iter->my_offset = iter->_my_reader.record_end_offset;
|
||||
int ofs = unpack_uint(iter->_my_reader.record, iter->_my_reader.record_length, (uint64_t*)&iter->_their_reader.read.offset);
|
||||
if (ofs == -1) {
|
||||
WHYF("Malformed ACK");
|
||||
@ -847,7 +848,8 @@ enum meshms_status meshms_message_iterator_prev(struct meshms_message_iterator *
|
||||
break;
|
||||
case MESSAGE_BLOCK_TYPE_MESSAGE:
|
||||
iter->type = MESSAGE_SENT;
|
||||
iter->offset = iter->_my_reader.record_end_offset;
|
||||
iter->my_offset = iter->_my_reader.record_end_offset;
|
||||
iter->their_offset = 0;
|
||||
iter->text = (const char *)iter->_my_reader.record;
|
||||
iter->text_length = iter->_my_reader.record_length;
|
||||
iter->delivered = iter->_my_reader.record_end_offset <= iter->metadata.their_last_ack;
|
||||
|
3
meshms.h
3
meshms.h
@ -136,7 +136,8 @@ struct meshms_message_iterator {
|
||||
// (mine). For MESSAGE_RECEIVED and ACK_RECEIVED, it is the byte position
|
||||
// within the remote ply (theirs).
|
||||
time_s_t timestamp;
|
||||
uint64_t offset;
|
||||
uint64_t my_offset;
|
||||
uint64_t their_offset; // 0 for records from MY_PLY
|
||||
const char *text; // text of UTF8 message (NUL terminated)
|
||||
size_t text_length; // excluding terminating NUL
|
||||
union {
|
||||
|
10
meshms_cli.c
10
meshms_cli.c
@ -166,7 +166,7 @@ static int app_meshms_list_messages(const struct cli_parsed *parsed, struct cli_
|
||||
return status;
|
||||
}
|
||||
const char *names[]={
|
||||
"_id","offset","age","type","message"
|
||||
"_id","my_offset","their_offset","age","type","message"
|
||||
};
|
||||
cli_start_table(context, NELS(names), names);
|
||||
bool_t marked_delivered = 0;
|
||||
@ -178,6 +178,7 @@ static int app_meshms_list_messages(const struct cli_parsed *parsed, struct cli_
|
||||
case MESSAGE_SENT:
|
||||
if (iter.delivered && !marked_delivered){
|
||||
cli_put_long(context, id++, ":");
|
||||
cli_put_long(context, iter.my_offset, ":");
|
||||
cli_put_long(context, iter.metadata.their_last_ack_offset, ":");
|
||||
cli_put_long(context, iter.timestamp ? (now - iter.timestamp):(long)-1, ":");
|
||||
cli_put_string(context, "ACK", ":");
|
||||
@ -186,7 +187,8 @@ static int app_meshms_list_messages(const struct cli_parsed *parsed, struct cli_
|
||||
}
|
||||
// TODO new message format here
|
||||
cli_put_long(context, id++, ":");
|
||||
cli_put_long(context, iter.offset, ":");
|
||||
cli_put_long(context, iter.my_offset, ":");
|
||||
cli_put_long(context, iter.their_offset, ":");
|
||||
cli_put_long(context, iter.timestamp ? (now - iter.timestamp):(long)-1, ":");
|
||||
cli_put_string(context, ">", ":");
|
||||
cli_put_string(context, iter.text, "\n");
|
||||
@ -197,6 +199,7 @@ static int app_meshms_list_messages(const struct cli_parsed *parsed, struct cli_
|
||||
if (iter.read && !marked_read) {
|
||||
cli_put_long(context, id++, ":");
|
||||
cli_put_long(context, iter.metadata.read_offset, ":");
|
||||
cli_put_long(context, 0, ":");
|
||||
cli_put_long(context, iter.timestamp ? (now - iter.timestamp):(long)-1, ":");
|
||||
cli_put_string(context, "MARK", ":");
|
||||
cli_put_string(context, "read", "\n");
|
||||
@ -204,7 +207,8 @@ static int app_meshms_list_messages(const struct cli_parsed *parsed, struct cli_
|
||||
}
|
||||
// TODO new message format here
|
||||
cli_put_long(context, id++, ":");
|
||||
cli_put_long(context, iter.offset, ":");
|
||||
cli_put_long(context, iter.my_offset, ":");
|
||||
cli_put_long(context, iter.their_offset, ":");
|
||||
cli_put_long(context, iter.timestamp ? (now - iter.timestamp):(long)-1, ":");
|
||||
cli_put_string(context, "<", ":");
|
||||
cli_put_string(context, iter.text, "\n");
|
||||
|
@ -341,7 +341,7 @@ static enum meshms_status reopen_meshms_message_iterator(httpd_request *r)
|
||||
r->u.msglist.finished = status != MESHMS_STATUS_UPDATED;
|
||||
if (!r->u.msglist.finished) {
|
||||
r->u.msglist.latest.which_ply = r->u.msglist.iter.which_ply;
|
||||
r->u.msglist.latest.offset = r->u.msglist.iter.offset;
|
||||
r->u.msglist.latest.offset = r->u.msglist.iter.which_ply == MY_PLY ? r->u.msglist.iter.my_offset : r->u.msglist.iter.their_offset;
|
||||
r->u.msglist.current.their_ack = r->u.msglist.latest.their_ack = r->u.msglist.iter.metadata.their_last_ack;
|
||||
}
|
||||
}
|
||||
@ -418,7 +418,8 @@ static int restful_meshms_messagelist_json_content_chunk(struct http_request *hr
|
||||
"type",
|
||||
"my_sid",
|
||||
"their_sid",
|
||||
"offset",
|
||||
"my_offset",
|
||||
"their_offset",
|
||||
"token",
|
||||
"text",
|
||||
"delivered",
|
||||
@ -450,9 +451,9 @@ static int restful_meshms_messagelist_json_content_chunk(struct http_request *hr
|
||||
case LIST_ROWS:
|
||||
{
|
||||
r->u.msglist.current.which_ply = r->u.msglist.iter.which_ply;
|
||||
r->u.msglist.current.offset = r->u.msglist.iter.offset;
|
||||
r->u.msglist.current.offset = (r->u.msglist.iter.which_ply == MY_PLY) ? r->u.msglist.iter.my_offset : r->u.msglist.iter.their_offset;
|
||||
if ( r->u.msglist.finished
|
||||
|| (r->u.msglist.token.which_ply == r->u.msglist.iter.which_ply && r->u.msglist.iter.offset <= r->u.msglist.token.offset)
|
||||
|| (r->u.msglist.token.which_ply == r->u.msglist.current.which_ply && r->u.msglist.current.offset <= r->u.msglist.token.offset)
|
||||
) {
|
||||
time_ms_t now;
|
||||
if (r->u.msglist.end_time && (now = gettime_ms()) < r->u.msglist.end_time) {
|
||||
@ -479,7 +480,7 @@ static int restful_meshms_messagelist_json_content_chunk(struct http_request *hr
|
||||
// if you haven't seen the current ack && this is the message that was acked.
|
||||
// output the ack now
|
||||
if (r->u.msglist.token.their_ack != r->u.msglist.latest.their_ack &&
|
||||
r->u.msglist.iter.offset <= r->u.msglist.latest.their_ack){
|
||||
r->u.msglist.current.offset <= r->u.msglist.latest.their_ack){
|
||||
_messagelist_json_ack(r, b);
|
||||
if (!strbuf_overrun(b)){
|
||||
++r->u.msglist.rowcount;
|
||||
@ -497,7 +498,9 @@ static int restful_meshms_messagelist_json_content_chunk(struct http_request *hr
|
||||
strbuf_putc(b, ',');
|
||||
strbuf_json_hex(b, r->u.msglist.iter.their_sid.binary, sizeof r->u.msglist.iter.their_sid.binary);
|
||||
strbuf_putc(b, ',');
|
||||
strbuf_sprintf(b, "%"PRIu64, r->u.msglist.iter.offset);
|
||||
strbuf_sprintf(b, "%"PRIu64, r->u.msglist.iter.my_offset);
|
||||
strbuf_putc(b, ',');
|
||||
strbuf_sprintf(b, "%"PRIu64, r->u.msglist.iter.their_offset);
|
||||
strbuf_putc(b, ',');
|
||||
strbuf_json_string(b, alloca_meshms_token(&r->u.msglist.current));
|
||||
strbuf_putc(b, ',');
|
||||
@ -523,7 +526,9 @@ static int restful_meshms_messagelist_json_content_chunk(struct http_request *hr
|
||||
strbuf_putc(b, ',');
|
||||
strbuf_json_hex(b, r->u.msglist.iter.their_sid.binary, sizeof r->u.msglist.iter.their_sid.binary);
|
||||
strbuf_putc(b, ',');
|
||||
strbuf_sprintf(b, "%"PRIu64, r->u.msglist.iter.offset);
|
||||
strbuf_sprintf(b, "%"PRIu64, r->u.msglist.iter.my_offset);
|
||||
strbuf_putc(b, ',');
|
||||
strbuf_sprintf(b, "%"PRIu64, r->u.msglist.iter.their_offset);
|
||||
strbuf_putc(b, ',');
|
||||
strbuf_json_string(b, alloca_meshms_token(&r->u.msglist.current));
|
||||
strbuf_putc(b, ',');
|
||||
@ -577,6 +582,8 @@ static void _messagelist_json_ack(struct httpd_request *r, strbuf b)
|
||||
strbuf_putc(b, ',');
|
||||
strbuf_json_hex(b, r->u.msglist.iter.their_sid.binary, sizeof r->u.msglist.iter.their_sid.binary);
|
||||
strbuf_putc(b, ',');
|
||||
strbuf_sprintf(b, "%"PRIu64, r->u.msglist.iter.my_offset);
|
||||
strbuf_putc(b, ',');
|
||||
strbuf_sprintf(b, "%"PRIu64, r->u.msglist.iter.metadata.their_last_ack_offset);
|
||||
strbuf_putc(b, ',');
|
||||
strbuf_json_string(b, alloca_meshms_token(&r->u.msglist.current));
|
||||
|
40
tests/meshms
40
tests/meshms
@ -52,8 +52,8 @@ setup_InitiallyEmpty() {
|
||||
test_InitiallyEmpty() {
|
||||
executeOk_servald meshms list messages $SIDA1 $SIDA2
|
||||
tfw_cat --stdout
|
||||
assertStdoutIs --stdout --line=1 -e '5\n'
|
||||
assertStdoutIs --stdout --line=2 -e '_id:offset:age:type:message\n'
|
||||
assertStdoutIs --stdout --line=1 -e '6\n'
|
||||
assertStdoutIs --stdout --line=2 -e '_id:my_offset:their_offset:age:type:message\n'
|
||||
assertStdoutLineCount '==' 2
|
||||
}
|
||||
|
||||
@ -69,25 +69,25 @@ test_SendAndList() {
|
||||
tfw_cat --stderr
|
||||
executeOk_servald meshms list messages $SIDA1 $SIDA2
|
||||
tfw_cat --stderr
|
||||
assertStdoutGrep --stdout --matches=1 "^0:12:$rexp_age:>:Message 1\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^0:12:0:$rexp_age:>:Message 1\$"
|
||||
executeOk_servald meshms send message $SIDA1 $SIDA2 "Message 2"
|
||||
tfw_cat --stderr
|
||||
executeOk_servald meshms list messages $SIDA1 $SIDA2
|
||||
tfw_cat --stderr
|
||||
assertStdoutGrep --stdout --matches=1 "^0:30:$rexp_age:>:Message 2\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^1:12:$rexp_age:>:Message 1\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^0:30:0:$rexp_age:>:Message 2\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^1:12:0:$rexp_age:>:Message 1\$"
|
||||
executeOk_servald meshms send message $SIDA1 $SIDA2 "Message 3"
|
||||
executeOk_servald meshms list messages $SIDA1 $SIDA2
|
||||
tfw_cat --stdout
|
||||
assertStdoutGrep --stdout --matches=1 "^0:48:$rexp_age:>:Message 3\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^1:30:$rexp_age:>:Message 2\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^2:12:$rexp_age:>:Message 1\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^0:48:0:$rexp_age:>:Message 3\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^1:30:0:$rexp_age:>:Message 2\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^2:12:0:$rexp_age:>:Message 1\$"
|
||||
assertStdoutLineCount '==' 5
|
||||
executeOk_servald meshms list messages $SIDA2 $SIDA1
|
||||
tfw_cat --stdout
|
||||
assertStdoutGrep --stdout --matches=1 "^0:48:$rexp_age:<:Message 3\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^1:30:$rexp_age:<:Message 2\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^2:12:$rexp_age:<:Message 1\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^0:3:48:$rexp_age:<:Message 3\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^1:3:30:$rexp_age:<:Message 2\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^2:3:12:$rexp_age:<:Message 1\$"
|
||||
assertStdoutLineCount '==' 5
|
||||
}
|
||||
|
||||
@ -142,20 +142,20 @@ test_MessageThreading() {
|
||||
set_instance +B
|
||||
wait_until has_unread_messages $SIDB
|
||||
executeOk_servald meshms list messages $SIDB $SIDA
|
||||
assertStdoutGrep --stdout --matches=1 "^0:46:$rexp_age:<:Still waiting\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^1:24:$rexp_age:<:Hello can you hear me\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^2:60:$rexp_age:>:Never mind\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^3:41:$rexp_age:>:Help Im trapped in a test case factory\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^0:69:46:$rexp_age:<:Still waiting\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^1:69:24:$rexp_age:<:Hello can you hear me\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^2:60:0:$rexp_age:>:Never mind\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^3:41:0:$rexp_age:>:Help Im trapped in a test case factory\$"
|
||||
assertStdoutLineCount '==' 6
|
||||
set_instance +A
|
||||
wait_until has_unread_messages $SIDA
|
||||
wait_until messages_delivered $SIDA $SIDB
|
||||
executeOk_servald meshms list messages $SIDA $SIDB
|
||||
assertStdoutGrep --stdout --matches=1 "^0:60:$rexp_age:<:Never mind\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^1:41:$rexp_age:<:Help Im trapped in a test case factory\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^2:69:$rexp_age:ACK:delivered\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^3:46:$rexp_age:>:Still waiting\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^4:24:$rexp_age:>:Hello can you hear me\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^0:55:60:$rexp_age:<:Never mind\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^1:55:41:$rexp_age:<:Help Im trapped in a test case factory\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^2:46:69:$rexp_age:ACK:delivered\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^3:46:0:$rexp_age:>:Still waiting\$"
|
||||
assertStdoutGrep --stdout --matches=1 "^4:24:0:$rexp_age:>:Hello can you hear me\$"
|
||||
assertStdoutLineCount '==' 7
|
||||
}
|
||||
|
||||
|
@ -92,9 +92,9 @@ setup_MeshmsListMessages() {
|
||||
meshms_add_messages $SIDA1 $SIDA2 '><>>A>A<>><><><>>>A>A><<<<<>><>>A<<>'
|
||||
let NROWS=NSENT+NRECV+(NACK?1:0)
|
||||
executeOk_servald meshms list messages $SIDA1 $SIDA2
|
||||
delivered_offset=$(sed -n -e '/^[0-9]\+:[0-9]\+:[0-9]\+:ACK:delivered$/{n;s/^[0-9]\+:\([0-9]\+\):[0-9]\+:>:.*/\1/p;q}' "$TFWSTDOUT")
|
||||
delivered_offset=$(sed -n -e '/^[0-9]\+:[0-9]\+:[0-9]\+:[0-9]\+:ACK:delivered$/{n;s/^[0-9]\+:\([0-9]\+\):[0-9]\+:[0-9]\+:>:.*/\1/p;q}' "$TFWSTDOUT")
|
||||
[ -z "$delivered_offset" ] && delivered_offset=0
|
||||
read_offset=$(sed -n -e 's/^[0-9]\+:\([0-9]\+\):[0-9]\+MARK:read$/\1/p' "$TFWSTDOUT")
|
||||
read_offset=$(sed -n -e 's/^[0-9]\+:[0-9]\+:\([0-9]\+\):[0-9]\+:MARK:read$/\1/p' "$TFWSTDOUT")
|
||||
[ -z "$read_offset" ] && read_offset=0
|
||||
tfw_log delivered_offset="$delivered_offset" read_offset="$read_offset"
|
||||
}
|
||||
@ -113,11 +113,12 @@ test_MeshmsListMessages() {
|
||||
assertStdoutGrep --line=$lnum "my_sid=$SIDA1,"
|
||||
assertStdoutGrep --line=$lnum "their_sid=$SIDA2,"
|
||||
text="$(sed -n -e $lnum's/.*\<text=\([^ ]*\), .*/\1/p' "$TFWSTDOUT")"
|
||||
offset="$(sed -n -e $lnum's/.*\<offset=\([0-9]\+\).*/\1/p' "$TFWSTDOUT")"
|
||||
my_offset="$(sed -n -e $lnum's/.*\<my_offset=\([0-9]\+\).*/\1/p' "$TFWSTDOUT")"
|
||||
their_offset="$(sed -n -e $lnum's/.*\<their_offset=\([0-9]\+\).*/\1/p' "$TFWSTDOUT")"
|
||||
is_delivered="$(sed -n -e $lnum's/.*\<delivered=\(true\|false\).*/\1/p' "$TFWSTDOUT")"
|
||||
is_read="$(sed -n -e $lnum's/.*\<read=\(true\|false\).*/\1/p' "$TFWSTDOUT")"
|
||||
ack_offset="$(sed -n -e $lnum's/.*\<ack_offset=\(null\|[0-9]\+\).*/\1/p' "$TFWSTDOUT")"
|
||||
tfw_log text="$text" offset="$offset" is_delivered="$is_delivered" is_read="$is_read" ack_offset="$ack_offset"
|
||||
tfw_log text="$text" my_offset="$my_offset" their_offset="$their_offset" is_delivered="$is_delivered" is_read="$is_read" ack_offset="$ack_offset"
|
||||
case ${MESSAGE[$j]} in
|
||||
'>'|'<')
|
||||
echo -n "${TEXT[$j]}" | tr ' \n' . >text_fixture
|
||||
@ -129,7 +130,7 @@ test_MeshmsListMessages() {
|
||||
case ${MESSAGE[$j]} in
|
||||
'>')
|
||||
assertStdoutGrep --line=$lnum 'type=MESSAGE_SENT,'
|
||||
if [ "$offset" -le "$delivered_offset" ]; then
|
||||
if [ "$my_offset" -le "$delivered_offset" ]; then
|
||||
assert [ "$is_delivered" = true ]
|
||||
else
|
||||
assert [ "$is_delivered" = false ]
|
||||
@ -138,7 +139,7 @@ test_MeshmsListMessages() {
|
||||
;;
|
||||
'<')
|
||||
assertStdoutGrep --line=$lnum 'type=MESSAGE_RECEIVED,'
|
||||
if [ "$offset" -le "$read_offset" ]; then
|
||||
if [ "$their_offset" -le "$read_offset" ]; then
|
||||
assert [ "$is_read" = true ]
|
||||
else
|
||||
assert [ "$is_read" = false ]
|
||||
|
@ -216,9 +216,10 @@ setup_MeshmsListMessages() {
|
||||
meshms_add_messages $SIDA1 $SIDA2 '><>>A>A<>><><><>>>A>A><<<<<>><>>A<<>'
|
||||
let NROWS=NSENT+NRECV+(NACK?1:0)
|
||||
executeOk_servald meshms list messages $SIDA1 $SIDA2
|
||||
delivered_offset=$($SED -n -e '/^[0-9]\+:[0-9]\+:[0-9]\+:ACK:delivered$/{n;s/^[0-9]\+:\([0-9]\+\):[0-9]\+:>:.*/\1/p;q}' "$TFWSTDOUT")
|
||||
tfw_cat --stdout
|
||||
delivered_offset=$($SED -n -e '/^[0-9]\+:[0-9]\+:[0-9]\+:[0-9]\+:ACK:delivered$/{n;s/^[0-9]\+:\([0-9]\+\):[0-9]\+:[0-9]\+:>:.*/\1/p;q}' "$TFWSTDOUT")
|
||||
[ -z "$delivered_offset" ] && delivered_offset=0
|
||||
read_offset=$($SED -n -e 's/^[0-9]\+:\([0-9]\+\):[0-9]\+:MARK:read$/\1/p' "$TFWSTDOUT")
|
||||
read_offset=$($SED -n -e 's/^[0-9]\+:[0-9]\+:\([0-9]\+\):[0-9]\+:MARK:read$/\1/p' "$TFWSTDOUT")
|
||||
[ -z "$read_offset" ] && read_offset=0
|
||||
tfw_log "delivered: $delivered_offset; read: $read_offset"
|
||||
}
|
||||
@ -247,13 +248,13 @@ test_MeshmsListMessages() {
|
||||
'>')
|
||||
assertJq messages.json '.['$i'].type == ">"'
|
||||
assertJqIs messages.json '.['$i'].text' "${TEXT[$j]}"
|
||||
assertJq messages.json '.['$i'].delivered == (.['$i'].offset <= '$delivered_offset')'
|
||||
assertJq messages.json '.['$i'].delivered == (.['$i'].my_offset <= '$delivered_offset')'
|
||||
let ++i
|
||||
;;
|
||||
'<')
|
||||
assertJq messages.json '.['$i'].type == "<"'
|
||||
assertJqIs messages.json '.['$i'].text' "${TEXT[$j]}"
|
||||
assertJq messages.json '.['$i'].read == (.['$i'].offset <= '$read_offset')'
|
||||
assertJq messages.json '.['$i'].read == (.['$i'].their_offset <= '$read_offset')'
|
||||
let ++i
|
||||
;;
|
||||
'ACK')
|
||||
|
Loading…
Reference in New Issue
Block a user