def testHierarchySending(self): sendScope = Scope("/this/is/a/test") superScopes = sendScope.superScopes(True) outConnector = self._getOutConnector(sendScope, activate=False) outConfigurator = rsb.eventprocessing.OutRouteConfigurator( connectors=[outConnector]) informer = createInformer(sendScope, dataType=str, configurator=outConfigurator) # set up listeners on the complete hierarchy listeners = [] receivers = [] for scope in superScopes: inConnector = self._getInPushConnector(scope, activate=False) inConfigurator = rsb.eventprocessing.InPushRouteConfigurator( connectors=[inConnector]) listener = createListener(scope, configurator=inConfigurator) listeners.append(listener) receiver = SettingReceiver(scope) listener.addHandler(receiver) receivers.append(receiver) data = "a string to test" informer.publishData(data) for receiver in receivers: with receiver.resultCondition: while receiver.resultEvent is None: receiver.resultCondition.wait(10) if receiver.resultEvent is None: self.fail("Listener on scope %s did not receive an event" % receiver.scope) self.assertEqual(receiver.resultEvent.data, data) for listener in listeners: listener.deactivate() informer.deactivate()
def testNotifyHierarchy(self): bus = Bus() targetScope = Scope("/this/is/a/test") scopes = targetScope.superScopes(True) sinksByScope = {} for scope in scopes: sinksByScope[scope] = StubSink(scope) bus.addSink(sinksByScope[scope]) notNotifiedSiblingSink = StubSink(Scope("/not/notified")) bus.addSink(notNotifiedSiblingSink) notNotifiedChildSink = StubSink(targetScope.concat(Scope("/child"))) bus.addSink(notNotifiedChildSink) event = Event(scope=targetScope) bus.handle(event) for scope, sink in sinksByScope.items(): self.assertTrue(event in sink.events) self.assertEqual(1, len(sink.events))