public void TestRawBytesSideChannel()
        {
            var str1 = "Test string";
            var str2 = "Test string, second";

            var strSender   = new RawBytesChannel(new Guid("9a5b8954-4f82-11ea-b238-784f4387d1f7"));
            var strReceiver = new RawBytesChannel(new Guid("9a5b8954-4f82-11ea-b238-784f4387d1f7"));
            var dictSender  = new Dictionary <Guid, SideChannel> {
                { strSender.ChannelId, strSender }
            };
            var dictReceiver = new Dictionary <Guid, SideChannel> {
                { strReceiver.ChannelId, strReceiver }
            };

            strSender.SendRawBytes(Encoding.ASCII.GetBytes(str1));
            strSender.SendRawBytes(Encoding.ASCII.GetBytes(str2));

            byte[] fakeData = SideChannelUtils.GetSideChannelMessage(dictSender);
            SideChannelUtils.ProcessSideChannelData(dictReceiver, fakeData);

            var messages = strReceiver.GetAndClearReceivedMessages();

            Assert.AreEqual(messages.Count, 2);
            Assert.AreEqual(Encoding.ASCII.GetString(messages[0]), str1);
            Assert.AreEqual(Encoding.ASCII.GetString(messages[1]), str2);
        }
Exemple #2
0
        /// <summary>
        /// Performs a single environment update to the Academy, and Agent
        /// objects within the environment.
        /// </summary>
        public void EnvironmentStep()
        {
            if (!m_HadFirstReset)
            {
                ForcedFullReset();
            }

            AgentPreStep?.Invoke(m_StepCount);

            m_StepCount      += 1;
            m_TotalStepCount += 1;
            AgentIncrementStep?.Invoke();

            using (TimerStack.Instance.Scoped("AgentSendState"))
            {
                AgentSendState?.Invoke();
            }

            using (TimerStack.Instance.Scoped("DecideAction"))
            {
                DecideAction?.Invoke();
            }

            // If the communicator is not on, we need to clear the SideChannel sending queue
            if (!IsCommunicatorOn)
            {
                SideChannelUtils.GetSideChannelMessage();
            }

            using (TimerStack.Instance.Scoped("AgentAct"))
            {
                AgentAct?.Invoke();
            }
        }
        public void TestFloatPropertiesSideChannel()
        {
            var k1        = "gravity";
            var k2        = "length";
            int wasCalled = 0;

            var propA        = new FloatPropertiesChannel();
            var propB        = new FloatPropertiesChannel();
            var dictReceiver = new Dictionary <Guid, SideChannel> {
                { propA.ChannelId, propA }
            };
            var dictSender = new Dictionary <Guid, SideChannel> {
                { propB.ChannelId, propB }
            };

            propA.RegisterCallback(k1, f => { wasCalled++; });
            var tmp = propB.GetPropertyWithDefault(k2, 3.0f);

            Assert.AreEqual(tmp, 3.0f);
            propB.SetProperty(k2, 1.0f);
            tmp = propB.GetPropertyWithDefault(k2, 3.0f);
            Assert.AreEqual(tmp, 1.0f);

            byte[] fakeData = SideChannelUtils.GetSideChannelMessage(dictSender);
            SideChannelUtils.ProcessSideChannelData(dictReceiver, fakeData);

            tmp = propA.GetPropertyWithDefault(k2, 3.0f);
            Assert.AreEqual(tmp, 1.0f);

            Assert.AreEqual(wasCalled, 0);
            propB.SetProperty(k1, 1.0f);
            Assert.AreEqual(wasCalled, 0);
            fakeData = SideChannelUtils.GetSideChannelMessage(dictSender);
            SideChannelUtils.ProcessSideChannelData(dictReceiver, fakeData);
            Assert.AreEqual(wasCalled, 1);

            var keysA = propA.ListProperties();

            Assert.AreEqual(2, keysA.Count);
            Assert.IsTrue(keysA.Contains(k1));
            Assert.IsTrue(keysA.Contains(k2));

            var keysB = propA.ListProperties();

            Assert.AreEqual(2, keysB.Count);
            Assert.IsTrue(keysB.Contains(k1));
            Assert.IsTrue(keysB.Contains(k2));
        }
        public void TestIntegerSideChannel()
        {
            var intSender   = new TestSideChannel();
            var intReceiver = new TestSideChannel();
            var dictSender  = new Dictionary <Guid, SideChannel> {
                { intSender.ChannelId, intSender }
            };
            var dictReceiver = new Dictionary <Guid, SideChannel> {
                { intReceiver.ChannelId, intReceiver }
            };

            intSender.SendInt(4);
            intSender.SendInt(5);
            intSender.SendInt(6);

            byte[] fakeData = SideChannelUtils.GetSideChannelMessage(dictSender);
            SideChannelUtils.ProcessSideChannelData(dictReceiver, fakeData);

            Assert.AreEqual(intReceiver.messagesReceived[0], 4);
            Assert.AreEqual(intReceiver.messagesReceived[1], 5);
            Assert.AreEqual(intReceiver.messagesReceived[2], 6);
        }