Adapted issue #79 integration tests scripts to be used for #119

This commit is contained in:
andsel
2015-12-01 23:20:51 +01:00
parent 7325c8e7bc
commit 490c6a763d
3 changed files with 22 additions and 12 deletions
@@ -14,11 +14,13 @@ class PublisherThread extends Thread {
private final String host = "localhost"
private final byte[] payload
private final int numToSend
private final boolean oneClientPerTopic
PublisherThread(int pubId, int numToSend, byte[] payload) {
PublisherThread(int pubId, int numToSend, byte[] payload, boolean oneClientPerTopic) {
this.numToSend = numToSend
this.payload = payload
this.pubId = pubId
this.oneClientPerTopic = oneClientPerTopic
}
@Override
@@ -29,26 +31,28 @@ class PublisherThread extends Thread {
mqtt.setCleanSession(true)
mqtt.setHost(host, 1883)
def postFix = oneClientPerTopic ? subId : ""
mqtt.setClientId("PublisherClient${pubId}")
BlockingConnection connection = mqtt.blockingConnection()
connection.connect()
(1..numToSend).each {
connection.publish("/topic${pubId}", this.payload, QoS.AT_MOST_ONCE, false)
connection.publish("/topic${postFix}", this.payload, QoS.AT_MOST_ONCE, false)
}
connection.publish("/exit${pubId}", 'Exit'.bytes, QoS.AT_MOST_ONCE, false)
connection.publish("/exit${postFix}", 'Exit'.bytes, QoS.AT_MOST_ONCE, false)
connection.disconnect()
}
}
if (args.size() < 1) {
println "Usage: groovy issue79_stress_multipub.groovy num_publishers"
if (args.size() < 2) {
println "Usage: groovy issue79_stress_multipub.groovy num_publishers [single_topic]"
}
boolean singleTopic = (args.size() == 2 && args[1] == "single_topic")
final byte[] payload = 'Hello world!!'.bytes
int numPublishers = args[0] as Integer
(1..numPublishers).each { numPub ->
def pubTh = new PublisherThread(numPub, 5, payload)
def pubTh = new PublisherThread(numPub, 5, payload, singleTopic)
pubTh.start()
}
@@ -12,9 +12,11 @@ class SubscriberThread extends Thread {
private final int subId
private final String host = "localhost"
private final boolean oneClientPerTopic
SubscriberThread(int subId) {
SubscriberThread(int subId, boolean oneClientPerTopic) {
this.subId = subId
this.oneClientPerTopic = oneClientPerTopic
}
@Override
@@ -28,12 +30,14 @@ class SubscriberThread extends Thread {
mqtt.setClientId("SubscriberClient${subId}")
BlockingConnection connection = mqtt.blockingConnection()
connection.connect()
Topic[] topics = [new Topic("/topic${subId}", QoS.AT_MOST_ONCE), new Topic("/exit${subId}", QoS.AT_MOST_ONCE)]
def postFix = oneClientPerTopic ? subId : ""
Topic[] topics = [new Topic("/topic${postFix}", QoS.AT_MOST_ONCE), new Topic("/exit${postFix}", QoS.AT_MOST_ONCE)]
byte[] qoses = connection.subscribe(topics)
boolean exit = false
while (!exit) {
Message message = connection.receive()
if (message.topic == "/exit${subId}") {
if (message.topic == "/exit${postFix}") {
exit = true
}
message.ack()
@@ -44,12 +48,13 @@ class SubscriberThread extends Thread {
}
if (args.size() < 1) {
println "Usage: groovy issue79_stress_multisub.groovy num_subscribers"
println "Usage: groovy issue79_stress_multisub.groovy num_subscribers [single_topic]"
}
int numSubscriber = args[0] as Integer
boolean singleTopic = (args.size() == 2 && args[1] == "single_topic")
(1..numSubscriber).each { numSub ->
def subTh = new SubscriberThread(numSub)
def subTh = new SubscriberThread(numSub, singleTopic)
subTh.start()
}