Commit 4e8fb796 authored by Operator for ID30's avatar Operator for ID30
Browse files

Fix of bug in RouterActor

parent 6fb7b786
......@@ -50,10 +50,12 @@ class RouterActor(AbstractActor):
def trigger(self, inData):
logger.debug('In router actor "{0}"'.format(self.name))
listActor = None
if self.itemName in inData and not inData[self.itemName] in [None, 'None', 'null']:
if self.itemName in inData:
logger.debug('In router actor "{0}", itemName {1} in inData'.format(self.name, self.itemName))
value = inData[self.itemName]
logger.debug('In router actor "{0}", value = {1}'.format(self.name, value))
if value in [None, 'None', 'null']:
value = 'null'
if not isinstance(value, dict) and value in self.dictValues:
listActor = self.dictValues[value]
if listActor is None:
......
......@@ -27,7 +27,7 @@ import time
def run(name, **kwargs):
time.sleep(5)
time.sleep(1)
reply = None
if name is not None:
reply = 'Hello ' + name + '!'
......
......@@ -50,7 +50,7 @@ class TestPythonActor(unittest.TestCase):
}
actor.connect(stopActor)
actor.trigger(inData)
stopActor.join(timeout=5)
stopActor.join(timeout=10)
outData = stopActor.outData
self.assertIsNotNone(outData)
self.assertEqual(outData['reply'], 'Hello Ragnar!')
......@@ -97,5 +97,36 @@ class TestPythonActor(unittest.TestCase):
self.assertIsNotNone(outData)
logger.info(outData)
def test_RouterActor(self):
start = StartActor()
stop = StopActor()
router = RouterActor(
self,
itemName="a",
listPort=['other', 'null']
)
pythonActor1 = PythonActor(script='pypushflow.test.pythonActor1.py')
pythonActor2 = PythonActor(script='pypushflow.test.pythonActor2.py')
# Connections
start.connect(router)
router.connect(pythonActor1, 'other')
router.connect(pythonActor2, 'null')
pythonActor1.connect(stop)
pythonActor2.connect(stop)
# Run
inData = {'a': 1}
start.trigger(inData)
stop.join(timeout=5)
outData = stop.outData
logger.info(outData)
self.assertIsNotNone(outData)
self.assertTrue(outData['actor1'])
# Run 2
inData = {'a': None}
start.trigger(inData)
stop.join(timeout=5)
outData = stop.outData
logger.info(outData)
self.assertIsNotNone(outData)
self.assertTrue(outData['actor2'])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment