mil.dod.th.ose.core.integration/src/mil/dod/th/ose/core/integration/TestMissionProgramming.java
@Test
    public void testMultipleThreads() throws Exception
    {
        final SemaphoreService service = new SemaphoreService();
        
        m_Context.registerService(SemaphoreService.class, service, null);
        String serviceName = SemaphoreService.class.getName();
        ServiceReference<?> serviceRef = m_Context.getServiceReference(serviceName);
        //verify that service works
        SemaphoreService serv = (SemaphoreService) m_Context.getService(serviceRef);
        //verify service is registered and returning what is expected
        assertThat(serv.getSemaphoreA().getClass().equals(Semaphore.class), is(true));
        
        EventHandlerSyncer executionSyncerA = new EventHandlerSyncer(m_Context, Program.TOPIC_PROGRAM_EXECUTED, 
                String.format("(%s=%s)", Program.EVENT_PROP_PROGRAM_NAME, "threadA"));
        EventHandlerSyncer executionSyncerB = new EventHandlerSyncer(m_Context, Program.TOPIC_PROGRAM_EXECUTED, 
                String.format("(%s=%s)", Program.EVENT_PROP_PROGRAM_NAME, "threadB"));
        
        MissionProgramSchedule schedule = new MissionProgramSchedule().withIndefiniteInterval(false).
                withImmediately(false).withActive(true).withAtReset(false);
        MissionProgramParameters params = new MissionProgramParameters().withTemplateName("thread-a-template").
            withProgramName("threadA").
            withSchedule(schedule).withParameters(new MapEntry("semServiceRef", serviceName));
        Program programA = m_MissionProgramManager.loadParameters(params);
        programA.execute();

        schedule = new MissionProgramSchedule().withIndefiniteInterval(false).withImmediately(false).withActive(true).
            withAtReset(false);
        params = new MissionProgramParameters().withTemplateName("thread-b-template").withProgramName("threadB").
                withSchedule(schedule).withParameters(new MapEntry("semServiceRef", serviceName));
        Program programB = m_MissionProgramManager.loadParameters(params);
        programB.execute();
        
        executionSyncerA.waitForEvent(5);
        executionSyncerB.waitForEvent(5);
    }
/**
     * Test that missions running on different threads will wait for the other to complete. 
     */
Test that missions running on different threads will wait for the other to complete.
Test that missions running on different threads will wait for the other to complete .
@Test
    public void testMultipleThreads() throws Exception
    {
        final SemaphoreService service = new SemaphoreService();
        m_Context.registerService(SemaphoreService.class, service, null);
        String serviceName = SemaphoreService.class.getName();
        ServiceReference<?> serviceRef = m_Context.getServiceReference(serviceName);
        SemaphoreService serv = (SemaphoreService) m_Context.getService(serviceRef);
        assertThat(serv.getSemaphoreA().getClass().equals(Semaphore.class), is(true));
        EventHandlerSyncer executionSyncerA = new EventHandlerSyncer(m_Context, Program.TOPIC_PROGRAM_EXECUTED, 
                String.format("(%s=%s)", Program.EVENT_PROP_PROGRAM_NAME, "threadA"));
        EventHandlerSyncer executionSyncerB = new EventHandlerSyncer(m_Context, Program.TOPIC_PROGRAM_EXECUTED, 
                String.format("(%s=%s)", Program.EVENT_PROP_PROGRAM_NAME, "threadB"));
        MissionProgramSchedule schedule = new MissionProgramSchedule().withIndefiniteInterval(false).
                withImmediately(false).withActive(true).withAtReset(false);
        MissionProgramParameters params = new MissionProgramParameters().withTemplateName("thread-a-template").
            withProgramName("threadA").
            withSchedule(schedule).withParameters(new MapEntry("semServiceRef", serviceName));
        Program programA = m_MissionProgramManager.loadParameters(params);
        programA.execute();
        schedule = new MissionProgramSchedule().withIndefiniteInterval(false).withImmediately(false).withActive(true).
            withAtReset(false);
        params = new MissionProgramParameters().withTemplateName("thread-b-template").withProgramName("threadB").
                withSchedule(schedule).withParameters(new MapEntry("semServiceRef", serviceName));
        Program programB = m_MissionProgramManager.loadParameters(params);
        programB.execute();
        executionSyncerA.waitForEvent(5);
        executionSyncerB.waitForEvent(5);
    }
@ Test public void testMultipleThreads ( ) throws Exception { final SemaphoreService service = new SemaphoreService ( ) ; m_Context . registerService ( SemaphoreService . class , service , null ) ; String serviceName = SemaphoreService . class . getName ( ) ; ServiceReference < ? > serviceRef = m_Context . getServiceReference ( serviceName ) ; SemaphoreService serv = ( SemaphoreService ) m_Context . getService ( serviceRef ) ; assertThat ( serv . getSemaphoreA ( ) . getClass ( ) . equals ( Semaphore . class ) , is ( true ) ) ; EventHandlerSyncer executionSyncerA = new EventHandlerSyncer ( m_Context , Program . TOPIC_PROGRAM_EXECUTED , String . format ( "(%s=%s)" , Program . EVENT_PROP_PROGRAM_NAME , "threadA" ) ) ; EventHandlerSyncer executionSyncerB = new EventHandlerSyncer ( m_Context , Program . TOPIC_PROGRAM_EXECUTED , String . format ( "(%s=%s)" , Program . EVENT_PROP_PROGRAM_NAME , "threadB" ) ) ; MissionProgramSchedule schedule = new MissionProgramSchedule ( ) . withIndefiniteInterval ( false ) . withImmediately ( false ) . withActive ( true ) . withAtReset ( false ) ; MissionProgramParameters params = new MissionProgramParameters ( ) . withTemplateName ( "thread-a-template" ) . withProgramName ( "threadA" ) . withSchedule ( schedule ) . withParameters ( new MapEntry ( "semServiceRef" , serviceName ) ) ; Program programA = m_MissionProgramManager . loadParameters ( params ) ; programA . execute ( ) ; schedule = new MissionProgramSchedule ( ) . withIndefiniteInterval ( false ) . withImmediately ( false ) . withActive ( true ) . withAtReset ( false ) ; params = new MissionProgramParameters ( ) . withTemplateName ( "thread-b-template" ) . withProgramName ( "threadB" ) . withSchedule ( schedule ) . withParameters ( new MapEntry ( "semServiceRef" , serviceName ) ) ; Program programB = m_MissionProgramManager . loadParameters ( params ) ; programB . execute ( ) ; executionSyncerA . waitForEvent ( 5 ) ; executionSyncerB . waitForEvent ( 5 ) ; }
Test that missions running on different threads will wait for the other to complete.
Test that missions running on different threads will wait for the other to complete .
//verify that service works //verify service is registered and returning what is expected