summaryrefslogtreecommitdiffstats
path: root/tests/testsuites/omprog-transactions-bin.sh
blob: a8be3e413ea051c95a4a20f6e245d2ddec0ee6c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash

outfile=$RSYSLOG_OUT_LOG

status="OK"
echo "<= $status" >> $outfile
echo $status

in_transaction=false
fail_on_commit=false
retry_count=0

read line
while [[ -n "$line" ]]; do
    message=${line//$'\n'}
    echo "=> $message" >> $outfile

    if [[ "$message" == "BEGIN TRANSACTION" ]]; then
        in_transaction=true
        status="OK"
    elif [[ "$message" == "COMMIT TRANSACTION" ]]; then
        in_transaction=false
        if [[ $fail_on_commit == true ]]; then
            status="Error: could not commit transaction"
            fail_on_commit=false
        else
            status="OK"
        fi
    else
        if [[ $in_transaction == true ]]; then
            status="DEFER_COMMIT"
        else
            # Should not occur
            status="Error: received a message out of a transaction"
        fi
    fi

    # First command line argument ($1) indicates whether to test for negative
    # cases. If --failed_messages is specified, an error is returned for certain
    # messages, forcing them to be retried twice. If --failed_commits is
    # specified, the error is returned when committing the transaction.
    if [[ "$1" != "" && ($message == *04* || $message == *07*) ]]; then
        if [[ $retry_count < 2 ]]; then
            if [[ "$1" == "--failed_commits" ]]; then
                fail_on_commit=true
            else
                status="Error: could not process log message"
            fi
            let "retry_count++"
        else
            retry_count=0
        fi
    fi

    echo "<= $status" >> $outfile
    echo $status
    read line
done

exit 0