Skip to content
This repository was archived by the owner on May 5, 2020. It is now read-only.

Commit faaced5

Browse files
committed
Always call amqicdir
Fixes #29
1 parent 3ab02db commit faaced5

File tree

5 files changed

+192
-105
lines changed

5 files changed

+192
-105
lines changed

server/mq.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ stop()
2424
config()
2525
{
2626
: ${MQ_QMGR_NAME?"ERROR: You need to set the MQ_QMGR_NAME environment variable"}
27+
# Populate and update the contents of /var/mqm - this is needed for
28+
# bind-mounted volumes, and also to migrate data from previous versions of MQ
29+
/opt/mqm/bin/amqicdir -i -f
30+
ls -l /var/mqm
2731
source /opt/mqm/bin/setmqenv -s
2832
echo "----------------------------------------"
2933
dspmqver
@@ -85,10 +89,6 @@ monitor()
8589
}
8690

8791
mq-license-check.sh
88-
# If /var/mqm is empty (because it's mounted from a new host volume), then populate it
89-
if [ ! "$(ls -A /var/mqm)" ]; then
90-
/opt/mqm/bin/amqicdir -i -f
91-
fi
9292
config
9393
trap stop SIGTERM SIGINT
9494
monitor

test/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ FROM ubuntu:16.04
1616

1717
MAINTAINER Arthur Barr <arthur.barr@uk.ibm.com>
1818

19-
ENV NODE_VERSION 6.3.0
19+
ENV NODE_VERSION 6.4.0
2020

2121
RUN export DEBIAN_FRONTEND=noninteractive \
2222
&& apt-get update -y \

test/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "test.js",
77
"dependencies": {
88
"chai": "^3.5.0",
9-
"mocha": "^2.5.3"
9+
"mocha": "^3.0.2"
1010
},
1111
"devDependencies": {},
1212
"scripts": {

test/run.sh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,38 @@
1616

1717
NETWORK=mqtest
1818
IMAGE=${1:-"mq:9"}
19+
# Shouldn't go to /tmp, as MQ won't work with tmpfs
20+
TEMP_DIR=${HOME}/tmp/mqtest
21+
1922
set -x
23+
24+
docker pull ${IMAGE}
25+
2026
# Build a container image with the tests
2127
docker build -t mq-docker-test .
28+
29+
# Set up directory for test volumes on the host
30+
rm -rf ${TEMP_DIR}
31+
mkdir -p ${TEMP_DIR}
32+
2233
# Create a network for the tests. The test container will run in this network,
2334
# as well as any containers the tests run.
2435
docker network create ${NETWORK}
36+
2537
# Run the tests
2638
docker run \
2739
--tty \
2840
--interactive \
2941
--rm \
3042
--name mq-docker-test \
3143
--volume /var/run/docker.sock:/var/run/docker.sock \
44+
--volume ${TEMP_DIR}:${TEMP_DIR} \
3245
--net ${NETWORK} \
3346
--env DOCKER_NETWORK=${NETWORK} \
34-
--env DOCKER_IMAGE=$1 \
47+
--env DOCKER_IMAGE=${IMAGE} \
48+
--env TEMP_DIR=${TEMP_DIR} \
3549
mq-docker-test
36-
# Clean up the network
50+
51+
# Clean up
3752
docker network rm ${NETWORK}
53+
#rm -rf ${TEMP_DIR}

test/test.js

Lines changed: 168 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,168 @@
1-
/**
2-
* © Copyright IBM Corporation 2016
3-
*
4-
*
5-
* Licensed under the Apache License, Version 2.0 (the "License");
6-
* you may not use this file except in compliance with the License.
7-
* You may obtain a copy of the License at
8-
*
9-
* http://www.apache.org/licenses/LICENSE-2.0
10-
*
11-
* Unless required by applicable law or agreed to in writing, software
12-
* distributed under the License is distributed on an "AS IS" BASIS,
13-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
* See the License for the specific language governing permissions and
15-
* limitations under the License.
16-
**/
17-
const exec = require('child_process').exec;
18-
const assert = require('chai').assert;
19-
const net = require('net');
20-
21-
// Pre-requisites for running this test:
22-
// * Docker network created
23-
// * Env. variable called DOCKER_NETWORK with the name of the network
24-
// * Env. variable called DOCKER_IMAGE with the name of the image to test
25-
26-
const DOCKER_NETWORK = process.env.DOCKER_NETWORK;
27-
const DOCKER_IMAGE = process.env.DOCKER_IMAGE;
28-
29-
describe('MQ Docker sample', function() {
30-
describe('when launching container', function () {
31-
this.timeout(3000);
32-
it('should display the license when LICENSE=view', function (done) {
33-
console.log(`docker run --rm --env LICENSE=view ${DOCKER_IMAGE}`);
34-
exec(`docker run --rm --env LICENSE=view ${DOCKER_IMAGE}`, function (err, stdout, stderr) {
35-
assert.equal(err.code, 1);
36-
assert.isTrue(stdout.includes("terms"));
37-
done();
38-
});
39-
});
40-
it('should fail if LICENSE is not set', function (done) {
41-
exec(`docker run --rm ${DOCKER_IMAGE}`, function (err, stdout, stderr) {
42-
assert.equal(err.code, 1);
43-
done();
44-
});
45-
});
46-
it('should fail if MQ_QMGR_NAME is not set', function (done) {
47-
exec(`docker run --rm --env LICENSE=accept ${DOCKER_IMAGE}`, function (err, stdout, stderr) {
48-
assert.equal(err.code, 1);
49-
assert.isTrue(stderr.includes("ERROR"));
50-
done();
51-
});
52-
});
53-
});
54-
55-
describe('with running container', function() {
56-
var containerId = null;
57-
var containerAddr = null;
58-
const QMGR_NAME = "foo";
59-
60-
beforeEach(function(done) {
61-
this.timeout(10000);
62-
exec(`docker run -d --env LICENSE=accept --env MQ_QMGR_NAME=${QMGR_NAME} --net ${DOCKER_NETWORK} ${DOCKER_IMAGE}`, function (err, stdout, stderr) {
63-
if (err) throw err;
64-
containerId = stdout.trim();
65-
// Run dspmq every second, until the queue manager comes up
66-
let timer = setInterval(function() {
67-
exec(`docker exec ${containerId} dspmq -n`, function (err, stdout, stderr) {
68-
if (err) throw err;
69-
if (stdout && stdout.includes("RUNNING")) {
70-
// Queue manager is up, so clear the timer
71-
clearInterval(timer);
72-
exec(`docker inspect --format '{{ .NetworkSettings.Networks.${DOCKER_NETWORK}.IPAddress }}' ${containerId}`, function (err, stdout, stderr) {
73-
if (err) throw err;
74-
containerAddr = stdout.trim();
75-
done();
76-
});
77-
}
78-
});
79-
}, 1000);
80-
81-
});
82-
});
83-
84-
afterEach(function(done) {
85-
exec(`docker rm --force ${containerId}`, function (err, stdout, stderr) {
86-
done();
87-
});
88-
});
89-
90-
it('should be listening on port 1414 on the Docker network', function (done) {
91-
const client = net.connect({host: containerAddr, port: 1414}, () => {
92-
client.on('close', done);
93-
client.end();
94-
});
95-
});
96-
});
97-
});
1+
/**
2+
* © Copyright IBM Corporation 2016
3+
*
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
**/
17+
const assert = require('chai').assert;
18+
const exec = require('child_process').exec;
19+
const fs = require('fs');
20+
const net = require('net');
21+
22+
// Pre-requisites for running this test:
23+
// * Docker network created
24+
// * Env. variable called DOCKER_NETWORK with the name of the network
25+
// * Env. variable called DOCKER_IMAGE with the name of the image to test
26+
27+
const DOCKER_NETWORK = process.env.DOCKER_NETWORK;
28+
const DOCKER_IMAGE = process.env.DOCKER_IMAGE;
29+
const QMGR_NAME = "qm1";
30+
const VOLUME_PREFIX = process.env.TEMP_DIR + "/tmp";
31+
32+
describe('MQ Docker sample', function() {
33+
describe('when launching container', function () {
34+
this.timeout(3000);
35+
it('should display the license when LICENSE=view', function (done) {
36+
exec(`docker run --rm --env LICENSE=view ${DOCKER_IMAGE}`, function (err, stdout, stderr) {
37+
assert.equal(err.code, 1);
38+
assert.isTrue(stdout.includes("terms"));
39+
done();
40+
});
41+
});
42+
it('should fail if LICENSE is not set', function (done) {
43+
exec(`docker run --rm ${DOCKER_IMAGE}`, function (err, stdout, stderr) {
44+
assert.equal(err.code, 1);
45+
done();
46+
});
47+
});
48+
it('should fail if MQ_QMGR_NAME is not set', function (done) {
49+
exec(`docker run --rm --env LICENSE=accept ${DOCKER_IMAGE}`, function (err, stdout, stderr) {
50+
assert.equal(err.code, 1);
51+
assert.isTrue(stderr.includes("ERROR"));
52+
done();
53+
});
54+
});
55+
});
56+
57+
// Utility function to run a container and wait until MQ starts
58+
let runContainer = function(options) {
59+
return new Promise((resolve, reject) => {
60+
let cmd = `docker run -d --env LICENSE=accept --env MQ_QMGR_NAME=${QMGR_NAME} --net ${DOCKER_NETWORK} ${options} ${DOCKER_IMAGE}`;
61+
exec(cmd, function (err, stdout, stderr) {
62+
if (err) reject(err);
63+
let containerId = stdout.trim();
64+
// Run dspmq every second, until the queue manager comes up
65+
let timer = setInterval(function() {
66+
exec(`docker exec ${containerId} dspmq -n`, function (err, stdout, stderr) {
67+
if (err) reject(err);
68+
if (stdout && stdout.includes("RUNNING")) {
69+
// Queue manager is up, so clear the timer
70+
clearInterval(timer);
71+
exec(`docker inspect --format '{{ .NetworkSettings.Networks.${DOCKER_NETWORK}.IPAddress }}' ${containerId}`, function (err, stdout, stderr) {
72+
if (err) reject(err);
73+
resolve({id: containerId, addr: stdout.trim()});
74+
});
75+
}
76+
});
77+
}, 1000);
78+
});
79+
});
80+
};
81+
82+
describe('with running container', function() {
83+
let container = null;
84+
85+
describe('and implicit volume', function() {
86+
before(function() {
87+
this.timeout(20000);
88+
return runContainer("")
89+
.then((details) => {
90+
container = details;
91+
});
92+
});
93+
it('should be listening on port 1414 on the Docker network', function (done) {
94+
const client = net.connect({host: container.addr, port: 1414}, () => {
95+
client.on('close', done);
96+
client.end();
97+
});
98+
});
99+
});
100+
101+
describe('and an empty bind-mounted volume', function() {
102+
let volumeDir = null;
103+
before(function() {
104+
volumeDir = fs.mkdtempSync(VOLUME_PREFIX);
105+
});
106+
107+
before(function() {
108+
this.timeout(20000);
109+
return runContainer(`--volume ${volumeDir}:/var/mqm`)
110+
.then((details) => {
111+
container = details;
112+
});
113+
});
114+
115+
after(function(done) {
116+
exec(`rm -rf ${volumeDir}`, function (err, stdout, stderr) {
117+
if (err) throw err;
118+
done();
119+
});
120+
});
121+
122+
it('should be listening on port 1414 on the Docker network', function (done) {
123+
const client = net.connect({host: container.addr, port: 1414}, () => {
124+
client.on('close', done);
125+
client.end();
126+
});
127+
});
128+
});
129+
130+
// This can happen if the entire volume directory is actually a filesystem.
131+
// See https://github.com/ibm-messaging/mq-docker/issues/29
132+
describe('and a non-empty bind-mounted volume', function() {
133+
let volumeDir = null;
134+
before(function() {
135+
volumeDir = fs.mkdtempSync(VOLUME_PREFIX);
136+
fs.writeFileSync(`${volumeDir}/foo.txt`, 'Hello world');
137+
});
138+
139+
before(function() {
140+
this.timeout(20000);
141+
return runContainer(`--volume ${volumeDir}:/var/mqm`)
142+
.then((details) => {
143+
container = details;
144+
});
145+
});
146+
147+
after(function(done) {
148+
exec(`rm -rf ${volumeDir}`, function (err, stdout, stderr) {
149+
if (err) throw err;
150+
done();
151+
});
152+
});
153+
154+
it('should be listening on port 1414 on the Docker network', function (done) {
155+
const client = net.connect({host: container.addr, port: 1414}, () => {
156+
client.on('close', done);
157+
client.end();
158+
});
159+
});
160+
});
161+
162+
afterEach(function(done) {
163+
exec(`docker rm --force ${container.id}`, function (err, stdout, stderr) {
164+
done();
165+
});
166+
});
167+
});
168+
});

0 commit comments

Comments
 (0)