def test_PropertyChangeListener_EC_APP(self):
        self.localEvent = threading.Event()
        self.eventFlag = False

        self._devBooter, self._devMgr = self.launchDeviceManager(
            execDeviceNode, self._domMgr)
        self.assertNotEqual(self._devBooter, None)
        self._domMgr.installApplication(
            "/waveforms/PropertyChangeListenerNoJava/PropertyChangeListenerNoJava.sad.xml"
        )
        appFact = self._domMgr._get_applicationFactories()[0]
        self.assertNotEqual(appFact, None)
        app = appFact.create(appFact._get_name(), [], [])
        self.assertNotEqual(app, None)
        self._app = app

        c = None
        a = self.dom.apps[0]
        # component with external property
        c = filter(lambda c: c.name == 'PropertyChange_C1', a.comps)[0]
        # assembly controller
        c2 = filter(lambda c: c.name == 'PropertyChange_P1', a.comps)[0]
        self.assertNotEqual(a, None)
        self.assertNotEqual(c, None)
        self.assertNotEqual(c2, None)

        # check if channel is valid
        self.assertNotEqual(self.channel1, None)
        self.assertNotEqual(
            self.channel1._narrow(CosEventChannelAdmin.EventChannel), None)

        sub = Subscriber(self.channel1)

        t = float(0.5)
        regid = a.registerPropertyListener(self.channel1,
                                           ['prop1', 'app_prop1'], t)
        app.start()
        time.sleep(1)

        # assign 3 changed values
        c.prop1 = 100.0
        time.sleep(.6)  # wait for listener to receive notice
        c.prop1 = 200.0
        time.sleep(.6)  # wait for listener to receive notice
        c.prop1 = 300.0
        time.sleep(.6)  # wait for listener to receive notice

        for n in range(4):
            xx = sub.getData()
            self.assertNotEqual(xx, None)

        # unregister
        a.unregisterPropertyListener(regid)

        self.assertRaises(CF.InvalidIdentifier, a.unregisterPropertyListener,
                          regid)

        app.releaseObject()
        self._app = None
    def test_PropertyChangeListener_EC_APP(self):
        self.localEvent = threading.Event()
        self.eventFlag = False

        self._devBooter, self._devMgr = self.launchDeviceManager(execDeviceNode, self._domMgr)
        self.assertNotEqual(self._devBooter, None)
        self._domMgr.installApplication("/waveforms/PropertyChangeListener/PropertyChangeListener.sad.xml")
        appFact = self._domMgr._get_applicationFactories()[0]
        self.assertNotEqual(appFact, None)
        app = appFact.create(appFact._get_name(), [], [])
        self.assertNotEqual(app, None)
        self._app = app

        ps=None
        c=None
        d=redhawk.attach(scatest.getTestDomainName())
        a=d.apps[0]
        # component with external property
        c=filter( lambda c : c.name == 'PropertyChange_C1', a.comps )[0]
        # assembly controller
        c2=filter( lambda c : c.name == 'PropertyChange_P1', a.comps )[0]
        self.assertNotEqual(a,None)
        self.assertNotEqual(c,None)
        self.assertNotEqual(c2,None)
        ps = a.ref._narrow(CF.PropertySet)
        self.assertNotEqual(ps,None)

        # check if channel is valid
        self.assertNotEqual(self.channel1, None)
        self.assertNotEqual(self.channel1._narrow(CosEventChannelAdmin.EventChannel), None)

        sub = Subscriber( self.channel1 )

        t=float(0.5)
        regid=ps.registerPropertyListener( self.channel1, ['prop1', 'app_prop1'],t)
        app.start()
        time.sleep(1)

        # assign 3 changed values
        c.prop1 = 100.0
        time.sleep(.6)   # wait for listener to receive notice
        c.prop1 = 200.0
        time.sleep(.6)   # wait for listener to receive notice
        c.prop1 = 300.0
        time.sleep(.6)   # wait for listener to receive notice

        for n in range(4):
            xx=sub.getData()
            self.assertNotEqual(xx, None)

        # unregister
        ps.unregisterPropertyListener( regid )

        self.assertRaises( CF.InvalidIdentifier,
            ps.unregisterPropertyListener, regid )

        app.releaseObject()
        self._app=None
    def test_PropertyChangeListener_EC_PYTHON(self):
        self.localEvent = threading.Event()
        self.eventFlag = False

        self._devBooter, self._devMgr = self.launchDeviceManager(
            execDeviceNode, self._domMgr)
        self.assertNotEqual(self._devBooter, None)
        self._domMgr.installApplication(
            "/waveforms/PropertyChangeListenerNoJava/PropertyChangeListenerNoJava.sad.xml"
        )
        appFact = self._domMgr._get_applicationFactories()[0]
        self.assertNotEqual(appFact, None)
        app = appFact.create(appFact._get_name(), [], [])
        self.assertNotEqual(app, None)
        self._app = app

        ps = None
        c = None
        d = redhawk.attach(scatest.getTestDomainName())
        a = d.apps[0]
        c = filter(lambda c: c.name == 'PropertyChange_P1', a.comps)[0]
        self.assertNotEqual(c, None)
        ps = c.ref._narrow(CF.PropertySet)
        self.assertNotEqual(ps, None)

        # check if channel is valid
        self.assertNotEqual(self.channel1, None)
        self.assertNotEqual(
            self.channel1._narrow(CosEventChannelAdmin.EventChannel), None)

        sub = Subscriber(self.channel1)

        t = float(0.5)
        regid = ps.registerPropertyListener(self.channel1, ['prop1'], t)
        app.start()
        time.sleep(1)

        # assign 3 changed values
        c.prop1 = 100.0
        time.sleep(.6)  # wait for listener to receive notice
        c.prop1 = 200.0
        time.sleep(.6)  # wait for listener to receive notice
        c.prop1 = 300.0
        time.sleep(.6)  # wait for listener to receive notice

        for n in range(4):
            xx = sub.getData()
            self.assertNotEqual(xx, None)

        # unregister
        ps.unregisterPropertyListener(regid)

        self.assertRaises(CF.InvalidIdentifier, ps.unregisterPropertyListener,
                          regid)

        app.releaseObject()
        self._app = None
class ComponentTerminationTest(scatest.CorbaTestCase):
    def setUp(self):
        self.launchDomainManager()
        self.launchDeviceManager("/nodes/test_GPP_node/DeviceManager.dcd.xml")

        self._event = threading.Event()
        self._subscriber = Subscriber(self._domainManager, 'IDM_Channel', self._idmMessageReceived)

    def tearDown(self):
        # Remove the subscriber
        self._subscriber.terminate()

        # Continue normal teardown
        scatest.CorbaTestCase.tearDown(self)

    def _idmMessageReceived(self, message):
        if message.typecode().equal(StandardEvent._tc_AbnormalComponentTerminationEventType):
            self._event.set()

    def _test_UnhandledException(self, lang):
        waveform_name = 'svc_fn_error_' + lang + '_w'
        sad_file = os.path.join('/waveforms', waveform_name, waveform_name + '.sad.xml')
        app = self._domainManager.createApplication(sad_file, waveform_name, [], [])

        try:
            app.start()
        except CF.Resource.StartError:
            # Python in particular will throw a CORBA exception if the start()
            # call has not finished when the exception handler terminates the
            # component. It doesn't matter for this test, so ignore it.
            pass

        self._event.wait(1)
        self.failUnless(self._event.isSet(), 'No unexpected termination message received')

    def test_UnhandledExceptionCpp(self):
        """
        Test that unhandled exceptions in C++ service function cause components
        to terminate abnormally.
        """
        self._test_UnhandledException('cpp')

    def test_UnhandledExceptionPy(self):
        """
        Test that unhandled exceptions in Python service function cause
        components to terminate abnormally.
        """
        self._test_UnhandledException('py')

    @scatest.requireJava
    def test_UnhandledExceptionJava(self):
        """
        Test that unhandled exceptions in Java service function cause
        components to terminate abnormally.
        """
        self._test_UnhandledException('java')
Пример #5
0
 def test_eventChannelPull(self):
     sub = Subscriber(self._domMgr, self.channelName)
     pub = Publisher(self._domMgr, self.channelName)
     payload = 'hello'
     data = _any.to_any(payload)
     pub.push(data)
     rec_data = self._waitData(sub, 1.0)
     self.assertEquals(rec_data, payload)
     pub.terminate()
     sub.terminate()
Пример #6
0
 def test_eventChannelCB(self):
     queue = Queue.Queue()
     sub = Subscriber(self._domMgr, self.channelName, dataArrivedCB=queue.put)
     pub = Publisher(self._domMgr, self.channelName)
     payload = 'hello'
     data = _any.to_any(payload)
     pub.push(data)
     rec_data = queue.get(timeout=1.0)
     self.assertEquals(rec_data._v, payload)
     pub.terminate()
     sub.terminate()
Пример #7
0
    def setUp(self):
        domBooter, domMgr = self.launchDomainManager()

        # Create an event channel to receive the device and service start/stop
        # messages (the name must match the findbys in the DCD), and connect a
        # subscriber
        eventMgr = domMgr._get_eventChannelMgr()
        channel = eventMgr.createForRegistrations('test_events')
        self._started = Queue.Queue()
        self._stopped = Queue.Queue()
        self._subscriber = Subscriber(channel, dataArrivedCB=self._messageReceived)
Пример #8
0
    def _test_PropertyChangeListener_EC_Comps(self, app_name, comp_name):
        self.localEvent = threading.Event()
        self.eventFlag = False

        self._devBooter, self._devMgr = self.launchDeviceManager(execDeviceNode, self._domMgr)
        self.assertNotEqual(self._devBooter, None)
        self._domMgr.installApplication(app_name)
        appFact = self._domMgr._get_applicationFactories()[0]
        self.assertNotEqual(appFact, None)
        app = appFact.create(appFact._get_name(), [], [])
        self.assertNotEqual(app, None)
        self._app = app

        c=None
        a=self.dom.apps[0]
        c=filter( lambda c : c.name == comp_name, a.comps )[0]
        self.assertNotEqual(c,None)

        # check if channel is valid
        self.assertNotEqual(self.channel1, None)
        self.assertNotEqual(self.channel1._narrow(CosEventChannelAdmin.EventChannel), None)

        sub = Subscriber( self.dom, self.channel_name )

        t=float(0.5)
        regid=c.registerPropertyListener( self.channel1, ['prop1'],t)
        app.start()
        time.sleep(1)

        # assign 3 changed values
        c.prop1 = 100.0
        time.sleep(.6)   # wait for listener to receive notice
        c.prop1 = 200.0
        time.sleep(.6)   # wait for listener to receive notice
        c.prop1 = 300.0
        time.sleep(.6)   # wait for listener to receive notice

        for n in range(4):
            xx=sub.getData()
            self.assertNotEqual(xx, None)

        # unregister
        c.unregisterPropertyListener( regid )

        self.assertRaises( CF.InvalidIdentifier,
            c.unregisterPropertyListener, regid )

        app.stop()
        app.releaseObject()
        self._app=None
Пример #9
0
 def test_eventChannelForceDelete(self):
     sub = Subscriber(self._domMgr, self.channelName)
     pub = Publisher(self._domMgr, self.channelName)
     payload = 'hello'
     data = _any.to_any(payload)
     pub.push(data)
     rec_data = self._waitData(sub, 1.0)
     self.assertEquals(rec_data, payload)
     self.ecm.forceRelease(self.channelName)
     self.assertRaises(CF.EventChannelManager.ChannelDoesNotExist, self.ecm.release, self.channelName)
Пример #10
0
def forward_event_to_waveform(domain, evt_chan, wave, port, msg_id):
    """Forwards message on an event channel to specified waveform input port

    Parameters
    ----------
    domain : str
        The name of the active domain.

    evt_chan : str
        The name of the event channel (on the specified domain)

    wave : str
        The name of the waveform on the domain

    port : str
        The name of the port on the waveform to forward messages.
    """
    # access the event channel and waveform port
    dom = redhawk.attach(domain)
    e_chan = DT.find_event_channel_from_domain(domain, evt_chan)
    wfm = DT.find_waveform_from_domain(domain, wave)
    port_inst = wfm.getPort(port)

    # setup message source and connect to waveform port
    # FIXME: there can be multiple messages on an event channnel.
    #       1) should this filter messages based on this msg id?
    #       2) Do I need a separate message source per msg_id?
    msg_src = sb.MessageSource(msg_id)
    msg_port = msg_src.getPort("msgOut")
    msg_port.connectPort(port_inst, "conn_" + str(uuid.uuid1()))
    msg_src.start()

    # ----------------------  setup to forward messages ---------------------
    # setup the forwarder
    f = Forwarder(msg_src)

    # subscribe to channel with the callback in forwarder
    sub = Subscriber(dom, channel_name=evt_chan, dataArrivedCB=f.forward)

    # -----------  run forwarding until user hits enter  --------------------
    raw_input("Hit enter to exit")
    msg_src.releaseObject()
Пример #11
0
class DeviceStartorder(scatest.CorbaTestCase):
    def setUp(self):
        domBooter, domMgr = self.launchDomainManager()

        # Create an event channel to receive the device and service start/stop
        # messages (the name must match the findbys in the DCD), and connect a
        # subscriber
        eventMgr = domMgr._get_eventChannelMgr()
        channel = eventMgr.createForRegistrations('test_events')
        self._started = Queue.Queue()
        self._stopped = Queue.Queue()
        self._subscriber = Subscriber(channel, dataArrivedCB=self._messageReceived)

    def tearDown(self):
        self._subscriber.terminate()

        scatest.CorbaTestCase.tearDown(self)

    def _messageReceived(self, message):
        payload = message.value(CF._tc_Properties)
        if not payload:
            return
        for dt in payload:
            if dt.id == 'state_change':
                value = properties.props_to_dict(dt.value.value(CF._tc_Properties))
                identifier = value['state_change::identifier']
                if value['state_change::event'] == 'start':
                    self._started.put(identifier)
                elif value['state_change::event'] == 'stop':
                    self._stopped.put(identifier)

    def _verifyStartOrder(self, startorder):
        for identifier in startorder:
            try:
                received = self._started.get(timeout=1.0)
            except Queue.Empty:
                self.fail('Did not receive start message for ' + identifier)
            self.assertEqual(received, identifier)
        self.failUnless(self._started.empty(), msg='Too many start messages received')

    def _verifyStopOrder(self, startorder):
        for identifier in startorder[::-1]:
            try:
                received = self._stopped.get(timeout=1.0)
            except Queue.Empty:
                self.fail('Did not receive stop message for ' + identifier)
            self.assertEqual(received, identifier)
        self.failUnless(self._stopped.empty(), msg='Too many stop messages received')

    def test_StartOrder(self):
        """
        Test that device/service start order runs correctly
        """
        devBooter, devMgr = self.launchDeviceManager("/nodes/startorder_events/DeviceManager.dcd.xml")

        startorder = ('startorder_events:start_event_device_3',
                      'start_event_service_1',
                      'startorder_events:start_event_device_1')

        # Verify that start calls were received in the right order
        self._verifyStartOrder(startorder)

        # Check that the devices are started as expected
        for dev in devMgr._get_registeredDevices():
            dev_id = dev._get_identifier()
            expected = dev_id in startorder
            self.assertEqual(expected, dev._get_started(), msg='Device '+dev_id+' started state is incorrect')

        # Also services, if supported
        for svc in devMgr._get_registeredServices():
            expected = svc.serviceName in startorder
            if svc.serviceObject._is_a(CF.Resource._NP_RepositoryId):
                started = svc.serviceObject._narrow(CF.Resource)._get_started()
            else:
                started = False
            self.assertEqual(expected, started, msg='Service '+svc.serviceName+' started state is incorrect')

        # Shut down the node so that it stops all of the devices and services
        devMgr.shutdown()

        # Check that stop was called in the reverse order of start
        self._verifyStopOrder(startorder)

    def test_StartOrderException(self):
        """
        Test that the node continues along the device/service start order even
        if one of them throws an exception
        """
        devBooter, devMgr = self.launchDeviceManager("/nodes/startorder_fail/DeviceManager.dcd.xml")

        startorder = ('startorder_fail:start_event_device_1',
                      'startorder_fail:fail_device_1',
                      'startorder_fail:start_event_device_2')

        # Verify that start calls were received in the right order, and that
        # the device manager continued after the failing device
        self._verifyStartOrder(startorder)

        # Check that the devices are started as expected, with the device that
        # was configured to fail not started
        for dev in devMgr._get_registeredDevices():
            label = dev._get_label()
            expected = not label.startswith('fail_')
            self.assertEqual(expected, dev._get_started(), msg='Device '+label+' started state is incorrect')

        # Shut down the node so that it stops all of the devices and services
        devMgr.shutdown()

        # Check that stop was called in the reverse order of start
        self._verifyStopOrder(startorder)
    def setUp(self):
        self.launchDomainManager()
        self.launchDeviceManager("/nodes/test_GPP_node/DeviceManager.dcd.xml")

        self._event = threading.Event()
        self._subscriber = Subscriber(self._domainManager, 'IDM_Channel', self._idmMessageReceived)
Пример #13
0
 def terminate(self):
     if self._ecm:
         self._ecm._unregister( self._creg )
     Subscriber.terminate(self)
Пример #14
0
 def __init__(self, ecm, creg ):
     Subscriber.__init__(self, creg.channel )
     self._ecm = ecm
     self._creg = creg
Пример #15
0
 def __init__(self, ecm, creg ):
     Subscriber.__init__(self, creg.channel )
     self._ecm = ecm
     self._creg = creg