| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# Asserts that a given notification set has happened. |
| 4 |
# |
| 5 |
# ==== Usage ==== |
| 6 |
# |
| 7 |
# --let $expected_notifications= N,NOTIFICATION_TYPE2|M,NOTIFICATION_TYPE2 |
| 8 |
# [--let $truncate_notification_table= 0] |
| 9 |
# --source ../include/assert_notifications.inc |
| 10 |
# |
| 11 |
# Parameters: |
| 12 |
# |
| 13 |
# $expected_notifications |
| 14 |
# A string describing the set of notifications expected. |
| 15 |
# The string takes the form of N,DESCRIPTION1|M,DESCRIPTION2 |
| 16 |
# |
| 17 |
# - N and M are the occurrences of the given notification description |
| 18 |
# - DESCRIPTION1 and DESCRIPTION2 are strings used to describe the |
| 19 |
# the notification and will be compared using the operator LIKE, |
| 20 |
# e.g., LIKE "DESCRIPTION1" |
| 21 |
# |
| 22 |
# $truncate_notification_table |
| 23 |
# Whether to truncate the notification table or not at the end |
| 24 |
# of the assertion |
| 25 |
|
| 26 |
|
| 27 |
if (!$expected_notifications) |
| 28 |
{ |
| 29 |
--die "Missing argument '$expected_notifications'" |
| 30 |
} |
| 31 |
|
| 32 |
if ($truncate_notification_table) |
| 33 |
{ |
| 34 |
--let $_truncate_notification_table= $truncate_notification_table |
| 35 |
} |
| 36 |
|
| 37 |
if (!$_truncate_notification_table) |
| 38 |
{ |
| 39 |
--let $_truncate_notification_table= 1 |
| 40 |
} |
| 41 |
|
| 42 |
--let $_expected_notifications=$expected_notifications |
| 43 |
--let $_expected_notifications_count=0 |
| 44 |
|
| 45 |
# count notifications |
| 46 |
while (`SELECT HEX('$_expected_notifications') != HEX('')`) |
| 47 |
{ |
| 48 |
# next notification |
| 49 |
--let $_tuple= `SELECT SUBSTRING_INDEX('$_expected_notifications', '|', 1)` |
| 50 |
--let $_notification_count= `SELECT SUBSTRING_INDEX('$_tuple', ',', 1)` |
| 51 |
|
| 52 |
# increment the number of notifications to check at the end |
| 53 |
--let $_expected_notifications_count= `SELECT $_expected_notifications_count + $_notification_count` |
| 54 |
|
| 55 |
# next |
| 56 |
--let $_expected_notifications= `SELECT LTRIM(SUBSTRING('$_expected_notifications', LENGTH('$_tuple') + 2 ))` |
| 57 |
} |
| 58 |
|
| 59 |
# wait for the notifications to be inserted in the table |
| 60 |
--let $_saved_show_rpl_debug_info= $show_rpl_debug_info |
| 61 |
--let show_rpl_debug_info=0 |
| 62 |
--let $_c = $_expected_notifications_count |
| 63 |
--let $wait_condition= SELECT COUNT(*) = $_c FROM gms_listener_example |
| 64 |
--source include/wait_condition.inc |
| 65 |
--let $show_rpl_debug_info= $_saved_show_rpl_debug_info |
| 66 |
|
| 67 |
if (!$success) |
| 68 |
{ |
| 69 |
--query_vertical SELECT * FROM test.gms_listener_example |
| 70 |
--die "Timed out while waiting for gms_listener_example to have $_c rows!" |
| 71 |
} |
| 72 |
|
| 73 |
# reset _expected_notifications |
| 74 |
--let $_expected_notifications=$expected_notifications |
| 75 |
|
| 76 |
# assert each of them |
| 77 |
while (`SELECT HEX('$_expected_notifications') != HEX('')`) |
| 78 |
{ |
| 79 |
# next notification |
| 80 |
--let $_tuple= `SELECT SUBSTRING_INDEX('$_expected_notifications', '|', 1)` |
| 81 |
--let $_notification_count= `SELECT SUBSTRING_INDEX('$_tuple', ',', 1)` |
| 82 |
--let $_notification= `SELECT SUBSTRING_INDEX(LTRIM(SUBSTRING('$_tuple', LENGTH('$_notification_count') + 2)), '|', 1)` |
| 83 |
|
| 84 |
# assert |
| 85 |
--let $assert_cond= COUNT(*)=$_notification_count FROM test.gms_listener_example WHERE log_message LIKE "$_notification" |
| 86 |
--let $assert_text= Assert that there are $_notification_count notifications logged of type $_notification |
| 87 |
--source include/assert.inc |
| 88 |
|
| 89 |
# move to the next notification |
| 90 |
--let $_expected_notifications= `SELECT LTRIM(SUBSTRING('$_expected_notifications', LENGTH('$_tuple') + 2 ))` |
| 91 |
} |
| 92 |
|
| 93 |
# assert again that no other notification was inserted meanwhile |
| 94 |
--let $assert_cond= COUNT(*)=$_expected_notifications_count FROM test.gms_listener_example |
| 95 |
--let $assert_text= Assert that there are $_expected_notifications_count notifications logged |
| 96 |
--source include/assert.inc |
| 97 |
|
| 98 |
if (`SELECT $_truncate_notification_table <> 0`) |
| 99 |
{ |
| 100 |
--echo [Truncating gms_listener_example Table] |
| 101 |
--disable_result_log |
| 102 |
--disable_query_log |
| 103 |
|
| 104 |
# clean up the notification table |
| 105 |
SET SESSION SQL_LOG_BIN=0; |
| 106 |
--let $_saved_super_read_only=`SELECT @@global.super_read_only` |
| 107 |
SET GLOBAL SUPER_READ_ONLY=OFF; |
| 108 |
TRUNCATE gms_listener_example; |
| 109 |
--eval SET GLOBAL SUPER_READ_ONLY=$_saved_super_read_only |
| 110 |
SET SESSION SQL_LOG_BIN=1; |
| 111 |
|
| 112 |
--enable_query_log |
| 113 |
--enable_result_log |
| 114 |
} |