Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,44 @@ public void testDisconnectForcibly() throws Exception {
}
}
}

@Test
public void testMqttConnectOptionsConstructorWithCredentials() throws Exception {
String methodName = Utility.getMethodName();
LoggingUtilities.banner(log, cclass, methodName);

int before_thread_count = Thread.activeCount();
URI uri = new URI("tcp://iot.eclipse.org:1882");
IMqttAsyncClient client = clientFactory.createMqttAsyncClient(uri, "client-1");

String username = "foo";
char[] password = "bar".toCharArray();

MqttConnectOptions options = new MqttConnectOptions(username, password);
options.setAutomaticReconnect(true);
options.setConnectionTimeout(2);
client.connect(options);

Thread.sleep(1000);

try {
// this would deadlock before fix
client.disconnect(0).waitForCompletion();
} finally {
client.close();
}

int after_count = Thread.activeCount();
Thread[] tarray = new Thread[after_count];
while (after_count > before_thread_count) {
after_count = Thread.enumerate(tarray);
for (int i = 0; i < after_count; ++i) {
log.info(i + " " + tarray[i].getName());
}
Thread.sleep(100);
}
Assert.assertEquals(before_thread_count, after_count);
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ public class MqttConnectOptions {
public MqttConnectOptions() {
// Initialise Base MqttConnectOptions Object
}

/**
* Constructs a new <code>MqttConnectOptions</code> object with username and password using the default
* values.
*
* The defaults are:
* <ul>
* <li>The keepalive interval is 60 seconds</li>
* <li>Clean Session is true</li>
* <li>The message delivery retry interval is 15 seconds</li>
* <li>The connection timeout period is 30 seconds</li>
* <li>No Will message is set</li>
* <li>A standard SocketFactory is used</li>
* </ul>
* More information about these values can be found in the setter methods.
*/
public MqttConnectOptions(String userName, char[] password) {
this.userName = userName;
this.password = password.clone();
}

/**
* Returns the password to use for the connection.
Expand Down