예제 #1
0
 public void PollOne()
 {
     Assert.Equal(0, context.PollOne());
     context.Post(() => { });
     context.Post(() => { });
     Assert.Equal(1, context.PollOne());
 }
예제 #2
0
        public void PollOne()
        {
            MOCK_ContextPollOne((IntPtr context, ref int count) =>
            {
                Assert.Equal(pointer, context);
                count = 1;
                return((int)Yogi.ErrorCode.Ok);
            });

            Assert.Equal(1, context.PollOne());
        }
예제 #3
0
        public void SendBroadcastAsync()
        {
            var branchA = new Yogi.Branch(context,
                                          "{\"name\":\"a\", \"_transceive_byte_limit\": 5}");
            var branchB = new Yogi.Branch(context, "{\"name\":\"b\"}");

            RunContextUntilBranchesAreConnected(context, branchA, branchB);

            // Receive a broadcast to verify that it has actually been sent
            bool broadcastReceived = false;

            branchB.ReceiveBroadcastAsync(Yogi.EncodingType.Json, (res, _, payload) =>
            {
                Assert.Equal(Yogi.ErrorCode.Ok, res.ErrorCode);
                Assert.Equal(bigJsonView, payload);
                broadcastReceived = true;
            });

            GC.Collect();

            // Send with retry = true
            int n       = 3;
            var results = new List <Yogi.Result>();

            for (int i = 0; i < n; ++i)
            {
                var oid = branchA.SendBroadcastAsync(bigJsonView, true, (res, opid) =>
                {
                    Assert.Equal(Yogi.ErrorCode.Ok, res.ErrorCode);
                    Assert.True(opid.IsValid);
                    results.Add(res);
                });
                Assert.True(oid.IsValid);
            }

            while (results.Count != n)
            {
                context.Poll();
            }

            // Send with retry = false
            do
            {
                branchA.SendBroadcastAsync(bigJsonView, false, (res, _) =>
                {
                    results.Add(res);
                });

                context.PollOne();
            } while (results[results.Count - 1].ErrorCode == Yogi.ErrorCode.Ok);

            Assert.Equal(Yogi.ErrorCode.TxQueueFull, results[results.Count - 1].ErrorCode);

            // Verify that a broadcast has actually been sent
            while (!broadcastReceived)
            {
                context.RunOne();
            }

            GC.KeepAlive(branchA);
            GC.KeepAlive(branchB);
        }