Ejemplo n.º 1
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress NodeIp      = (IPAddress)ArgumentValues["Node IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

            log.Trace("(NodeIp:'{0}',PrimaryPort:{1})", NodeIp, PrimaryPort);

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                // Step 1
                await client.ConnectAsync(NodeIp, PrimaryPort, false);

                byte[] request = new byte[] { 0x46, 0x84, 0x21, 0x46, 0x87 };
                await client.SendRawAsync(request);

                Message responseMessage = await client.ReceiveMessageAsync();

                // Step 1 Acceptance
                bool statusOk = responseMessage.Response.Status == Status.ErrorProtocolViolation;

                Passed = statusOk;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Implementation of the test itself.
        /// </summary>
        /// <returns>true if the test passes, false otherwise.</returns>
        public override async Task <bool> RunAsync()
        {
            IPAddress ServerIp    = (IPAddress)ArgumentValues["Server IP"];
            int       PrimaryPort = (int)ArgumentValues["primary Port"];

            log.Trace("(ServerIp:'{0}',PrimaryPort:{1})", ServerIp, PrimaryPort);

            bool res = false;

            Passed = false;

            ProtocolClient client = new ProtocolClient();

            try
            {
                MessageBuilder mb = client.MessageBuilder;

                // Step 1
                await client.ConnectAsync(ServerIp, PrimaryPort, false);

                byte[]  payload        = Encoding.UTF8.GetBytes("test");
                Message requestMessage = mb.CreatePingRequest(payload);

                byte[] messageData = ProtocolHelper.GetMessageBytes(requestMessage);
                byte[] part1       = new byte[6];
                byte[] part2       = new byte[messageData.Length - part1.Length];
                Array.Copy(messageData, 0, part1, 0, part1.Length);
                Array.Copy(messageData, part1.Length, part2, 0, part2.Length);
                await client.SendRawAsync(part1);


                log.Trace("Entering 500 seconds wait...");
                await Task.Delay(500 * 1000);

                log.Trace("Wait completed.");

                // We should be disconnected by now, so sending or receiving should throw.
                bool disconnectedOk = false;
                try
                {
                    await client.SendRawAsync(part2);

                    await client.ReceiveMessageAsync();
                }
                catch
                {
                    log.Trace("Expected exception occurred.");
                    disconnectedOk = true;
                }

                // Step 1 Acceptance
                Passed = disconnectedOk;

                res = true;
            }
            catch (Exception e)
            {
                log.Error("Exception occurred: {0}", e.ToString());
            }
            client.Dispose();

            log.Trace("(-):{0}", res);
            return(res);
        }