Skip to content

Commit

Permalink
Merge pull request #12730 from rabbitmq/test-amqp10-session-link-deta…
Browse files Browse the repository at this point in the history
…ils-in-ui

Test amqp10 session and link information in management ui
  • Loading branch information
michaelklishin authored Nov 18, 2024
2 parents 047cc5a + a8e7d69 commit b1c82b4
Show file tree
Hide file tree
Showing 14 changed files with 298 additions and 35 deletions.
12 changes: 6 additions & 6 deletions deps/rabbitmq_management/priv/www/js/tmpl/connection.ejs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h2>Connection <%= fmt_string(connection.name) %> <%= fmt_maybe_vhost(connection.vhost) %></h1>

<% if (!disable_stats) { %>
<div class="section">
<div class="section" id="connection-overview-section">
<h2>Overview</h2>
<div class="hider updatable">
<%= data_rates('data-rates-conn', connection, 'Data rates') %>
Expand Down Expand Up @@ -86,7 +86,7 @@
<% if (connection.protocol === 'AMQP 1-0') { %>
<div class="section">
<div class="section" id="connection-sessions-section">
<h2 class="updatable" >Sessions (<%=(sessions.length)%>)</h2>
<div class="hider updatable">
<%= format('sessions-list', {'sessions': sessions}) %>
Expand All @@ -95,7 +95,7 @@
<% } else { %>
<div class="section">
<div class="section" id="connection-channels-section">
<h2 class="updatable" >Channels (<%=(channels.length)%>) </h2>
<div class="hider updatable">
<%= format('channels-list', {'channels': channels, 'mode': 'connection'}) %>
Expand Down Expand Up @@ -149,7 +149,7 @@
<% } %>
<% if (properties_size(connection.client_properties) > 0) { %>
<div class="section-hidden">
<div class="section-hidden" id="connection-client-properies-section">
<h2>Client properties</h2>
<div class="hider">
<%= fmt_table_long(connection.client_properties) %>
Expand All @@ -158,7 +158,7 @@
<% } %>
<% if(connection.reductions || connection.garbage_collection) { %>
<div class="section-hidden">
<div class="section-hidden" id="connection-runtime-metrics-section">
<h2>Runtime Metrics (Advanced)</h2>
<div class="hider updatable">
<%= data_reductions('reductions-rates-conn', connection) %>
Expand Down Expand Up @@ -197,7 +197,7 @@
<% } %>
<% } %>

<div class="section-hidden">
<div class="section-hidden" id="connection-close-section">
<h2>Close this connection</h2>
<div class="hider">
<form action="#/connections" method="delete" class="confirm">
Expand Down
4 changes: 2 additions & 2 deletions deps/rabbitmq_management/priv/www/js/tmpl/connections.ejs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<h1>Connections</h1>
<div class="section">
<div class="section" id="connections-paging-section">
<%= paginate_ui(connections, 'connections') %>
</div>
<div class="updatable">
<div class="updatable" id="connections-table-section">
<% if (connections.items.length > 0) { %>
<table class="list">
<thead>
Expand Down
16 changes: 8 additions & 8 deletions deps/rabbitmq_management/priv/www/js/tmpl/sessions-list.ejs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% if (sessions.length > 0) { %>
<table class="list">
<table class="list" id="sessions">
<thead>
<tr>
<th>Channel number</th>
Expand All @@ -18,7 +18,7 @@
for (var i = 0; i < sessions.length; i++) {
var session = sessions[i];
%>
<tr>
<tr class="session">
<td class="c"><%= fmt_string(session.channel_number) %></td>
<td class="c"><%= fmt_string(session.handle_max) %></td>
<td class="c"><%= fmt_string(session.next_incoming_id) %></td>
Expand All @@ -30,9 +30,9 @@
</tr>
<% if (session.incoming_links.length > 0) { %>
<tr>
<td colspan="8">
<td colspan="8" >
<p>Incoming Links (<%=(session.incoming_links.length)%>) <span class="help" id="incoming-links"></span></p>
<table class="list">
<table class="list" id="incoming-links">
<thead>
<tr>
<th>Link handle</th>
Expand All @@ -50,7 +50,7 @@
for (var j = 0; j < session.incoming_links.length; j++) {
var in_link = session.incoming_links[j];
%>
<tr>
<tr class="link">
<td class="c"><%= fmt_string(in_link.handle) %></td>
<td class="c"><%= fmt_string(in_link.link_name) %></td>
<td class="c"><%= fmt_string(in_link.target_address) %></td>
Expand All @@ -68,9 +68,9 @@
<% } %>
<% if (session.outgoing_links.length > 0) { %>
<tr>
<td colspan="8">
<td colspan="8" >
<p>Outgoing Links (<%=(session.outgoing_links.length)%>) <span class="help" id="outgoing-links"></span></p>
<table class="list">
<table class="list" id="outgoing-links">
<thead>
<tr>
<th>Link handle</th>
Expand All @@ -88,7 +88,7 @@
for (var k = 0; k < session.outgoing_links.length; k++) {
var out_link = session.outgoing_links[k];
%>
<tr>
<tr class="link">
<td class="c"><%= fmt_string(out_link.handle) %></td>
<td class="c"><%= fmt_string(out_link.link_name) %></td>
<td class="c"><%= fmt_string(out_link.source_address) %></td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public static void main(String args[]) throws Exception {
String username = args.length > 0 ? args[0] : getEnv("RABBITMQ_AMQP_USERNAME", "guest");
String password = args.length > 1 ? args[1] : getEnv("RABBITMQ_AMQP_PASSWORD", "guest");

boolean usemtls = Boolean.parseBoolean(getEnv("AMQP_USE_MTLS", "false"));
String certsLocation = getEnv("RABBITMQ_CERTS");
boolean usemtls = Boolean.parseBoolean(getEnv("AMQP_USE_MTLS", "false"));

if ("amqps".equals(scheme)) {
List<String> connectionParams = new ArrayList<String>();
String certsLocation = getEnv("RABBITMQ_CERTS");

connectionParams.add("transport.trustStoreLocation=" + certsLocation + "/truststore.jks");
connectionParams.add("transport.trustStorePassword=foobar");
Expand Down Expand Up @@ -84,6 +84,8 @@ public static void main(String args[]) throws Exception {
TextMessage receivedMessage = (TextMessage) messageConsumer.receive(2000L);

assertEquals(message.getText(), receivedMessage.getText());

Thread.sleep(60000);
}
}
private static Connection createConnection(ConnectionFactory factory,
Expand Down
5 changes: 3 additions & 2 deletions selenium/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
"author": "",
"license": "ISC",
"dependencies": {
"chromedriver": "^128.0.0",
"chromedriver": "^130.0.4",
"ejs": "^3.1.8",
"express": "^4.18.2",
"geckodriver": "^3.0.2",
"http-proxy": "^1.18.1",
"mqtt": "^5.3.3",
"path": "^0.12.7",
"proxy": "^1.0.2",
"selenium-webdriver": "^4.19.0",
"rhea": "^3.0.3",
"selenium-webdriver": "^4.26.0",
"xmlhttprequest": "^1.8.0"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions selenium/short-suite-management-ui
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ authnz-mgt/oauth-with-uaa.sh
mgt/vhosts.sh
mgt/exchanges.sh
mgt/limits.sh
mgt/amqp10-connections.sh
9 changes: 9 additions & 0 deletions selenium/suites/mgt/amqp10-connections.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

TEST_CASES_PATH=/connections/amqp10
TEST_CONFIG_PATH=/basic-auth

source $SCRIPT/../../bin/suite_template $@
run
17 changes: 17 additions & 0 deletions selenium/test/basic-auth/imports/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
"vhosts": [
{
"name": "/"
},
{
"name": "other"
}
],
"permissions": [
Expand All @@ -79,6 +82,20 @@
"configure": ".*",
"write": ".*",
"read": ".*"
},
{
"user": "rabbit_no_management",
"vhost": "other",
"configure": ".*",
"write": ".*",
"read": ".*"
},
{
"user": "monitoring-only",
"vhost": "other",
"configure": ".*",
"write": ".*",
"read": ".*"
}
]

Expand Down
140 changes: 140 additions & 0 deletions selenium/test/connections/amqp10/sessions-for-monitoring-user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
const { By, Key, until, Builder } = require('selenium-webdriver')
require('chromedriver')
const assert = require('assert')
const { buildDriver, goToHome, captureScreensFor, teardown, delay } = require('../../utils')

const LoginPage = require('../../pageobjects/LoginPage')
const OverviewPage = require('../../pageobjects/OverviewPage')
const ConnectionsPage = require('../../pageobjects/ConnectionsPage')
const ConnectionPage = require('../../pageobjects/ConnectionPage')

var container = require('rhea') // https://github.com/amqp/rhea
var receivedAmqpMessageCount = 0
var untilConnectionEstablished = new Promise((resolve, reject) => {
container.on('connection_open', function(context) {
resolve()
})
})

container.on('message', function (context) {
receivedAmqpMessageCount++
})
container.once('sendable', function (context) {
context.sender.send({body:'first message'})
})


describe('Given an amqp10 connection opened, listed and clicked on it', function () {
let captureScreen
let connectionsPage
let connectionPage
let connection

before(async function () {
driver = buildDriver()
await goToHome(driver)
login = new LoginPage(driver)
overview = new OverviewPage(driver)
connectionsPage = new ConnectionsPage(driver)
connectionPage = new ConnectionPage(driver)
captureScreen = captureScreensFor(driver, __filename)
await login.login('monitoring-only', 'guest')
await overview.isLoaded()

connection = container.connect(
{'host': process.env.RABBITMQ_HOSTNAME || 'rabbitmq',
'port': process.env.RABBITMQ_AMQP_PORT || 5672,
'username' : process.env.RABBITMQ_AMQP_USERNAME || 'guest',
'password' : process.env.RABBITMQ_AMQP_PASSWORD || 'guest',
'id': "selenium-connection-id",
'container_id': "selenium-container-id"
})
connection.open_receiver({
source: 'examples',
target: 'receiver-target',
name: 'receiver-link'
})
sender = connection.open_sender({
target: 'examples',
source: 'sender-source',
name: 'sender-link'
})
await untilConnectionEstablished
await overview.clickOnConnectionsTab()
await connectionsPage.isLoaded()

connections_table = await connectionsPage.getConnectionsTable(20)
assert.equal(1, connections_table.length)
await connectionsPage.clickOnConnection(2)
await connectionPage.isLoaded()
})


it('can list session information', async function () {
let sessions = await connectionPage.getSessions()
assert.equal(1, sessions.sessions.length)
let session = connectionPage.getSessionInfo(sessions.sessions, 0)
//console.log("session: " + JSON.stringify(session))
assert.equal(0, session.channelNumber)
assert.equal(1, session.nextIncomingId)
assert.equal(0, session.outgoingUnsettledDeliveries)
})

it('can list link information', async function () {
let sessions = await connectionPage.getSessions()
assert.equal(1, sessions.incoming_links.length)
assert.equal(1, sessions.outgoing_links.length)

let incomingLink = connectionPage.getIncomingLinkInfo(sessions.incoming_links, 0)
//console.log("incomingLink: " + JSON.stringify(incomingLink))
assert.equal(1, incomingLink.handle)
assert.equal("sender-link", incomingLink.name)
assert.equal("examples", incomingLink.targetAddress)
assert.equal("mixed", incomingLink.sndSettleMode)
assert.equal("0", incomingLink.unconfirmedMessages)
assert.equal(1, incomingLink.deliveryCount)

let outgoingLink = connectionPage.getOutgoingLinkInfo(sessions.outgoing_links, 0)
//console.log("outgoingLink: " + JSON.stringify(outgoingLink))
assert.equal(0, outgoingLink.handle)
assert.equal("receiver-link", outgoingLink.name)
assert.equal("examples", outgoingLink.sourceAddress)
assert.equal("examples", outgoingLink.queueName)

assert.equal(false, outgoingLink.sendSettled)
assert.equal("unlimited", outgoingLink.maxMessageSize)

})

it('display live link information', async function () {
var untilMessageReceived = new Promise((resolve, reject) => {
container.on('message', function(context) {
resolve()
})
})
sender.send({body:'second message'})
await untilMessageReceived
assert.equal(2, receivedAmqpMessageCount)

await delay(5*1000) // wait until page refreshes
let sessions = await connectionPage.getSessions()
let incomingLink = connectionPage.getIncomingLinkInfo(sessions.incoming_links, 0)
assert.equal(2, incomingLink.deliveryCount)

//console.log("incomingLink: " + JSON.stringify(incomingLink))
//console.log("outgoingLink: " + JSON.stringify(outgoingLink))
})


after(async function () {
await teardown(driver, this, captureScreen)
try {
if (connection != null) {
connection.close()
}
} catch (error) {
console.error("Failed to close amqp10 connection due to " + error);
}
})

})
19 changes: 14 additions & 5 deletions selenium/test/exchanges/management.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,31 @@ describe('Exchange management', function () {
})

it('display summary of exchanges', async function () {
assert.equal("All exchanges (8)", await exchanges.getPagingSectionHeaderText())
assert.equal("All exchanges (15)", await exchanges.getPagingSectionHeaderText())
})

it('list all default exchanges', async function () {
actual_table = await exchanges.getExchangesTable(3)
console.log("a :" + actual_table)
expected_table = [
let actual_table = await exchanges.getExchangesTable(3)

let expected_table = [
["/", "(AMQP default)", "direct"],
["/", "amq.direct", "direct"],
["/", "amq.fanout", "fanout"],
["/", "amq.headers", "headers"],
["/", "amq.match", "headers"],
["/", "amq.rabbitmq.event", "topic"],
["/", "amq.rabbitmq.trace", "topic"],
["/", "amq.topic", "topic"]
["/", "amq.topic", "topic"],

["other", "(AMQP default)", "direct"],
["other", "amq.direct", "direct"],
["other", "amq.fanout", "fanout"],
["other", "amq.headers", "headers"],
["other", "amq.match", "headers"],
["other", "amq.rabbitmq.trace", "topic"],
["other", "amq.topic", "topic"]
]

console.log("e :" + actual_table)
assert.deepEqual(actual_table, expected_table)
})
Expand Down
Loading

0 comments on commit b1c82b4

Please sign in to comment.