@Test void testGetConnectionShouldReturnExistingConnectionToGatewayDeviceWhenInCache() throws Exception { final String deviceIdentification = "LM_DVC_1"; final String gatewayDeviceIdentification = "LM_GATEWAY_1"; final Iec60870Device device = Iec60870DeviceFactory.createLightMeasurementDevice(deviceIdentification, gatewayDeviceIdentification); when(this.iec60870DeviceRepository.findByDeviceIdentification(deviceIdentification)) .thenReturn(Optional.of(device)); final RequestMetadata requestMetadata = RequestMetadataFactory.forDevice(deviceIdentification); final ClientConnection expectedConnection = ClientConnectionFactory.forDevice(gatewayDeviceIdentification); this.connectionCache.addConnection(gatewayDeviceIdentification, expectedConnection); final ClientConnection actualConnection = this.clientConnectionService.getConnection(requestMetadata); assertThat(actualConnection).isEqualTo(expectedConnection); }
public ClientConnection getConnection(final RequestMetadata requestMetadata) throws ConnectionFailureException { final String deviceIdentification = requestMetadata.getDeviceIdentification(); LOGGER.debug("Get connection called for device {}.", deviceIdentification); final Iec60870Device device = this.getIec60870Device(deviceIdentification); final String connectionDeviceIdentification = this.getConnectionDeviceIdentification(device); if (device.hasGatewayDevice()) { LOGGER.debug("Getting connection for device {} using gateway device {}.", deviceIdentification, connectionDeviceIdentification); } final ClientConnection cachedDeviceConnection = this.connectionCache .getConnection(connectionDeviceIdentification); if (cachedDeviceConnection != null) { LOGGER.info("Connection found in cache for device {}.", connectionDeviceIdentification); return cachedDeviceConnection; } else { LOGGER.info("No connection found in cache for device {}, creating new connection.", connectionDeviceIdentification); return this.createConnection(requestMetadata); } }
ClientConnectionService { public ClientConnection getConnection(final RequestMetadata requestMetadata) throws ConnectionFailureException { final String deviceIdentification = requestMetadata.getDeviceIdentification(); LOGGER.debug("Get connection called for device {}.", deviceIdentification); final Iec60870Device device = this.getIec60870Device(deviceIdentification); final String connectionDeviceIdentification = this.getConnectionDeviceIdentification(device); if (device.hasGatewayDevice()) { LOGGER.debug("Getting connection for device {} using gateway device {}.", deviceIdentification, connectionDeviceIdentification); } final ClientConnection cachedDeviceConnection = this.connectionCache .getConnection(connectionDeviceIdentification); if (cachedDeviceConnection != null) { LOGGER.info("Connection found in cache for device {}.", connectionDeviceIdentification); return cachedDeviceConnection; } else { LOGGER.info("No connection found in cache for device {}, creating new connection.", connectionDeviceIdentification); return this.createConnection(requestMetadata); } } }
ClientConnectionService { public ClientConnection getConnection(final RequestMetadata requestMetadata) throws ConnectionFailureException { final String deviceIdentification = requestMetadata.getDeviceIdentification(); LOGGER.debug("Get connection called for device {}.", deviceIdentification); final Iec60870Device device = this.getIec60870Device(deviceIdentification); final String connectionDeviceIdentification = this.getConnectionDeviceIdentification(device); if (device.hasGatewayDevice()) { LOGGER.debug("Getting connection for device {} using gateway device {}.", deviceIdentification, connectionDeviceIdentification); } final ClientConnection cachedDeviceConnection = this.connectionCache .getConnection(connectionDeviceIdentification); if (cachedDeviceConnection != null) { LOGGER.info("Connection found in cache for device {}.", connectionDeviceIdentification); return cachedDeviceConnection; } else { LOGGER.info("No connection found in cache for device {}, creating new connection.", connectionDeviceIdentification); return this.createConnection(requestMetadata); } }  }
ClientConnectionService { public ClientConnection getConnection(final RequestMetadata requestMetadata) throws ConnectionFailureException { final String deviceIdentification = requestMetadata.getDeviceIdentification(); LOGGER.debug("Get connection called for device {}.", deviceIdentification); final Iec60870Device device = this.getIec60870Device(deviceIdentification); final String connectionDeviceIdentification = this.getConnectionDeviceIdentification(device); if (device.hasGatewayDevice()) { LOGGER.debug("Getting connection for device {} using gateway device {}.", deviceIdentification, connectionDeviceIdentification); } final ClientConnection cachedDeviceConnection = this.connectionCache .getConnection(connectionDeviceIdentification); if (cachedDeviceConnection != null) { LOGGER.info("Connection found in cache for device {}.", connectionDeviceIdentification); return cachedDeviceConnection; } else { LOGGER.info("No connection found in cache for device {}, creating new connection.", connectionDeviceIdentification); return this.createConnection(requestMetadata); } }  ClientConnection getConnection(final RequestMetadata requestMetadata); void closeConnection(final String deviceIdentification); synchronized void close(final ClientConnection connection); @PreDestroy void closeAllConnections(); }
ClientConnectionService { public ClientConnection getConnection(final RequestMetadata requestMetadata) throws ConnectionFailureException { final String deviceIdentification = requestMetadata.getDeviceIdentification(); LOGGER.debug("Get connection called for device {}.", deviceIdentification); final Iec60870Device device = this.getIec60870Device(deviceIdentification); final String connectionDeviceIdentification = this.getConnectionDeviceIdentification(device); if (device.hasGatewayDevice()) { LOGGER.debug("Getting connection for device {} using gateway device {}.", deviceIdentification, connectionDeviceIdentification); } final ClientConnection cachedDeviceConnection = this.connectionCache .getConnection(connectionDeviceIdentification); if (cachedDeviceConnection != null) { LOGGER.info("Connection found in cache for device {}.", connectionDeviceIdentification); return cachedDeviceConnection; } else { LOGGER.info("No connection found in cache for device {}, creating new connection.", connectionDeviceIdentification); return this.createConnection(requestMetadata); } }  ClientConnection getConnection(final RequestMetadata requestMetadata); void closeConnection(final String deviceIdentification); synchronized void close(final ClientConnection connection); @PreDestroy void closeAllConnections();  }