示例#1
0
        async Task Run(IEnv env)
        {
            _expectedCount = 0M;
            var endpoints = Servers.Select(m => new SimEndpoint(m, Port)).ToArray();

            var lib = new BackendClient(env, endpoints);

            await lib.AddItem(0, 1);

            _expectedCount = 1M;

            for (int i = 0; i < Iterations; i++)
            {
                try {
                    var curr = i % RingSize;
                    var next = (i + 1) % RingSize;
                    await lib.MoveItem(curr, next, 1);

                    await env.Delay(Delay);
                } catch (ArgumentException ex) {
                    env.Error("Unexpected error", ex);
                }
            }

            _actualCount = await lib.Count();

            if (HaltOnCompletion)
            {
                env.Halt("DONE");
            }
        }
        async Task HandleRequest(IConn conn)
        {
            using (conn) {
                var req = await conn.Read(5.Sec());

                try {
                    _env.Debug($"{req}");

                    await _env.SimulateWork(35.Ms());

                    switch (req)
                    {
                    case AddItemRequest r:
                        await AddItem(conn, r);

                        break;

                    case MoveItemRequest r:
                        await MoveItem(conn, r);

                        break;

                    case CountRequest r:
                        var amount = _store.Count();
                        await conn.Write(new CountResponse(amount));

                        break;
                    }
                } catch (Exception ex) {
                    _env.Error($"Error while processing {req}", ex);
                }
            }
        }