Exemplo n.º 1
0
def test_deprecate_non_existent_workflow_type():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60")

    conn.deprecate_workflow_type.when.called_with(
        "test-domain", "non-existent", "v1.0"
    ).should.throw(SWFResponseError)
Exemplo n.º 2
0
def test_describe_non_existent_workflow_type():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60")

    conn.describe_workflow_type.when.called_with(
        "test-domain", "non-existent", "v1.0"
    ).should.throw(SWFUnknownResourceFault)
Exemplo n.º 3
0
def test_register_with_wrong_parameter_type():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60")

    conn.register_workflow_type.when.called_with(
        "test-domain", "test-workflow", 12
    ).should.throw(SWFResponseError)
Exemplo n.º 4
0
def test_register_with_wrong_parameter_type():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60")

    conn.register_activity_type.when.called_with(
        "test-domain", "test-activity", 12
    ).should.throw(SWFSerializationException)
Exemplo n.º 5
0
def test_register_already_existing_domain():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60", description="A test domain")

    conn.register_domain.when.called_with(
        "test-domain", "60", description="A test domain"
    ).should.throw(SWFResponseError)
Exemplo n.º 6
0
def test_register_already_existing_workflow_type():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60")
    conn.register_workflow_type("test-domain", "test-workflow", "v1.0")

    conn.register_workflow_type.when.called_with(
        "test-domain", "test-workflow", "v1.0"
    ).should.throw(SWFResponseError)
Exemplo n.º 7
0
def test_deprecate_already_deprecated_domain():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60", description="A test domain")
    conn.deprecate_domain("test-domain")

    conn.deprecate_domain.when.called_with(
        "test-domain"
    ).should.throw(SWFDomainDeprecatedFault)
Exemplo n.º 8
0
def test_register_already_existing_activity_type():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60")
    conn.register_activity_type("test-domain", "test-activity", "v1.0")

    conn.register_activity_type.when.called_with(
        "test-domain", "test-activity", "v1.0"
    ).should.throw(SWFTypeAlreadyExistsFault)
Exemplo n.º 9
0
    def setUpClass(cls):
        if TEST_DOMAIN is None:
            return
        cls.domain = TestDomain(boto.connect_swf())
        cls.log = logging.getLogger("flowsertest.testcase")

        # This tests registration of domains, workflows and activites.
        cls.domain.register(raise_exists=False)
Exemplo n.º 10
0
def test_register_already_existing_activity_type():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60")
    conn.register_activity_type("test-domain", "test-activity", "v1.0")

    conn.register_activity_type.when.called_with(
        "test-domain", "test-activity",
        "v1.0").should.throw(SWFTypeAlreadyExistsFault)
Exemplo n.º 11
0
def test_describe_domain():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60", description="A test domain")

    domain = conn.describe_domain("test-domain")
    domain["configuration"]["workflowExecutionRetentionPeriodInDays"].should.equal("60")
    domain["domainInfo"]["description"].should.equal("A test domain")
    domain["domainInfo"]["name"].should.equal("test-domain")
    domain["domainInfo"]["status"].should.equal("REGISTERED")
Exemplo n.º 12
0
def test_describe_domain():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60", description="A test domain")

    domain = conn.describe_domain("test-domain")
    domain["configuration"]["workflowExecutionRetentionPeriodInDays"].should.equal("60")
    domain["domainInfo"]["description"].should.equal("A test domain")
    domain["domainInfo"]["name"].should.equal("test-domain")
    domain["domainInfo"]["status"].should.equal("REGISTERED")
Exemplo n.º 13
0
def test_register_workflow_type():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60")
    conn.register_workflow_type("test-domain", "test-workflow", "v1.0")

    types = conn.list_workflow_types("test-domain", "REGISTERED")
    actype = types["typeInfos"][0]
    actype["workflowType"]["name"].should.equal("test-workflow")
    actype["workflowType"]["version"].should.equal("v1.0")
Exemplo n.º 14
0
def test_deprecate_already_deprecated_workflow_type():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60")
    conn.register_workflow_type("test-domain", "test-workflow", "v1.0")
    conn.deprecate_workflow_type("test-domain", "test-workflow", "v1.0")

    conn.deprecate_workflow_type.when.called_with(
        "test-domain", "test-workflow", "v1.0"
    ).should.throw(SWFTypeDeprecatedFault)
Exemplo n.º 15
0
def test_list_domains_reverse_order():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("b-test-domain", "60")
    conn.register_domain("a-test-domain", "60")
    conn.register_domain("c-test-domain", "60")

    all_domains = conn.list_domains("REGISTERED", reverse_order=True)
    names = [domain["name"] for domain in all_domains["domainInfos"]]
    names.should.equal(["c-test-domain", "b-test-domain", "a-test-domain"])
Exemplo n.º 16
0
def test_deprecate_already_deprecated_activity_type():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60")
    conn.register_activity_type("test-domain", "test-activity", "v1.0")
    conn.deprecate_activity_type("test-domain", "test-activity", "v1.0")

    conn.deprecate_activity_type.when.called_with(
        "test-domain", "test-activity", "v1.0"
    ).should.throw(SWFResponseError)
Exemplo n.º 17
0
def test_deprecate_domain():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60", description="A test domain")
    conn.deprecate_domain("test-domain")

    all_domains = conn.list_domains("DEPRECATED")
    domain = all_domains["domainInfos"][0]

    domain["name"].should.equal("test-domain")
Exemplo n.º 18
0
 def make_swf_environment(self):
     conn = boto.connect_swf()
     conn.register_domain("TestDomain", "50")
     conn.register_workflow_type(
         "TestDomain", "test-workflow", "v1.2",
         task_list="test-task-list", default_child_policy="TERMINATE",
         default_execution_start_to_close_timeout="6",
         default_task_start_to_close_timeout="3",
     )
     return conn
Exemplo n.º 19
0
 def make_swf_environment(self):
     conn = boto.connect_swf()
     conn.register_domain("TestDomain", "50")
     conn.register_workflow_type(
         "TestDomain", "test-workflow", "v1.2",
         task_list="test-task-list", default_child_policy="TERMINATE",
         default_execution_start_to_close_timeout="6",
         default_task_start_to_close_timeout="3",
     )
     return conn
Exemplo n.º 20
0
def test_register_domain():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60", description="A test domain")

    all_domains = conn.list_domains("REGISTERED")
    domain = all_domains["domainInfos"][0]

    domain["name"].should.equal("test-domain")
    domain["status"].should.equal("REGISTERED")
    domain["description"].should.equal("A test domain")
Exemplo n.º 21
0
def test_list_workflow_types():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60")
    conn.register_workflow_type("test-domain", "b-test-workflow", "v1.0")
    conn.register_workflow_type("test-domain", "a-test-workflow", "v1.0")
    conn.register_workflow_type("test-domain", "c-test-workflow", "v1.0")

    all_workflow_types = conn.list_workflow_types("test-domain", "REGISTERED")
    names = [activity_type["workflowType"]["name"] for activity_type in all_workflow_types["typeInfos"]]
    names.should.equal(["a-test-workflow", "b-test-workflow", "c-test-workflow"])
Exemplo n.º 22
0
def test_deprecate_activity_type():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60")
    conn.register_activity_type("test-domain", "test-activity", "v1.0")
    conn.deprecate_activity_type("test-domain", "test-activity", "v1.0")

    actypes = conn.list_activity_types("test-domain", "DEPRECATED")
    actype = actypes["typeInfos"][0]
    actype["activityType"]["name"].should.equal("test-activity")
    actype["activityType"]["version"].should.equal("v1.0")
Exemplo n.º 23
0
    def __init__(self, decision_function, decision_object=None, swf_domain=None, swf_task_list=None, workflow_type=None,
                 workflow_version=None, aws_access_key_id=None, aws_secret_access_key=None):
        """

        :param decision_function:
        :param swf_domain:
        :param swf_task_list:
        :param workflow_type:
        :param workflow_version:
        :param aws_access_key_id:
        :param aws_secret_access_key:
        :return:
        """

        self._decision_object = decision_object
        self._swf = boto.connect_swf(aws_access_key_id=aws_access_key_id,
                                     aws_secret_access_key=aws_secret_access_key)
        self._decision_function = decision_function

        registry = Registry()
        self._scanner = venusian.Scanner(registry=registry, mode='remote', caller='decision_worker')
        self._scanner.parent_decision_worker = decision_function

        # Some trickery here -- scan the module that the activity worker method is found in
        self._scanner.scan(sys.modules[decision_function.orig.__module__], categories=('pyswfaws.activity_task',
                                                                                       'pyswfaws.decision_task'))

        # More trickery -- make sure that timers know that we're in a remote mode
        PTimer.is_remote_mode = True
        PMarker.is_remote_mode = True

        if hasattr(self._decision_function, 'swf_options'):

            # Give preference to the values in the constructor
            self._swf_domain = self.choose_first_not_none('An SWF domain must be specified by the activity worker '
                                                          'constructor or the activity function', swf_domain,
                                                          decision_function.swf_options['domain'])
            self._swf_task_list = self.choose_first_not_none('An SWF task list must be specified by the activity '
                                                             'worker constructor or the activity function',
                                                             swf_task_list, decision_function.swf_options['task_list'])
            self._wf_type = self.choose_first_not_none('An SWF activity type must be specified by the activity '
                                                             'worker constructor or the activity function',
                                                             workflow_type, decision_function.swf_options['wf_type'])
            self._wf_version = self.choose_first_not_none('An SWF activity version must be specified by the '
                                                                'activity worker constructor or the activity function',
                                                                workflow_version, decision_function.swf_options[
                                                                    'wf_version'])

            self._input_serializer = decision_function.serialization_options['input_serializer']
            self._input_data_store = decision_function.serialization_options['input_data_store']
            self._result_serializer = decision_function.serialization_options['result_serializer']
            self._result_data_store = decision_function.serialization_options['result_data_store']
        else:
            raise Exception('Activity function has no "swf_options" attribute; are you sure the function was properly '
                            'decorated?')
Exemplo n.º 24
0
def setup_swf_environment():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60", description="A test domain")
    conn.register_workflow_type(
        "test-domain", "test-workflow", "v1.0",
        task_list="queue", default_child_policy="TERMINATE",
        default_execution_start_to_close_timeout="300",
        default_task_start_to_close_timeout="300",
    )
    conn.register_activity_type("test-domain", "test-activity", "v1.1")
    return conn
Exemplo n.º 25
0
def test_list_activity_types_reverse_order():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60")
    conn.register_activity_type("test-domain", "b-test-activity", "v1.0")
    conn.register_activity_type("test-domain", "a-test-activity", "v1.0")
    conn.register_activity_type("test-domain", "c-test-activity", "v1.0")

    all_activity_types = conn.list_activity_types("test-domain", "REGISTERED",
                                                  reverse_order=True)
    names = [activity_type["activityType"]["name"] for activity_type in all_activity_types["typeInfos"]]
    names.should.equal(["c-test-activity", "b-test-activity", "a-test-activity"])
Exemplo n.º 26
0
    def __init__(self, activity_function, activity_object=None, swf_domain=None, swf_task_list=None, activity_type=None,
                 activity_version=None, aws_access_key_id=None, aws_secret_access_key=None):
        """
        Inits an activity worker

        A few things to note:
        * If no AWS credentials are passed in, then it will be assumed that they should be sought after by Boto.  The
        places that Boto uses and their order of precedence can be found here:  http://boto.readthedocs.org/en/latest/boto_config_tut.html
        * If one of the swf_ arguments are left None, the constructor will fall back to using the data supplied by
        the @decision_task decorator.

        :param activity_function: the activity function being used
        :param swf_domain: SWF domain used by this worker
        :param swf_task_list: SWF task list that this worker is listening to
        :param aws_access_key_id: Access key to use for S3 and SWF.  If none is supplied, boto will fallback to looking for credentials elsewhere.
        :param aws_secret_access_key: Secret key to use for S3 and SWF.  If none is supplied, boto will fallback to looking for credentials elsewhere.
        :return:
        """

        self._activity_object = activity_object
        self._swf = boto.connect_swf(aws_access_key_id=aws_access_key_id,
                                     aws_secret_access_key=aws_secret_access_key)
        self._activity_function = activity_function

        registry = Registry()
        scanner = venusian.Scanner(registry=registry, mode='remote', caller='activity_worker')

        # Some trickery here -- scan the module that the activity worker method is found in
        scanner.scan(sys.modules[activity_function.orig.__module__], categories=('pyswfaws.activity_task', ))

        if hasattr(self._activity_function, 'swf_options'):

            # Give preference to the values in the constructor
            self._swf_domain = self.choose_first_not_none('An SWF domain must be specified by the activity worker '
                                                          'constructor or the activity function', swf_domain,
                                                          activity_function.swf_options['domain'])
            self._swf_task_list = self.choose_first_not_none('An SWF task list must be specified by the activity '
                                                             'worker constructor or the activity function',
                                                             swf_task_list, activity_function.swf_options['task_list'])
            self._activity_type = self.choose_first_not_none('An SWF activity type must be specified by the activity '
                                                             'worker constructor or the activity function',
                                                             activity_type, activity_function.swf_options['task_type'])
            self._activity_version = self.choose_first_not_none('An SWF activity version must be specified by the '
                                                                'activity worker constructor or the activity function',
                                                                activity_version, activity_function.swf_options[
                                                                    'task_version'])

            self._input_serializer = activity_function.serialization_options['input_serializer']
            self._input_data_store = activity_function.serialization_options['input_data_store']
            self._result_serializer = activity_function.serialization_options['result_serializer']
            self._result_data_store = activity_function.serialization_options['result_data_store']
        else:
            raise Exception('Activity function has no "swf_options" attribute; are you sure the function was properly '
                            'decorated?')
Exemplo n.º 27
0
def setup_swf_environment():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60", description="A test domain")
    conn.register_workflow_type(
        "test-domain", "test-workflow", "v1.0",
        task_list="queue", default_child_policy="TERMINATE",
        default_execution_start_to_close_timeout="300",
        default_task_start_to_close_timeout="300",
    )
    conn.register_activity_type("test-domain", "test-activity", "v1.1")
    return conn
Exemplo n.º 28
0
def test_describe_activity_type():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60")
    conn.register_activity_type("test-domain", "test-activity", "v1.0",
                                task_list="foo", default_task_heartbeat_timeout="32")

    actype = conn.describe_activity_type("test-domain", "test-activity", "v1.0")
    actype["configuration"]["defaultTaskList"]["name"].should.equal("foo")
    infos = actype["typeInfo"]
    infos["activityType"]["name"].should.equal("test-activity")
    infos["activityType"]["version"].should.equal("v1.0")
    infos["status"].should.equal("REGISTERED")
Exemplo n.º 29
0
def setup_workflow():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60", description="A test domain")
    conn = mock_basic_workflow_type("test-domain", conn)
    conn.register_activity_type(
        "test-domain", "test-activity", "v1.1",
        default_task_heartbeat_timeout="600",
        default_task_schedule_to_close_timeout="600",
        default_task_schedule_to_start_timeout="600",
        default_task_start_to_close_timeout="600",
    )
    wfe = conn.start_workflow_execution("test-domain", "uid-abcd1234", "test-workflow", "v1.0")
    conn.run_id = wfe["runId"]
    return conn
Exemplo n.º 30
0
def test_describe_workflow_type():
    conn = boto.connect_swf("the_key", "the_secret")
    conn.register_domain("test-domain", "60")
    conn.register_workflow_type("test-domain", "test-workflow", "v1.0",
                                task_list="foo", default_child_policy="TERMINATE")

    actype = conn.describe_workflow_type("test-domain", "test-workflow", "v1.0")
    actype["configuration"]["defaultTaskList"]["name"].should.equal("foo")
    actype["configuration"]["defaultChildPolicy"].should.equal("TERMINATE")
    actype["configuration"].keys().should_not.contain("defaultTaskStartToCloseTimeout")
    infos = actype["typeInfo"]
    infos["workflowType"]["name"].should.equal("test-workflow")
    infos["workflowType"]["version"].should.equal("v1.0")
    infos["status"].should.equal("REGISTERED")
Exemplo n.º 31
0
    def setUp(self):
        # SWF preparation
        self.domain = DOMAIN
        self.workflow_type_name = "test-workflow"
        self.workflow_type_version = "v1.2"
        self.decision_task_list = "test-task-list"

        self.conn = boto.connect_swf()
        self.conn.register_domain(self.domain.name, "50")
        self.conn.register_workflow_type(
            self.domain.name, self.workflow_type_name, self.workflow_type_version,
            task_list=self.decision_task_list, default_child_policy="TERMINATE",
            default_execution_start_to_close_timeout="6",
            default_task_start_to_close_timeout="3",
        )

        # S3 preparation in case we use jumbo fields
        self.s3_conn = boto.connect_s3()
        self.s3_conn.create_bucket("jumbo-bucket")
Exemplo n.º 32
0
    def setUp(self):
        # SWF preparation
        self.domain = DOMAIN
        self.workflow_type_name = "test-workflow"
        self.workflow_type_version = "v1.2"
        self.decision_task_list = "test-task-list"

        self.conn = boto.connect_swf()
        self.conn.register_domain(self.domain.name, "50")
        self.conn.register_workflow_type(
            self.domain.name, self.workflow_type_name, self.workflow_type_version,
            task_list=self.decision_task_list, default_child_policy="TERMINATE",
            default_execution_start_to_close_timeout="6",
            default_task_start_to_close_timeout="3",
        )

        # S3 preparation in case we use jumbo fields
        self.s3_conn = boto.connect_s3()
        self.s3_conn.create_bucket("jumbo-bucket")
Exemplo n.º 33
0
    def setUpClass(cls):
        LiveSwfWorkflowTest.swf = boto.connect_swf()

        LiveSwfWorkflowTest.activity_task_a_process = Process(target=LiveSwfWorkflowTest.start_activity_worker_a)
        LiveSwfWorkflowTest.activity_task_b_process = Process(target=LiveSwfWorkflowTest.start_activity_worker_b)
        LiveSwfWorkflowTest.decision_task_a_process = Process(target=LiveSwfWorkflowTest.start_decisioner_a)
        LiveSwfWorkflowTest.decision_task_b_process = Process(target=LiveSwfWorkflowTest.start_decisioner_b)
        LiveSwfWorkflowTest.decision_task_c_process = Process(target=LiveSwfWorkflowTest.start_decisioner_c)
        LiveSwfWorkflowTest.decision_task_d_process = Process(target=LiveSwfWorkflowTest.start_decisioner_d)
        LiveSwfWorkflowTest.decision_task_e_process = Process(target=LiveSwfWorkflowTest.start_decisioner_e)
        LiveSwfWorkflowTest.decision_task_f_process = Process(target=LiveSwfWorkflowTest.start_decisioner_f)

        LiveSwfWorkflowTest.activity_task_a_process.start()
        LiveSwfWorkflowTest.activity_task_b_process.start()
        LiveSwfWorkflowTest.decision_task_a_process.start()
        LiveSwfWorkflowTest.decision_task_b_process.start()
        LiveSwfWorkflowTest.decision_task_c_process.start()
        LiveSwfWorkflowTest.decision_task_d_process.start()
        LiveSwfWorkflowTest.decision_task_e_process.start()
        LiveSwfWorkflowTest.decision_task_f_process.start()
        time.sleep(10)
Exemplo n.º 34
0
def test_deprecate_non_existent_domain():
    conn = boto.connect_swf("the_key", "the_secret")

    conn.deprecate_domain.when.called_with(
        "non-existent"
    ).should.throw(SWFResponseError)
Exemplo n.º 35
0
def test_register_with_wrong_parameter_type():
    conn = boto.connect_swf("the_key", "the_secret")

    conn.register_domain.when.called_with(
        "test-domain", 60, description="A test domain"
    ).should.throw(SWFResponseError)