private bool ProcessInternal(object incomingRealObject)
        {
            if (incomingRealObject is YourConnectionIdEvent yourConnectionId)
            {
                _playerInfo             = new JPlayer();
                PlayerInfo.ConnectionId = yourConnectionId.ConnectionId;
                _connected = true;
                connectWatcher.Signal();
            }
            else if (incomingRealObject is YourPlayerEvent yourPlayerEvent)
            {
                PlayerInfo.Id   = yourPlayerEvent.PlayerId;
                PlayerInfo.Name = yourPlayerEvent.PlayerName;
                _signup         = true;
                Debug.WriteLine("Zwalniam SIGNUP");
                signupWatcher.Signal();
            }
            else
            {
                ProcessWaiters(incomingRealObject);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void Consistently_updated_by_multiple_threads()
        {
            const int itemCount = 10;
            var       items     = new int[itemCount];

            for (var i = 0; i < itemCount; i++)
            {
                items[i] = i;
            }

            var itemsRef = Ref.Of(items.ToArray());

            const int threadCount = 10;
            var       latch       = new CountdownLatch(threadCount);

            for (var i = threadCount - 1; i >= 0; i--)
            {
                var delay  = i * 10;
                var thread = new Thread(() =>
                {
                    Thread.Sleep(delay);
                    itemsRef.Swap(xs => xs.Reverse().ToArray());
                    latch.Signal();
                })
                {
                    IsBackground = true
                };
                thread.Start();
            }

            latch.Wait();

            CollectionAssert.AreEqual(items, itemsRef.Value);
        }
        public void Error(bool systemError)
        {
            Type expected;

            if (systemError)
            {
                expected = typeof(Exception);
                SimpleImpl.throwSystemError = true;
            }
            else
            {
                expected = typeof(TestError);
                SimpleImpl.throwSystemError = false;
            }

            // Test synchronous RPC:
            try
            {
                simpleClient.error();
                Assert.Fail("Expected " + expected.Name + " to be thrown");
            }
            catch (Exception e)
            {
                Assert.AreEqual(expected, e.GetType());
            }

            // Test asynchronous RPC (future):
            var future = new CallFuture <object>();

            simpleClient.error(future);
            try
            {
                future.WaitForResult(2000);
                Assert.Fail("Expected " + expected.Name + " to be thrown");
            }
            catch (Exception e)
            {
                Assert.AreEqual(expected, e.GetType());
            }

            Assert.IsNotNull(future.Error);
            Assert.AreEqual(expected, future.Error.GetType());
            Assert.IsNull(future.Result);

            // Test asynchronous RPC (callback):
            Exception errorRef = null;
            var       latch    = new CountdownLatch(1);

            simpleClient.error(new CallbackCallFuture <object>(
                                   result => Assert.Fail("Expected " + expected.Name),
                                   exception =>
            {
                errorRef = exception;
                latch.Signal();
            }));

            Assert.IsTrue(latch.Wait(2000), "Timed out waiting for error");
            Assert.IsNotNull(errorRef);
            Assert.AreEqual(expected, errorRef.GetType());
        }
Ejemplo n.º 4
0
 public void Start(String ip, int port, CountdownLatch latch)
 {
     try
     {
         _webapp = WebApp.Start <Startup>(String.Format("http://{0}:{1}", ip, port));
         PacChatServer.GetServer().Logger.Info("Bind success. REST Server is listening on " + ip + ":" + port);
         latch.Signal();
     } catch (Exception e)
     {
         PacChatServer.GetServer().Logger.Error(e);
     }
 }
Ejemplo n.º 5
0
        public void Error()
        {
            // Test synchronous RPC:
            try
            {
                simpleClient.error();
                Assert.Fail("Expected " + typeof(TestError).Name + " to be thrown");
            }
            catch (TestError)
            {
                // Expected
            }
            catch (Exception e)
            {
                Assert.Fail("Unexpected error: " + e);
            }

            // Test asynchronous RPC (future):
            var future = new CallFuture <object>();

            simpleClient.error(future);
            try
            {
                future.WaitForResult(2000);
                Assert.Fail("Expected " + typeof(TestError).Name + " to be thrown");
            }
            catch (TestError)
            {
            }

            Assert.IsNotNull(future.Error);
            Assert.AreEqual(typeof(TestError), future.Error.GetType());
            Assert.IsNull(future.Result);

            // Test asynchronous RPC (callback):
            Exception errorRef = null;
            var       latch    = new CountdownLatch(1);

            simpleClient.error(new CallbackCallFuture <object>(
                                   result => Assert.Fail("Expected " + typeof(TestError).Name),
                                   exception =>
            {
                errorRef = exception;
                latch.Signal();
            }));

            Assert.IsTrue(latch.Wait(2000), "Timed out waiting for error");
            Assert.IsNotNull(errorRef);
            Assert.AreEqual(typeof(TestError), errorRef.GetType());
        }
Ejemplo n.º 6
0
        //[Test]
        public void PerformanceTest()
        {
            const int  threadCount   = 8;
            const long runTimeMillis = 10 * 1000L;


            long rpcCount = 0;

            int[] runFlag = { 1 };

            var startLatch = new CountdownLatch(threadCount);

            for (int ii = 0; ii < threadCount; ii++)
            {
                new Thread(() =>
                {
                    {
                        try
                        {
                            startLatch.Signal();
                            startLatch.Wait(2000);

                            while (Interlocked.Add(ref runFlag[0], 0) == 1)
                            {
                                Interlocked.Increment(ref rpcCount);
                                Assert.AreEqual("Hello, World!", simpleClient.hello("World!"));
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    }
                }).Start();
            }

            startLatch.Wait(2000);
            Thread.Sleep(2000);
            Interlocked.Exchange(ref runFlag[0], 1);

            string results = "Completed " + rpcCount + " RPCs in " + runTimeMillis +
                             "ms => " + ((rpcCount / (double)runTimeMillis) * 1000) + " RPCs/sec, " +
                             (runTimeMillis / (double)rpcCount) + " ms/RPC.";

            Debug.WriteLine(results);
        }
Ejemplo n.º 7
0
        public override object Respond(Message message, object request)
        {
            if (message.Name == "send")
            {
                var genericRecord = (GenericRecord)((GenericRecord)request)["message"];

                return("Sent message to [" + genericRecord["to"] +
                       "] from [" + genericRecord["from"] + "] with body [" +
                       genericRecord["body"] + "]");
            }
            if (message.Name == "fireandforget")
            {
                allMessages.Signal();
                return(null);
            }

            throw new NotSupportedException();
        }
            public override object Respond(Message message, object request)
            {
                if (message.Name == "hello")
                {
                    string greeting = ((GenericRecord)request)["greeting"].ToString();
                    if (greeting == "wait")
                    {
                        // Step 3a:
                        waitLatch.Signal();

                        // Step 3b:
                        ackLatch.Wait();
                    }
                    return(greeting);
                }
                if (message.Name == "ack")
                {
                    ackLatch.Signal();
                }

                throw new NotSupportedException();
            }
Ejemplo n.º 9
0
        public void TaskManagerTest()
        {
            using (var host = new ServiceHost(typeof(MessageQueue)))
            {
                var binding = new NetTcpBinding();
                binding.TransactionFlow = true;
                binding.TransactionProtocol = TransactionProtocol.WSAtomicTransactionOctober2004;
                binding.TransferMode = TransferMode.Streamed;

                host.AddServiceEndpoint(
                    typeof(IMessageQueue),
                    binding,
                    c_queueUrl
                );

                host.Open();

                var cf = new ChannelFactory<IAsyncMessageQueue>(binding, c_queueUrl);

                var queuesrv = cf.CreateChannel();
                string qn = Guid.NewGuid().ToString("N");

                const int mcnt = 3;

                for (int i = 0; i < mcnt; i++)
                {
                    queuesrv.PutMessage(qn, new Message(), TimeSpan.MaxValue);
                }

                var latch = new CountdownLatch(mcnt);

                TaskManager tm = new TaskManager(() => cf.CreateChannel());
                tm.Tasks.Add(
                    new TaskInfo
                    {
                        Queue = qn,
                        Task = new TestTask(() => latch.Signal()),
                        VisibilitySpan = TimeSpan.FromMinutes(1),
                        MaxInstances = mcnt,
                        PollSpan =
                        TimeSpan.FromMilliseconds(500)
                    });

                tm.Start();

                Assert.IsTrue(latch.Wait(6000));
            }
        }
Ejemplo n.º 10
0
 public void Signal()
 {
     _countdownLatch.Signal();
 }
Ejemplo n.º 11
0
 public override void fireandforget(org.apache.avro.test.Message message)
 {
     allMessages.Signal();
 }
Ejemplo n.º 12
0
 public virtual void OnBindSuccess(IPEndPoint address)
 {
     latch.Signal();
 }