@Deactivate
    public void deactivate(ComponentContext context) {

        try {
            controller.getDevices().forEach(device -> {
                deviceBuilderExecutor.execute(new DeviceFactory(device, false));
            });
            deviceBuilderExecutor.awaitTermination(1000, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            log.error("Device builder did not terminate");
        }
        deviceBuilderExecutor.shutdownNow();
        netCfgService.unregisterConfigFactory(factory);
        netCfgService.removeListener(cfgLister);
        providerRegistry.unregister(this);
        providerService = null;
        log.info("Stopped");
    }
@Test
    public void testDeactivate() {
        this.addDevice();
        provider.deactivate(null);
        assertAfter(DELAY, TEST_DURATION, () ->
                assertNull("Device should be removed", controller.getDevice(deviceId)));
        assertTrue("Network config factory not removed", cfgFactories.isEmpty());
        assertFalse("Network config listener not removed", netCfgListeners.contains(provider.cfgLister));
        assertFalse("Provider not unregistered", providerRegistry.getProviders().contains(provider.id()));
        assertNull("Provider registry not removed", provider.providerService);
    }