Example #1
0
def test_object_patching(env, pre_call, post_call, expected):
    """Test if the object patching and the "pre_call" and "post_call"
    prameters work as expected."""
    def pem(env, resource):
        with resource.request() as req:
            yield req
            yield env.timeout(1)

    resource = simpy.Resource(env, 1)
    monitor = monitoring.Monitor()
    monitor.configure(monitoring.resource_collector(resource))
    monitoring.patch(resource, monitor, pre_call=pre_call, post_call=post_call)
    env.start(pem(env, resource))
    simpy.simulate(env)

    # Convert the data and replace the ID-lists with their length.
    monitor._backend.data = [(t, len(u), len(q)) for t, u, q in monitor.data]

    assert monitor.data == expected
Example #2
0
def test_object_patching(env, pre_call, post_call, expected):
    """Test if the object patching and the "pre_call" and "post_call"
    prameters work as expected."""

    def pem(env, resource):
        with resource.request() as req:
            yield req
            yield env.timeout(1)

    resource = simpy.Resource(env, 1)
    monitor = monitoring.Monitor()
    monitor.configure(monitoring.resource_collector(resource))
    monitoring.patch(resource, monitor, pre_call=pre_call, post_call=post_call)
    env.start(pem(env, resource))
    simpy.simulate(env)

    # Convert the data and replace the ID-lists with their length.
    monitor._backend.data = [(t, len(u), len(q)) for t, u, q in monitor.data]

    assert monitor.data == expected
Example #3
0
def get_resource_monitor(resource):
    monitor = monitoring.Monitor()
    monitor.configure(monitoring.resource_collector(resource))
    monitoring.patch(resource, monitor, pre_call=("request", "release"))
    return monitor
Example #4
0
def get_resource_monitor(resource):
    monitor = monitoring.Monitor()
    monitor.configure(monitoring.resource_collector(resource))
    monitoring.patch(resource, monitor, pre_call=('request', 'release'))
    return monitor