Skip to content

Commit c7f6a71

Browse files
Merge pull request #12786 from rabbitmq/replace-java-amqp10-client-with-javascript
Selenium suites: replace Java AMQP 1.0 client with a JavaScript one
2 parents 7da1c8a + 0ba194a commit c7f6a71

File tree

8 files changed

+120
-257
lines changed

8 files changed

+120
-257
lines changed

selenium/Dockerfile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ COPY package.json package.json
77

88
FROM base as test
99
RUN npm install
10-
RUN mkdir -p /code/amqp10-roundtriptest
11-
COPY amqp10-roundtriptest /code/amqp10-roundtriptest
12-
RUN mvn -f /code/amqp10-roundtriptest package
1310

1411
ENTRYPOINT [ "npm" ]
1512
CMD [ "" ]

selenium/amqp10-roundtriptest/pom.xml

Lines changed: 0 additions & 103 deletions
This file was deleted.

selenium/amqp10-roundtriptest/run

Lines changed: 0 additions & 16 deletions
This file was deleted.

selenium/amqp10-roundtriptest/src/main/java/com/rabbitmq/amqp1_0/RoundTripTest.java

Lines changed: 0 additions & 96 deletions
This file was deleted.

selenium/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"scripts": {
77
"fakeportal": "node fakeportal/app.js",
88
"fakeproxy": "node fakeportal/proxy.js",
9-
"amqp10_roundtriptest": "eval $(cat $ENV_FILE ) && amqp10-roundtriptest/run",
109
"test": " eval $(cat $ENV_FILE ) && mocha --recursive --trace-warnings --timeout 40000"
1110
},
1211
"keywords": [],

selenium/test/amqp.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
var container = require('rhea') // https://github.com/amqp/rhea
2+
var fs = require('fs');
3+
var path = require('path');
4+
5+
function getAmqpConnectionOptions() {
6+
return {
7+
'host': process.env.RABBITMQ_HOSTNAME || 'rabbitmq',
8+
'port': process.env.RABBITMQ_AMQP_PORT || 5672,
9+
'username' : process.env.RABBITMQ_AMQP_USERNAME || 'guest',
10+
'password' : process.env.RABBITMQ_AMQP_PASSWORD || 'guest',
11+
'id': "selenium-connection-id",
12+
'container_id': "selenium-container-id"
13+
}
14+
}
15+
function getAmqpsConnectionOptions() {
16+
let options = getAmqpConnectionOptions()
17+
let useMtls = process.env.AMQP_USE_MTLS || false
18+
if (useMtls) {
19+
options['enable_sasl_external'] = true
20+
}
21+
options['transport'] = 'tls'
22+
let certsLocation = getEnv("RABBITMQ_CERTS");
23+
options['key'] = fs.readFileSync(path.resolve(certsLocation,'client_rabbitmq_key.pem'))
24+
options['cert'] = fs.readFileSync(path.resolve(certsLocation,'client_rabbitmq_certificate.pem'))
25+
options['ca'] = fs.readFileSync(path.resolve(certsLocation,'ca_rabbitmq_certificate.pem'))
26+
}
27+
function getConnectionOptions() {
28+
switch(process.env.RABBITMQ_AMQP_SCHEME || 'amqp'){
29+
case 'amqp':
30+
return getAmqpConnectionOptions()
31+
case 'amqps':
32+
return getAmqpsConnectionOptions()
33+
}
34+
}
35+
module.exports = {
36+
37+
open: () => {
38+
let promise = new Promise((resolve, reject) => {
39+
container.on('connection_open', function(context) {
40+
resolve()
41+
})
42+
})
43+
let connection = container.connect(getConnectionOptions())
44+
let receiver = connection.open_receiver({
45+
source: 'examples',
46+
target: 'receiver-target',
47+
name: 'receiver-link'
48+
})
49+
let sender = connection.open_sender({
50+
target: 'examples',
51+
source: 'sender-source',
52+
name: 'sender-link'
53+
})
54+
return {
55+
'connection': connection,
56+
'promise' : promise,
57+
'receiver' : receiver,
58+
'sender' : sender
59+
}
60+
},
61+
close: (connection) => {
62+
if (connection != null) {
63+
connection.close()
64+
}
65+
},
66+
once: (event, callback) => {
67+
container.once(event, callback)
68+
},
69+
on: (event, callback) => {
70+
container.on(event, callback)
71+
}
72+
}

selenium/test/authnz-msg-protocols/amqp10.js

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
const assert = require('assert')
22
const { tokenFor, openIdConfiguration } = require('../utils')
33
const { reset, expectUser, expectVhost, expectResource, allow, verifyAll } = require('../mock_http_backend')
4-
const {execSync} = require('child_process')
4+
const { open: openAmqp, once: onceAmqp, on: onAmqp, close: closeAmqp } = require('../amqp')
5+
6+
var receivedAmqpMessageCount = 0
7+
var untilConnectionEstablished = new Promise((resolve, reject) => {
8+
onAmqp('connection_open', function(context) {
9+
resolve()
10+
})
11+
})
12+
13+
onAmqp('message', function (context) {
14+
receivedAmqpMessageCount++
15+
})
16+
onceAmqp('sendable', function (context) {
17+
context.sender.send({body:'first message'})
18+
})
519

620
const profiles = process.env.PROFILES || ""
721
var backends = ""
@@ -15,10 +29,8 @@ describe('Having AMQP 1.0 protocol enabled and the following auth_backends: ' +
1529
let expectations = []
1630
let username = process.env.RABBITMQ_AMQP_USERNAME
1731
let password = process.env.RABBITMQ_AMQP_PASSWORD
18-
let usemtls = process.env.AMQP_USE_MTLS
19-
let amqpClientCommand = "npm run amqp10_roundtriptest" +
20-
(usemtls ? "" : " " + username + " " + password)
21-
32+
let amqp;
33+
2234
before(function () {
2335
if (backends.includes("http") && username.includes("http")) {
2436
reset()
@@ -39,13 +51,29 @@ describe('Having AMQP 1.0 protocol enabled and the following auth_backends: ' +
3951
}
4052
})
4153

42-
it('can open an AMQP 1.0 connection', function () {
43-
console.log(execSync(amqpClientCommand).toString())
54+
it('can open an AMQP 1.0 connection', async function () {
55+
amqp = openAmqp()
56+
await untilConnectionEstablished
57+
var untilMessageReceived = new Promise((resolve, reject) => {
58+
onAmqp('message', function(context) {
59+
resolve()
60+
})
61+
})
62+
amqp.sender.send({body:'second message'})
63+
await untilMessageReceived
64+
assert.equal(2, receivedAmqpMessageCount)
4465
})
4566

4667
after(function () {
47-
if ( backends.includes("http") ) {
48-
verifyAll(expectations)
68+
if ( backends.includes("http") ) {
69+
verifyAll(expectations)
70+
}
71+
try {
72+
if (amqp != null) {
73+
closeAmqp(amqp.connection)
4974
}
75+
} catch (error) {
76+
console.error("Failed to close amqp10 connection due to " + error);
77+
}
5078
})
5179
})

0 commit comments

Comments
 (0)