use of org.eclipse.paho.client.mqttv3.persist.MemoryPersistence in project azure-iot-sdk-java by Azure.
the class MqttTest method constructorThrowsExceptionIfMqttAsyncClientFails.
/*
**Tests_SRS_Mqtt_25_045: [**The constructor throws IOException if MqttException is thrown and doesn't instantiate this instance.**]**
*/
@Test(expected = IOException.class)
public void constructorThrowsExceptionIfMqttAsyncClientFails() throws IOException, MqttException {
Mqtt mockMqtt = null;
try {
//arrange
new NonStrictExpectations() {
{
new MemoryPersistence();
result = mockMemoryPersistence;
new MqttAsyncClient(serverUri, clientId, mockMemoryPersistence);
result = mockMqttException;
}
};
//act
mockMqtt = instantiateMqtt(true);
} finally {
testCleanUp(mockMqtt);
}
}
use of org.eclipse.paho.client.mqttv3.persist.MemoryPersistence in project azure-iot-sdk-java by Azure.
the class MqttTest method connectionLostAttemptsToReconnect.
/*
**Tests_SRS_Mqtt_25_026: [**The function shall notify all its concrete classes by calling abstract method onReconnect at the entry of the function**]**
*/
/*
**Tests_SRS_Mqtt_25_029: [**The function shall notify all its concrete classes by calling abstract method onReconnectComplete at the exit of the function**]**
*/
@Test
public void connectionLostAttemptsToReconnect() throws IOException, MqttException {
//arrange
Mqtt mockMqtt = null;
Throwable t = new Throwable();
try {
new StrictExpectations() {
{
new MemoryPersistence();
result = mockMemoryPersistence;
new MqttAsyncClient(serverUri, clientId, mockMemoryPersistence);
result = mockMqttAsyncClient;
mockMqttAsyncClient.setCallback((Mqtt) any);
new MqttConnectOptions();
result = mockMqttConnectionOptions;
mockMqttConnectionOptions.setKeepAliveInterval(anyInt);
mockMqttConnectionOptions.setCleanSession(anyBoolean);
mockMqttConnectionOptions.setMqttVersion(anyInt);
mockMqttConnectionOptions.setUserName(anyString);
mockMqttConnectionOptions.setPassword(password.toCharArray());
mockMqttConnectionOptions.setSocketFactory(mockIotHubSSLContext.getIotHubSSlContext().getSocketFactory());
mockMqttAsyncClient.isConnected();
result = false;
mockMqttAsyncClient.isConnected();
result = false;
mockMqttAsyncClient.connect(mockMqttConnectionOptions);
result = mockMqttToken;
mockMqttToken.waitForCompletion();
mockMqttAsyncClient.isConnected();
result = true;
}
};
//act
try {
mockMqtt = instantiateMqtt(true);
mockMqtt.connectionLost(t);
} catch (Exception e) {
System.out.print("Completed throwing exception - " + e.getCause() + e.getMessage());
}
} finally {
testCleanUp(mockMqtt);
}
}
use of org.eclipse.paho.client.mqttv3.persist.MemoryPersistence in project azure-iot-sdk-java by Azure.
the class MqttTest method connectionLostAttemptsToReconnectAgainIfConnectFails.
/*
**Tests_SRS_Mqtt_25_027: [**The function shall attempt to reconnect to the IoTHub in a loop with exponential backoff until it succeeds**]**
*/
@Test
public void connectionLostAttemptsToReconnectAgainIfConnectFails() throws IOException, MqttException {
//arrange
Mqtt mockMqtt = null;
Throwable t = new Throwable();
try {
new StrictExpectations() {
{
new MemoryPersistence();
result = mockMemoryPersistence;
new MqttAsyncClient(serverUri, clientId, mockMemoryPersistence);
result = mockMqttAsyncClient;
mockMqttAsyncClient.setCallback((Mqtt) any);
new MqttConnectOptions();
result = mockMqttConnectionOptions;
mockMqttConnectionOptions.setKeepAliveInterval(anyInt);
mockMqttConnectionOptions.setCleanSession(anyBoolean);
mockMqttConnectionOptions.setMqttVersion(anyInt);
mockMqttConnectionOptions.setUserName(anyString);
mockMqttConnectionOptions.setPassword(password.toCharArray());
mockMqttConnectionOptions.setSocketFactory(mockIotHubSSLContext.getIotHubSSlContext().getSocketFactory());
mockMqttAsyncClient.isConnected();
result = false;
mockMqttAsyncClient.isConnected();
result = false;
mockMqttAsyncClient.connect(mockMqttConnectionOptions);
result = mockMqttException;
mockMqttAsyncClient.isConnected();
result = false;
mockMqttAsyncClient.isConnected();
result = false;
mockMqttAsyncClient.connect(mockMqttConnectionOptions);
result = mockMqttToken;
mockMqttToken.waitForCompletion();
mockMqttAsyncClient.isConnected();
result = true;
}
};
//act
try {
mockMqtt = instantiateMqtt(true);
mockMqtt.connectionLost(t);
} catch (Exception e) {
System.out.print("Completed throwing exception - " + e.getCause() + e.getMessage());
}
} finally {
testCleanUp(mockMqtt);
}
}
use of org.eclipse.paho.client.mqttv3.persist.MemoryPersistence in project ignite by apache.
the class IgniteMqttStreamerTest method beforeTest.
/**
* @throws Exception If failed.
*/
@Before
@SuppressWarnings("unchecked")
public void beforeTest() throws Exception {
grid().<Integer, String>getOrCreateCache(defaultCacheConfiguration());
// find an available local port
try (ServerSocket ss = new ServerSocket(0)) {
port = ss.getLocalPort();
}
// create the broker
broker = new BrokerService();
broker.setDeleteAllMessagesOnStartup(true);
broker.setPersistent(false);
broker.setPersistenceAdapter(null);
broker.setPersistenceFactory(null);
PolicyMap plcMap = new PolicyMap();
PolicyEntry plc = new PolicyEntry();
plc.setQueuePrefetch(1);
broker.setDestinationPolicy(plcMap);
broker.getDestinationPolicy().setDefaultEntry(plc);
broker.setSchedulerSupport(false);
// add the MQTT transport connector to the broker
broker.addConnector("mqtt://localhost:" + port);
broker.setStartAsync(false);
broker.start(true);
// create the broker URL
brokerUrl = "tcp://localhost:" + port;
// create the client and connect
client = new MqttClient(brokerUrl, UUID.randomUUID().toString(), new MemoryPersistence());
client.connect();
// create mqtt streamer
dataStreamer = grid().dataStreamer(DEFAULT_CACHE_NAME);
streamer = createMqttStreamer(dataStreamer);
}
Aggregations