2014-06-11 07:51:08 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Tests for MeshMS Java API.
|
|
|
|
#
|
|
|
|
# Copyright 2014 Serval Project Inc.
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
source "${0%/*}/../testframework.sh"
|
|
|
|
source "${0%/*}/../testdefs.sh"
|
|
|
|
source "${0%/*}/../testdefs_java.sh"
|
2014-06-17 06:34:30 +00:00
|
|
|
source "${0%/*}/../testdefs_meshms.sh"
|
2014-06-11 07:51:08 +00:00
|
|
|
|
|
|
|
setup() {
|
|
|
|
setup_servald
|
|
|
|
setup_servald_so
|
|
|
|
compile_java_classes
|
|
|
|
set_instance +A
|
|
|
|
executeOk_servald config \
|
|
|
|
set log.console.level debug \
|
2014-07-13 20:35:58 +00:00
|
|
|
set debug.httpd on \
|
|
|
|
set debug.meshms on
|
|
|
|
set_extra_config
|
2014-06-17 06:34:30 +00:00
|
|
|
create_identities 4
|
2014-06-11 07:51:08 +00:00
|
|
|
start_servald_server
|
|
|
|
}
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
stop_all_servald_servers
|
|
|
|
kill_all_servald_processes
|
|
|
|
assert_no_servald_processes
|
|
|
|
report_all_servald_servers
|
|
|
|
}
|
|
|
|
|
2014-07-13 20:35:58 +00:00
|
|
|
set_extra_config() {
|
|
|
|
:
|
|
|
|
}
|
|
|
|
|
2014-06-11 07:51:08 +00:00
|
|
|
doc_MeshmsListConversations="Java API list MeshMS conversations"
|
|
|
|
setup_MeshmsListConversations() {
|
|
|
|
setup
|
|
|
|
# create 3 threads, with all permutations of incoming and outgoing messages
|
|
|
|
executeOk_servald meshms send message $SIDA1 $SIDA2 "Message One"
|
|
|
|
executeOk_servald meshms send message $SIDA3 $SIDA1 "Message Two"
|
|
|
|
executeOk_servald meshms send message $SIDA1 $SIDA4 "Message Three"
|
|
|
|
executeOk_servald meshms send message $SIDA4 $SIDA1 "Message Four"
|
|
|
|
}
|
|
|
|
test_MeshmsListConversations() {
|
|
|
|
executeJavaOk org.servalproject.test.Meshms meshms-list-conversations $SIDA1
|
2014-06-17 06:34:30 +00:00
|
|
|
tfw_cat --stderr
|
2014-06-11 07:51:08 +00:00
|
|
|
assertStdoutLineCount '==' 3
|
|
|
|
assertStdoutGrep "my_sid=$SIDA1, their_sid=$SIDA2, read=true, last_message=0, read_offset=0"
|
|
|
|
assertStdoutGrep "my_sid=$SIDA1, their_sid=$SIDA3, read=false, last_message=14, read_offset=0"
|
2014-07-14 06:51:12 +00:00
|
|
|
assertStdoutGrep "my_sid=$SIDA1, their_sid=$SIDA4, read=false, last_message=24, read_offset=0"
|
2014-06-11 07:51:08 +00:00
|
|
|
executeOk_servald meshms read messages $SIDA1
|
|
|
|
executeJavaOk org.servalproject.test.Meshms meshms-list-conversations $SIDA1
|
|
|
|
assertStdoutLineCount '==' 3
|
|
|
|
assertStdoutGrep "my_sid=$SIDA1, their_sid=$SIDA2, read=true, last_message=0, read_offset=0"
|
|
|
|
assertStdoutGrep "my_sid=$SIDA1, their_sid=$SIDA3, read=true, last_message=14, read_offset=14"
|
2014-07-14 06:51:12 +00:00
|
|
|
assertStdoutGrep "my_sid=$SIDA1, their_sid=$SIDA4, read=true, last_message=24, read_offset=24"
|
2014-06-11 07:51:08 +00:00
|
|
|
}
|
|
|
|
|
2014-06-17 06:34:30 +00:00
|
|
|
doc_MeshmsListMessages="Java API list MeshMS messages in one conversation"
|
|
|
|
setup_MeshmsListMessages() {
|
|
|
|
setup
|
|
|
|
meshms_add_messages $SIDA1 $SIDA2 '><>>A>A<>><><><>>>A>A><<<<A<>><>>A<<>'
|
|
|
|
let NROWS=NSENT+NRECV+(NACK?1:0)
|
|
|
|
executeOk_servald meshms list messages $SIDA1 $SIDA2
|
2014-07-14 06:51:12 +00:00
|
|
|
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")
|
2014-06-17 06:34:30 +00:00
|
|
|
[ -z "$delivered_offset" ] && delivered_offset=0
|
2014-07-14 06:51:12 +00:00
|
|
|
read_offset=$(sed -n -e 's/^[0-9]\+:\([0-9]\+\):[0-9]\+MARK:read$/\1/p' "$TFWSTDOUT")
|
2014-06-17 06:34:30 +00:00
|
|
|
[ -z "$read_offset" ] && read_offset=0
|
|
|
|
tfw_log delivered_offset="$delivered_offset" read_offset="$read_offset"
|
|
|
|
}
|
|
|
|
test_MeshmsListMessages() {
|
|
|
|
executeJavaOk org.servalproject.test.Meshms meshms-list-messages $SIDA1 $SIDA2
|
|
|
|
assertStdoutLineCount '==' $(($NROWS + 2))
|
|
|
|
assertStdoutIs --line=1 -e "read_offset=$read_offset\n"
|
|
|
|
assertStdoutIs --line=2 -e "latest_ack_offset=$delivered_offset\n"
|
|
|
|
seen_ack=false
|
|
|
|
let lnum=3
|
|
|
|
for ((j = NMESSAGE-1; j >= 0; --j)); do
|
|
|
|
case ${MESSAGE[$j]} in
|
|
|
|
'ACK') $seen_ack && continue
|
|
|
|
esac
|
|
|
|
assertStdoutGrep --line=$lnum 'token=[-_A-Za-z0-9=]\+,'
|
|
|
|
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")"
|
|
|
|
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"
|
|
|
|
case ${MESSAGE[$j]} in
|
|
|
|
'>'|'<')
|
|
|
|
echo -n "${TEXT[$j]}" | tr ' \n' . >text_fixture
|
|
|
|
echo -n "$text" >text_list
|
|
|
|
assert --dump-on-fail=text_fixture --dump-on-fail=text_list cmp text_fixture text_list
|
|
|
|
assert [ "$ack_offset" = null ]
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
case ${MESSAGE[$j]} in
|
|
|
|
'>')
|
|
|
|
assertStdoutGrep --line=$lnum 'type=MESSAGE_SENT,'
|
|
|
|
if [ "$offset" -le "$delivered_offset" ]; then
|
|
|
|
assert [ "$is_delivered" = true ]
|
|
|
|
else
|
|
|
|
assert [ "$is_delivered" = false ]
|
|
|
|
fi
|
|
|
|
let ++lnum
|
|
|
|
;;
|
|
|
|
'<')
|
|
|
|
assertStdoutGrep --line=$lnum 'type=MESSAGE_RECEIVED,'
|
|
|
|
if [ "$offset" -le "$read_offset" ]; then
|
|
|
|
assert [ "$is_read" = true ]
|
|
|
|
else
|
|
|
|
assert [ "$is_read" = false ]
|
|
|
|
fi
|
|
|
|
let ++lnum
|
|
|
|
;;
|
|
|
|
'ACK')
|
|
|
|
assertStdoutGrep --line=$lnum 'type=ACK_RECEIVED,'
|
|
|
|
assert [ "$text" = null ]
|
|
|
|
assert [ "$ack_offset" = "$delivered_offset" ]
|
|
|
|
seen_ack=true
|
|
|
|
let ++lnum
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2014-07-13 20:35:58 +00:00
|
|
|
doc_MeshmsListMessagesNewSince="Java API list MeshMS messages in one conversation since token"
|
|
|
|
setup_MeshmsListMessagesNewSince() {
|
|
|
|
set_extra_config() {
|
|
|
|
executeOk_servald config set api.restful.newsince_timeout 1s \
|
|
|
|
set api.restful.newsince_poll_ms 500
|
|
|
|
}
|
|
|
|
setup
|
|
|
|
meshms_add_messages $SIDA1 $SIDA2 '><>>A>A<>><><><>>>A>A><<<<A<>><>>A<<>'
|
|
|
|
let NROWS=NSENT+NRECV+(NACK?1:0)
|
|
|
|
executeJavaOk org.servalproject.test.Meshms meshms-list-messages "$SIDA1" "$SIDA2"
|
|
|
|
tfw_cat --stdout --stderr
|
|
|
|
assertStdoutLineCount == $(($NROWS + 2))
|
|
|
|
replayStdout | sed -n -e '3,$p' >messages
|
|
|
|
tfw_preserve messages
|
|
|
|
for ((i = 0; i < NROWS; i += 3)); do
|
|
|
|
let lnum=i+1
|
|
|
|
token[$i]=$(sed -n -e $lnum's/.*\<token=\([^ ]*\), .*/\1/p' messages)
|
|
|
|
assert [ -n "${token[$i]}" ]
|
|
|
|
done
|
|
|
|
}
|
|
|
|
test_MeshmsListMessagesNewSince() {
|
|
|
|
list() {
|
|
|
|
executeJavaOk org.servalproject.test.Meshms meshms-list-messages-since "$SIDA1" "$SIDA2" "${token[$i]}"
|
|
|
|
replayStdout >messages$i
|
|
|
|
tfw_preserve messages$i
|
|
|
|
}
|
|
|
|
for ((i = 0; i < NROWS; i += 3)); do
|
|
|
|
# At most fifteen requests going at once
|
|
|
|
[ $i -ge 15 ] && fork_wait %list$((i-15))
|
|
|
|
fork %list$i list
|
|
|
|
done
|
|
|
|
fork_wait_all
|
|
|
|
for ((i = 0; i < NROWS; i += 3)); do
|
|
|
|
>tmp
|
|
|
|
[ $i -gt 0 ] && sed -n -e "1,${i}p" messages >tmp
|
|
|
|
tfw_preserve tmp
|
|
|
|
assert cmp tmp messages$i
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
grepall() {
|
|
|
|
local pattern="$1"
|
|
|
|
shift
|
|
|
|
for file; do
|
|
|
|
grep "$pattern" "$file" || return $?
|
|
|
|
done
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_MeshmsListMessagesNewSinceArrival="Java API list newly arriving MeshMS messages in one conversation"
|
|
|
|
setup_MeshmsListMessagesNewSinceArrival() {
|
|
|
|
set_extra_config() {
|
|
|
|
executeOk_servald config set api.restful.newsince_timeout 60s \
|
|
|
|
set api.restful.newsince_poll_ms 500
|
|
|
|
}
|
|
|
|
setup
|
|
|
|
meshms_add_messages $SIDA1 $SIDA2 '><>A>'
|
|
|
|
let NROWS=NSENT+NRECV+(NACK?1:0)
|
|
|
|
executeJavaOk org.servalproject.test.Meshms meshms-list-messages "$SIDA1" "$SIDA2"
|
|
|
|
tfw_cat --stdout --stderr
|
|
|
|
assertStdoutLineCount == $(($NROWS + 2))
|
|
|
|
token=$(sed -n -e '3s/.*\<token=\([^ ]*\), .*/\1/p' "$TFWSTDOUT")
|
|
|
|
assert [ -n "$token" ]
|
|
|
|
}
|
|
|
|
test_MeshmsListMessagesNewSinceArrival() {
|
|
|
|
list() {
|
|
|
|
runJava org.servalproject.test.Meshms meshms-list-messages-since "$SIDA1" "$SIDA2" "$token" >messages$i
|
|
|
|
}
|
|
|
|
for i in 1 2 3; do
|
|
|
|
fork %list$i list
|
|
|
|
done
|
|
|
|
wait_until [ -e messages1 -a -e messages2 -a -e messages3 ]
|
|
|
|
for message in '>Rumplestiltskin' 'A' '<Howdydoody' '>Eulenspiegel'; do
|
|
|
|
meshms_add_messages $SIDA1 $SIDA2 "${message:0:1}" "${message:1}"
|
|
|
|
wait_until grepall "${message:1}" messages{1,2,3}
|
|
|
|
done
|
|
|
|
fork_terminate_all
|
|
|
|
fork_wait_all
|
|
|
|
}
|
|
|
|
teardown_MeshmsListMessagesNewSinceArrival() {
|
|
|
|
tfw_preserve messages{1,2,3}
|
|
|
|
teardown
|
|
|
|
}
|
|
|
|
|
2014-06-17 06:34:30 +00:00
|
|
|
doc_MeshmsListMessagesNoIdentity="Java API list MeshMS messages from unknown identity"
|
|
|
|
test_MeshmsListMessagesNoIdentity() {
|
2014-06-19 07:57:05 +00:00
|
|
|
SIDX=0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
|
2014-06-17 06:34:30 +00:00
|
|
|
executeJavaOk org.servalproject.test.Meshms meshms-list-messages $SIDX $SIDA2
|
|
|
|
assertStdoutGrep 'MeshMSUnknownIdentityException'
|
|
|
|
tfw_cat --stdout --stderr
|
|
|
|
}
|
|
|
|
|
2014-06-19 07:57:05 +00:00
|
|
|
doc_MeshmsSend="Java API send MeshMS message"
|
|
|
|
test_MeshmsSend() {
|
|
|
|
executeJavaOk org.servalproject.test.Meshms meshms-send-message $SIDA1 $SIDA2 "Hello World"
|
|
|
|
executeOk_servald meshms list messages $SIDA1 $SIDA2
|
|
|
|
assertStdoutGrep --matches=1 ':>:Hello World'
|
|
|
|
executeJavaOk org.servalproject.test.Meshms meshms-send-message $SIDA2 $SIDA1 "Hello Back!"
|
|
|
|
executeOk_servald meshms list messages $SIDA1 $SIDA2
|
|
|
|
assertStdoutGrep --matches=1 ':>:Hello World$'
|
|
|
|
assertStdoutGrep --matches=1 ':<:Hello Back!$'
|
|
|
|
}
|
|
|
|
|
|
|
|
doc_MeshmsSendNoIdentity="Java API send MeshMS message from unknown identity"
|
|
|
|
test_MeshmsSendNoIdentity() {
|
|
|
|
SIDX=0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF
|
|
|
|
executeJavaOk org.servalproject.test.Meshms meshms-send-message $SIDX $SIDA2 "Hello World"
|
|
|
|
assertStdoutGrep 'MeshMSUnknownIdentityException'
|
|
|
|
tfw_cat --stdout --stderr
|
|
|
|
}
|
|
|
|
|
2014-06-24 02:42:48 +00:00
|
|
|
doc_MeshmsReadAllConversations="Java API MeshMS mark all conversations read"
|
|
|
|
setup_MeshmsReadAllConversations() {
|
|
|
|
setup
|
|
|
|
# create 3 threads, with all permutations of incoming and outgoing messages
|
|
|
|
executeOk_servald meshms send message $SIDA1 $SIDA2 "Message1"
|
|
|
|
executeOk_servald meshms send message $SIDA3 $SIDA1 "Message2"
|
|
|
|
executeOk_servald meshms send message $SIDA1 $SIDA4 "Message3"
|
|
|
|
executeOk_servald meshms send message $SIDA4 $SIDA1 "Message4"
|
|
|
|
executeOk_servald meshms list conversations $SIDA1
|
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA2::0:0\$"
|
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA3:unread:11:0\$"
|
2014-07-14 06:51:12 +00:00
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA4:unread:20:0\$"
|
2014-06-24 02:42:48 +00:00
|
|
|
}
|
|
|
|
test_MeshmsReadAllConversations() {
|
|
|
|
executeJavaOk org.servalproject.test.Meshms meshms-mark-all-conversations-read $SIDA1
|
|
|
|
assertStdoutIs -e 'UPDATED\n'
|
|
|
|
executeOk_servald meshms list conversations $SIDA1
|
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA2::0:0\$"
|
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA3::11:11\$"
|
2014-07-14 06:51:12 +00:00
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA4::20:20\$"
|
2014-06-24 02:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_MeshmsReadAllMessages="Java API MeshMS mark all conversations read"
|
|
|
|
setup_MeshmsReadAllMessages() {
|
|
|
|
setup
|
|
|
|
# create 3 threads, with all permutations of incoming and outgoing messages
|
|
|
|
executeOk_servald meshms send message $SIDA1 $SIDA2 "Message1"
|
|
|
|
executeOk_servald meshms send message $SIDA3 $SIDA1 "Message2"
|
|
|
|
executeOk_servald meshms send message $SIDA1 $SIDA2 "Message3"
|
|
|
|
executeOk_servald meshms send message $SIDA1 $SIDA4 "Message4"
|
|
|
|
executeOk_servald meshms send message $SIDA4 $SIDA1 "Message5"
|
|
|
|
executeOk_servald meshms send message $SIDA1 $SIDA2 "Message6"
|
|
|
|
executeOk_servald meshms list conversations $SIDA2
|
2014-07-14 06:51:12 +00:00
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA1:unread:45:0\$"
|
2014-06-24 02:42:48 +00:00
|
|
|
}
|
|
|
|
test_MeshmsReadAllMessages() {
|
|
|
|
executeJavaOk org.servalproject.test.Meshms meshms-mark-all-messages-read $SIDA2 $SIDA1
|
|
|
|
assertStdoutIs -e 'UPDATED\n'
|
|
|
|
executeOk_servald meshms list conversations $SIDA2
|
2014-07-14 06:51:12 +00:00
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA1::45:45\$"
|
2014-06-24 02:42:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc_MeshmsReadMessage="Java API MeshMS mark a message as read"
|
|
|
|
setup_MeshmsReadMessage() {
|
|
|
|
setup
|
|
|
|
# create 3 threads, with all permutations of incoming and outgoing messages
|
|
|
|
executeOk_servald meshms send message $SIDA1 $SIDA2 "Message1"
|
|
|
|
executeOk_servald meshms send message $SIDA3 $SIDA1 "Message2"
|
|
|
|
executeOk_servald meshms send message $SIDA1 $SIDA2 "Message3"
|
|
|
|
executeOk_servald meshms send message $SIDA1 $SIDA4 "Message4"
|
|
|
|
executeOk_servald meshms send message $SIDA4 $SIDA1 "Message5"
|
|
|
|
executeOk_servald meshms send message $SIDA1 $SIDA2 "Message6"
|
|
|
|
executeOk_servald meshms list conversations $SIDA2
|
2014-07-14 06:51:12 +00:00
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA1:unread:45:0\$"
|
2014-06-24 02:42:48 +00:00
|
|
|
}
|
|
|
|
test_MeshmsReadMessage() {
|
|
|
|
executeJavaOk org.servalproject.test.Meshms meshms-advance-read-offset $SIDA2 $SIDA1 22
|
|
|
|
assertStdoutIs -e 'UPDATED\n'
|
|
|
|
executeOk_servald meshms list conversations $SIDA2
|
2014-07-14 06:51:12 +00:00
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA1:unread:45:22\$"
|
2014-06-24 02:42:48 +00:00
|
|
|
executeJavaOk org.servalproject.test.Meshms meshms-advance-read-offset $SIDA2 $SIDA1 11
|
|
|
|
assertStdoutIs -e 'OK\n'
|
|
|
|
executeOk_servald meshms list conversations $SIDA2
|
2014-07-14 06:51:12 +00:00
|
|
|
assertStdoutGrep --stderr --matches=1 ":$SIDA1:unread:45:22\$"
|
2014-06-24 02:42:48 +00:00
|
|
|
}
|
|
|
|
|
2014-06-11 07:51:08 +00:00
|
|
|
runTests "$@"
|