Newer
Older
#!/bin/sh
#
# The integration test scenario for yeastx workflow.
#
# --- include external sources ------------------------
source common.bash
# --------------------
MY_DATA=$WORK/data-yeastx
TEMPLATE_INCOMING_CONTENT=$MY_DATA/expected-output/template_incoming_content_yeastx.txt
METABOL_DB=metabol_dev
# --------------------
tpylak
committed
# Changes last-modification-time so that the order is the same as the alphabetical order.
function change_modification_time_alphabetically {
local dir=$1
local file
# modification data format: YYYYMMDDhhmm
local modification_time=200811221122
for file in `ls -1 $dir | sort`; do
local full_path=$dir/$file
# change the modification date format
touch -t $modification_time $full_path
modification_time=$(($modification_time+1))
done
}
# Prepare template incoming data and some destination data structures
function prepare_data {
# Prepare empty incoming data
rm -fr $MY_DATA
mkdir -p $MY_DATA
tpylak
committed
local SRC=$TEMPLATE/data-yeastx
tpylak
committed
cp -R $SRC/* $MY_DATA/
tpylak
committed
tpylak
committed
chmod -R 700 $MY_DATA/incoming*
tpylak
committed
# DSS processes files ordered by modification time, so in this way we make the tests more predictable.
change_modification_time_alphabetically $MY_DATA/incoming
function build_and_install_components {
local use_local_source=$1
local install_dss=true
local install_dmv=false
local install_openbis=true
local reinstall_all=false
build_and_install $install_dss $install_dmv $install_openbis $use_local_source $reinstall_all
function refresh_components_and_start_openbis {
local use_local_source=false
local install_dss=false
local install_dmv=false
local install_openbis=false
local reinstall_all=false
build_and_install $install_dss $install_dmv $install_openbis $use_local_source $reinstall_all
}
function build_and_install_yeastx {
cp $INSTALL/datastore_server-plugins.jar $WORK/datastore_server_yeastx/lib/
chmod_exec $WORK/datastore_server_yeastx/takeCifsOwnershipRecursive.sh
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
echo Dropping metabolomics database
psql_cmd=`run_psql`
$psql_cmd -U postgres -c "drop database $METABOL_DB"
}
function check_file_exists {
local file=$1
if [ -e $marker ]; then echo true; else echo false; fi
}
function assert_correct_incoming_content {
local dir_name=$1
local expected_file_count=$2
local has_error_marker=$3
local dir=$MY_DATA/incoming/$dir_name
assert_dir_exists $dir
if [ ! -e $dir ]; then
return
fi
assert_files_number $dir $expected_file_count
local marker=$dir/_delete_me_after_correcting_errors
local error_log=$dir/error-log.txt
if [ "$has_error_marker" = "true" ]; then
assert_file_exists $marker
assert_file_exists $error_log
else
assert_file_not_exists $marker
assert_file_not_exists $error_log
fi
}
# prints all the error messages from incoming folder in a canonic form
function print_incoming_errorlog_fingerprint {
local incoming_dir=$1
for dir in `ls -1 $incoming_dir | sort`; do
echo $dir --------------------
local error_log=$incoming_dir/$dir/error-log.txt
if [ -e $error_log ]; then
while read line; do
# remove all prefixes with dates
line=${line//*ERROR/ERROR}
# remove all warnings
line=${line//*WARNING*/}
echo $line
done < $error_log
fi
done
}
# checks that the error messages for the folders which could not be processed
# in the incomming folder are correct
function assert_correct_errorlogs {
local incoming_dir=$1
tpylak
committed
local errorlogs=$WORK/incoming_current_content.txt
print_incoming_errorlog_fingerprint $incoming_dir > $errorlogs
tpylak
committed
echo [INFO] Comparing error logs in the incoming directory with the expected template.
diff -w $TEMPLATE_INCOMING_CONTENT $errorlogs
if [ $? -ne 0 ]; then
report_error "Unexpected content of the error logs in the incoming directory $incoming_dir (see the report above)."
function count_db_table_records {
local db=$1
local table=$2
local psql=`run_psql`
local count=`$psql -U postgres -d $db -c "select count(*) from $table" \
| head -n 3 | tail -n 1 | awk '{gsub(/ /,"");print}'`
function assert_correct_datasets_metabol_database {
local eicms_runs=`count_db_table_records $METABOL_DB eic_ms_runs`
local fiams_runs=`count_db_table_records $METABOL_DB fia_ms_runs`
# one run comes from the incoming and one from incoming-*ml
assert_equals "Wrong number of eic MS runs in the metablomics db" 2 $eicms_runs
assert_equals "Wrong number of fia MS runs in the metablomics db" 2 $fiams_runs
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
}
function assert_correct_incoming_contents {
local incoming_dir=$1
# check content of incoming directory
assert_files_number $incoming_dir 12
assert_correct_incoming_content faulty-duplicated-mapping 4 true
assert_correct_incoming_content faulty-experiment-code 4 true
assert_correct_incoming_content faulty-mapped-file-does-not-exist 3 true
assert_correct_incoming_content faulty-no-email-specified 3 true
assert_correct_incoming_content faulty-no-mapping 4 true
assert_correct_incoming_content faulty-non-unique-mapping 6 true
assert_correct_incoming_content faulty-to-many-mapping-files 4 true
assert_correct_incoming_content faulty-unknow-property 4 true
assert_correct_incoming_content faulty-unknown-mapping 8 true
assert_correct_incoming_content faulty-wrong-conversion 6 true
assert_correct_incoming_content ignore-empty-dir 0 false
assert_correct_incoming_content ignore-no-index 1 false
assert_correct_errorlogs $incoming_dir
# check content of dropboxes
assert_files_number "$MY_DATA/dropbox-eicml/TEST&TEST_PROJECT&EXP_TEST.*.mzXML" 6
assert_files_number "$MY_DATA/dropbox-fiaml/TEST&TEST_PROJECT&EXP_TEST.*.mzXML" 2
local registered_datasets=16
# check content of the store
local store=$MY_DATA/store
local store_files_count=`find $store -type f | wc -l`
assert_equals "Wrong number of files in the store $store" $registered_datasets $store_files_count
# check the number of datasets in openbis database
local datasets=`count_db_table_records $DATABASE data`
# there will be one additional dataset placeholder for the incoming-*ml files which specify
# the parent code which does not exist
assert_equals "Wrong number of datasets in the openbis db" $(($registered_datasets+1)) $datasets
# check each dataset in openbis database.
# Result set columns are:
# id;experiment_code;data_store_code;code;is_placeholder;data_id_parent;is_complete;data_producer_code;production_timestamp
local pattern="[0-9]*;EXP_TEST;DSS1;20[0-9]*-[0-9]*;[ft];[0-9]*;[TFU]*;;.*"
local i=2;
while [ $i -lt 18 ]; do
assert_correct_dataset_content_in_database $i $pattern
i=$(( $i +1))
done
}
function integration_tests_yeastx {
build_and_install_yeastx
switch_dss "on" datastore_server_yeastx
sleep 90
assert_correct_incoming_contents $MY_DATA/incoming
switch_dss "off" datastore_server_yeastx
shutdown_openbis_server
exit_if_assertion_failed
}
function build_from_local_source_and_test {
build_and_install_components true
integration_tests_yeastx
}
function build_from_svn_source_and_test {
build_and_install_components false
integration_tests_yeastx
}
# can be called only if the build has been already done
function test_without_build {
refresh_components_and_start_openbis