Skip to content

Commit

Permalink
tmp commit
Browse files Browse the repository at this point in the history
Signed-off-by: riccardomodanese <riccardo.modanese@eurotech.com>
  • Loading branch information
riccardomodanese committed Mar 3, 2025
1 parent 48a6ae0 commit 3a8ad38
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ public void setUsernamePasswordCredentials(String username, String password) {
@When("I start the simulator")
public void startSimulator() throws Exception {
currentDevice.started();

logger.info("Starting simulator to broker {} - account {} - client id {} - obj id {}",
nodeUri, currentDevice.getAccountName(), currentDevice.getClientId(), currentDevice);
final GatewayConfiguration configuration = new GatewayConfiguration(nodeUri, currentDevice.getAccountName(), currentDevice.getClientId());

final Set<Application> apps = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1991,15 +1991,19 @@ public void searchForConnectionFromDeviceWithClientIDStatusAndUser(String client
User connectionUserId = userService.findByName(connectionUsername);
Assert.assertNotNull("Coonection username not valid!", connectionUserId);
while (executions++ < timeout) {
logger.info("searchForConnectionFromDeviceWithClientIDStatusAndUser ITERATION: ", executions);
if (searchForConnectionFromDeviceWithClientIDStatusAndUser(clientId, account.getId(), status, connectionUserId.getId(), false)) {
return;
}
Thread.sleep(1000);
}
logger.info("searchForConnectionFromDeviceWithClientIDStatusAndUser completed iterations: ", executions);
searchForConnectionFromDeviceWithClientIDStatusAndUser(clientId, account.getId(), status, connectionUserId.getId(), true);
logger.info("searchForConnectionFromDeviceWithClientIDStatusAndUser completed search: ", executions);
}

private boolean searchForConnectionFromDeviceWithClientIDStatusAndUser(String clientId, KapuaId accountId, String connectionStatus, KapuaId connectionUserId, boolean timeoutOccurred) throws Exception {
boolean retValue = true;
try {
Device device = deviceRegistryService.findByClientId(accountId, clientId);
if (timeoutOccurred) {
Expand All @@ -2016,9 +2020,9 @@ private boolean searchForConnectionFromDeviceWithClientIDStatusAndUser(String cl
}
} else {
if (connectionUserId != null) {
return deviceConnection != null && connectionStatus.equals(deviceConnection.getStatus().name()) && connectionUserId.equals(deviceConnection.getUserId());
retValue = deviceConnection != null && connectionStatus.equals(deviceConnection.getStatus().name()) && connectionUserId.equals(deviceConnection.getUserId());
} else {
return deviceConnection != null && connectionStatus.equals(deviceConnection.getStatus().name());
retValue = deviceConnection != null && connectionStatus.equals(deviceConnection.getStatus().name());
}
}
stepData.put(DEVICE_CONNECTION, deviceConnection);
Expand All @@ -2027,10 +2031,12 @@ private boolean searchForConnectionFromDeviceWithClientIDStatusAndUser(String cl
dcv.add(deviceConnection);
tmpConnLst.addItems(dcv);
stepData.put(DEVICE_CONNECTION_LIST, tmpConnLst);
} catch (KapuaException ex) {
verifyException(ex);
} catch (Throwable ex) {
logger.info("searchForConnectionFromDeviceWithClientIDStatusAndUser step exception");
verifyException((KapuaException)ex);
}
return true;
logger.info("searchForConnectionFromDeviceWithClientIDStatusAndUser end");
return retValue;
}

@Then("The connection user is {string}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void deliveryComplete(final IMqttDeliveryToken token) {

@Override
public void connectionLost(final Throwable cause) {
logger.warn("CONNECTION LOST!!!!", cause);
handleDisconnected();
}
});
Expand Down Expand Up @@ -164,14 +165,19 @@ public void whenDisconnected(final Runnable runnable) {
protected void handleConnected() {
//double check the connection
//in case of stealing link very close to each other the old device can try to execute the onConnected while the connection is dropped
logger.info("Calling handleConnected {}", this);
if (client.isConnected()) {
final Runnable runnable = this.onConnected;
logger.info("Calling handleConnected {} CONNECTED {}", this, runnable);
if (runnable != null) {
runnable.run();
}
logger.info("Calling handleConnected {} STARTED RUNNABLE", this);
}
else {
logger.info("Calling handleConnected {} NOT CONNECTED", this);
logger.warn("Device not still connected. Skip onConnected code execution");
logger.warn("===>", new Exception());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,20 @@ public void close() {
}

protected void connected() {
logger.info("Connected ... sending birth certificate ...");
logger.info("Connected... calling modules... {}", this);
for (final Module module : modules) {
try {
logger.info("Connected... calling module {} ... {}", module, this);
module.connected(transport);
logger.info("Connected... calling module {} DONE... {}", module, this);
} catch (final Exception e) {
logger.warn("Failed to call module: {}", module, e);
}
}
}

protected void disconnected() {
logger.info("Disconnected ... {}", this);
for (final Module module : modules) {
try {
module.disconnected(transport);
Expand Down

0 comments on commit 3a8ad38

Please sign in to comment.