Esempio n. 1
0
        public void AdvancedAMAgatherInfoTestMethod()
        {
            //Setup communicatro stub
            List <MQCommodityWrapper> mqCommodityWrapper = new List <MQCommodityWrapper>();
            List <MQReqWrapper>       mqReqyWrapper      = new List <MQReqWrapper>();
            MQUser mqUser             = new MQUser();
            CommStubStaticReturn comm = new CommStubStaticReturn();

            comm.qAllmarket   = mqCommodityWrapper;
            comm.qAllrequests = mqReqyWrapper;
            comm.quser        = mqUser;

            //Run AMA for a while
            AdvancedAMA agent = new AdvancedAMA(3, 1000, comm);

            agent.enable(true);
            System.Threading.Thread.Sleep(1500);
            agent.enable(false);


            //Verify if AMA has collected the info from the communicator stub
            Assert.IsNotNull(agent.commoditiesInfo);
            Assert.IsNotNull(agent.requestsInfo);
            Assert.IsNotNull(agent.userData);
            Assert.AreEqual(mqCommodityWrapper, agent.commoditiesInfo);
            Assert.AreEqual(mqReqyWrapper, agent.requestsInfo);
            Assert.AreEqual(mqUser, agent.userData);
        }
Esempio n. 2
0
        public void AskCompareTestTrue()
        {
            //Create process that will count each time the AlgoAskCompare condition is "true"
            AlgoCountProcess testProcess = new AlgoCountProcess(agent, comm, commodity);

            testProcess.addCondition(new AlgoAskCompare(10 + 1));
            agent.add(testProcess);

            //Run AMA once
            agent.enable(true);
            System.Threading.Thread.Sleep(1500);
            agent.enable(false);

            //AMA ran once - count should be "1"
            Assert.AreEqual(1, testProcess.count);
        }
Esempio n. 3
0
        public void HasNoActiveRequestTestTrue()
        {
            //Create process that will count each time the AlgoAskCompare condition is "true"
            AlgoCountProcess testProcess = new AlgoCountProcess(agent, comm, commodity);

            testProcess.addCondition(new HasNoActiveRequest());
            testProcess.requestID = -1;
            agent.add(testProcess);

            //Run AMA once
            agent.enable(true);
            System.Threading.Thread.Sleep(1500);
            agent.enable(false);

            //AMA ran once but condition is not met - count should be "0"
            Assert.AreEqual(1, testProcess.count);
        }
        public void MomentumIncreaseTrue()
        {
            //Create process that will count each time the AlgoAskCompare condition is "true"
            AlgoCountProcess         testProcess          = new AlgoCountProcess(agent, comm, commodity);
            HistoryDalImplementation sqlStub              = new SQLserverMomentumStub(true);
            MomentumIncrease         momentumIncreaseCond = new MomentumIncrease(1, 10, 20); momentumIncreaseCond.sql = sqlStub;

            testProcess.addCondition(momentumIncreaseCond);
            agent.add(testProcess);

            //Run AMA once
            agent.enable(true);
            System.Threading.Thread.Sleep(1500);
            agent.enable(false);

            //AMA ran once - count should be "1"
            Assert.AreEqual(1, testProcess.count);
        }
        public void TestAdvancedAMATimer()
        {
            //setup
            int maxReq        = 10;
            int amaUpdateCost = 3;
            int interval      = 1000;

            AdvancedAMA      amaTest   = new AdvancedAMA(maxReq, interval, new CommStubStaticReturn());
            AlgoCountProcess testLogic = new AlgoCountProcess(amaTest, new CommStubStaticReturn(), 0);

            amaTest.add(testLogic);
            amaTest.enable(true);

            //interval*2 because the ama waits the interval once enabled
            //to run the first time
            System.Threading.Thread.Sleep(interval * 2);

            amaTest.enable(false);

            Task.WaitAll();
            Assert.AreEqual(maxReq - amaUpdateCost, testLogic.count);
        }