tests: call destroy for lwm2m devices to shut down executors inside fwLwM2MDevice and swLwM2MDevice in the test scope
This commit is contained in:
parent
6f66fdb347
commit
ac2844b51f
@ -38,7 +38,7 @@ public class FwLwM2MDevice extends BaseInstanceEnabler implements Destroyable {
|
||||
|
||||
private static final List<Integer> supportedResources = Arrays.asList(0, 1, 2, 3, 5, 6, 7, 9);
|
||||
|
||||
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(ThingsBoardThreadFactory.forName(getClass().getSimpleName()));
|
||||
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(ThingsBoardThreadFactory.forName(getClass().getSimpleName() + "-test-scope"));
|
||||
|
||||
private final AtomicInteger state = new AtomicInteger(0);
|
||||
|
||||
|
||||
@ -45,6 +45,7 @@ import org.eclipse.leshan.core.request.BootstrapRequest;
|
||||
import org.eclipse.leshan.core.request.DeregisterRequest;
|
||||
import org.eclipse.leshan.core.request.RegisterRequest;
|
||||
import org.eclipse.leshan.core.request.UpdateRequest;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
@ -65,8 +66,11 @@ public class LwM2MTestClient {
|
||||
private final ScheduledExecutorService executor;
|
||||
private final String endpoint;
|
||||
private LeshanClient client;
|
||||
private FwLwM2MDevice fwLwM2MDevice;
|
||||
private SwLwM2MDevice swLwM2MDevice;
|
||||
|
||||
public void init(Security security, NetworkConfig coapConfig) throws InvalidDDFFileException, IOException {
|
||||
Assert.assertNull("client already initialized", client);
|
||||
String[] resources = new String[]{"0.xml", "1.xml", "2.xml", "3.xml", "5.xml", "9.xml"};
|
||||
List<ObjectModel> models = new ArrayList<>();
|
||||
for (String resourceName : resources) {
|
||||
@ -77,8 +81,8 @@ public class LwM2MTestClient {
|
||||
initializer.setInstancesForObject(SECURITY, security);
|
||||
initializer.setInstancesForObject(SERVER, new Server(123, 300));
|
||||
initializer.setInstancesForObject(DEVICE, new SimpleLwM2MDevice());
|
||||
initializer.setInstancesForObject(FIRMWARE, new FwLwM2MDevice());
|
||||
initializer.setInstancesForObject(SOFTWARE_MANAGEMENT, new SwLwM2MDevice());
|
||||
initializer.setInstancesForObject(FIRMWARE, fwLwM2MDevice = new FwLwM2MDevice());
|
||||
initializer.setInstancesForObject(SOFTWARE_MANAGEMENT, swLwM2MDevice = new SwLwM2MDevice());
|
||||
initializer.setClassForObject(LwM2mId.ACCESS_CONTROL, DummyInstanceEnabler.class);
|
||||
|
||||
DtlsConnectorConfig.Builder dtlsConfig = new DtlsConnectorConfig.Builder();
|
||||
@ -229,6 +233,12 @@ public class LwM2MTestClient {
|
||||
|
||||
public void destroy() {
|
||||
client.destroy(true);
|
||||
if (fwLwM2MDevice != null) {
|
||||
fwLwM2MDevice.destroy();
|
||||
}
|
||||
if (swLwM2MDevice != null) {
|
||||
swLwM2MDevice.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ public class SwLwM2MDevice extends BaseInstanceEnabler implements Destroyable {
|
||||
|
||||
private static final List<Integer> supportedResources = Arrays.asList(0, 1, 2, 3, 4, 6, 7, 9);
|
||||
|
||||
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(ThingsBoardThreadFactory.forName(getClass().getSimpleName()));
|
||||
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(ThingsBoardThreadFactory.forName(getClass().getSimpleName() + "-test-scope"));
|
||||
|
||||
private final AtomicInteger state = new AtomicInteger(0);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user