llRequestAgentData() public method

public llRequestAgentData ( string id, int data ) : OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString
id string
data int
return OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString
Ejemplo n.º 1
0
        public void TestLlRequestAgentDataOnline()
        {
            TestHelpers.InMethod();
//            TestHelpers.EnableLogging();

            UUID userId = TestHelpers.ParseTail(0x1);

            UserAccount ua1 = UserAccountHelpers.CreateUserWithInventory(m_scene, userId);

            SceneObjectPart part = SceneHelpers.AddSceneObject(m_scene).RootPart;
            TaskInventoryItem scriptItem = TaskInventoryHelpers.AddScript(m_scene.AssetService, part);

            LSL_Api apiGrp1 = new LSL_Api();
            apiGrp1.Initialize(m_engine, part, scriptItem, null);

            // Initially long timeout to test cache
            apiGrp1.LlRequestAgentDataCacheTimeoutMs = 20000;

            // Offline test
            {
                apiGrp1.llRequestAgentData(userId.ToString(), ScriptBaseClass.DATA_ONLINE);

                Assert.That(m_engine.PostedEvents.ContainsKey(scriptItem.ItemID));

                List<EventParams> events = m_engine.PostedEvents[scriptItem.ItemID];
                Assert.That(events.Count, Is.EqualTo(1));
                EventParams eventParams = events[0];
                Assert.That(eventParams.EventName, Is.EqualTo("dataserver"));

                string data = eventParams.Params[1].ToString();
                Assert.AreEqual(0, int.Parse(data));

                m_engine.PostedEvents.Clear();
            }

            // Online test.  Should get the 'wrong' result because of caching.
            ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, ua1);

            {
                apiGrp1.llRequestAgentData(userId.ToString(), ScriptBaseClass.DATA_ONLINE);

                Assert.That(m_engine.PostedEvents.ContainsKey(scriptItem.ItemID));

                List<EventParams> events = m_engine.PostedEvents[scriptItem.ItemID];
                Assert.That(events.Count, Is.EqualTo(1));
                EventParams eventParams = events[0];
                Assert.That(eventParams.EventName, Is.EqualTo("dataserver"));

                string data = eventParams.Params[1].ToString();
                Assert.AreEqual(0, int.Parse(data));

                m_engine.PostedEvents.Clear();
            }

            apiGrp1.LlRequestAgentDataCacheTimeoutMs = 1;

            // Make absolutely sure that we should trigger cache timeout.
            Thread.Sleep(apiGrp1.LlRequestAgentDataCacheTimeoutMs + 1);

            {
                apiGrp1.llRequestAgentData(userId.ToString(), ScriptBaseClass.DATA_ONLINE);

                Assert.That(m_engine.PostedEvents.ContainsKey(scriptItem.ItemID));

                List<EventParams> events = m_engine.PostedEvents[scriptItem.ItemID];
                Assert.That(events.Count, Is.EqualTo(1));
                EventParams eventParams = events[0];
                Assert.That(eventParams.EventName, Is.EqualTo("dataserver"));

                string data = eventParams.Params[1].ToString();
                Assert.AreEqual(1, int.Parse(data));

                m_engine.PostedEvents.Clear();
            }

            m_scene.CloseAgent(userId, false);

            Thread.Sleep(apiGrp1.LlRequestAgentDataCacheTimeoutMs + 1 + 1);

            {
                apiGrp1.llRequestAgentData(userId.ToString(), ScriptBaseClass.DATA_ONLINE);

                Assert.That(m_engine.PostedEvents.ContainsKey(scriptItem.ItemID));

                List<EventParams> events = m_engine.PostedEvents[scriptItem.ItemID];
                Assert.That(events.Count, Is.EqualTo(1));
                EventParams eventParams = events[0];
                Assert.That(eventParams.EventName, Is.EqualTo("dataserver"));

                string data = eventParams.Params[1].ToString();
                Assert.AreEqual(0, int.Parse(data));

                m_engine.PostedEvents.Clear();
            }
        }