summaryrefslogtreecommitdiff
path: root/cpp/src/tests/ipv6_test
blob: 9d1cb2acddf1c111b89bcb5c51c8cabb99afbbad (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash

#
# 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.
#

# Check whether we have any globally configured IPv6 addresses
# - if not then we can't run the tests because ipv6 lookups won't
#   work within the qpid code. This is a deliberate feature to avoid
#   getting addresses that can't be routed by the machine.

if ip -f inet6 -o addr | cut -f 9 -s -d' ' | grep global > /dev/null ; then
    echo "IPv6 addresses configured continuing"
else
    echo "No global IPv6 addresses configured - skipping test"
    exit 0
fi


# Run a simple test over IPv6
source ./test_env.sh

CONFIG=$(dirname $0)/config.null
TEST_HOSTNAME=::1
COUNT=10

trap cleanup EXIT

error() { echo $*; exit 1; }

# Don't need --no-module-dir or --no-data-dir as they are set as env vars in test_env.sh
COMMON_OPTS="--daemon --auth no --config $CONFIG"

# Record all broker ports started
unset PORTS
declare -a PORTS

# Start new brokers:
#   $1 must be integer
#   $2 = extra opts
# Append used ports to PORTS variable
start_brokers() {
    local -a ports
    for (( i=0; $i<$1; i++)) do
        ports[$i]=$($QPIDD_EXEC --port 0 $COMMON_OPTS $2)
    done
    PORTS=( ${PORTS[@]} ${ports[@]} )
}

stop_brokers() {
    for port in "${PORTS[@]}";
    do
        $QPIDD_EXEC -qp $port
    done
    PORTS=()
}

cleanup() {
    stop_brokers
}

start_brokers 1
PORT=${PORTS[0]}
echo "Started IPv6 smoke perftest on broker port $PORT"

## Test connection via connection settings
./qpid-perftest --count ${COUNT} --port ${PORT} -b $TEST_HOSTNAME --summary

## Test connection with a URL
URL="amqp:[$TEST_HOSTNAME]:$PORT"

./qpid-send -b $URL --content-string=hello -a "foo;{create:always}"
MSG=`./qpid-receive -b $URL -a "foo;{create:always}" --messages 1`
test "$MSG" = "hello" || { echo "receive failed '$MSG' != 'hello'"; exit 1; }

stop_brokers

# Federation smoke test follows

# Start 2 brokers

# In a distribution, the python tools will be absent.
if [ ! -f $QPID_CONFIG_EXEC ] || [ ! -f $QPID_ROUTE_EXEC ] ; then
    echo "python tools absent - skipping federation test."
else

    start_brokers 2
    echo "Started Federated brokers on ports ${PORTS[*]}"
    # Make broker urls
    BROKER0="[::1]:${PORTS[0]}"
    BROKER1="[::1]:${PORTS[1]}"
    TEST_QUEUE=ipv6-fed-test

    $QPID_CONFIG_EXEC -b $BROKER0 add queue $TEST_QUEUE
    $QPID_CONFIG_EXEC -b $BROKER1 add queue $TEST_QUEUE
    $QPID_ROUTE_EXEC dynamic add $BROKER1 $BROKER0 amq.direct
    $QPID_CONFIG_EXEC -b $BROKER1 bind amq.direct $TEST_QUEUE $TEST_QUEUE
    $QPID_ROUTE_EXEC route map $BROKER1

    ./datagen --count 100 | tee rdata-in |
        ./qpid-send -b amqp:$BROKER0 -a amq.direct/$TEST_QUEUE --content-stdin
    ./qpid-receive -b amqp:$BROKER1 -a $TEST_QUEUE --print-content yes -m 0 > rdata-out

    cmp rdata-in rdata-out || { echo "Federated data over IPv6 does not compare"; exit 1; }

    stop_brokers
    rm rdata-in rdata-out
fi

# Cluster smoke test follows
test -z $CLUSTER_LIB && exit 0	# Exit if cluster not supported.

## Test failover in a cluster using IPv6 only
. cpg_check.sh
cpg_enabled || exit 0

pick_port() {
    # We need a fixed port to set --cluster-url. Use qpidd to pick a free port.
    # Note this method is racy
    PICK=$($QPIDD_EXEC -dp0)
    $QPIDD_EXEC -qp $PICK
    echo $PICK
}

ssl_cluster_broker() {		# $1 = port
    $QPIDD_EXEC $COMMON_OPTS --load-module  $CLUSTER_LIB --cluster-name ipv6_test.$HOSTNAME.$$ --cluster-url amqp:[$TEST_HOSTNAME]:$1 --port $1
    # Wait for broker to be ready
    ./qpid-ping -b $TEST_HOSTNAME -qp $1 || { echo "Cannot connect to broker on $1"; exit 1; }
    echo "Running IPv6 cluster broker on port $1"
}

PORT1=`pick_port`; ssl_cluster_broker $PORT1
PORT2=`pick_port`; ssl_cluster_broker $PORT2

# Pipe receive output to uniq to remove duplicates
./qpid-receive --connection-options "{reconnect:true, reconnect-timeout:5}" --failover-updates -b amqp:[$TEST_HOSTNAME]:$PORT1 -a "foo;{create:always}" -f | uniq > ssl_test_receive.tmp &

./qpid-send -b amqp:[$TEST_HOSTNAME]:$PORT2 --content-string=one -a "foo;{create:always}"

$QPIDD_EXEC -qp $PORT1 # Kill broker 1 receiver should fail-over.
./qpid-send -b amqp:[$TEST_HOSTNAME]:$PORT2 --content-string=two -a "foo;{create:always}" --send-eos 1
wait				# Wait for qpid-receive
{ echo one; echo two; } > ssl_test_receive.cmp
diff  ssl_test_receive.tmp ssl_test_receive.cmp || { echo "Failover failed"; exit 1; }

$QPIDD_EXEC -qp $PORT2

rm -f ssl_test_receive.*