Commit ac2844b51f7239b9ad2f67d6b4da94756475a4f1
1 parent
6f66fdb3
tests: call destroy for lwm2m devices to shut down executors inside fwLwM2MDevic…
…e and swLwM2MDevice in the test scope
Showing
3 changed files
with
14 additions
and
4 deletions
... | ... | @@ -38,7 +38,7 @@ public class FwLwM2MDevice extends BaseInstanceEnabler implements Destroyable { |
38 | 38 | |
39 | 39 | private static final List<Integer> supportedResources = Arrays.asList(0, 1, 2, 3, 5, 6, 7, 9); |
40 | 40 | |
41 | - private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(ThingsBoardThreadFactory.forName(getClass().getSimpleName())); | |
41 | + private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(ThingsBoardThreadFactory.forName(getClass().getSimpleName() + "-test-scope")); | |
42 | 42 | |
43 | 43 | private final AtomicInteger state = new AtomicInteger(0); |
44 | 44 | ... | ... |
... | ... | @@ -45,6 +45,7 @@ import org.eclipse.leshan.core.request.BootstrapRequest; |
45 | 45 | import org.eclipse.leshan.core.request.DeregisterRequest; |
46 | 46 | import org.eclipse.leshan.core.request.RegisterRequest; |
47 | 47 | import org.eclipse.leshan.core.request.UpdateRequest; |
48 | +import org.junit.Assert; | |
48 | 49 | |
49 | 50 | import java.io.IOException; |
50 | 51 | import java.net.InetSocketAddress; |
... | ... | @@ -65,8 +66,11 @@ public class LwM2MTestClient { |
65 | 66 | private final ScheduledExecutorService executor; |
66 | 67 | private final String endpoint; |
67 | 68 | private LeshanClient client; |
69 | + private FwLwM2MDevice fwLwM2MDevice; | |
70 | + private SwLwM2MDevice swLwM2MDevice; | |
68 | 71 | |
69 | 72 | public void init(Security security, NetworkConfig coapConfig) throws InvalidDDFFileException, IOException { |
73 | + Assert.assertNull("client already initialized", client); | |
70 | 74 | String[] resources = new String[]{"0.xml", "1.xml", "2.xml", "3.xml", "5.xml", "9.xml"}; |
71 | 75 | List<ObjectModel> models = new ArrayList<>(); |
72 | 76 | for (String resourceName : resources) { |
... | ... | @@ -77,8 +81,8 @@ public class LwM2MTestClient { |
77 | 81 | initializer.setInstancesForObject(SECURITY, security); |
78 | 82 | initializer.setInstancesForObject(SERVER, new Server(123, 300)); |
79 | 83 | initializer.setInstancesForObject(DEVICE, new SimpleLwM2MDevice()); |
80 | - initializer.setInstancesForObject(FIRMWARE, new FwLwM2MDevice()); | |
81 | - initializer.setInstancesForObject(SOFTWARE_MANAGEMENT, new SwLwM2MDevice()); | |
84 | + initializer.setInstancesForObject(FIRMWARE, fwLwM2MDevice = new FwLwM2MDevice()); | |
85 | + initializer.setInstancesForObject(SOFTWARE_MANAGEMENT, swLwM2MDevice = new SwLwM2MDevice()); | |
82 | 86 | initializer.setClassForObject(LwM2mId.ACCESS_CONTROL, DummyInstanceEnabler.class); |
83 | 87 | |
84 | 88 | DtlsConnectorConfig.Builder dtlsConfig = new DtlsConnectorConfig.Builder(); |
... | ... | @@ -229,6 +233,12 @@ public class LwM2MTestClient { |
229 | 233 | |
230 | 234 | public void destroy() { |
231 | 235 | client.destroy(true); |
236 | + if (fwLwM2MDevice != null) { | |
237 | + fwLwM2MDevice.destroy(); | |
238 | + } | |
239 | + if (swLwM2MDevice != null) { | |
240 | + swLwM2MDevice.destroy(); | |
241 | + } | |
232 | 242 | } |
233 | 243 | |
234 | 244 | } | ... | ... |
... | ... | @@ -39,7 +39,7 @@ public class SwLwM2MDevice extends BaseInstanceEnabler implements Destroyable { |
39 | 39 | |
40 | 40 | private static final List<Integer> supportedResources = Arrays.asList(0, 1, 2, 3, 4, 6, 7, 9); |
41 | 41 | |
42 | - private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(ThingsBoardThreadFactory.forName(getClass().getSimpleName())); | |
42 | + private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(ThingsBoardThreadFactory.forName(getClass().getSimpleName() + "-test-scope")); | |
43 | 43 | |
44 | 44 | private final AtomicInteger state = new AtomicInteger(0); |
45 | 45 | ... | ... |