/*----< test Comm instance >-----------------------------------*/ public static bool testComm() { bool test = true; Comm comm = new Comm("http://localhost", 8081); CommMessage csndMsg = new CommMessage(CommMessage.MessageType.request); csndMsg.command = "show"; csndMsg.author = "Jim Fawcett"; csndMsg.to = "http://localhost:8081/IPluggableComm"; csndMsg.from = "http://localhost:8081/IPluggableComm"; comm.postMessage(csndMsg); CommMessage crcvMsg = comm.getMessage(); if (ClientEnvironment.verbose) { crcvMsg.show(); } crcvMsg = comm.getMessage(); if (ClientEnvironment.verbose) { crcvMsg.show(); } if (!compareMsgs(csndMsg, crcvMsg)) { test = false; } bool testFileTransfer = true; List <string> names = getClientFileList(); foreach (string name in names) { bool transferSuccess = comm.postFile(ClientEnvironment.fileStorage, ServiceEnvironment.fileStorage, name); } foreach (string name in names) { if (!compareFileBytes(name)) { testFileTransfer = false; break; } } csndMsg.type = CommMessage.MessageType.closeReceiver; comm.postMessage(csndMsg); crcvMsg = comm.getMessage(); if (ClientEnvironment.verbose) { crcvMsg.show(); } if (!compareMsgs(csndMsg, crcvMsg)) { test = false; } csndMsg.type = CommMessage.MessageType.closeSender; comm.postMessage(csndMsg); if (ClientEnvironment.verbose) { csndMsg.show(); } return(test && testFileTransfer); }
public static bool testComm1(Comm comm, CommMessage csndMsg, bool test) { comm.postMessage(csndMsg); CommMessage crcvMsg = comm.getMessage(); if (ClientEnvironment.verbose) { crcvMsg.show(); } if (!compareMsgs(csndMsg, crcvMsg)) { test = false; } TestUtilities.checkResult(test, "csndMsg equals crcvMsg"); TestUtilities.putLine(comm.size().ToString() + " messages left in queue"); TestUtilities.putLine(); TestUtilities.vbtitle("testing connect to new EndPoint"); csndMsg.to = "http://DESKTOP-J98AUHN:8081/IMessagePassingComm"; comm.postMessage(csndMsg); crcvMsg = comm.getMessage(); if (ClientEnvironment.verbose) { crcvMsg.show(); } if (!compareMsgs(csndMsg, crcvMsg)) { test = false; } TestUtilities.checkResult(test, "csndMsg equals crcvMsg"); TestUtilities.putLine(comm.size().ToString() + " messages left in queue"); TestUtilities.putLine(); return(test); }
/*----< test Comm instance >-----------------------------------*/ public static bool testComm() { TestUtilities.vbtitle("testing Comm"); bool test = true; Comm comm = new Comm("http://localhost", 8081); CommMessage csndMsg = new CommMessage(CommMessage.MessageType.request); csndMsg.command = "show"; csndMsg.author = "Jim Fawcett"; csndMsg.to = "http://localhost:8081/IMessagePassingComm"; csndMsg.from = "http://localhost:8081/IMessagePassingComm"; comm.postMessage(csndMsg); CommMessage crcvMsg = comm.getMessage(); crcvMsg.show(); if (!compareMsgs(csndMsg, crcvMsg)) { test = false; } TestUtilities.checkResult(test, "csndMsg equals crcvMsg"); TestUtilities.putLine(); TestUtilities.vbtitle("testing file transfer"); bool testFileTransfer = true; List <string> names = getClientFileList(); foreach (string name in names) { TestUtilities.putLine(string.Format("transferring file \"{0}\"", name)); bool transferSuccess = comm.postFile(name, ""); TestUtilities.checkResult(transferSuccess, "transfer"); } foreach (string name in names) { if (!compareFileBytes(name)) { testFileTransfer = false; break; } } TestUtilities.checkResult(testFileTransfer, "file transfers"); TestUtilities.vbtitle("test receiver close"); csndMsg.type = CommMessage.MessageType.closeReceiver; comm.postMessage(csndMsg); crcvMsg = comm.getMessage(); if (ClientEnvironment.verbose) { crcvMsg.show(); } if (!compareMsgs(csndMsg, crcvMsg)) { test = false; } TestUtilities.checkResult(test, "closeReceiver"); TestUtilities.putLine(); csndMsg.type = CommMessage.MessageType.closeSender; comm.postMessage(csndMsg); csndMsg.show(); return(test && testFileTransfer); }
/*----< compare binary file's bytes >--------------------------*/ /*----< test Comm instance >-----------------------------------*/ public static bool testComm() { TestUtilities.title("testing Comm"); bool test = true; Comm comm = new Comm("http://localhost", 8081, "../../clientFolder"); CommMessage csndMsg = new CommMessage(CommMessage.MessageType.request); csndMsg.command = "show"; csndMsg.author = "Jim Fawcett"; csndMsg.to = "http://localhost:8081/IMessagePassingComm"; csndMsg.from = "http://localhost:8081/IMessagePassingComm"; comm.postMessage(csndMsg); CommMessage crcvMsg = comm.getMessage(); //if (localEnvironment.verbose) crcvMsg.show(); crcvMsg = comm.getMessage(); //if (localEnvironment.verbose) crcvMsg.show(); if (!compareMsgs(csndMsg, crcvMsg)) { test = false; } TestUtilities.checkResult(test, "csndMsg equals crcvMsg"); TestUtilities.putLine(); TestUtilities.title("testing file transfer"); TestUtilities.title("test receiver close"); csndMsg.type = CommMessage.MessageType.closeReceiver; comm.postMessage(csndMsg); crcvMsg = comm.getMessage(); //if (localEnvironment.verbose) crcvMsg.show(); //if (!compareMsgs(csndMsg, crcvMsg)) test = false; TestUtilities.checkResult(test, "closeReceiver"); TestUtilities.putLine(); csndMsg.type = CommMessage.MessageType.closeSender; comm.postMessage(csndMsg); //if(localEnvironment.verbose) csndMsg.show(); // comm.getMessage() would fail because server has shut down // no rcvMsg so no compare TestUtilities.putLine("last message received\n"); return(test); }
public static bool testComm3(Comm comm, CommMessage csndMsg, bool test) { TestUtilities.vbtitle("test receiver close"); csndMsg.type = CommMessage.MessageType.closeReceiver; if (ClientEnvironment.verbose) { csndMsg.show(); } comm.postMessage(csndMsg); CommMessage crcvMsg = comm.getMessage(); if (ClientEnvironment.verbose) { crcvMsg.show(); } if (!compareMsgs(csndMsg, crcvMsg)) { test = false; } TestUtilities.checkResult(test, "closeReceiver"); TestUtilities.putLine(comm.size().ToString() + " messages left in queue"); TestUtilities.putLine(); csndMsg.type = CommMessage.MessageType.closeSender; comm.postMessage(csndMsg); if (ClientEnvironment.verbose) { csndMsg.show(); } TestUtilities.putLine(comm.size().ToString() + " messages left in queue"); // comm.getMessage() would fail because server has shut down // no rcvMsg so no compare TestUtilities.putLine("last message received\n"); TestUtilities.putLine("Test comm.restart on same port - expected to fail"); if (comm.restart(8081)) { CommMessage newerMsg = new CommMessage(CommMessage.MessageType.request); newerMsg.to = ClientEnvironment.endPoint; newerMsg.from = ClientEnvironment.endPoint; comm.postMessage(newerMsg); CommMessage newReply = comm.getMessage(); newReply.show(); } else { Console.Write("\n can't restart but won't fail test"); } return(test); }
/*----< test Sender and Receiver classes >---------------------*/ public static bool testSndrRcvr() { TestUtilities.vbtitle("testing Sender & Receiver"); bool test = true; Receiver rcvr = new Receiver(); rcvr.start("http://localhost", 8080); Sender sndr = new Sender("http://localhost", 8080); CommMessage sndMsg = new CommMessage(CommMessage.MessageType.request); sndMsg.command = "show"; sndMsg.author = "Jim Fawcett"; sndMsg.to = "http://localhost:8080/IMessagePassingComm"; sndMsg.from = "http://localhost:8080/IMessagePassingComm"; sndr.postMessage(sndMsg); CommMessage rcvMsg; // get connection message rcvMsg = rcvr.getMessage(); if (ClientEnvironment.verbose) { rcvMsg.show(); } // get first info message rcvMsg = rcvr.getMessage(); if (ClientEnvironment.verbose) { rcvMsg.show(); } if (!compareMsgs(sndMsg, rcvMsg)) { test = false; } TestUtilities.checkResult(test, "sndMsg equals rcvMsg"); TestUtilities.putLine(); sndMsg.type = CommMessage.MessageType.closeReceiver; sndr.postMessage(sndMsg); rcvMsg = rcvr.getMessage(); if (ClientEnvironment.verbose) { rcvMsg.show(); } if (!compareMsgs(sndMsg, rcvMsg)) { test = false; } TestUtilities.checkResult(test, "Close Receiver"); TestUtilities.putLine(); sndMsg.type = CommMessage.MessageType.closeSender; if (ClientEnvironment.verbose) { sndMsg.show(); } sndr.postMessage(sndMsg); // rcvr.getMessage() would fail because server has shut down // no rcvMsg so no compare TestUtilities.putLine("last message received\n"); return(test); }
} = new List <string>(); // for tested files /*-------------------------------------------<For recieving messages it always runs till killed>------------------------------------------*/ private static void ThreadProc() { bool result = true; while (result) { CommMessage commMessage = childbuilder.getMessage(); commMessage.show(); if (commMessage.command == "BUILD") { BuildrequestName = commMessage.xmlString; startBuildProcess(commMessage.xmlString); } if (commMessage.command == "Kill") { result = false; } if (commMessage.command == "SentFiles") { BuildProcess(); } if (commMessage.command == "SendDllFiles") { bool check = true; do { check = childbuilder.postFile(commMessage.xmlString, BuildFolderPath + "/", commMessage.fileName + "/"); } while (!check); } if (commMessage.command == "sendReadyMessage") { ReadyMessage(); } } }
public static void ThreadProc() // Creates the thread process used for communication with MotherBuilder { bool result = true; while (result) { CommMessage MessageCommunication = childbuilder.getMessage(); MessageCommunication.show(); if (MessageCommunication.command == "BUILD") { BuildRequestName = MessageCommunication.xmlString; startBuildProcess(MessageCommunication.xmlString); } if (MessageCommunication.command == "Kill") { childbuilder.closeConnection(); CommMessage ReceiverClose = new CommMessage(CommMessage.MessageType.closeReceiver); ReceiverClose.from = "http://localhost:" + PortChildBuilder.ToString() + "/IMessagePassingComm"; ReceiverClose.to = MessageCommunication.from; ReceiverClose.author = "Child" + PortChildBuilder.ToString(); childbuilder.postMessage(ReceiverClose); result = false; } if (MessageCommunication.command == "SentFiles") { ProcessBuild(); } } }
/*----< test Sender and Receiver classes >---------------------*/ public static bool testSndrRcvr() { bool test = true; Receiver rcvr = new Receiver(); rcvr.start("http://localhost", 8080); Sender sndr = new Sender("http://localhost", 8080); CommMessage sndMsg = new CommMessage(CommMessage.MessageType.request); sndMsg.command = "show"; sndMsg.author = "Jim Fawcett"; sndMsg.to = "http://localhost:8080/IPluggableComm"; sndMsg.from = "http://localhost:8080/IPluggableComm"; sndr.postMessage(sndMsg); CommMessage rcvMsg; // get connection message rcvMsg = rcvr.getMessage(); if (ClientEnvironment.verbose) { rcvMsg.show(); } // get first info message rcvMsg = rcvr.getMessage(); if (ClientEnvironment.verbose) { rcvMsg.show(); } if (!compareMsgs(sndMsg, rcvMsg)) { test = false; } sndMsg.type = CommMessage.MessageType.closeReceiver; sndr.postMessage(sndMsg); rcvMsg = rcvr.getMessage(); if (ClientEnvironment.verbose) { rcvMsg.show(); } if (!compareMsgs(sndMsg, rcvMsg)) { test = false; } sndMsg.type = CommMessage.MessageType.closeSender; if (ClientEnvironment.verbose) { sndMsg.show(); } sndr.postMessage(sndMsg); // rcvr.getMessage() would fail because server has shut down // no rcvMsg so no compare return(test); }
/*----------------------------------------------------<This is the recieving thread>--------------------------------------------*/ private void rcvThreadProc() { while (true) { CommMessage repoMsg = repo.getMessage(); repoMsg.show(); if (repoMsg.command == null) { continue; } if (repoMsg.command == "RequestRepositoryFiles") { CommMessage replyRepositoryFiles = new CommMessage(CommMessage.MessageType.reply); replyRepositoryFiles.command = "getRepositoryFiles"; replyRepositoryFiles.from = "http://localhost:8081/IMessagePassingComm"; replyRepositoryFiles.to = "http://localhost:8080/IMessagePassingComm"; replyRepositoryFiles.author = "repository"; replyRepositoryFiles.arguments = getRepoFiles(); repo.postMessage(replyRepositoryFiles); } if (repoMsg.command == "RequestRepositoryXMLFiles") { CommMessage replyRepositoryXMLFiles = new CommMessage(CommMessage.MessageType.reply); replyRepositoryXMLFiles.command = "getRepositoryXMLFiles"; replyRepositoryXMLFiles.from = "http://localhost:8081/IMessagePassingComm"; replyRepositoryXMLFiles.to = "http://localhost:8080/IMessagePassingComm"; replyRepositoryXMLFiles.author = "repository"; replyRepositoryXMLFiles.arguments = getRepoXMLFiles(); repo.postMessage(replyRepositoryXMLFiles); } if (repoMsg.command == "sendBuildRequest") { sendBuildRequestToBuildQueue(repoMsg.arguments); } if (repoMsg.command == "BuildRequest") { string path = generateXmlFile(repoMsg.arguments); CommMessage replMessage = new CommMessage(CommMessage.MessageType.reply); replMessage.from = from; replMessage.to = "http://localhost:8080/IMessagePassingComm"; replMessage.command = "RequestBuild"; replMessage.xmlString = path; replMessage.author = "Repository"; repo.postMessage(replMessage); } if (repoMsg.command == "RequestParsedFiles") { SendFilesToChild(repoMsg.arguments, repoMsg.fileName); CommMessage replymsg = new CommMessage(CommMessage.MessageType.reply); replymsg.from = repoMsg.to; replymsg.to = repoMsg.from; replymsg.author = "Repository"; replymsg.command = "SentFiles"; repo.postMessage(replymsg); } } }
public static void ReadyMessage() { CommMessage send = new CommMessage(CommMessage.MessageType.request); send.from = "http://localhost:" + PortChildBuilder.ToString() + "/IMessagePassingComm"; send.to = "http://localhost:8083/IMessagePassingComm"; send.author = "Butchi Venkata Akhil Rao"; send.command = "READY"; send.fileName = FolderPath + "/"; send.show(); childbuilder.postMessage(send); }
void ThreadProcessReceive() { while (true) { CommMessage RepositoryMessage = Repo.getMessage(); RepositoryMessage.show(); if (RepositoryMessage.command == null) { continue; } if (RepositoryMessage.command == "RequestRepositoryFiles") { CommMessage RepoFilesReply = new CommMessage(CommMessage.MessageType.reply); RepoFilesReply.command = "getRepositoryFiles"; RepoFilesReply.from = "http://localhost:8081/IMessagePassingComm"; RepoFilesReply.to = RepositoryMessage.from; RepoFilesReply.author = "repository"; RepoFilesReply.arguments = RepoFiles(); Repo.postMessage(RepoFilesReply); } if (RepositoryMessage.command == "RequestRepositoryXMLFiles") { CommMessage XMLFilesReply = new CommMessage(CommMessage.MessageType.reply); XMLFilesReply.command = "getRepositoryXMLFiles"; XMLFilesReply.from = "http://localhost:8081/IMessagePassingComm"; XMLFilesReply.to = RepositoryMessage.from; XMLFilesReply.author = "repository"; XMLFilesReply.arguments = getRepoXMLFiles(); Repo.postMessage(XMLFilesReply); } if (RepositoryMessage.command == "sendBuildRequest") { BuildRequestToQueue(RepositoryMessage.arguments); } if (RepositoryMessage.command == "BuildRequest") { XMLFileGeneration(RepositoryMessage.arguments); } if (RepositoryMessage.command == "RequestParsedFiles") { FilesToChild(RepositoryMessage.arguments, RepositoryMessage.fileName); CommMessage MessageReply = new CommMessage(CommMessage.MessageType.reply); MessageReply.from = RepositoryMessage.to; MessageReply.to = RepositoryMessage.from; MessageReply.author = "Repository"; MessageReply.command = "SentFiles"; Repo.postMessage(MessageReply); } } }
void listen_builder_thread() { Console.WriteLine("MB thread running: "); while (true) { CommMessage recv_msg = null; recv_msg = comm.getMessage(); Console.WriteLine("In MB:"); recv_msg.show(); // send reply message to child process if (recv_msg.port_number != 0 && recv_msg.msg_body.Equals("child")) { rd_q.enQ(recv_msg.port_number.ToString()); // enque the child's port number in the queue } } }
public static bool testComm2(Comm comm, CommMessage csndMsg, bool test) { string localEndPoint = "http://localhost:8081/IMessagePassingComm"; TestUtilities.vbtitle("testing file transfer"); bool testFileTransfer = true; List <string> names = getClientFileList(); foreach (string name in names) { TestUtilities.putLine(string.Format("transferring file \"{0}\"", name)); bool transferSuccess = comm.postFile(name); TestUtilities.checkResult(transferSuccess, "transfer"); } foreach (string name in names) { if (!compareFileBytes(name)) { testFileTransfer = false; break; } } TestUtilities.checkResult(testFileTransfer, "file transfers"); TestUtilities.putLine(comm.size().ToString() + " messages left in queue"); TestUtilities.putLine(); TestUtilities.vbtitle("test closeConnection then postMessage"); comm.closeConnection(); CommMessage newMsg = new CommMessage(CommMessage.MessageType.request); newMsg.to = localEndPoint; newMsg.from = localEndPoint; comm.postMessage(newMsg); CommMessage reply = comm.getMessage(); reply.show(); // if we get here, test passed TestUtilities.checkResult(true, "closeSenderConnenction then PostMessage"); TestUtilities.putLine(comm.size().ToString() + " messages left in queue"); TestUtilities.putLine(); return(testFileTransfer); }
/*-----------------------------<recieving messages thread>---------------------------*/ private void rcvThreadProc() { while (true) { CommMessage recieveMessage = testHarness.getMessage(); recieveMessage.show(); if (recieveMessage.command == "testRequest") { toAddress = recieveMessage.from; testRequestName = recieveMessage.xmlString; TestFolderPath = "../../../TestStorage"; Directory.CreateDirectory(TestFolderPath); ParseTestRequest(recieveMessage.fileName); } } }
public void start_builder(int ch_proc) { generate_xml(); Console.WriteLine("Mthr Builder started"); // start listening the br and rdQ thread // br_thread = new Thread(build_req_thread); br_thread.Start(); ///start listening the mb thread // build_thread = new Thread(listen_builder_thread); build_thread.Start(); //initiate child process// Console.WriteLine("after this"); int count = ch_proc; for (int i = 1; i <= count; ++i) { if (createProcess(i)) { Console.Write(" - succeeded"); } else { Console.Write(" - failed"); } } // send msg to repo for file request // CommMessage sndMsg_to_repo = new CommMessage(CommMessage.MessageType.request); sndMsg_to_repo.command = "Get_Files_From_Repo"; sndMsg_to_repo.author = "Salim Zhulkhrni"; sndMsg_to_repo.to = "http://localhost:8092/IPluggableComm"; sndMsg_to_repo.from = "http://localhost:8091/IMessagePassingComm"; sndMsg_to_repo.msg_body = "8091"; sndMsg_to_repo.port_number = 8091; comm.postMessage(sndMsg_to_repo); Console.WriteLine("Requested for files from Repo"); //Console.ReadLine(); sndMsg_to_repo.show(); }
/*-----------------------------------------------<This is reciever thread used for recieveing messages>------------------------------------------------------------*/ private void ThreadProc() { while (true) { CommMessage recieve = motherbuilder.getMessage(); recieve.show(); if (recieve.command == "startchildbuilder") { Console.WriteLine(recieve.arguments[0]); CallChild(Convert.ToInt32(recieve.arguments[0])); } else if (recieve.command == "StoreBuildRequests") { foreach (string f in recieve.arguments) { build_requests.enQ(f); } } else if (recieve.command == "KillProcess") { foreach (int childBuilderport in ChildBuilderPorts.Values) { Console.WriteLine(childBuilderport); CommMessage killMessage = new CommMessage(CommMessage.MessageType.connect); killMessage.author = "MotherBuilder"; killMessage.command = "Kill"; killMessage.from = this.from; killMessage.to = "http://localhost:" + childBuilderport + "/IMessagePassingComm"; motherbuilder.postMessage(killMessage); } } else if (recieve.command == "READY") { Console.WriteLine(" \n Requirement 6:Pool Processes shall use message-passing communication to access messages from the mother Builder process."); Console.WriteLine("=====================================================================================================================================================\n"); readyqueue.enQ(recieve); } } }
void ThreadProcess() // Receiver methods are called { while (true) { CommMessage rcv = motherbuilder.getMessage(); rcv.show(); Console.WriteLine("Requirement 3: The Communication Service shall support accessing build requests by Pool Processes from the mother Builder process, sending and receiving build requests, and sending and receiving files"); if (rcv.command == "startchildbuilder") { Console.WriteLine(rcv.arguments[0]); ChildCall(Convert.ToInt32(rcv.arguments[0])); } else if (rcv.command == "StoreBuildRequests") { foreach (string f in rcv.arguments) { BuildRequest.enQ(f); } } else if (rcv.command == "KillProcess") { foreach (int ChildPort in PortsChildBuilder.Values) { Console.WriteLine(ChildPort); CommMessage MessageKill = new CommMessage(CommMessage.MessageType.connect); MessageKill.author = "MotherBuilder"; MessageKill.command = "Kill"; MessageKill.from = this.from; MessageKill.to = "http://localhost:" + ChildPort + "/IMessagePassingComm"; motherbuilder.postMessage(MessageKill); } } else if (rcv.command == "READY") { readyqueue.enQ(rcv); } } }
/*----< test Sender and Receiver classes >---------------------*/ public static bool testSndrRcvr() { TestPCommService testComService = new TestPCommService(); TestUtilities.vbtitle("testing Sender & Receiver"); bool test = true; Receiver rcvr = new Receiver(); rcvr.start("http://localhost", 8080); Sender sndr = new Sender("http://localhost", 8080); CommMessage sndMsg = new CommMessage(CommMessage.MessageType.request); sndMsg.command = "show"; sndMsg.author = "Jim Fawcett"; sndMsg.to = "http://localhost:8080/IPluggableComm"; sndMsg.from = "http://localhost:8080/IPluggableComm"; sndr.postMessage(sndMsg); CommMessage rcvMsg; // get connection message rcvMsg = rcvr.getMessage(); if (verbose) { rcvMsg.show(); } // get first info message rcvMsg = rcvr.getMessage(); if (verbose) { rcvMsg.show(); } if (!testComService.compareMsgs(sndMsg, rcvMsg)) { test = false; } TestUtilities.checkResult(test, "sndMsg equals rcvMsg"); TestUtilities.putLine(); sndMsg.type = CommMessage.MessageType.closeReceiver; sndr.postMessage(sndMsg); rcvMsg = rcvr.getMessage(); if (verbose) { rcvMsg.show(); } if (!testComService.compareMsgs(sndMsg, rcvMsg)) { test = false; } TestUtilities.checkResult(test, "Close Receiver"); TestUtilities.putLine(); sndMsg.type = CommMessage.MessageType.closeSender; if (verbose) { sndMsg.show(); } sndr.postMessage(sndMsg); TestUtilities.putLine("last message received\n"); return(test); }
/*----< test Comm instance >-----------------------------------*/ /* * - Note: change every occurance of string "Odin" to your machine name * */ public static bool testComm() { TestUtilities.vbtitle("testing Comm"); bool test = true; Comm comm = new Comm("http://localhost", 8081); CommMessage csndMsg = new CommMessage(CommMessage.MessageType.request); csndMsg.command = "show"; csndMsg.author = "Jim Fawcett"; string localEndPoint = "http://localhost:8081/IMessagePassingComm"; csndMsg.to = localEndPoint; csndMsg.from = localEndPoint; comm.postMessage(csndMsg); CommMessage crcvMsg = comm.getMessage(); if (ClientEnvironment.verbose) { crcvMsg.show(); } if (!compareMsgs(csndMsg, crcvMsg)) { test = false; } TestUtilities.checkResult(test, "csndMsg equals crcvMsg"); TestUtilities.putLine(comm.size().ToString() + " messages left in queue"); TestUtilities.putLine(); TestUtilities.vbtitle("testing connect to new EndPoint"); csndMsg.to = "http://Odin:8081/IMessagePassingComm"; comm.postMessage(csndMsg); crcvMsg = comm.getMessage(); if (ClientEnvironment.verbose) { crcvMsg.show(); } if (!compareMsgs(csndMsg, crcvMsg)) { test = false; } TestUtilities.checkResult(test, "csndMsg equals crcvMsg"); TestUtilities.putLine(comm.size().ToString() + " messages left in queue"); TestUtilities.putLine(); TestUtilities.vbtitle("testing file transfer"); bool testFileTransfer = true; List <string> names = getClientFileList(); foreach (string name in names) { TestUtilities.putLine(string.Format("transferring file \"{0}\"", name)); bool transferSuccess = comm.postFile(name); TestUtilities.checkResult(transferSuccess, "transfer"); } foreach (string name in names) { if (!compareFileBytes(name)) { testFileTransfer = false; break; } } TestUtilities.checkResult(testFileTransfer, "file transfers"); TestUtilities.putLine(comm.size().ToString() + " messages left in queue"); TestUtilities.putLine(); TestUtilities.vbtitle("test closeConnection then postMessage"); comm.closeConnection(); CommMessage newMsg = new CommMessage(CommMessage.MessageType.request); newMsg.to = localEndPoint; newMsg.from = localEndPoint; comm.postMessage(newMsg); CommMessage reply = comm.getMessage(); reply.show(); // if we get here, test passed TestUtilities.checkResult(true, "closeSenderConnenction then PostMessage"); TestUtilities.putLine(comm.size().ToString() + " messages left in queue"); TestUtilities.putLine(); TestUtilities.vbtitle("test receiver close"); csndMsg.type = CommMessage.MessageType.closeReceiver; if (ClientEnvironment.verbose) { csndMsg.show(); } comm.postMessage(csndMsg); crcvMsg = comm.getMessage(); if (ClientEnvironment.verbose) { crcvMsg.show(); } if (!compareMsgs(csndMsg, crcvMsg)) { test = false; } TestUtilities.checkResult(test, "closeReceiver"); TestUtilities.putLine(comm.size().ToString() + " messages left in queue"); TestUtilities.putLine(); csndMsg.type = CommMessage.MessageType.closeSender; comm.postMessage(csndMsg); if (ClientEnvironment.verbose) { csndMsg.show(); } TestUtilities.putLine(comm.size().ToString() + " messages left in queue"); // comm.getMessage() would fail because server has shut down // no rcvMsg so no compare TestUtilities.putLine("last message received\n"); TestUtilities.putLine("Test comm.restart on same port - expected to fail"); if (comm.restart(8081)) { CommMessage newerMsg = new CommMessage(CommMessage.MessageType.request); newerMsg.to = ClientEnvironment.endPoint; newerMsg.from = ClientEnvironment.endPoint; comm.postMessage(newerMsg); CommMessage newReply = comm.getMessage(); newReply.show(); } else { Console.Write("\n can't restart but won't fail test"); } return(test && testFileTransfer); }
/*----< test Comm instance >-----------------------------------*/ public static bool testComm() { TestUtilities.vbtitle("testing Comm"); bool test = true; Comm comm = new Comm("http://localhost", 8081); CommMessage csndMsg = new CommMessage(CommMessage.MessageType.request); csndMsg.command = Msg.Command.show; csndMsg.author = "Jim Fawcett"; csndMsg.to = "http://localhost:8081/IPluggableComm"; csndMsg.from = "http://localhost:8081/IPluggableComm"; comm.postMessage(csndMsg); CommMessage crcvMsg = comm.getMessage(); if (ClientEnvironment.verbose) { crcvMsg.show(); } crcvMsg = comm.getMessage(); if (ClientEnvironment.verbose) { crcvMsg.show(); } if (!compareMsgs(csndMsg, crcvMsg)) { test = false; } TestUtilities.checkResult(test, "csndMsg equals crcvMsg"); TestUtilities.putLine(); bool testFileTransferResult = testFileTransfer(comm, csndMsg); TestUtilities.vbtitle("test receiver close"); csndMsg.type = CommMessage.MessageType.closeReceiver; comm.postMessage(csndMsg); crcvMsg = comm.getMessage(); if (ClientEnvironment.verbose) { crcvMsg.show(); } if (!compareMsgs(csndMsg, crcvMsg)) { test = false; } TestUtilities.checkResult(test, "closeReceiver"); TestUtilities.putLine(); csndMsg.type = CommMessage.MessageType.closeSender; comm.postMessage(csndMsg); if (ClientEnvironment.verbose) { csndMsg.show(); } // comm.getMessage() would fail because server has shut down // no rcvMsg so no compare TestUtilities.putLine("last message received\n"); return(test && testFileTransferResult); }