Example #1
0
 def setUp(self):
     self._domBooter, self._domMgr = self.launchDomainManager()
     # create listener interface
     orb = CORBA.ORB_init()
     self.chanMgr = ChannelManager(orb)
     self._app=None
     # Force creation
     self.channel1 = self.chanMgr.createEventChannel("TestChan", force=True)
    def test_ODMEvents_DeviceManager(self):
        # Test DeviceManager related events
        
        # launch DomainManager
        nodebooter, self._domMgr = self.launchDomainManager(debug=9)

        # connect to the channel
        domainName = scatest.getTestDomainName()
        channelManager = ChannelManager(self._orb)
        odmChannel = channelManager.getEventChannel('ODM_Channel', domainName)
        if odmChannel == None:
            self.fail("Could not connect to the ODM_Channel")

        
        # set up consumer
        consumer_admin = odmChannel.for_consumers()
        _proxy_supplier = consumer_admin.obtain_push_supplier()
        _consumer = ConsumerODM_i(self)
        _proxy_supplier.connect_push_consumer(_consumer._this())

        # start the device manager
        devBooter, devMgr = self.launchDeviceManager("/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml", debug=9)
        self.assertNotEqual(devMgr, None)

        timeout = 0.0
        while (_consumer.getAddedEventCount('DEVICE_MANAGER') < 1 and _consumer.getAddedEventCount('DEVICE') < 1 and timeout < 2):
            timeout += 0.2
            time.sleep(0.2)

        try:
            devMgr.shutdown()
        except CORBA.Exception:
            pass

        timeout = 0.0
        while (_consumer.getRemovedEventCount('DEVICE_MANAGER') < 1 and _consumer.getRemovedEventCount('DEVICE') < 1 and timeout < 2):
            timeout += 0.2
            time.sleep(0.2)

        # start the second device manager
        devBooter, devMgr = self.launchDeviceManager("/nodes/test_BasicService_node/DeviceManager.dcd.xml", debug=9)
        self.assertNotEqual(devMgr, None)

        timeout = 0.0
        while (_consumer.getAddedEventCount('DEVICE_MANAGER') < 2 and _consumer.getAddedEventCount('SERVICE') < 1 and timeout < 2):
            timeout += 0.2
            time.sleep(0.2)

        try:
            devMgr.shutdown()
        except CORBA.Exception:
            pass

        timeout = 0.0
        while (_consumer.getRemovedEventCount('DEVICE_MANAGER') < 2 and _consumer.getRemovedEventCount('SERVICE') < 1 and timeout < 2):
            timeout += 0.2
            time.sleep(0.2)


        self.assertEqual(_consumer.getAddedEventCount('DEVICE_MANAGER'), 2)
        self.assertEqual(_consumer.getAddedEventCount('DEVICE'), 1)
        self.assertEqual(_consumer.getAddedEventCount('SERVICE'), 1)
        self.assertEqual(_consumer.getRemovedEventCount('DEVICE_MANAGER'), 2)
        self.assertEqual(_consumer.getRemovedEventCount('DEVICE'), 1)
        self.assertEqual(_consumer.getRemovedEventCount('SERVICE'), 1)
        
        self.terminateChild(devBooter)
Example #3
0
class PropertyChangeListenerEventTest(scatest.CorbaTestCase):
    def setUp(self):
        self._domBooter, self._domMgr = self.launchDomainManager()
        # create listener interface
        orb = CORBA.ORB_init()
        self.chanMgr = ChannelManager(orb)
        self._app=None
        # Force creation
        self.channel1 = self.chanMgr.createEventChannel("TestChan", force=True)


    def tearDown(self):
        try:
            if self.channel1:
                self.chanMgr.destroyEventChannel("TestChan")                           
        except:
            pass

        try:
            self._app.stop()
            self._app.releaseObject()
        except AttributeError:
            pass

        try:
            self._devMgr.shutdown()
        except AttributeError:
            pass

        try:
            self.terminateChild(self._devBooter)
        except AttributeError:
            pass

        try:
            self.terminateChild(self._domBooter)
        except AttributeError:
            pass

        # Do all application and node booter shutdown before calling the base
        # class tearDown, or failures will occur.
        scatest.CorbaTestCase.tearDown(self)


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

        self._devBooter, self._devMgr = self.launchDeviceManager(execDeviceNode, self._domMgr)
        self.assertNotEqual(self._devBooter, None)
        if java_support:
            self._domMgr.installApplication("/waveforms/PropertyChangeListener/PropertyChangeListener.sad.xml")
        else:
            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_C1', 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

    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)
        if java_support:
            self._domMgr.installApplication("/waveforms/PropertyChangeListener/PropertyChangeListener.sad.xml")
        else:
            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

    def test_PropertyChangeListener_EC_JAVA(self):
        if not java_support:
            return
        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]
        c=filter( lambda c : c.name == 'PropertyChange_J1', 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

    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_ODMEvents_DeviceManager(self):
        # Test DeviceManager related events

        # launch DomainManager
        nodebooter, self._domMgr = self.launchDomainManager(debug=self.debuglevel)

        # connect to the channel
        domainName = scatest.getTestDomainName()
        channelManager = ChannelManager(self._orb)
        odmChannel = channelManager.getEventChannel('ODM_Channel', domainName)
        if odmChannel == None:
            self.fail("Could not connect to the ODM_Channel")


        # set up consumer
        consumer_admin = odmChannel.for_consumers()
        _proxy_supplier = consumer_admin.obtain_push_supplier()
        _consumer = ConsumerODM_i(self)
        _proxy_supplier.connect_push_consumer(_consumer._this())

        # start the device manager
        devBooter, devMgr = self.launchDeviceManager("/nodes/test_BasicTestDevice_node/DeviceManager.dcd.xml", debug=self.debuglevel)
        self.assertNotEqual(devMgr, None)

        timeout = 0.0
        while ((_consumer.getAddedEventCount('DEVICE_MANAGER') < 1 or _consumer.getAddedEventCount('DEVICE') < 1) and timeout < 2):
            timeout += 0.2
            time.sleep(0.2)

        try:
            devMgr.shutdown()
        except CORBA.Exception:
            pass

        timeout = 0.0
        while ((_consumer.getRemovedEventCount('DEVICE_MANAGER') < 1 or _consumer.getRemovedEventCount('DEVICE') < 1) and timeout < 2):
            timeout += 0.2
            time.sleep(0.2)

        # start the second device manager
        devBooter, devMgr = self.launchDeviceManager("/nodes/test_BasicService_node/DeviceManager.dcd.xml", debug=self.debuglevel)
        self.assertNotEqual(devMgr, None)

        timeout = 0.0
        while ((_consumer.getAddedEventCount('DEVICE_MANAGER') < 2 or _consumer.getAddedEventCount('SERVICE') < 1) and timeout < 2):
            timeout += 0.2
            time.sleep(0.2)

        try:
            devMgr.shutdown()
        except CORBA.Exception:
            pass

        timeout = 0.0
        while ((_consumer.getRemovedEventCount('DEVICE_MANAGER') < 2 or _consumer.getRemovedEventCount('SERVICE') < 1) and timeout < 2):
            timeout += 0.2
            time.sleep(0.2)


        self.assertEqual(_consumer.getAddedEventCount('DEVICE_MANAGER'), 2)
        self.assertEqual(_consumer.getAddedEventCount('DEVICE'), 1)
        self.assertEqual(_consumer.getAddedEventCount('SERVICE'), 1)
        self.assertEqual(_consumer.getRemovedEventCount('DEVICE_MANAGER'), 2)
        self.assertEqual(_consumer.getRemovedEventCount('DEVICE'), 1)
        self.assertEqual(_consumer.getRemovedEventCount('SERVICE'), 1)

        self.terminateChild(devBooter)