def testDeselectBadSelect(self): script = """ src : std.Counter() const_5 : std.Constantify(constant=5) const_0 : std.Constant(data=0, n=11) ds : std.Deselect() snk : io.StandardOut(store_tokens=1, quiet=1) const_0.token > ds.false src.integer > ds.true const_0.token > const_5.in const_5.out > ds.select ds.data > snk.token """ app_info, errors, warnings = compiler.compile(script, "testDeselectBadSelect") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.5) snk = d.actor_map['testDeselectBadSelect:snk'] actual = utils.report(self.rt1, snk) expected = [0] * 10 self.assert_lists_equal(expected, actual, min_length=10)
def testEmptyStringTriggerJoin(self): datafile = absolute_filename('data.txt') script = """ fname : std.Constant(data="%s") src : io.FileReader() join : text.LineJoin() snk : io.StandardOut(store_tokens=1, quiet=1) fname.token > src.filename src.out > join.line join.text > snk.token """ % (datafile, ) app_info, errors, warnings = compiler.compile(script, "testCustomTriggerJoin") d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.5) snk = d.actor_map['testCustomTriggerJoin:snk'] actual = utils.report(self.rt1, snk) with open(datafile, "r") as fp: expected = [l.rstrip() for l in fp.readlines()] expected = ['\n'.join(expected[:10]), '\n'.join(expected[10:])] self.assert_lists_equal(expected, actual, min_length=2)
def testAppDestructionAllRemote(self): script = """ src : std.CountTimer() sum : std.Sum() snk : io.StandardOut(store_tokens=1, quiet=1) src.integer > sum.integer sum.integer > snk.token """ app_info, errors, warnings = compiler.compile(script, "simple") d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(1) src = d.actor_map['simple:src'] csum = d.actor_map['simple:sum'] snk = d.actor_map['simple:snk'] utils.migrate(self.rt1, src, self.rt2.id) utils.migrate(self.rt1, csum, self.rt2.id) utils.migrate(self.rt1, snk, self.rt2.id) time.sleep(1) actual = utils.report(self.rt2, snk) expected = [sum(range(i + 1)) for i in range(1, 10)] self.assert_lists_equal(expected, actual) utils.delete_application(self.rt1, d.app_id) time.sleep(0.5) self.assertIsNone(utils.get_actor(self.rt1, src)) self.assertIsNone(utils.get_actor(self.rt1, csum)) self.assertIsNone(utils.get_actor(self.rt1, snk)) self.assertIsNone(utils.get_application(self.rt1, d.app_id))
def testDestroyAppWithLocalActors(self): rt = self.runtime script = """ src : std.CountTimer() snk : io.StandardOut(store_tokens=1) src.integer > snk.token """ app_info, errors, warnings = compiler.compile(script, "simple") d = deployer.Deployer(rt, app_info) app_id = d.deploy() time.sleep(0.2) src = d.actor_map['simple:src'] snk = d.actor_map['simple:snk'] applications = utils.get_applications(rt) assert app_id in applications d.destroy() applications = utils.get_applications(rt) assert app_id not in applications actors = utils.get_actors(rt) assert src not in actors assert snk not in actors
def testDeselectFalse(self): _log.analyze("TESTRUN", "+", {}) script = """ src : std.Counter() const_5 : std.Constantify(constant=5) const_0 : std.Constant(data=0, n=-1) const_1 : std.Constant(data=1, n=-1) comp : std.Compare(op="<=") ds : std.Deselect() snk : io.StandardOut(store_tokens=1, quiet=1) const_0.token > ds.case_true const_1.token > ds.case_false src.integer > comp.a src.integer > const_5.in const_5.out > comp.b comp.result > ds.select ds.data > snk.token """ app_info, errors, warnings = compiler.compile(script, "testDeselectFalse") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.5) snk = d.actor_map['testDeselectFalse:snk'] actual = utils.report(self.rt1, snk) expected = [0] * 5 + [1] * 5 self.assert_lists_equal(expected, actual, min_length=10) d.destroy()
def testStringConstantOnCompPort(self): _log.analyze("TESTRUN", "+", {}) script = """ define MEANING = "42" component Foo() -> out { i:std.Identity() MEANING > i.token i.token > .out } src : Foo() snk : io.StandardOut(store_tokens=1, quiet=1) src.out > snk.token """ app_info, errors, warnings = compiler.compile(script, "testStringConstantOnCompPort") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(.1) snk = d.actor_map['testStringConstantOnCompPort:snk'] actual = utils.report(self.rt1, snk) expected = ["42"]*10 self.assert_lists_equal(expected, actual, min_length=10) d.destroy()
def testSimpleState(self): _log.analyze("TESTRUN", "+", {}) script = """ src : std.CountTimer() sum : std.Sum() snk : io.StandardOut(store_tokens=1, quiet=1) src.integer > sum.integer sum.integer > snk.token """ app_info, errors, warnings = compiler.compile(script, "simple") d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(1) csum = d.actor_map['simple:sum'] snk = d.actor_map['simple:snk'] utils.migrate(self.rt1, csum, self.rt2.id) time.sleep(1) actual = utils.report(self.rt1, snk) expected = [sum(range(i+1)) for i in range(1,10)] self.assert_lists_equal(expected, actual) d.destroy()
def testDestroyAppWithLocalActors(self): rt = self.runtime script = """ src : std.CountTimer() snk : io.StandardOut(store_tokens=1) src.integer > snk.token """ app_info, errors, warnings = compiler.compile(script, "simple") d = deployer.Deployer(rt, app_info) app_id = d.deploy() time.sleep(0.2) src = d.actor_map['simple:src'] snk = d.actor_map['simple:snk'] applications = utils.get_applications(rt) assert app_id in applications assert d.destroy()['result'] == 'OK' applications = utils.get_applications(rt) assert app_id not in applications actors = utils.get_actors(rt) assert src not in actors assert snk not in actors
def testEmptyStringTriggerJoin(self): _log.analyze("TESTRUN", "+", {}) datafile = absolute_filename('data.txt') script = """ fname : std.Constant(data="%s") src : io.FileReader() join : text.LineJoin() snk : io.StandardOut(store_tokens=1, quiet=1) fname.token > src.filename src.out > join.line join.text > snk.token """ % (datafile, ) app_info, errors, warnings = compiler.compile(script, "testCustomTriggerJoin") d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.5) snk = d.actor_map['testCustomTriggerJoin:snk'] actual = utils.report(self.rt1, snk) with open(datafile, "r") as fp: expected = [l.rstrip() for l in fp.readlines()] expected = ['\n'.join(expected[:10]), '\n'.join(expected[10:])] self.assert_lists_equal(expected, actual, min_length=2) d.destroy()
def testRegexCaptureNoMatch(self): _log.analyze("TESTRUN", "+", {}) script = """ src : std.Constant(data="x24.1632", n=1) regex : text.RegexMatch(regex=!"(\d+)\.\d+") snk : io.StandardOut(store_tokens=1, quiet=1) term : std.Terminator() src.token > regex.text regex.no_match > snk.token regex.match > term.void """ app_info, errors, warnings = compiler.compile(script, "testRegexCaptureNoMatch") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(.1) snk = d.actor_map['testRegexCaptureNoMatch:snk'] actual = utils.report(self.rt1, snk) expected = ["x24.1632"] self.assert_lists_equal(expected, actual, min_length=1) d.destroy()
def test31(self): # Verify that fanout defined implicitly in scripts is handled correctly _log.analyze("TESTRUN", "+", {}) script = """ src : std.Counter() snk1 : io.StandardOut(store_tokens=1, quiet=1) snk2 : io.StandardOut(store_tokens=1, quiet=1) src.integer > snk1.token src.integer > snk2.token """ app_info, errors, warnings = compiler.compile(script, "test31") d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.1) snk1 = d.actor_map['test31:snk1'] snk2 = d.actor_map['test31:snk2'] actual1 = utils.report(self.rt1, snk1) actual2 = utils.report(self.rt1, snk2) expected = list(range(1, 10)) self.assert_lists_equal(expected, actual1) self.assert_lists_equal(expected, actual2) d.destroy()
def testBasicJoin(self): _log.analyze("TESTRUN", "+", {}) datafile = absolute_filename('data.txt') script = """ fname : std.Constant(data="%s") src : io.FileReader() join : text.LineJoin() snk : io.StandardOut(store_tokens=1, quiet=1) fname.token > src.filename src.out > join.line join.text > snk.token """ % (datafile, ) app_info, errors, warnings = compiler.compile(script, "testBasicJoin") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(1) snk = d.actor_map['testBasicJoin:snk'] actual = utils.report(self.rt1, snk) with open(datafile, "r") as fp: expected = ["\n".join([l.rstrip() for l in fp.readlines()])] self.assert_lists_equal(expected, actual, min_length=1) d.destroy()
def testDeselectFalse(self): script = """ src : std.Counter() const_5 : std.Constantify(constant=5) const_0 : std.Constant(data=0, n=-1) const_1 : std.Constant(data=1, n=-1) comp : std.Compare(op="<=") ds : std.Deselect() snk : io.StandardOut(store_tokens=1, quiet=1) const_0.token > ds.case_true const_1.token > ds.case_false src.integer > comp.a src.integer > const_5.in const_5.out > comp.b comp.result > ds.select ds.data > snk.token """ app_info, errors, warnings = compiler.compile(script, "testDeselectFalse") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.5) snk = d.actor_map['testDeselectFalse:snk'] actual = utils.report(self.rt1, snk) expected = [0] * 5 + [1] * 5 self.assert_lists_equal(expected, actual, min_length=10)
def testVoidActor(self): # Verify that the null port of a std.Void actor behaves as expected _log.analyze("TESTRUN", "+", {}) script = """ src1 : std.Counter() src2 : std.Void() join : std.Join() snk : io.StandardOut(store_tokens=1, quiet=1) src1.integer > join.token_1 src2.void > join.token_2 join.token > snk.token """ app_info, errors, warnings = compiler.compile(script, "testVoidActor") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.4) snk = d.actor_map['testVoidActor:snk'] actual = utils.report(self.rt1, snk) expected = list(range(1, 10)) self.assert_lists_equal(expected, actual) d.destroy()
def testBadSelect(self): _log.analyze("TESTRUN", "+", {}) script = """ src : std.Counter() const : std.Constant(data=2, n=-1) route : std.Select() snk : io.StandardOut(store_tokens=1, quiet=1) term : std.Terminator() src.integer > route.data const.token > route.select route.case_true > term.void route.case_false > snk.token """ app_info, errors, warnings = compiler.compile(script, "testBadSelect") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.5) snk = d.actor_map['testBadSelect:snk'] actual = utils.report(self.rt1, snk) expected = list(range(1, 10)) self.assert_lists_equal(expected, actual) d.destroy()
def testGreaterThanOrEqual(self): _log.analyze("TESTRUN", "+", {}) script = """ src : std.Counter() const : std.Constant(data=5, n=-1) pred : std.Compare(op=">=") snk : io.StandardOut(store_tokens=1, quiet=1) src.integer > pred.a const.token > pred.b pred.result > snk.token """ app_info, errors, warnings = compiler.compile(script, "testGreaterThanOrEqual") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.1) snk = d.actor_map['testGreaterThanOrEqual:snk'] actual = utils.report(self.rt1, snk) expected = [x >= 5 for x in range(1, 10)] self.assert_lists_equal(expected, actual) d.destroy()
def testComponentConstantArgumentAsImplicitActor(self): _log.analyze("TESTRUN", "+", {}) script = """ define FOO = "hup" component Count(data) -> seq { i : std.Identity() data > i.token i.token > .seq } src : Count(data=FOO) snk : io.StandardOut(store_tokens=1, quiet=1) src.seq > snk.token """ app_info, errors, warnings = compiler.compile(script, "testComponentConstantArgumentAsImplicitActor") d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(.1) snk = d.actor_map['testComponentConstantArgumentAsImplicitActor:snk'] actual = utils.report(self.rt1, snk) expected = ["hup"]*10 self.assert_lists_equal(expected, actual, min_length=10) d.destroy()
def testAppDestructionAllRemote(self): script = """ src : std.CountTimer() sum : std.Sum() snk : io.StandardOut(store_tokens=1, quiet=1) src.integer > sum.integer sum.integer > snk.token """ app_info, errors, warnings = compiler.compile(script, "simple") d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(1) src = d.actor_map['simple:src'] csum = d.actor_map['simple:sum'] snk = d.actor_map['simple:snk'] utils.migrate(self.rt1, src, self.rt2.id) utils.migrate(self.rt1, csum, self.rt2.id) utils.migrate(self.rt1, snk, self.rt2.id) time.sleep(1) actual = utils.report(self.rt2, snk) expected = [sum(range(i+1)) for i in range(1,10)] self.assert_lists_equal(expected, actual) utils.delete_application(self.rt1, d.app_id) time.sleep(0.5) self.assertIsNone(utils.get_actor(self.rt1, src)) self.assertIsNone(utils.get_actor(self.rt1, csum)) self.assertIsNone(utils.get_actor(self.rt1, snk)) self.assertIsNone(utils.get_application(self.rt1, d.app_id))
def testDeselectBadSelect(self): _log.analyze("TESTRUN", "+", {}) script = """ src : std.Counter() const_5 : std.Constantify(constant=5) const_0 : std.Constant(data=0, n=11) ds : std.Deselect() snk : io.StandardOut(store_tokens=1, quiet=1) const_0.token > ds.case_false src.integer > ds.case_true const_0.token > const_5.in const_5.out > ds.select ds.data > snk.token """ app_info, errors, warnings = compiler.compile(script, "testDeselectBadSelect") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.5) snk = d.actor_map['testDeselectBadSelect:snk'] actual = utils.report(self.rt1, snk) expected = [0] * 10 self.assert_lists_equal(expected, actual, min_length=10) d.destroy()
def handle_deploy(self, handle, connection, match, data, hdr): app_info, errors, warnings = compiler.compile( data["script"], filename=data["name"]) app_info["name"] = data["name"] d = deployer.Deployer( runtime=None, deployable=app_info, node_info=None, node=self.node) app_id = d.deploy() self.send_response( handle, connection, json.dumps({'application_id': app_id, 'actor_map': d.actor_map}))
def handle_deploy(self, handle, connection, match, data): print "data: ", data app_info, errors, warnings = compiler.compile( data["script"], filename=data["name"]) app_info["name"] = data["name"] d = deployer.Deployer( runtime=None, deployable=app_info, node_info=None, node=self.node) app_id = d.deploy() self.send_response( handle, connection, json.dumps({'application_id': app_id}))
def testAppDestructionAllRemote(self): _log.analyze("TESTRUN", "+", {}) script = """ src : std.CountTimer() sum : std.Sum() snk : io.StandardOut(store_tokens=1, quiet=1) src.integer > sum.integer sum.integer > snk.token """ import sys from twisted.python import log log.startLogging(sys.stdout) app_info, errors, warnings = compiler.compile(script, "simple") d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(.2) src = d.actor_map['simple:src'] csum = d.actor_map['simple:sum'] snk = d.actor_map['simple:snk'] utils.migrate(self.rt1, src, self.rt2.id) utils.migrate(self.rt1, csum, self.rt2.id) utils.migrate(self.rt1, snk, self.rt2.id) time.sleep(.5) actual = utils.report(self.rt2, snk) expected = [sum(range(i+1)) for i in range(1,10)] self.assert_lists_equal(expected, actual) utils.delete_application(self.rt1, d.app_id) for a in range(20): all_removed = None try: self.assertIsNone(utils.get_actor(self.rt1, csum)) self.assertIsNone(utils.get_actor(self.rt1, snk)) self.assertIsNone(utils.get_actor(self.rt2, src)) self.assertIsNone(utils.get_actor(self.rt2, csum)) self.assertIsNone(utils.get_actor(self.rt2, snk)) self.assertIsNone(utils.get_actor(self.rt3, src)) self.assertIsNone(utils.get_actor(self.rt3, csum)) self.assertIsNone(utils.get_actor(self.rt3, snk)) except AssertionError as e: print a, e all_removed = e if all_removed is None: break time.sleep(1) if all_removed: raise all_removed self.assertIsNone(utils.get_application(self.rt1, d.app_id)) self.assertIsNone(utils.get_application(self.rt2, d.app_id)) self.assertIsNone(utils.get_application(self.rt3, d.app_id))
def testDestroyAppWithMigratedActors(self): rt = self.runtime rt1 = self.runtimes[0] rt2 = self.runtimes[1] script = """ src : std.CountTimer() snk : io.StandardOut(store_tokens=1) src.integer > snk.token """ app_info, errors, warnings = compiler.compile(script, "simple") d = deployer.Deployer(rt, app_info) app_id = d.deploy() time.sleep(1.0) src = d.actor_map['simple:src'] snk = d.actor_map['simple:snk'] # FIXME --> remove when operating on closed pending connections during migration is fixed utils.disable(rt, src) utils.disable(rt, snk) # <-- utils.migrate(rt, snk, rt1.id) utils.migrate(rt, src, rt2.id) applications = utils.get_applications(rt) assert app_id in applications d.destroy() for retry in range(1, 5): applications = utils.get_applications(rt) if app_id in applications: print("Retrying in %s" % (retry * 0.2, )) time.sleep(0.2 * retry) else : break assert app_id not in applications for retry in range(1, 5): actors = [] actors.extend(utils.get_actors(rt)) actors.extend(utils.get_actors(rt1)) actors.extend(utils.get_actors(rt2)) intersection = [a for a in actors if a in d.actor_map.values()] if len(intersection) > 0: print("Retrying in %s" % (retry * 0.2, )) time.sleep(0.2 * retry) else: break for actor in d.actor_map.values(): assert actor not in actors
def testInlineScript(self): script = """ src : std.CountTimer() snk : io.StandardOut(store_tokens=1, quiet=1) src.integer > snk.token """ app_info, errors, warnings = compiler.compile(script, "simple") d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(1) snk = d.actor_map['simple:snk'] actual = utils.report(self.rt1, (snk)) self.assert_lists_equal(range(1, 20), actual)
def testLiteralOnPort(self): script = """ snk : io.StandardOut(store_tokens=1, quiet=1) 42 > snk.token """ app_info, errors, warnings = compiler.compile(script, "testLiteralOnPort") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(.1) snk = d.actor_map['testLiteralOnPort:snk'] actual = utils.report(self.rt1, snk) expected = [42]*10 self.assert_lists_equal(expected, actual, min_length=10)
def testLiteralOnPort(self): script = """ snk : io.StandardOut(store_tokens=1, quiet=1) 42 > snk.token """ app_info, errors, warnings = compiler.compile(script, "testLiteralOnPort") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(.1) snk = d.actor_map['testLiteralOnPort:snk'] actual = utils.report(self.rt1, snk) expected = [42] * 10 self.assert_lists_equal(expected, actual, min_length=10)
def testConstant(self): script = """ define FOO = 42 src : std.Constant(data=FOO, n=10) snk : io.StandardOut(store_tokens=1, quiet=1) src.token > snk.token """ app_info, errors, warnings = compiler.compile(script, "testConstant") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(.1) snk = d.actor_map['testConstant:snk'] actual = utils.report(self.rt1, snk) expected = [42] * 10 self.assert_lists_equal(expected, actual, min_length=10)
def testConstant(self): script = """ define FOO = 42 src : std.Constant(data=FOO, n=10) snk : io.StandardOut(store_tokens=1, quiet=1) src.token > snk.token """ app_info, errors, warnings = compiler.compile(script, "testConstant") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(.1) snk = d.actor_map['testConstant:snk'] actual = utils.report(self.rt1, snk) expected = [42]*10 self.assert_lists_equal(expected, actual, min_length=10)
def testConstantRecursiveOnPort(self): script = """ define FOO = BAR define BAR = "yay" snk : io.StandardOut(store_tokens=1, quiet=1) FOO > snk.token """ app_info, errors, warnings = compiler.compile(script, "testConstantRecursiveOnPort") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(.1) snk = d.actor_map['testConstantRecursiveOnPort:snk'] actual = utils.report(self.rt1, snk) expected = ["yay"]*10 self.assert_lists_equal(expected, actual, min_length=10)
def testConstantRecursiveOnPort(self): script = """ define FOO = BAR define BAR = "yay" snk : io.StandardOut(store_tokens=1, quiet=1) FOO > snk.token """ app_info, errors, warnings = compiler.compile( script, "testConstantRecursiveOnPort") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(.1) snk = d.actor_map['testConstantRecursiveOnPort:snk'] actual = utils.report(self.rt1, snk) expected = ["yay"] * 10 self.assert_lists_equal(expected, actual, min_length=10)
def test26(self): # Same as test20 script = """ src : std.Counter() ity : std.Identity() snk : io.StandardOut(store_tokens=1, quiet=1) src.integer > ity.token ity.token > snk.token """ app_info, errors, warnings = compiler.compile(script, "simple") d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.4) snk = d.actor_map['simple:snk'] actual = utils.report(self.rt1, snk) expected = list(range(1, 10)) self.assert_lists_equal(expected, actual)
def testConstantOnPort(self): _log.analyze("TESTRUN", "+", {}) script = """ define FOO = "Hello" snk : io.StandardOut(store_tokens=1, quiet=1) FOO > snk.token """ app_info, errors, warnings = compiler.compile(script, "testConstantOnPort") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(.1) snk = d.actor_map['testConstantOnPort:snk'] actual = utils.report(self.rt1, snk) expected = ["Hello"]*10 self.assert_lists_equal(expected, actual, min_length=10) d.destroy()
def test26(self): # Same as test20 script = """ src : std.Counter() ity : std.Identity() snk : io.StandardOut(store_tokens=1, quiet=1) src.integer > ity.token ity.token > snk.token """ app_info, errors, warnings = compiler.compile(script, "simple") d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.5) snk = d.actor_map['simple:snk'] actual = utils.report(self.rt1, snk) expected = list(range(1, 10)) self.assert_lists_equal(expected, actual)
def test11(self): _log.analyze("TESTRUN", "+", {}) # Same as test10, but scripted script = """ src : std.Counter() snk : io.StandardOut(store_tokens=1, quiet=1) src.integer > snk.token """ app_info, errors, warnings = compiler.compile(script, "simple") d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.06) snk = d.actor_map['simple:snk'] actual = utils.report(self.rt1, snk) self.assert_lists_equal(range(1, 10), actual) d.destroy()
def handle_deploy(self, handle, connection, match, data, hdr): try: _log.analyze(self.node.id, "+", {}) app_info, errors, warnings = compiler.compile( data["script"], filename=data["name"], verify=data["check"] if "check" in data else True) _log.analyze(self.node.id, "+ COMPILED", {'app_info': app_info, 'errors': errors, 'warnings': warnings}) app_info["name"] = data["name"] d = deployer.Deployer( runtime=None, deployable=app_info, node_info=None, node=self.node, verify=data["check"] if "check" in data else True) _log.analyze(self.node.id, "+ Deployer instanciated", {}) app_id = d.deploy() _log.analyze(self.node.id, "+ DEPLOYED", {}) status = calvinresponse.OK except: app_id = None status = calvinresponse.INTERNAL_ERROR self.send_response( handle, connection, json.dumps({'application_id': app_id, 'actor_map': d.actor_map}) if app_id else None, status=status)
def testTerminatorActor(self): # Verify that the null port of a std.Terminator actor behaves as expected script = """ src : std.Counter() term : std.Terminator() snk : io.StandardOut(store_tokens=1, quiet=1) src.integer > term.void src.integer > snk.token """ app_info, errors, warnings = compiler.compile(script, "testTerminatorActor") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.5) snk = d.actor_map['testTerminatorActor:snk'] actual = utils.report(self.rt1, snk) expected = list(range(1, 10)) self.assert_lists_equal(expected, actual)
def testComponentArgument(self): script = """ component Count(len) -> seq { src : std.Constant(data="hup", n=len) src.token > .seq } src : Count(len=5) snk : io.StandardOut(store_tokens=1, quiet=1) src.seq > snk.token """ app_info, errors, warnings = compiler.compile(script, "testComponentArgument") d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(.1) snk = d.actor_map['testComponentArgument:snk'] actual = utils.report(self.rt1, snk) expected = ["hup"]*5 self.assert_lists_equal(expected, actual, min_length=5)
def testRegexMultiCapture(self): script = """ src : std.Constant(data="24.1632", n=1) regex : text.RegexMatch(regex=!"(\d+)\.(\d+)") snk : io.StandardOut(store_tokens=1, quiet=1) term : std.Terminator() src.token > regex.text regex.match > snk.token regex.no_match > term.null """ app_info, errors, warnings = compiler.compile(script, "testRegexMultiCapture") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.5) snk = d.actor_map['testRegexMultiCapture:snk'] actual = utils.report(self.rt1, snk) expected = ["24"] self.assert_lists_equal(expected, actual, min_length=1)
def testBadOp(self): script = """ src : std.Counter() const : std.Constant(data=5, n=-1) pred : std.Compare(op="<>") snk : io.StandardOut(store_tokens=1, quiet=1) src.integer > pred.a const.token > pred.b pred.result > snk.token """ app_info, errors, warnings = compiler.compile(script, "testBadOp") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(.05) snk = d.actor_map['testBadOp:snk'] actual = utils.report(self.rt1, snk) expected = [0] * 10 self.assert_lists_equal(expected, actual)
def testComponentArgument(self): script = """ component Count(len) -> seq { src : std.Constant(data="hup", n=len) src.token > .seq } src : Count(len=5) snk : io.StandardOut(store_tokens=1, quiet=1) src.seq > snk.token """ app_info, errors, warnings = compiler.compile(script, "testComponentArgument") d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(.1) snk = d.actor_map['testComponentArgument:snk'] actual = utils.report(self.rt1, snk) expected = ["hup"] * 5 self.assert_lists_equal(expected, actual, min_length=5)
def testBadOp(self): script = """ src : std.Counter() const : std.Constant(data=5, n=-1) pred : std.Compare(op="<>") snk : io.StandardOut(store_tokens=1, quiet=1) src.integer > pred.a const.token > pred.b pred.result > snk.token """ app_info, errors, warnings = compiler.compile(script, "testBadOp") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.5) snk = d.actor_map['testBadOp:snk'] actual = utils.report(self.rt1, snk) expected = [0] * 10 self.assert_lists_equal(expected, actual)
def testTerminatorActor(self): # Verify that the null port of a std.Terminator actor behaves as expected script = """ src : std.Counter() term : std.Terminator() snk : io.StandardOut(store_tokens=1, quiet=1) src.integer > term.null src.integer > snk.token """ app_info, errors, warnings = compiler.compile(script, "testTerminatorActor") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(0.5) snk = d.actor_map['testTerminatorActor:snk'] actual = utils.report(self.rt1, snk) expected = list(range(1, 10)) self.assert_lists_equal(expected, actual)
def testLiteralOnCompPort(self): script = """ component Foo() -> out { i:std.Stringify() 42 > i.in i.out > .out } src : Foo() snk : io.StandardOut(store_tokens=1, quiet=1) src.out > snk.token """ app_info, errors, warnings = compiler.compile(script, "testLiteralOnCompPort") print errors d = deployer.Deployer(self.rt1, app_info) d.deploy() time.sleep(.1) snk = d.actor_map['testLiteralOnCompPort:snk'] actual = utils.report(self.rt1, snk) expected = ["42"]*10 self.assert_lists_equal(expected, actual, min_length=10)
def testCompileSimple(self): rt = self.runtime script = """ src : std.CountTimer() snk : io.StandardOut(store_tokens=1) src.integer > snk.token """ app_info, errors, warnings = compiler.compile(script, "simple") d = deployer.Deployer(rt, app_info) d.deploy() # ignoring app_id here time.sleep(0.2) src = d.actor_map['simple:src'] snk = d.actor_map['simple:snk'] utils.disconnect(rt, src) actual = actual_tokens(rt, snk) expected = expected_tokens(rt, src, 'std.CountTimer') self.assertListPrefix(expected, actual) d.destroy()
def testCompileSimple(self): rt = self.runtime script = """ src : std.CountTimer() snk : io.StandardOut(store_tokens=1) src.integer > snk.token """ app_info, errors, warnings = compiler.compile(script, "simple") d = deployer.Deployer(rt, app_info) d.deploy() # ignoring app_id here time.sleep(0.5) src = d.actor_map['simple:src'] snk = d.actor_map['simple:snk'] utils.disconnect(rt, src) actual = actual_tokens(rt, snk) expected = expected_tokens(rt, src, 'std.CountTimer') self.assertListPrefix(expected, actual) d.destroy()