Exemple #1
0
    def test_resource_accessed_through_context_manager_timeout(self):
        def fake_resource_constructor_func():
            return [99]

        r = mooq.Resource(c_func=fake_resource_constructor_func)

        self.GIVEN_resource_box_started(r)

        self.WHEN_access_of_resource_is_nested()

        self.THEN_exception_occurs(mooq.ResourceNotAvailable)
Exemple #2
0
    def test_resource_accessed_through_context_manager_no_constructor_args_kwargs(
            self):
        def fake_resource_constructor_func():
            return [99]

        r = mooq.Resource(c_func=fake_resource_constructor_func)

        self.GIVEN_resource_box_started(r)
        self.GIVEN_expect("resource retrieved to be", [99])

        self.WHEN_access_resource_through_context_manager()

        self.THEN_ExpectedActualMatch("resource retrieved")
Exemple #3
0
    def test_resource_accessed_through_context_manager(self):
        def fake_resource_constructor_func(a, b, c=7):
            return [a, b, c]

        r = mooq.Resource(c_func=fake_resource_constructor_func,
                          c_args=(1, 2),
                          c_kwargs={"c": 99})

        self.GIVEN_resource_box_started(r)
        self.GIVEN_expect("resource retrieved to be", [1, 2, 99])

        self.WHEN_access_resource_through_context_manager()

        self.THEN_ExpectedActualMatch("resource retrieved")
Exemple #4
0
    def GIVEN_ChannelResourceCreated(self, transport_type="in_memory"):
        if transport_type == "in_memory":
            c_func = mooq.InMemoryChannel
        elif transport_type == "rabbitmq":
            c_func = mooq.RabbitMQChannel
        else:
            raise NotImplementedError

        self.chan_resource = mooq.Resource(
            c_func=c_func,
            c_args=(),
            c_kwargs={"conn_resource": self.conn_resource})

        t = threading.Thread(target=self.chan_resource.box)
        t.start()

        self.threads_to_close.append(self.chan_resource)
        with self.conn_resource.access() as conn:
            conn.channel_resources.append(self.chan_resource)
Exemple #5
0
    def GIVEN_ConnectionResourceCreated(self,
                                        transport_type="in_memory",
                                        host="blah",
                                        port=1234):
        if transport_type == "in_memory":
            c_func = mooq.InMemoryConnection
        elif transport_type == "rabbitmq":
            c_func = mooq.RabbitMQConnection
        else:
            raise NotImplementedError

        self.conn_resource = mooq.Resource(c_func=c_func,
                                           c_args=(),
                                           c_kwargs={
                                               "host": host,
                                               "port": port
                                           })
        t = threading.Thread(target=self.conn_resource.box)
        t.start()

        self.threads_to_close.append(self.conn_resource)