コード例 #1
0
    def testFileReader(self):
        """
        Simple test for FileReader migration.
        Create a FileReader actor and connect it to a source and a sink.
        Migrate it from runtime1 to runtime2 and verify that at least 1 token was received after migration
        """
        # create simple temp file with some data to be read
        fd, temp_path = mkstemp()
        os.write(fd, "Bla")
        os.close(fd)

        # create actors and connect them
        dut = self.request_handler.new_actor(self.rt1, 'io.FileReader', 'dut')
        src = self.request_handler.new_actor_wargs(self.rt1, 'std.Trigger', 'src', data=temp_path, tick=0.5)
        snk = self.request_handler.new_actor_wargs(self.rt1, 'test.Sink', 'snk', store_tokens=1, quiet=1)

        self.request_handler.connect(self.rt1, snk, 'token', self.rt1.id, dut, 'out')
        self.request_handler.connect(self.rt1, dut, 'filename', self.rt1.id, src, 'data')

        self.migrate(self.rt1, self.rt2, dut)

        # Wait at least 1 token after migration
        actual = helpers.wait_for_tokens(self.request_handler, self.rt1, snk, size=1)
        helpers.wait_for_tokens(self.request_handler, self.rt1, snk, len(actual)+1)

        # Cleanup
        os.remove(temp_path)
コード例 #2
0
def testSleepWithTimer():
    global constrained_process
    script_name = "testSleepWithTimer"
    script = """
    temp : sensor.Temperature(period=15)
    snk : test.Sink(store_tokens=1, quiet=1)
    temp.centigrade > snk.token

    rule first: node_attr_match(index=["node_name", {"organization": "com.ericsson", "purpose": "distributed-test", "group": "first", "name": "runtime1"}])
    rule constrained: node_attr_match(index=["node_name", {"organization": "com.ericsson", "purpose": "distributed-test", "group": "rest", "name": "constrained"}])
    apply snk: first
    apply temp: constrained
    """
    resp = request_handler.deploy_application(runtime1, script_name, script)
    snk_id = resp['actor_map'][script_name + ':snk']
    temp_id = resp['actor_map'][script_name + ':temp']

    # verify placement
    assert verify_actor_placement(request_handler, runtime1, temp_id,
                                  constrained_id)

    # wait for constrained enterring sleep
    constrained_process.wait()
    assert constrained_process.poll() is not None
    time.sleep(10)
    constrained_process = subprocess.Popen(calvin_command, shell=True)

    # verify data
    wait_for_tokens(request_handler, runtime1, snk_id, 1, 10)
    actual = request_handler.report(runtime1, snk_id)
    assert len(actual) >= 1

    # remove app
    request_handler.delete_application(runtime1, resp['application_id'])
コード例 #3
0
def testRegistryAttribute():
    script_name = "testRegistryAttribute"
    script = """
    tick : std.Trigger(data=null, tick=1)
    attr: context.RegistryAttribute(attribute="node_name.name")
    snk : test.Sink(store_tokens=1, quiet=0.1)

    tick.data > attr.trigger
    attr.value > snk.token

    rule first: node_attr_match(index=["node_name", {"organization": "com.ericsson", "purpose": "distributed-test", "group": "first", "name": "runtime1"}])
    rule constrained: node_attr_match(index=["node_name", {"organization": "com.ericsson", "purpose": "distributed-test", "group": "rest", "name": "constrained"}])
    apply tick, snk: first
    apply attr: constrained
    """
    resp = request_handler.deploy_application(runtime1, script_name, script)
    attr_id = resp['actor_map'][script_name + ':attr']
    snk_id = resp['actor_map'][script_name + ':snk']

    # verify placement
    assert verify_actor_placement(request_handler, runtime1, attr_id,
                                  constrained_id)

    # verify data
    wait_for_tokens(request_handler, runtime1, snk_id, 5, 20)
    actual = request_handler.report(runtime1, snk_id)
    assert len(actual) >= 5
    assert all(x == "constrained" for x in actual)

    # remove app
    request_handler.delete_application(runtime1, resp['application_id'])
コード例 #4
0
def testLocalConnections():
    script_name = "testLocalConnections"
    script = """
    src : std.CountTimer(sleep=0.1)
    id1 : std.Identity()
    id2 : std.Identity()
    snk : test.Sink(store_tokens=1, quiet=1)
    src.integer > id1.token
    id1.token > id2.token
    id2.token > snk.token

    rule first: node_attr_match(index=["node_name", {"organization": "com.ericsson", "purpose": "distributed-test", "group": "first", "name": "runtime1"}])
    rule constrained: node_attr_match(index=["node_name", {"organization": "com.ericsson", "purpose": "distributed-test", "group": "rest", "name": "constrained"}])
    apply src, snk: first
    apply id1, id2: constrained
    """
    resp = request_handler.deploy_application(runtime1, script_name, script)
    id1_id = resp['actor_map'][script_name + ':id1']
    id2_id = resp['actor_map'][script_name + ':id2']
    snk_id = resp['actor_map'][script_name + ':snk']

    # verify placement
    assert verify_actor_placement(request_handler, runtime1, id1_id,
                                  constrained_id)
    assert verify_actor_placement(request_handler, runtime1, id2_id,
                                  constrained_id)

    # verify data
    wait_for_tokens(request_handler, runtime1, snk_id, 5, 20)
    actual = request_handler.report(runtime1, snk_id)
    assert len(actual) >= 5

    # remove app
    request_handler.delete_application(runtime1, resp['application_id'])
コード例 #5
0
def testActorWithCalvinsysFromShadow():
    script_name = "testTemperatureFromShadow"
    script = """
    temp : sensor.Temperature(period=1)
    snk : test.Sink(store_tokens=1, quiet=1)
    temp.centigrade > snk.token

    rule second: node_attr_match(index=["node_name", {"organization": "com.ericsson", "purpose": "distributed-test", "group": "rest", "name": "runtime2"}])
    rule constrained: node_attr_match(index=["node_name", {"organization": "com.ericsson", "purpose": "distributed-test", "group": "rest", "name": "constrained"}])
    apply snk: second
    apply temp: constrained
    """
    resp = request_handler.deploy_application(runtime2, script_name, script)
    temp_id = resp['actor_map'][script_name + ':temp']
    snk_id = resp['actor_map'][script_name + ':snk']

    # verify actor placement and data
    assert verify_actor_placement(request_handler, runtime2, temp_id,
                                  constrained_id)
    wait_for_tokens(request_handler, runtime2, snk_id, 2, 20)
    actual = request_handler.report(runtime2, snk_id)
    assert len(actual) >= 2

    # migrate temp to runtime1
    request_handler.migrate(runtime2, temp_id, runtime1.id)

    # verify placement
    assert verify_actor_placement(request_handler, runtime1, temp_id,
                                  runtime1.id)

    # delete application
    request_handler.delete_application(runtime2, resp['application_id'])
コード例 #6
0
def testDataAndDestructionRouted():
    script_name = "testDataAndDestruction"
    script = """
    src : std.CountTimer(sleep=0.1)
    id : std.Identity()
    snk : test.Sink(store_tokens=1, quiet=1)
    src.integer > id.token
    id.token > snk.token

    rule second: node_attr_match(index=["node_name", {"organization": "com.ericsson", "purpose": "distributed-test", "group": "rest", "name": "runtime2"}])
    rule constrained: node_attr_match(index=["node_name", {"organization": "com.ericsson", "purpose": "distributed-test", "group": "rest", "name": "constrained"}])
    apply src, snk: second
    apply id: constrained
    """
    resp = request_handler.deploy_application(runtime2, script_name, script)

    # verify placement
    assert verify_actor_placement(request_handler, runtime2,
                                  resp['actor_map'][script_name + ':id'],
                                  constrained_id)

    # verify data
    wait_for_tokens(request_handler, runtime2,
                    resp['actor_map'][script_name + ':snk'], 5, 20)
    actual = request_handler.report(runtime2,
                                    resp['actor_map'][script_name + ':snk'])
    assert len(actual) >= 5

    # remove app
    request_handler.delete_application(runtime2, resp['application_id'])

    # verify actor removal
    assert verify_actor_removal(request_handler, runtime2,
                                resp['actor_map'][script_name + ':id'])
コード例 #7
0
def testPortConnect():
    script_name = "testPortConnect"
    script = """
    src : std.CountTimer(sleep=0.1)
    id : std.Identity()
    snk : test.Sink(store_tokens=1, quiet=1)
    src.integer > id.token
    id.token > snk.token

    rule first: node_attr_match(index=["node_name", {"organization": "com.ericsson", "purpose": "distributed-test", "group": "first", "name": "runtime1"}])
    rule constrained: node_attr_match(index=["node_name", {"organization": "com.ericsson", "purpose": "distributed-test", "group": "rest", "name": "constrained"}])
    apply src, snk: first
    apply id: constrained
    """

    resp = request_handler.deploy_application(runtime1, script_name, script)

    app_id = resp['application_id']
    identity_id = resp['actor_map'][script_name + ':id']
    snk_id = resp['actor_map'][script_name + ':snk']

    # verify placement
    assert verify_actor_placement(request_handler, runtime1, identity_id,
                                  constrained_id)

    # wait for tokens
    wait_for_tokens(request_handler, runtime1,
                    resp['actor_map'][script_name + ':snk'], 5)
    actual = request_handler.report(runtime1,
                                    resp['actor_map'][script_name + ':snk'])

    # migrate snk to rt2
    request_handler.migrate(runtime1, snk_id, runtime2.id)

    # verify placement
    assert verify_actor_placement(request_handler, runtime2, snk_id,
                                  runtime2.id)

    # verify tokens
    expected = len(actual) + 5
    wait_for_tokens(request_handler, runtime2,
                    resp['actor_map'][script_name + ':snk'], expected, 20)
    actual = request_handler.report(runtime2,
                                    resp['actor_map'][script_name + ':snk'])
    assert len(actual) >= expected

    # delete app
    request_handler.delete_application(runtime1, app_id)

    # verify removal
    assert verify_actor_removal(request_handler, runtime1, identity_id)
コード例 #8
0
def testMigration():
    script_name = "testMigration"
    script = """
    src : std.CountTimer(sleep=0.1)
    id : std.Identity()
    snk : test.Sink(store_tokens=1, quiet=1)
    src.integer > id.token
    id.token > snk.token

    rule first: node_attr_match(index=["node_name", {"organization": "com.ericsson", "purpose": "distributed-test", "group": "first", "name": "runtime1"}])
    rule constrained: node_attr_match(index=["node_name", {"organization": "com.ericsson", "purpose": "distributed-test", "group": "rest", "name": "constrained"}])
    apply src, snk: first
    apply id: constrained
    """
    resp = request_handler.deploy_application(runtime1, script_name, script)

    # verify placement
    assert verify_actor_placement(request_handler, runtime1,
                                  resp['actor_map'][script_name + ':id'],
                                  constrained_id)

    # verify data
    wait_for_tokens(request_handler, runtime1,
                    resp['actor_map'][script_name + ':snk'], 5, 20)
    actual = request_handler.report(runtime1,
                                    resp['actor_map'][script_name + ':snk'])
    assert len(actual) >= 5

    # migrate id to rt2 and verify placement
    request_handler.migrate(runtime1, resp['actor_map'][script_name + ':id'],
                            runtime2.id)

    # verify placement
    assert verify_actor_placement(request_handler, runtime2,
                                  resp['actor_map'][script_name + ':id'],
                                  runtime2.id)

    wait_for_tokens(request_handler, runtime1,
                    resp['actor_map'][script_name + ':snk'], 10, 20)
    actual = request_handler.report(runtime1,
                                    resp['actor_map'][script_name + ':snk'])
    assert len(actual) >= 10

    # delete application
    request_handler.delete_application(runtime1, resp['application_id'])
コード例 #9
0
    def testFileReader(self):
        """
        Simple test for FileReader migration.
        Create a FileReader actor and connect it to a source and a sink.
        Migrate it from runtime1 to runtime2 and verify that at least 1 token was received after migration
        """
        # create simple temp file with some data to be read
        fd, temp_path = mkstemp()
        os.write(fd, "Bla")
        os.close(fd)

        # create actors and connect them
        dut = self.request_handler.new_actor(self.rt1, 'io.FileReader', 'dut')
        src = self.request_handler.new_actor_wargs(self.rt1,
                                                   'std.Trigger',
                                                   'src',
                                                   data=temp_path,
                                                   tick=0.5)
        snk = self.request_handler.new_actor_wargs(self.rt1,
                                                   'test.Sink',
                                                   'snk',
                                                   store_tokens=1,
                                                   quiet=1)

        self.request_handler.connect(self.rt1, snk, 'token', self.rt1.id, dut,
                                     'out')
        self.request_handler.connect(self.rt1, dut, 'filename', self.rt1.id,
                                     src, 'data')

        self.migrate(self.rt1, self.rt2, dut)

        # Wait at least 1 token after migration
        actual = helpers.wait_for_tokens(self.request_handler,
                                         self.rt1,
                                         snk,
                                         size=1)
        helpers.wait_for_tokens(self.request_handler, self.rt1, snk,
                                len(actual) + 1)

        # Cleanup
        os.remove(temp_path)
コード例 #10
0
def testSleepWithoutTimers():
    global constrained_process
    script_name = "testSleepWithoutTimers"
    script = """
    src : std.CountTimer(sleep=15)
    id : std.Identity()
    snk : test.Sink(store_tokens=1, quiet=1)
    src.integer > id.token
    id.token > snk.token

    rule first: node_attr_match(index=["node_name", {"organization": "com.ericsson", "purpose": "distributed-test", "group": "first", "name": "runtime1"}])
    rule constrained: node_attr_match(index=["node_name", {"organization": "com.ericsson", "purpose": "distributed-test", "group": "rest", "name": "constrained"}])
    apply src, snk: first
    apply id: constrained
    """
    resp = request_handler.deploy_application(runtime1, script_name, script)
    id_id = resp['actor_map'][script_name + ':id']
    snk_id = resp['actor_map'][script_name + ':snk']

    # verify placement
    assert verify_actor_placement(request_handler, runtime1, id_id,
                                  constrained_id)

    # wait for constrained enterring sleep
    constrained_process.wait()
    assert constrained_process.poll() is not None
    time.sleep(10)
    constrained_process = subprocess.Popen(calvin_command, shell=True)

    # verify data
    wait_for_tokens(request_handler, runtime1, snk_id, 1, 10)
    actual = request_handler.report(runtime1, snk_id)
    assert len(actual) >= 1

    # remove app
    request_handler.delete_application(runtime1, resp['application_id'])