mil.dod.th.ose.core.integration/src/mil/dod/th/ose/core/integration/TestCustomCommsService.java
@SuppressWarnings("unchecked")
    public final void testShutdown() throws BundleException, PhysicalLinkException, InterruptedException, 
        CCommException, IllegalArgumentException, FactoryException, PersistenceFailedException, IOException
    {
        CustomCommsService customCommsService = ServiceUtils.getService(m_Context, CustomCommsService.class);
        
        final PhysicalLink cLink = customCommsService.createPhysicalLink(PhysicalLinkTypeEnum.I_2_C);
        
        cLink.open();
        
        final LinkLayer lLayer = customCommsService.createLinkLayer(ExampleLinkLayer.class.getName(), cLink.getName());
        
        customCommsService.createTransportLayer(EchoTransport.class.getName(), "tl-shutdown", lLayer.getName());
        
        EventHandlerSyncer listener;
        for (LinkLayer linkLayer : customCommsService.getLinkLayers())
        {
            listener = new EventHandlerSyncer(m_Context, LinkLayer.TOPIC_ACTIVATED,  
                    String.format("(%s=%s)", FactoryDescriptor.EVENT_PROP_OBJ_UUID, linkLayer.getUuid().toString()));
            linkLayer.activateLayer();
            listener.waitForEvent(5);
            assertThat(linkLayer.isActivated(), is(true));
        }
        
        LogReaderService logReader = ServiceUtils.getService(m_Context, LogReaderService.class);
        
        final Semaphore physicalLinkClosedSemaphore = new Semaphore(0);
        
        logReader.addLogListener(new LogListener()
        {
            @Override
            public void logged(LogEntry entry)
            {
                if ("Example PhysicalLink closed".equals(entry.getMessage()))
                {
                    physicalLinkClosedSemaphore.release();
                }
            }
        });
        
        final Semaphore linkDeactivatedSemaphore = new Semaphore(0);
        
        logReader.addLogListener(new LogListener()
        {
            @Override
            public void logged(LogEntry entry)
            {
                if ("ExampleLinkLayer deactivated".equals(entry.getMessage()))
                {
                    linkDeactivatedSemaphore.release();
                }
            }
        });
        
        ServiceReference<AssetDirectoryService> ccsServiceRef = 
                ServiceUtils.getServiceReference(m_Context, CustomCommsService.class);
        Bundle ccsBundle = ccsServiceRef.getBundle();
        ccsBundle.stop();
        
        // verify log message is read
        assertThat(linkDeactivatedSemaphore.tryAcquire(10, TimeUnit.SECONDS), is(true));
        assertThat(physicalLinkClosedSemaphore.tryAcquire(5, TimeUnit.SECONDS), is(true));
        
        ccsBundle.start();
    }
/**
     * Verify the {@link CustomCommsService} will deactivate all layers when stopped.
     */
Verify the  CustomCommsService will deactivate all layers when stopped.
Verify the CustomCommsService will deactivate all layers when stopped .
@SuppressWarnings("unchecked")
    public final void testShutdown() throws BundleException, PhysicalLinkException, InterruptedException, 
        CCommException, IllegalArgumentException, FactoryException, PersistenceFailedException, IOException
    {
        CustomCommsService customCommsService = ServiceUtils.getService(m_Context, CustomCommsService.class);
        final PhysicalLink cLink = customCommsService.createPhysicalLink(PhysicalLinkTypeEnum.I_2_C);
        cLink.open();
        final LinkLayer lLayer = customCommsService.createLinkLayer(ExampleLinkLayer.class.getName(), cLink.getName());
        customCommsService.createTransportLayer(EchoTransport.class.getName(), "tl-shutdown", lLayer.getName());
        EventHandlerSyncer listener;
        for (LinkLayer linkLayer : customCommsService.getLinkLayers())
        {
            listener = new EventHandlerSyncer(m_Context, LinkLayer.TOPIC_ACTIVATED,  
                    String.format("(%s=%s)", FactoryDescriptor.EVENT_PROP_OBJ_UUID, linkLayer.getUuid().toString()));
            linkLayer.activateLayer();
            listener.waitForEvent(5);
            assertThat(linkLayer.isActivated(), is(true));
        }
        LogReaderService logReader = ServiceUtils.getService(m_Context, LogReaderService.class);
        final Semaphore physicalLinkClosedSemaphore = new Semaphore(0);
        logReader.addLogListener(new LogListener()
        {
            @Override
            public void logged(LogEntry entry)
            {
                if ("Example PhysicalLink closed".equals(entry.getMessage()))
                {
                    physicalLinkClosedSemaphore.release();
                }
            }
        });
        final Semaphore linkDeactivatedSemaphore = new Semaphore(0);
        logReader.addLogListener(new LogListener()
        {
            @Override
            public void logged(LogEntry entry)
            {
                if ("ExampleLinkLayer deactivated".equals(entry.getMessage()))
                {
                    linkDeactivatedSemaphore.release();
                }
            }
        });
        ServiceReference<AssetDirectoryService> ccsServiceRef = 
                ServiceUtils.getServiceReference(m_Context, CustomCommsService.class);
        Bundle ccsBundle = ccsServiceRef.getBundle();
        ccsBundle.stop();
        assertThat(linkDeactivatedSemaphore.tryAcquire(10, TimeUnit.SECONDS), is(true));
        assertThat(physicalLinkClosedSemaphore.tryAcquire(5, TimeUnit.SECONDS), is(true));
        ccsBundle.start();
    }
@ SuppressWarnings ( "unchecked" ) public final void testShutdown ( ) throws BundleException , PhysicalLinkException , InterruptedException , CCommException , IllegalArgumentException , FactoryException , PersistenceFailedException , IOException { CustomCommsService customCommsService = ServiceUtils . getService ( m_Context , CustomCommsService . class ) ; final PhysicalLink cLink = customCommsService . createPhysicalLink ( PhysicalLinkTypeEnum . I_2_C ) ; cLink . open ( ) ; final LinkLayer lLayer = customCommsService . createLinkLayer ( ExampleLinkLayer . class . getName ( ) , cLink . getName ( ) ) ; customCommsService . createTransportLayer ( EchoTransport . class . getName ( ) , "tl-shutdown" , lLayer . getName ( ) ) ; EventHandlerSyncer listener ; for ( LinkLayer linkLayer : customCommsService . getLinkLayers ( ) ) { listener = new EventHandlerSyncer ( m_Context , LinkLayer . TOPIC_ACTIVATED , String . format ( "(%s=%s)" , FactoryDescriptor . EVENT_PROP_OBJ_UUID , linkLayer . getUuid ( ) . toString ( ) ) ) ; linkLayer . activateLayer ( ) ; listener . waitForEvent ( 5 ) ; assertThat ( linkLayer . isActivated ( ) , is ( true ) ) ; } LogReaderService logReader = ServiceUtils . getService ( m_Context , LogReaderService . class ) ; final Semaphore physicalLinkClosedSemaphore = new Semaphore ( 0 ) ; logReader . addLogListener ( new LogListener ( ) { @ Override public void logged ( LogEntry entry ) { if ( "Example PhysicalLink closed" . equals ( entry . getMessage ( ) ) ) { physicalLinkClosedSemaphore . release ( ) ; } } } ) ; final Semaphore linkDeactivatedSemaphore = new Semaphore ( 0 ) ; logReader . addLogListener ( new LogListener ( ) { @ Override public void logged ( LogEntry entry ) { if ( "ExampleLinkLayer deactivated" . equals ( entry . getMessage ( ) ) ) { linkDeactivatedSemaphore . release ( ) ; } } } ) ; ServiceReference < AssetDirectoryService > ccsServiceRef = ServiceUtils . getServiceReference ( m_Context , CustomCommsService . class ) ; Bundle ccsBundle = ccsServiceRef . getBundle ( ) ; ccsBundle . stop ( ) ; assertThat ( linkDeactivatedSemaphore . tryAcquire ( 10 , TimeUnit . SECONDS ) , is ( true ) ) ; assertThat ( physicalLinkClosedSemaphore . tryAcquire ( 5 , TimeUnit . SECONDS ) , is ( true ) ) ; ccsBundle . start ( ) ; }
Verify the {@link CustomCommsService} will deactivate all layers when stopped.
Verify the { @link CustomCommsService } will deactivate all layers when stopped .
// verify log message is read