Example #1
0
        public void Fire(BaseRtmResponse response)
        {
            AllMessages?.Invoke(this, new RtmMessageEventArgs <BaseRtmResponse>(response));

            switch (response)
            {
            case HelloResponse helloResponse:
                HelloMessage?.Invoke(this, new RtmMessageEventArgs <HelloResponse>(helloResponse));
                break;

            case PongResponse pongResponse:
                PongMessage?.Invoke(this, new RtmMessageEventArgs <PongResponse>(pongResponse));
                break;

            case UserTypingResponse userTypingResponse:
                UserTypingMessage?.Invoke(this, new RtmMessageEventArgs <UserTypingResponse>(userTypingResponse));
                break;

            case BaseMessageResponse messageResponse:
                switch (messageResponse)
                {
                case BotMessageResponse botMessageResponse:
                    BotMessage?.Invoke(this, new RtmMessageEventArgs <BotMessageResponse>(botMessageResponse));
                    break;

                default:
                    UserMessage?.Invoke(this, new RtmMessageEventArgs <UserMessageResponse>(messageResponse));
                    break;
                }
                break;

            default:
                throw new NotImplementedException();
            }
        }
        public void PongSentReceivedTest()
        {
            var msg = new PongMessage
            {
                FarAddress     = _address2,
                PingMdc        = new byte[] { 1, 2, 3 },
                ExpirationTime = (long)(new Timestamper().EpochSeconds + 1200),
                FarPublicKey   = _privateKey2.PublicKey
            };

            _discoveryHandlers[0].SendMessage(msg);
            Thread.Sleep(200);
            _discoveryManagers[1].Received(1).OnIncomingMessage(Arg.Is <DiscoveryMessage>(x => x.MessageType == MessageType.Pong));

            var msg2 = new PongMessage
            {
                FarAddress     = _address,
                PingMdc        = new byte[] { 1, 2, 3 },
                ExpirationTime = (long)(new Timestamper().EpochSeconds + 1200),
                FarPublicKey   = _privateKey.PublicKey
            };

            _discoveryHandlers[1].SendMessage(msg2);
            Thread.Sleep(200);
            _discoveryManagers[0].Received(1).OnIncomingMessage(Arg.Is <DiscoveryMessage>(x => x.MessageType == MessageType.Pong));
        }
        public void Pong()
        {
            var    msg  = new PongMessage();
            string text = msg.Write();

            Assert.AreEqual("3", text);
        }
Example #4
0
        public void GetBytesTest()
        {
            PongMessage message = new PongMessage(12);

            byte[] actual = message.GetBytes();
            Assert.Equal("0013000c000000000000000000000000", actual.ToHex());
        }
        public void ProcessPongMessage(PongMessage discoveryMessage)
        {
            PingMessage sentPingMessage = Interlocked.Exchange(ref _lastSentPing, null);

            if (sentPingMessage == null)
            {
                return;
            }

            if (Bytes.AreEqual(sentPingMessage.Mdc, discoveryMessage.PingMdc))
            {
                _receivedPong = true;
                NodeStats.AddNodeStatsEvent(NodeStatsEventType.DiscoveryPongIn);
                if (IsBonded)
                {
                    UpdateState(NodeLifecycleState.Active);
                }

                RefreshNodeContactTime();
            }
            else
            {
                // ignore spoofed message
                _receivedPong = false;
                return;
            }
        }
Example #6
0
        public void Can_request_and_reply_and_then_unsubscribe()
        {
            using (var bus = container.Resolve <IStartableServiceBus>())
            {
                bus.Start();

                using (bus.AddInstanceSubscription(this))
                {
                    bus.Send(bus.Endpoint, new PingMessage());

                    handle.WaitOne(TimeSpan.FromSeconds(30), false);

                    Assert.NotNull(message);
                }

                handle.Reset();

                message = null;
                container.Resolve <ITransport>().MessageArrived += m => handle.Set();
                bus.Send(bus.Endpoint, new PingMessage());

                handle.WaitOne(TimeSpan.FromSeconds(30), false);

                Assert.Null(message);
            }
        }
Example #7
0
        private async Task should_pong_monitor(
            [Frozen] Mock <IMonitoringFactory> monitoringFactory,
            Mock <IPingPongMonitor> pingPongMonitor,
            Mock <IWebSocketClient> webSocket,
            SlackConnection slackConnection)
        {
            // given
            monitoringFactory
            .Setup(x => x.CreatePingPongMonitor())
            .Returns(pingPongMonitor.Object);

            var connectionInfo = new ConnectionInformation {
                WebSocket = webSocket.Object
            };
            await slackConnection.Initialise(connectionInfo);

            var inboundMessage = new PongMessage
            {
                Timestamp = DateTime.Now
            };

            // when
            webSocket.Raise(x => x.OnMessage += null, null, inboundMessage);

            // then
            pingPongMonitor.Verify(x => x.Pong(), Times.Once);
        }
        public void The_pipeline_should_have_insertable_items()
        {
            // two consumers, one for each type of message

            IndiscriminantConsumer <PingMessage> pingConsumer = new IndiscriminantConsumer <PingMessage>();
            IndiscriminantConsumer <PongMessage> pongConsumer = new IndiscriminantConsumer <PongMessage>();

            UnsubscribeAction pingToken = _pipeline.Subscribe(pingConsumer);
            UnsubscribeAction pongToken = _pipeline.Subscribe(pongConsumer);

            PipelineViewer.Trace(_pipeline);

            PingMessage pingMessage = new PingMessage();
            PongMessage pongMessage = new PongMessage();

            _pipeline.Dispatch(pingMessage, accept => true);
            _pipeline.Dispatch(pongMessage, accept => true);

            Assert.AreEqual(pingMessage, pingConsumer.Consumed);
            Assert.AreEqual(pongMessage, pongConsumer.Consumed);

            pingToken();
            pongToken();

            PipelineViewer.Trace(_pipeline);
        }
        public async Task PongSentReceivedTest()
        {
            var msg = new PongMessage
            {
                FarAddress     = _address2,
                PingMdc        = new byte[] { 1, 2, 3 },
                ExpirationTime = Timestamper.Default.UnixTime.SecondsLong + 1200,
                FarPublicKey   = _privateKey2.PublicKey
            };

            _discoveryHandlers[0].SendMessage(msg);
            await SleepWhileWaiting();

            _discoveryManagersMocks[1].Received(1).OnIncomingMessage(Arg.Is <DiscoveryMessage>(x => x.MessageType == MessageType.Pong));

            var msg2 = new PongMessage
            {
                FarAddress     = _address,
                PingMdc        = new byte[] { 1, 2, 3 },
                ExpirationTime = Timestamper.Default.UnixTime.SecondsLong + 1200,
                FarPublicKey   = _privateKey.PublicKey
            };

            _discoveryHandlers[1].SendMessage(msg2);
            await SleepWhileWaiting();

            _discoveryManagersMocks[0].Received(1).OnIncomingMessage(Arg.Is <DiscoveryMessage>(x => x.MessageType == MessageType.Pong));
        }
Example #10
0
        private async Task should_raise_event(
            Mock <IWebSocketClient> webSocket,
            SlackConnection slackConnection)
        {
            // given
            var connectionInfo = new ConnectionInformation {
                WebSocket = webSocket.Object
            };
            await slackConnection.Initialise(connectionInfo);

            DateTime lastTimestamp = DateTime.MinValue;

            slackConnection.OnPong += timestamp =>
            {
                lastTimestamp = timestamp;
                return(Task.CompletedTask);
            };

            var inboundMessage = new PongMessage
            {
                Timestamp = DateTime.Now
            };

            // when
            webSocket.Raise(x => x.OnMessage += null, null, inboundMessage);

            // then
            lastTimestamp.ShouldBe(inboundMessage.Timestamp);
        }
		public void The_pipeline_should_have_insertable_items()
		{
			// two consumers, one for each type of message

			IndiscriminantConsumer<PingMessage> pingConsumer = new IndiscriminantConsumer<PingMessage>();
			IndiscriminantConsumer<PongMessage> pongConsumer = new IndiscriminantConsumer<PongMessage>();

			UnsubscribeAction pingToken = _pipeline.Subscribe(pingConsumer);
			UnsubscribeAction pongToken = _pipeline.Subscribe(pongConsumer);

			PipelineViewer.Trace(_pipeline);

			PingMessage pingMessage = new PingMessage();
			PongMessage pongMessage = new PongMessage();

			_pipeline.Dispatch(pingMessage, accept => true);
			_pipeline.Dispatch(pongMessage, accept => true);

			Assert.AreEqual(pingMessage, pingConsumer.Consumed);
			Assert.AreEqual(pongMessage, pongConsumer.Consumed);

			pingToken();
			pongToken();

			PipelineViewer.Trace(_pipeline);
		}
Example #12
0
    void OnReadyMessage(NetworkMessage msg)
    {
        ReadyMessage ready = msg.ReadMessage <ReadyMessage>();

        if (PongManager.instance.AuthUser(ready.user_id, ready.token))
        {
            Player player = findPlayer(msg.conn.connectionId);

            if (player != null)
            {
                player.user_id = ready.user_id;
                player.token   = ready.token;

                if (hostId == 0)
                {
                    hostId = player.connectionId;
                }
                else
                {
                    guestId = player.connectionId;
                }

                onPlayerJoined(player);

                PongMessage.SendStart(player.connectionId, hostId == player.connectionId);
            }
        }
    }
Example #13
0
    public override void OnStartClient()
    {
        CanvasScaler scaler = transform.GetComponent <CanvasScaler>();

        Bar.deltaScaler = scaler.referenceResolution.y / Screen.height;

        Transform panel = transform.Find("Panel");

        oppBar = panel.Find("OppBar").GetComponent <Bar>();
        ball   = panel.Find("Ball").GetComponent <Ball>();
        ball.Reset();
        mainMenu = panel.GetComponent <LobbyMainMenu>();

        if (NetworkClient.allClients.Count > 0)
        {
            NetworkClient client = NetworkClient.allClients[0];
            client.RegisterHandler(PongMsgType.Start, OnStartMessage);
            PongMessage.client = client;
        }

        string user_id, token;

        PongManager.GetUserIdAndToken(out user_id, out token);
        PongMessage.SendReady(user_id, token);
    }
Example #14
0
        private static Task <PongMessage> SendPingAsync(PingMessage pingMessage)
        {
            var tcs = new TaskCompletionSource <PongMessage>();

            IConsumer.MessageReceivedHandler del = delegate(object sender, Message message) {
                object obj = Serializer.Deserialize(message.Content);
                if (obj.GetType().Equals(typeof(PongMessage)))
                {
                    PongMessage pongMessage = (PongMessage)obj;
                    if (pongMessage.PingId.Equals(pingMessage.PingId))
                    {
                        Console.WriteLine(string.Format("Pong recibido: {0}", pongMessage.PingId.Id));
                        tcs.TrySetResult(pongMessage);
                    }
                }
            };
            consumer.MessageReceived += del;
            Task <PongMessage> ret = tcs.Task;

            delegates.Add(ret, del);
            Console.WriteLine(string.Format("Enviando Ping: {0}...", pingMessage.PingId.Id));
            producer.SendMessage(new Message(Serializer.Serialize(pingMessage)));
            Console.WriteLine(string.Format("Ping enviado: {0}", pingMessage.PingId.Id));
            return(ret);
        }
Example #15
0
        public void ParseTest()
        {
            PongMessage message = new PongMessage();

            message.ParsePayload("000c000000000000000000000000".HexToByteArray());

            Assert.Equal(12, message.DataLength);
        }
Example #16
0
 public void Handle(PongMessage message, IDocumentSession session)
 {
     session.Store(new ReceivedTrack
     {
         Id          = message.Id,
         MessageType = "PongMessage"
     });
 }
Example #17
0
    private void OnMessageReceived(byte[] message)
    {
        PongMessage pongMessage = new PongMessage(message, networkTimeService.NetworkTimestampMs);

        LastPing = pongMessage.RoundTripTime;

        //DIContainer.Logger.Debug(string.Format("Received pong message. RTT: {0}", LastPing));
    }
Example #18
0
        public void SendPong(PingMessage discoveryMessage)
        {
            PongMessage msg = _discoveryMessageFactory.CreateOutgoingMessage <PongMessage>(ManagedNode);

            msg.PingMdc = discoveryMessage.Mdc;
            _discoveryManager.SendMessage(msg);
            NodeStats.AddNodeStatsEvent(NodeStatsEventType.DiscoveryPongOut);
        }
Example #19
0
        public void Consume(PongMessage message)
        {
            var times = Interlocked.Increment(ref Count);

            if (times == PerformanceTester.Times)
            {
                ReceivedAll.SetResult(true);
            }
        }
Example #20
0
        public void I_should_be_able_to_retrieve_a_single_message_by_position()
        {
            PingMessage ping = new PingMessage();
            PongMessage pong = new PongMessage();

            MessageGroup group = MessageGroup.Build <MessageGroup>()
                                 .Add(ping)
                                 .Add(pong);

            PingMessage thePing = group.Get <PingMessage>(0);
        }
Example #21
0
        public void Can_do_roundtrip()
        {
            PongMessage           msg        = PongMessage.Instance;
            PongMessageSerializer serializer = new PongMessageSerializer();

            byte[] serialized = serializer.Serialize(msg);
            Assert.AreEqual(0xc0, serialized[0]);
            PongMessage deserialized = serializer.Deserialize(serialized);

            Assert.NotNull(deserialized);
        }
Example #22
0
        public static PingMessage SendPing()
        {
            PingMessage        pingMessage = PingService.CreatePingMessage();
            Task <PongMessage> task        = SendPingAsync(pingMessage);

            task.Wait(60000);
            PongMessage pongMessage = task.Result;

            consumer.MessageReceived -= delegates[task];
            return(pingMessage);
        }
        public void ProcessPongMessage(PongMessage discoveryMessage)
        {
            if (_isPongExpected)
            {
                NodeStats.AddNodeStatsEvent(NodeStatsEventType.DiscoveryPongIn);
                RefreshNodeContactTime();

                UpdateState(NodeLifecycleState.Active);
            }

            _isPongExpected = false;
        }
Example #24
0
        public void The_wrong_type_of_message_should_not_blow_up_the_test()
        {
            var consumer = new IndiscriminantConsumer <PingMessage>();

            _pipeline.ConnectInstance(consumer);

            var message = new PongMessage();

            _pipeline.Dispatch(message);

            Assert.AreEqual(null, consumer.Consumed);
        }
Example #25
0
        public void I_should_be_able_to_split_a_bunch_of_messages_from_a_group()
        {
            PingMessage ping = new PingMessage();
            PongMessage pong = new PongMessage();

            MessageGroup group = MessageGroup.Build <MessageGroup>()
                                 .Add(ping)
                                 .Add(pong);

            object[] items = group.ToArray();

            Assert.That(items.Length, Is.EqualTo(2));
        }
Example #26
0
        public void I_should_get_an_exception_when_I_try_to_get_an_unmatched_type()
        {
            PingMessage ping = new PingMessage();
            PongMessage pong = new PongMessage();

            MessageGroup group = MessageGroup.Build <MessageGroup>()
                                 .Add(ping)
                                 .Add(pong);

            Assert.Throws <ArgumentException>(() =>
            {
                PingMessage thePing = group.Get <PingMessage>(1);
            });
        }
        public void SendPong(PingMessage discoveryMessage)
        {
            PongMessage msg = _discoveryMessageFactory.CreateOutgoingMessage <PongMessage>(ManagedNode);

            msg.PingMdc = discoveryMessage.Mdc;

            _discoveryManager.SendMessage(msg);
            NodeStats.AddNodeStatsEvent(NodeStatsEventType.DiscoveryPongOut);
            _sentPong = true;
            if (IsBonded)
            {
                UpdateState(NodeLifecycleState.Active);
            }
        }
Example #28
0
        public void One()
        {
            PingMessage ping = new PingMessage();
            PongMessage pong = new PongMessage();

            MessageGroup group = MessageGroup.Build <MessageGroup>()
                                 .Add(ping)
                                 .Add(pong);

            Assert.That(group.Count, Is.EqualTo(2));

            Assert.That(group[0], Is.TypeOf(typeof(PingMessage)));
            Assert.That(group[1], Is.TypeOf(typeof(PongMessage)));
        }
    void FixedUpdate()
    {
        if (!localPlayer)
        {
            return;
        }

        if (Mathf.Abs(lastBarX - transform.localPosition.x) > 1)
        {
            lastBarX = transform.localPosition.x;

            PongMessage.SendBarPos(transform.localPosition.x, Time.realtimeSinceStartup);
        }
    }
Example #30
0
        public void I_should_be_able_to_split_the_group_into_individual_messages_and_handle_each_one_on_its_own()
        {
            IServiceBus bus = MockRepository.GenerateMock <IServiceBus>();

            PingMessage ping = new PingMessage();
            PongMessage pong = new PongMessage();

            MessageGroup group = MessageGroup.Build <MessageGroup>()
                                 .Add(ping)
                                 .Add(pong);

            bus.Expect(x => x.Publish(ping));
            bus.Expect(x => x.Publish(pong));

            group.Split(bus);

            bus.VerifyAllExpectations();
        }
Example #31
0
		public void Echo_reply_should_work()
		{
			var echoConsumer = new TestMessageConsumer<PingMessage>();
			RemoteBus.Subscribe(echoConsumer);

			var replyConsumer = new TestMessageConsumer<PongMessage>();
			LocalBus.Subscribe(replyConsumer);

			var echoMessage = new PingMessage();
			LocalBus.Publish(echoMessage);

			echoConsumer.ShouldHaveReceivedMessage(echoMessage, _timeout);

			PongMessage replyMessage = new PongMessage(echoMessage.CorrelationId);
			RemoteBus.Publish(replyMessage);

			replyConsumer.ShouldHaveReceivedMessage(replyMessage, _timeout);
		}
        public void SendPong(PingMessage discoveryMessage)
        {
            if (!ManagedNode.Address.Address.MapToIPv4().Equals(discoveryMessage.FarAddress.Address.MapToIPv4()))
            {
                _logger.Error($"Sending message to a different address: {ManagedNode.Address} vs {discoveryMessage.FarAddress}");
            }

            PongMessage msg = _discoveryMessageFactory.CreateOutgoingMessage <PongMessage>(ManagedNode);

            msg.PingMdc = discoveryMessage.Mdc;
            _discoveryManager.SendMessage(msg);
            NodeStats.AddNodeStatsEvent(NodeStatsEventType.DiscoveryPongOut);
            _sentPong = true;
            if (IsBonded)
            {
                UpdateState(NodeLifecycleState.Active);
            }
        }
Example #33
0
        public void PingPong()
        {
            var raws = new[] {
                "PING GDN-7T4JZ11"
            };

            var msg = MessageAssert.TypeAndRoundTrip<PingMessage>(raws[0]);
            Assert.AreEqual("GDN-7T4JZ11", msg.Target, "Target");

            var pong = new PongMessage { Target = msg.Target };
            Assert.AreEqual("PONG GDN-7T4JZ11", pong.ToString(), "Pong Reply");
        }
Example #34
0
 public void Handle(PongMessage pong)
 {
     Console.WriteLine("Received pong message");
 }
		public void A_component_should_be_subscribed_to_multiple_messages_on_the_pipeline()
		{
			PingPongConsumer consumer = MockRepository.GenerateMock<PingPongConsumer>();

			_builder.Expect(x => x.GetInstance<PingPongConsumer>()).Return(consumer).Repeat.Twice();

			_pipeline.Subscribe<PingPongConsumer>();

			PipelineViewer.Trace(_pipeline);

			PingMessage ping = new PingMessage();
			consumer.Expect(x => x.Consume(ping));
			_pipeline.Dispatch(ping);

			PongMessage pong = new PongMessage(ping.CorrelationId);
			consumer.Expect(x => x.Consume(pong));
			_pipeline.Dispatch(pong);

			_builder.VerifyAllExpectations();
			consumer.VerifyAllExpectations();
		}
		public void The_wrong_type_of_message_should_not_blow_up_the_test()
		{
			IndiscriminantConsumer<PingMessage> consumer = new IndiscriminantConsumer<PingMessage>();

			_pipeline.Subscribe(consumer);

			PongMessage message = new PongMessage();

			_pipeline.Dispatch(message);

			Assert.AreEqual(null, consumer.Consumed);
		}