コード例 #1
0
        public void CheckInProgressCountersGoToZero()
        {
            using (var conn = Config.GetUnsecuredConnection())
            {
                conn.CompletionMode = ResultCompletionMode.Concurrent;
                Task <Counters> counters = null;
                Task[]          allTasks = new Task[5000];
                for (int i = 0; i < 5000; i++)
                {
                    var tmp = conn.Strings.Get(5, "foo" + i);
                    if (i == 2500)
                    {
                        counters = tmp.ContinueWith(x =>
                        {
                            return(conn.GetCounters(false));
                        }, TaskContinuationOptions.ExecuteSynchronously);
                    }
                    allTasks[i] = tmp;
                }

                var c = conn.Wait(counters);
                Console.WriteLine("in progress during: {0}", c.AsyncCallbacksInProgress);
                Assert.AreNotEqual(0, c.AsyncCallbacksInProgress, "async during");

                conn.WaitAll(allTasks);
                PubSub.AllowReasonableTimeToPublishAndProcess();
                Assert.AreEqual(0, conn.GetCounters(false).AsyncCallbacksInProgress, "async @ end");
                Assert.AreEqual(0, c.SyncCallbacksInProgress, "sync @ end");
            }
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: simonmatt/booksleeve
        public void HappilyMurderedClientDoesntGetError()
        {
            using (var victim = Config.GetUnsecuredConnection(waitForOpen: true))
                using (var murderer = Config.GetUnsecuredConnection(allowAdmin: true))
                {
                    const int VictimDB = 4;
                    victim.Wait(victim.Strings.GetString(VictimDB, "kill me quick"));
                    victim.CompletionMode = ResultCompletionMode.PreserveOrder;
                    var clients = murderer.Wait(murderer.Server.ListClients());
                    var target  = clients.Single(x => x.Database == VictimDB);

                    int i = 0;
                    victim.Closed += (s, a) =>
                    {
                        Interlocked.Increment(ref i);
                    };
                    var errors = new List <Exception>();
                    victim.Shutdown += (s, a) =>
                    {
                        if (a.Exception != null)
                        {
                            lock (errors)
                            {
                                errors.Add(a.Exception);
                            }
                        }
                    };
                    victim.Error += (s, a) =>
                    {
                        lock (errors)
                        {
                            errors.Add(a.Exception);
                        }
                    };
                    victim.Wait(victim.Server.Ping());
                    murderer.Wait(murderer.Server.KillClient(target.Address));

                    PubSub.AllowReasonableTimeToPublishAndProcess();

                    Assert.AreEqual(1, Interlocked.CompareExchange(ref i, 0, 0));
                    lock (errors)
                    {
                        foreach (var err in errors)
                        {
                            Console.WriteLine(err.Message);
                        }
                        Assert.AreEqual(0, errors.Count);
                    }
                    Assert.AreEqual(ShutdownType.ServerClosed, victim.ShutdownType);
                }
        }
コード例 #3
0
        private void TestSubscriberNameOnRemote(bool setName)
        {
            string id = Config.CreateUniqueName();

            using (var pub = new RedisConnection(Config.RemoteHost, allowAdmin: true))
                using (var sub = new RedisSubscriberConnection(Config.RemoteHost))
                {
                    List <string> errors = new List <string>();
                    EventHandler <BookSleeve.ErrorEventArgs> errorHandler = (sender, args) =>
                    {
                        lock (errors) errors.Add(args.Exception.Message);
                    };
                    pub.Error += errorHandler;
                    sub.Error += errorHandler;

                    if (setName)
                    {
                        pub.Name = "pub_" + id;
                        sub.Name = "sub_" + id;
                    }
                    int count     = 0;
                    var subscribe = sub.Subscribe("foo" + id, (key, payload) => Interlocked.Increment(ref count));

                    Task pOpen = pub.Open(), sOpen = sub.Open();
                    pub.WaitAll(pOpen, sOpen, subscribe);

                    Assert.AreEqual(0, Interlocked.CompareExchange(ref count, 0, 0), "init message count");
                    pub.Wait(pub.Publish("foo" + id, "hello"));

                    PubSub.AllowReasonableTimeToPublishAndProcess();
                    var clients = setName ? pub.Wait(pub.Server.ListClients()) : null;
                    Assert.AreEqual(1, Interlocked.CompareExchange(ref count, 0, 0), "got message");
                    lock (errors)
                    {
                        foreach (var error in errors)
                        {
                            Console.WriteLine(error);
                        }
                        Assert.AreEqual(0, errors.Count, "zero errors");
                    }
                    if (setName)
                    {
                        Assert.AreEqual(1, clients.Count(x => x.Name == pub.Name), "pub has name");
                        Assert.AreEqual(1, clients.Count(x => x.Name == sub.Name), "sub has name");
                    }
                }
        }