summaryrefslogtreecommitdiff
path: root/qpid/cpp/src/tests/replication_test
blob: 6e0c1c8d3b84bbe723c3020731a73c210acf35f7 (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
61
62
63
64
65
66
67
68
69
70
71
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
#!/bin/sh

#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
# 
#   http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
#

# Run a test of the replication feature
MY_DIR=`dirname \`which $0\``
PYTHON_DIR=${MY_DIR}/../../../python
trap stop_brokers INT TERM QUIT

stop_brokers() {
    if [ x$BROKER_A != x ]; then
        ../qpidd -q --port $BROKER_A
        unset BROKER_A
    fi      
    if [ x$BROKER_B != x ]; then
        ../qpidd -q --port $BROKER_B
        unset BROKER_B
    fi
}

if test -d ${PYTHON_DIR} && test -f ../.libs/replicating_listener.so && test -f ../.libs/replication_exchange.so;  then
    rm -f queue-*.repl replication-*.log #cleanup from any earlier runs

    ../qpidd --daemon --port 0 --no-data-dir --no-module-dir --auth no --load-module ../.libs/replicating_listener.so --replication-queue replication --create-replication-queue true  --log-enable info+ --log-to-file replication-source.log  --log-to-stderr 0 > qpidd.port
    BROKER_A=`cat qpidd.port`

    ../qpidd --daemon --port 0 --no-data-dir --no-module-dir --auth no --load-module ../.libs/replication_exchange.so  --log-enable info+ --log-to-file replication-dest.log  --log-to-stderr 0 > qpidd.port
    BROKER_B=`cat qpidd.port`
    PYTHONPATH=$PYTHON_DIR
    export PYTHONPATH
    echo "Running replication test between localhost:$BROKER_A and localhost:$BROKER_B"

    $PYTHON_DIR/commands/qpid-config -a "localhost:$BROKER_B" add exchange replication replication
    $PYTHON_DIR/commands/qpid-route --ack 5 queue add "localhost:$BROKER_B" "localhost:$BROKER_A" replication replication

    #create test queues

    $PYTHON_DIR/commands/qpid-config -a "localhost:$BROKER_A" add queue queue-a --generate-queue-events 2
    $PYTHON_DIR/commands/qpid-config -a "localhost:$BROKER_A" add queue queue-b --generate-queue-events 2
    $PYTHON_DIR/commands/qpid-config -a "localhost:$BROKER_A" add queue queue-c --generate-queue-events 1
    $PYTHON_DIR/commands/qpid-config -a "localhost:$BROKER_A" add queue queue-d --generate-queue-events 2

    $PYTHON_DIR/commands/qpid-config -a "localhost:$BROKER_B" add queue queue-a
    $PYTHON_DIR/commands/qpid-config -a "localhost:$BROKER_B" add queue queue-b
    $PYTHON_DIR/commands/qpid-config -a "localhost:$BROKER_B" add queue queue-c
    #queue-d deliberately not declared on DR; this error case should be handled

    #publish and consume from test queues on broker A:
    i=1
    while [ $i -le 10 ]; do
        echo Message $i for A >> queue-a-input.repl
        i=`expr $i + 1`
    done
    i=1
    while [ $i -le 20 ]; do
        echo Message $i for B >> queue-b-input.repl 
        i=`expr $i + 1`
    done
    i=1
    while [ $i -le 15 ]; do
        echo Message $i for C >> queue-c-input.repl 
        i=`expr $i + 1`
    done

    ./sender --port $BROKER_A --routing-key queue-a --send-eos 1 < queue-a-input.repl
    ./sender --port $BROKER_A --routing-key queue-b --send-eos 1 < queue-b-input.repl
    ./sender --port $BROKER_A --routing-key queue-c --send-eos 1 < queue-c-input.repl
    echo dummy | ./sender --port $BROKER_A --routing-key queue-d --send-eos 1

    ./receiver --port $BROKER_A --queue queue-a --messages 5 > /dev/null 
    ./receiver --port $BROKER_A --queue queue-b --messages 10 > /dev/null
    ./receiver --port $BROKER_A --queue queue-c --messages 10 > /dev/null
    ./receiver --port $BROKER_A --queue queue-d > /dev/null
    
    #shutdown broker A then check that broker Bs versions of the queues are as expected
    ../qpidd -q --port $BROKER_A
    unset BROKER_A

    #validate replicated queues:
    ./receiver --port $BROKER_B --queue queue-a > queue-a-backup.repl
    ./receiver --port $BROKER_B --queue queue-b > queue-b-backup.repl
    ./receiver --port $BROKER_B --queue queue-c > queue-c-backup.repl

    stop_brokers

    tail -5 queue-a-input.repl > queue-a-expected.repl
    tail -10 queue-b-input.repl > queue-b-expected.repl
    diff queue-a-backup.repl queue-a-expected.repl || FAIL=1
    diff queue-b-backup.repl queue-b-expected.repl || FAIL=1
    diff queue-c-backup.repl queue-c-input.repl || FAIL=1

    grep 'queue-d does not exist' replication-dest.log > /dev/null || echo "WARNING: Expected error to be logged!"

    if [ x$FAIL != x ]; then
        echo replication test failed: expectations not met!
        exit 1
    else 
        echo queue state replicated as expected
        rm -f queue-*.repl replication-*.log
    fi

else
    echo "Skipping replication test, plugins not built or python utils not located"
fi