Example #1
0
        static void Main(string[] args)
        {
            Console.Title = "ConcurrentClient1Demo";
            "Starting the Execution of Client Main".title();
            "Implemented in C# using .Net Framework and Visual Studio 2015 - Req#1".title();
            try
            {
                Client myClient1 = new Client(true);
                string clistr    = "http://localhost:8080/ClientIService";
                string Repostr   = "http://localhost:8080/RepoIService";
                string Thstr     = "http://localhost:8080/TestHarnessIService";
                myClient1.CreateClientRecvChannel(clistr);
                Thread.Sleep(5000);
                /* Send all the code to be tested to the Repository */
                string filepath = Path.GetFullPath(myClient1.ToSendPath);
                Console.WriteLine("\nRetrieving files from {0}\n", filepath);
                string[] files = Directory.GetFiles(filepath);
                "Client is sending the Repository server before sending the Test Request to the Test Harness- Req#6".title();
                foreach (string file in files)
                {
                    string filename = Path.GetFileName(file);
                    //   Console.WriteLine("file retrieved is {0} \n", filename);
                    string str = "Sending the retireved test library " + filename + "to Repository using filestream service - Req#6";
                    str.title();
                    myClient1.uploadFile(filename, Repostr);
                }
                // this sleep ensures that the code to be tested files
                // are sent to the Repository before the Testharness starts
                // copying them to local directory. Removal of this sleep
                // might result in testharness unable to load the dll files
                // and return the result message as file not loaded.
                Thread.Sleep(10000);
                Message msg = myClient1.buildTestMessage(clistr, Thstr);
                "Sending the test Request from concurrent client 2 to TestHarness - Req#4,6".title();
                hrt.Start();
                /* start the timer */
                myClient1.sendTestRequest(msg);

                /* Wait for the TestHarness to complete the execution before
                 * sending the query to the repository. This sleep ensures that
                 * TestHarness completes the execution before the client executes
                 * Query logs. Removal of this sleep might result in repository
                 * returning empty message as it has  not yet stored logs. */
                Thread.Sleep(20000);
                hrt.Start();
                myClient1.makeQuery("test1", clistr, Repostr);
            }
            catch (Exception ex)
            {
                Console.Write("\n\n  {0}\n\n", ex.Message);
            }
            Console.ReadLine();
        }
Example #2
0
        public void SendLogToRepo(string threadName, string tempLogPath, MessageClient msgSenderRepo, MessageServer msgReciever)
        {
            int        trycount = 0;
            HiResTimer hrt      = new HiResTimer();

            while (trycount <= 5)
            {
                trycount++;
                Console.WriteLine("\n({0})Sending logs to repository...", threadName);
                Message msgToRepo = msgSenderRepo.SetupUploadMessageToRepo(threadName, tempLogPath, "http://localhost:4140/ICommService/BasicHttp", "http://localhost:8180/ICommService/BasicHttp");

                msgSenderRepo.channel.PostMessage(msgToRepo);
                Console.WriteLine("\n({0})Waiting for message from repository...", threadName);
                hrt.Start();
                Message msgFromRepo = msgReciever.TryGetMessage("Repository", threadName);
                hrt.Stop();
                Console.WriteLine("");
                Console.WriteLine("\n({0})Recieved message from repository in {0} microsec.", threadName, hrt.ElapsedMicroseconds);
                Console.WriteLine("");
                TestLoadStatus loadStat = msgReciever.Parse(msgFromRepo);
                Console.WriteLine(loadStat.loadMessage);
                if (loadStat.status)
                {
                    break;
                }
                if (trycount <= 5)
                {
                    Thread.Sleep(500);
                    continue;
                }
                throw new Exception("Failed sending logs to repository");
            }
        }
 // uploads logs and test results to repo
 public void uploadFileToRepo(string filePath, string filename, ICommunicator repoChannel)
 {
     try
     {
         hrt.Start();
         using (var inputStream = new FileStream(filePath, FileMode.Open))
         {
             FileTransferMessage msg = new FileTransferMessage();
             msg.filename = filename;
             msg.transferStream = inputStream;
             repoChannel.upLoadFile(msg);
         }
         hrt.Stop();
         Console.Write("\n  Uploaded file \"{0}\" in {1} microsec.", filename, hrt.ElapsedMicroseconds);
     }
     catch (Exception e)
     {
         Console.Write("\n  can't find \"{0}\" exception {1}", filePath, e);
     }
 }
Example #4
0
        public void BuildMessage(string messagebody)
        {
            Console.WriteLine("The Message submitted to TestHarness is: ");
            Console.WriteLine(XMLMessage);

            ClientWPF cl1     = new ClientWPF();
            string    Repostr = "http://localhost:8080/RepoIService";



            Message msg = new Message();

            msg.body = messagebody;

            Console.WriteLine("The Message body which is being sent to TestHarness: ");
            Console.WriteLine(msg.body);
            string frommessage = "http://localhost:8080/ClientIService" + count++;

            //count++;
            msg.author = "Jashwanth";
            msg.to     = "TH";
            msg.from   = frommessage;
            cl1.CreateClientRecvChannel(msg.from);

            /* Send all the code to be tested to the Repository */
            string filepath = System.IO.Path.GetFullPath(cl1.ToSendPath);

            Console.WriteLine("\n  retrieving files from\n {0}\n", filepath);
            string[] files = Directory.GetFiles(filepath);
            hrt.Start();
            foreach (string file in files)
            {
                string filename = System.IO.Path.GetFileName(file);
                Console.WriteLine("\nfile retrieved is {0} \n", filename);
                cl1.uploadFile(filename, Repostr);
            }
            /* this sleep ensures that client copies code before  sending the request*/
            Thread.Sleep(10000);
            cl1.sendTestRequest(msg);
            hrt.Stop();
            ulong  time        = hrt.ElapsedMicroseconds;
            double millisecond = time / 1000.0;

            TimerTextBox.Text = millisecond.ToString() + "ms";
            string timetaken = "Total time to get the response in milli seconds is " + millisecond.ToString() + " - Req 12";

            timetaken.title();
            Thread.Sleep(20000);
        }
Example #5
0
        public void Phase2(string tempPath, string threadName, List <TestInfo> requestInfo, MessageClient msgSenderRepo, MessageClient msgSenderCL, MessageServer msgReciever)
        {
            HiResTimer hrt = new HiResTimer();

            Console.WriteLine("\n({1})Creating child AppDomain for {0}...", requestInfo[0].requestName, threadName);
            AppdomainManager manager  = new AppdomainManager();
            AppDomain        childApp = manager.createChildDomain();
            Loader           loader   = injectLoader(childApp);

            loader.SetTestList(requestInfo);
            Console.WriteLine("\n<------------------------------------------------------------>");
            Console.WriteLine("\n({0})Loading all DLLs required by this test request...", threadName);
            if (loader.LoadTests(tempPath))
            {
                Logger logger = injectLogger(childApp);
                Console.WriteLine("\n({0})Running tests...", threadName);
                hrt.Start();
                var resultList = loader.run();
                hrt.Stop();
                Console.WriteLine("\n({1})Tests execeted in {0} microsec.", hrt.ElapsedMicroseconds, threadName);
                Console.WriteLine("");
                if (resultList != null)
                {
                    logger.SetDataAndResultList(resultList);
                    Console.WriteLine("");
                    Console.WriteLine("\n<------------------------------------------------------------>");
                    Console.WriteLine("\n({0})Demonstrating the test log:\n", threadName);
                    logger.display();
                    string tempLogPath = Path.Combine(tempPath, "Logs");
                    Directory.CreateDirectory(tempLogPath);
                    logger.WriteLog(tempLogPath);
                    logger.writeLogSummary(tempLogPath);

                    SendLogToRepo(threadName, tempLogPath, msgSenderRepo, msgReciever);
                    Console.WriteLine("\n({0})Sending logs to client...", threadName);
                    Message msgToCL = msgSenderCL.SetupResultMessageToClient(logger.WriteToString(), resultList[0].authorName + " " + resultList[0].testTime.ToString("dd-MM-yyyy-HH_mm_ss"));
                    msgSenderCL.channel.PostMessage(msgToCL);

                    Console.WriteLine("");
                    Console.WriteLine("\n<***********************************************************>");
                }
                manager.unloadChild(childApp);
                Console.WriteLine("\n({0})Deleting temporary directory...", threadName);
                Directory.Delete(tempPath, true);
                Console.WriteLine("\n({0})Temporary directory deleted.", threadName);
            }
        }
Example #6
0
        public List <TestInfo> Phase1(string threadName, ref string tempPath, Message msg, MessageClient msgSenderRepo, MessageClient msgSenderCL, MessageServer msgReciever)
        {
            HiResTimer hrt = new HiResTimer();

            Console.WriteLine("\n({0})Parsing test request...", threadName);
            Parser          parser      = new Parser();
            List <TestInfo> requestInfo = parser.doParse(msg);

            Console.WriteLine("\n({0})The result of parsing:", threadName);
            parser.showParsed();

            Console.WriteLine("\n({0})Creating Temporary directory...", threadName);
            tempPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "..\\..\\..\\temp" + requestInfo[0].requestName);
            Directory.CreateDirectory(tempPath);

            Console.WriteLine("\n({0})Creating channel to send message to repository...", threadName);

            msgSenderRepo.CreateMessageChannel("http://localhost:8085/ICommService");
            Message msgToRepo = msgSenderRepo.SetupDownLoadMessageToRepo(threadName, requestInfo, tempPath, "http://localhost:4140/ICommService/BasicHttp", "http://localhost:8180/ICommService/BasicHttp");

            Console.WriteLine("\n({0})Sending message to repository...", threadName);

            msgSenderRepo.channel.PostMessage(msgToRepo);
            Console.WriteLine("\n({0})Waiting for message from repository...", threadName);
            hrt.Start();
            Message reply = msgReciever.TryGetMessage("Repository", threadName);

            hrt.Stop();
            TestLoadStatus stat = msgReciever.Parse(reply);

            Console.WriteLine("");
            Console.WriteLine("\n({0})Recieved message from repository in {2} microsec:\n{1}", threadName, stat.loadMessage, hrt.ElapsedMicroseconds);
            Console.WriteLine("");
            Console.WriteLine("\n({0})Creating channel to send message to client...", threadName);
            msgSenderCL.CreateMessageChannel(parser.ParseConnect(msg));
            Message loadMsgToCL = msgSenderCL.SetupLoadMessageToClient(stat);

            Console.WriteLine("\n({0})Sending load message to client...", threadName);
            msgSenderCL.channel.PostMessage(loadMsgToCL);
            Console.WriteLine("\n<---------------------------------------------------------------------->");

            return(requestInfo);
        }
Example #7
0
        void caseRunTest(CommandData cmdData)
        {
            string path = "../../../THtemp/" + cmdData.testAuthor + "_" + cmdData.dateTime + "_" + cmdData.xmlFile;

            System.IO.FileStream xml = new System.IO.FileStream(path, System.IO.FileMode.Open);
            q.enQ(xml);
            if (startlocal() == true)//now the log file is prepared and we should send it to the repository now
            {
                IFileService fs = null; IFileService fs2 = null;
                int          count = 0;
                while (true)
                {
                    try
                    {
                        fs  = TestHarness.fileSender.CreateChannel(RepoFRcvr);
                        fs2 = TestHarness.fileSender.CreateChannel(cmdData.url + "/CFRcvr");
                        break;
                    }
                    catch
                    {
                        Console.Write("\n  connection to service failed {0} times - trying again", ++count);
                        Thread.Sleep(500);
                        continue;
                    }
                }
                Console.Write("\n  Connected to {0}\n", RepoFRcvr);
                string relativeFilePath = "../../../THtemp/";
                string filepath         = Path.GetFullPath(relativeFilePath);
                string file             = filepath + cmdData.testAuthor + "_" + cmdData.dateTime + ".txt";
                Console.Write("----------this is for requirement 7 and 8------------------\n  sending file {0} to the client({1}) and reposetory", file, cmdData.url); timer.Start();
                if (!fileSender.SendFile(fs, file))
                {
                    Console.Write("\n  could not send file"); timer.Stop();
                }
                else
                {
                    timer.Stop();
                    Console.WriteLine("\nsend file {0} success in {1} ", file, timer.ElapsedTimeSpan);
                }
                if (!fileSender.SendFile(fs2, file))
                {
                    Console.Write("\n  could not send file"); timer.Stop();
                }
                else
                {
                    timer.Stop();
                    Console.WriteLine("\nsend file {0} success in {1} ", file, timer.ElapsedTimeSpan);
                }
            }
        }