Ejemplo n.º 1
0
    def test22(self):
        _log.analyze("TESTRUN", "+", {})
        src = utils.new_actor(self.rt1, 'std.Counter', 'src')
        ity = utils.new_actor(self.rt2, 'std.Identity', 'ity')
        snk = utils.new_actor_wargs(self.rt3, 'io.StandardOut', 'snk', store_tokens=1, quiet=1)

        utils.connect(self.rt2, ity, 'token', self.rt1.id, src, 'integer')
        utils.connect(self.rt3, snk, 'token', self.rt2.id, ity, 'token')

        interval = 0.5

        for retries in range(1, 5):
            time.sleep(retries * interval)
            actual = utils.report(self.rt3, snk)
            if len(actual) > 10:
                break

        self.assert_lists_equal(range(1, 11), actual)

        time.sleep(0.1)

        actual = utils.report(self.rt3, snk)

        self.assert_lists_equal(range(1, 10), actual)

        utils.delete_actor(self.rt1, src)
        utils.delete_actor(self.rt2, ity)
        utils.delete_actor(self.rt3, snk)
Ejemplo n.º 2
0
    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 testTwoStepMigrateSourceSink(self):
        src = utils.new_actor(self.rt1, 'std.CountTimer', 'src')
        snk = utils.new_actor_wargs(self.rt1, 'io.StandardOut', 'snk', store_tokens=1, quiet=1)

        utils.connect(self.rt1, snk, 'token', self.rt1.id, src, 'integer')

        time.sleep(1)
        utils.migrate(self.rt1, src, self.rt2.id)
        utils.report(self.rt1, snk)
        time.sleep(1)
        utils.migrate(self.rt1, snk, self.rt2.id)
        time.sleep(1)

        actual = utils.report(self.rt2, snk)
        self.assert_lists_equal(range(1,20), actual, min_length=15)
Ejemplo n.º 4
0
    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()
Ejemplo n.º 5
0
    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()
Ejemplo n.º 6
0
    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()
Ejemplo n.º 7
0
    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()
Ejemplo n.º 8
0
    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()
Ejemplo n.º 9
0
    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 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)
Ejemplo n.º 11
0
    def testSepDeployShadow(self):
        _log.analyze("TESTRUN", "+", {})
        global rt1
        global rt2
        global test_script_dir

        self.verify_storage()

        from calvin.Tools.cscontrol import control_deploy as deploy_app
        from collections import namedtuple
        DeployArgs = namedtuple('DeployArgs', ['node', 'attr', 'script','reqs', 'check'])
        args = DeployArgs(node='http://%s:5003' % ip_addr,
                          script=open(test_script_dir+"test_shadow1.calvin"), attr=None,
                                reqs=test_script_dir+"test_shadow1.deployjson", check=False)
        result = {}
        try:
            result = deploy_app(args)
        except:
            raise Exception("Failed deployment of app %s, no use to verify if requirements fulfilled" % args.script.name)
        #print "RESULT:", result
        time.sleep(2)

        actors = [utils.get_actors(rt1), utils.get_actors(rt2)]
        # src -> rt1, sum -> rt2, snk -> rt1
        assert result['actor_map']['test_shadow1:src'] in actors[0]
        assert result['actor_map']['test_shadow1:sum'] in actors[1]
        assert result['actor_map']['test_shadow1:snk'] in actors[0]
        
        actual = utils.report(rt1, result['actor_map']['test_shadow1:snk'])
        assert len(actual) > 5
        utils.delete_application(rt1, result['application_id'])
Ejemplo n.º 12
0
    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 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))
Ejemplo n.º 14
0
    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()
Ejemplo n.º 15
0
    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 test30(self):
        src = utils.new_actor(self.rt1, 'std.Counter', 'src')
        snk1 = utils.new_actor_wargs(self.rt1, 'io.StandardOut', 'snk1', store_tokens=1, quiet=1)
        snk2 = utils.new_actor_wargs(self.rt1, 'io.StandardOut', 'snk2', store_tokens=1, quiet=1)

        utils.set_port_property(self.rt1, src, 'out', 'integer', 'fanout', 2)

        utils.connect(self.rt1, snk1, 'token', self.rt1.id, src, 'integer')
        utils.connect(self.rt1, snk2, 'token', self.rt1.id, src, 'integer')

        time.sleep(0.2)

        actual1 = utils.report(self.rt1, snk1)
        actual2 = utils.report(self.rt1, snk2)

        self.assert_lists_equal(list(range(1, 10)), actual1)
        self.assert_lists_equal(list(range(1, 10)), actual2)
    def test21(self):
        src = utils.new_actor(self.rt1, 'std.Counter', 'src')
        ity = utils.new_actor(self.rt2, 'std.Identity', 'ity')
        snk = utils.new_actor_wargs(self.rt3, 'io.StandardOut', 'snk', store_tokens=1, quiet=1)

        utils.connect(self.rt3, snk, 'token', self.rt2.id, ity, 'token')
        utils.connect(self.rt2, ity, 'token', self.rt1.id, src, 'integer')

        time.sleep(0.1)

        actual = utils.report(self.rt3, snk)

        while len(actual) < 10:
            time.sleep(0.1)
            actual = utils.report(self.rt3, snk)

        self.assert_lists_equal(range(1, 11), actual)
Ejemplo n.º 18
0
def expected_tokens(rt, actor_id, src_actor_type):
    tokens = utils.report(rt, actor_id)

    if src_actor_type == 'std.CountTimer':
        return expected_counter(tokens)

    if src_actor_type == 'std.Sum':
        return expected_sum(tokens)

    return None
Ejemplo n.º 19
0
    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 testLocalSourceSink(self):
        src = utils.new_actor(self.rt1, 'std.CountTimer', 'src')
        snk = utils.new_actor_wargs(self.rt1, 'io.StandardOut', 'snk', store_tokens=1, quiet=1)

        utils.connect(self.rt1, snk, 'token', self.rt1.id, src, 'integer')

        time.sleep(.5)

        actual = utils.report(self.rt1, snk)

        self.assert_lists_equal(range(1, 10), actual)
    def testFileScript(self):
        scriptname = 'test1'
        scriptfile = absolute_filename("scripts/%s.calvin" % (scriptname, ))
        app_info, errors, warnings = compiler.compile_file(scriptfile)
        d = deployer.Deployer(self.rt1, app_info)
        d.deploy()
        time.sleep(1)
        src = d.actor_map['%s:src' % scriptname]
        snk = d.actor_map['%s:snk' % scriptname]

        actual = utils.report(self.rt1, snk)
        self.assert_lists_equal(range(1, 20), actual)
    def test10(self):
        # Two actors, doesn't seem to trigger the bug
        src = utils.new_actor(self.rt1, 'std.Counter', 'src')
        snk = utils.new_actor_wargs(self.rt1, 'io.StandardOut', 'snk', store_tokens=1, quiet=1)

        utils.connect(self.rt1, snk, 'token', self.rt1.id, src, 'integer')

        time.sleep(0.1)

        actual = utils.report(self.rt1, snk)

        self.assert_lists_equal(range(1, 10), actual)
    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)
Ejemplo n.º 24
0
    def test32(self):
        # Verify that fanout from component inports is handled correctly
        _log.analyze("TESTRUN", "+", {})
        script = """
            component Foo() in -> a, b{
              a : std.Identity()
              b : std.Identity()
              .in >  a.token
              .in > b.token
              a.token > .a
              b.token > .b
            }

            snk2 : io.StandardOut(store_tokens=1, quiet=1)
            snk1 : io.StandardOut(store_tokens=1, quiet=1)
            foo : Foo()
            req : std.Counter()
            req.integer > foo.in
            foo.a > snk1.token
            foo.b > snk2.token
        """
        app_info, errors, warnings = compiler.compile(script, "test32")
        d = deployer.Deployer(self.rt1, app_info)
        d.deploy()
        time.sleep(0.1)

        snk1 = d.actor_map['test32:snk1']
        snk2 = d.actor_map['test32: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()
Ejemplo n.º 25
0
    def test10(self):
        _log.analyze("TESTRUN", "+", {})
        # Two actors, doesn't seem to trigger the bug
        src = utils.new_actor(self.rt1, 'std.Counter', 'src')
        snk = utils.new_actor_wargs(self.rt1, 'io.StandardOut', 'snk', store_tokens=1, quiet=1)

        utils.connect(self.rt1, snk, 'token', self.rt1.id, src, 'integer')

        time.sleep(0.1)

        actual = utils.report(self.rt1, snk)

        self.assert_lists_equal(range(1, 10), actual)

        utils.delete_actor(self.rt1, src)
        utils.delete_actor(self.rt1, snk)
Ejemplo n.º 26
0
    def testMigrateSource(self):
        src = utils.new_actor(self.rt1, 'std.CountTimer', 'src')
        snk = utils.new_actor_wargs(self.rt1,
                                    'io.StandardOut',
                                    'snk',
                                    store_tokens=1,
                                    quiet=1)

        utils.connect(self.rt1, snk, 'token', self.rt1.id, src, 'integer')

        time.sleep(.4)
        utils.migrate(self.rt1, src, self.rt2.id)
        time.sleep(.6)

        actual = utils.report(self.rt1, snk)
        self.assert_lists_equal(range(1, 10), 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)
Ejemplo n.º 28
0
    def testMigrateSink(self):
        _log.analyze("TESTRUN", "+", {})
        src = utils.new_actor(self.rt1, 'std.CountTimer', 'src')
        snk = utils.new_actor_wargs(self.rt1, 'io.StandardOut', 'snk', store_tokens=1, quiet=1)

        utils.connect(self.rt1, snk, 'token', self.rt1.id, src, 'integer')

        time.sleep(.4)
        utils.migrate(self.rt1, snk, self.rt2.id)
        time.sleep(.6)

        actual = utils.report(self.rt2, snk)
        self.assert_lists_equal(range(1, 10), actual)

        utils.delete_actor(self.rt1, src)
        utils.delete_actor(self.rt2, snk)
Ejemplo n.º 29
0
    def test25(self):
        src = utils.new_actor(self.rt1, 'std.Counter', 'src')
        ity = utils.new_actor(self.rt1, 'std.Identity', 'ity')
        snk = utils.new_actor_wargs(self.rt1,
                                    'io.StandardOut',
                                    'snk',
                                    store_tokens=1,
                                    quiet=1)

        utils.connect(self.rt1, ity, 'token', self.rt1.id, src, 'integer')
        utils.connect(self.rt1, snk, 'token', self.rt1.id, ity, 'token')

        time.sleep(0.5)

        actual = utils.report(self.rt1, snk)

        self.assert_lists_equal(range(1, 10), actual)
Ejemplo n.º 30
0
    def testInlineScript(self):
        _log.analyze("TESTRUN", "+", {})
        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)

        d.destroy()
Ejemplo n.º 31
0
    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)
Ejemplo n.º 32
0
    def test20(self):
        _log.analyze("TESTRUN", "+", {})
        src = utils.new_actor(self.rt1, 'std.Counter', 'src')
        ity = utils.new_actor(self.rt1, 'std.Identity', 'ity')
        snk = utils.new_actor_wargs(self.rt1, 'io.StandardOut', 'snk', store_tokens=1, quiet=1)

        utils.connect(self.rt1, snk, 'token', self.rt1.id, ity, 'token')
        utils.connect(self.rt1, ity, 'token', self.rt1.id, src, 'integer')

        time.sleep(0.2)

        actual = utils.report(self.rt1, snk)

        self.assert_lists_equal(range(1, 11), actual)

        utils.delete_actor(self.rt1, src)
        utils.delete_actor(self.rt1, ity)
        utils.delete_actor(self.rt1, snk)
Ejemplo n.º 33
0
    def test11(self):
        # 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.5)

        snk = d.actor_map['simple:snk']
        actual = utils.report(self.rt1, snk)

        self.assert_lists_equal(range(1, 10), actual)
Ejemplo n.º 34
0
    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)
Ejemplo n.º 36
0
    def test25(self):
        _log.analyze("TESTRUN", "+", {})
        src = utils.new_actor(self.rt1, 'std.Counter', 'src')
        ity = utils.new_actor(self.rt1, 'std.Identity', 'ity')
        snk = utils.new_actor_wargs(self.rt1, 'io.StandardOut', 'snk', store_tokens=1, quiet=1)

        utils.connect(self.rt1, ity, 'token', self.rt1.id, src, 'integer')
        utils.connect(self.rt1, snk, 'token', self.rt1.id, ity, 'token')

        time.sleep(0.2)

        actual = utils.report(self.rt1, snk)

        self.assert_lists_equal(range(1, 10), actual)

        utils.delete_actor(self.rt1, src)
        utils.delete_actor(self.rt1, ity)
        utils.delete_actor(self.rt1, snk)
    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)
Ejemplo n.º 38
0
    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)
Ejemplo n.º 39
0
    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)
Ejemplo n.º 40
0
    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()
Ejemplo n.º 41
0
    def testEqual(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, "testEqual")
        print errors
        d = deployer.Deployer(self.rt1, app_info)
        d.deploy()
        time.sleep(0.5)

        snk = d.actor_map['testEqual:snk']
        actual = utils.report(self.rt1, snk)
        expected = [x == 5 for x in range(1, 10)]

        self.assert_lists_equal(expected, actual)
Ejemplo n.º 42
0
    def testRegexMatch(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, "testRegexMatch")
        print errors
        d = deployer.Deployer(self.rt1, app_info)
        d.deploy()
        time.sleep(0.5)

        snk = d.actor_map['testRegexMatch:snk']
        actual = utils.report(self.rt1, snk)
        expected = ["24.1632"]

        self.assert_lists_equal(expected, actual, min_length=1)
Ejemplo n.º 43
0
    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)
Ejemplo n.º 44
0
    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)
Ejemplo n.º 45
0
    def testSimpleState(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)
        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)
Ejemplo n.º 46
0
    def testMigrateSource(self):
        _log.analyze("TESTRUN", "+", {})
        src = utils.new_actor(self.rt1, 'std.CountTimer', 'src')
        snk = utils.new_actor_wargs(self.rt1, 'io.StandardOut', 'snk', store_tokens=1, quiet=1)

        utils.connect(self.rt1, snk, 'token', self.rt1.id, src, 'integer')

        time.sleep(1)
        utils.migrate(self.rt1, src, self.rt2.id)

        interval = 0.5
        for retries in range(1,5):
            time.sleep(interval * retries)
            actual = utils.report(self.rt1, snk)
            if len(actual) > 10 :
                break


        self.assert_lists_equal(range(1, 10), actual)

        utils.delete_actor(self.rt2, src)
        utils.delete_actor(self.rt1, snk)
Ejemplo n.º 47
0
    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)
Ejemplo n.º 48
0
    def testComponentArgumentAsImplicitActor(self):
        script = """
        component Count(data) -> seq {
            i : std.Identity()
            data > i.token
            i.token > .seq
        }
        src : Count(data="hup")
        snk : io.StandardOut(store_tokens=1, quiet=1)
        src.seq > snk.token
        """

        app_info, errors, warnings = compiler.compile(
            script, "testComponentArgumentAsImplicitActor")
        d = deployer.Deployer(self.rt1, app_info)
        d.deploy()
        time.sleep(.1)

        snk = d.actor_map['testComponentArgumentAsImplicitActor:snk']
        actual = utils.report(self.rt1, snk)
        expected = ["hup"] * 10

        self.assert_lists_equal(expected, actual, min_length=10)
Ejemplo n.º 49
0
    def testVoidActor(self):
        # Verify that the null port of a std.Void actor behaves as expected
        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)
Ejemplo n.º 50
0
    def testBasicJoin(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, "testBasicJoin")
        print errors
        d = deployer.Deployer(self.rt1, app_info)
        d.deploy()
        time.sleep(0.5)

        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)
Ejemplo n.º 51
0
    def testBadSelect(self):
        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.true  > term.null
            route.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)
Ejemplo n.º 52
0
    def testSepDeployShadow(self):
        _log.analyze("TESTRUN", "+", {})
        global rt1
        global rt2
        global test_script_dir

        self.verify_storage()

        from calvin.Tools.cscontrol import control_deploy as deploy_app
        from collections import namedtuple
        DeployArgs = namedtuple('DeployArgs',
                                ['node', 'attr', 'script', 'reqs', 'check'])
        args = DeployArgs(node='http://%s:5003' % ip_addr,
                          script=open(test_script_dir + "test_shadow1.calvin"),
                          attr=None,
                          reqs=test_script_dir + "test_shadow1.deployjson",
                          check=False)
        result = {}
        try:
            result = deploy_app(args)
        except:
            raise Exception(
                "Failed deployment of app %s, no use to verify if requirements fulfilled"
                % args.script.name)
        #print "RESULT:", result
        time.sleep(2)

        actors = [utils.get_actors(rt1), utils.get_actors(rt2)]
        # src -> rt1, sum -> rt2, snk -> rt1
        assert result['actor_map']['test_shadow1:src'] in actors[0]
        assert result['actor_map']['test_shadow1:sum'] in actors[1]
        assert result['actor_map']['test_shadow1:snk'] in actors[0]

        actual = utils.report(rt1, result['actor_map']['test_shadow1:snk'])
        assert len(actual) > 5
        utils.delete_application(rt1, result['application_id'])
Ejemplo n.º 53
0
def actual_tokens(rt, actor_id):
    return utils.report(rt, actor_id)