Example #1
0
        /*----< 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);
        }
Example #2
0
        /*----< enqueue a message for transmission to a Receiver >-----*/

        public void postMessage(CommMessage msg)
        {
            msg.threadId = Thread.CurrentThread.ManagedThreadId;
            TestUtilities.putLine(string.Format("sender enqueuing message on thread {0}", Thread.CurrentThread.ManagedThreadId));
            rcvQ.enQ(msg);
        }
Example #3
0
        /*----< main thread enqueues message for sending >-------------*/

        public void postMessage(CommMessage msg)
        {
            sndQ.enQ(msg);
        }
Example #4
0
        /*----< post message to remote Comm >--------------------------*/

        public void postMessage(CommMessage msg)
        {
            sndr.postMessage(msg);
        }
        /*----< 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/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;
            }
            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);
        }
        /*----< 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/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();

            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();

            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 && testFileTransfer);
        }
        /*----< 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(ClientEnvironment.fileStorage, "*.*");

            foreach (string name in names)
            {
                bool transferSuccess = comm.postFile(name, ClientEnvironment.fileStorage, ServiceEnvironment.fileStorage);
            }

            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();
            }
            // comm.getMessage() would fail because server has shut down
            // no rcvMsg so no compare

            return(test && testFileTransfer);
        }
        /*----< enqueue a message for transmission to a Receiver >-----*/

        public void postMessage(CommMessage msg)
        {
            msg.threadId = Thread.CurrentThread.ManagedThreadId;

            rcvQ.enQ(msg);
        }
        /*----< 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/IPluggableComm";
            csndMsg.from    = "http://localhost:8081/IPluggableComm";
            comm.postMessage(csndMsg);
            CommMessage crcvMsg = comm.getMessage();                // Testing Communication

            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();
            TestUtilities.vbtitle("testing file transfer");         //Testting 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, "../../../BuilderStorage");
                TestUtilities.checkResult(transferSuccess, "transfer");
            }
            testFileTransfer = false;
            TestUtilities.checkResult(testFileTransfer, "file transfers");
            TestUtilities.putLine();
            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");       //Closing Receiver and Sender
            TestUtilities.putLine();
            csndMsg.type = CommMessage.MessageType.closeSender;
            comm.postMessage(csndMsg);
            if (ClientEnvironment.verbose)
            {
                csndMsg.show();
            }
            return(test && testFileTransfer);
        }
Example #10
0
        /*----< enqueue a message for transmission to a Receiver >-----*/

        public void postMessage(CommMessage msg)
        {
            msg.threadId = Thread.CurrentThread.ManagedThreadId;
            Console.WriteLine("sender enqueuing message on thread {0}", Thread.CurrentThread.ManagedThreadId);
            rcvQ.enQ(msg);
        }
Example #11
0
        /*----< 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);
        }