public void InvalidSignatureShouldNotRecord()
        {
            var conobj    = LineProtocolConfiguration.InitConfiguration();
            var influxLib = new InfluxClient(conobj);
            var keystore  = new MockKeystore();

            keystore.AddKey("node-3", "BgIAAACkAABSU0ExAAQAAAEAAQBXZXt7QOileknWzBH2Sg+Yk4INDTbKA5XUUfUe23zUmr6eM1USCNHX3lidZfjk5Emuui1m8k0KnghxcJfOau8iPRpLg/lubMNojpLGe2MXn5GsyjgEpVdE+Cf0pLBAYHcBuBYHj99muMsJrJW1/InbKFa24JuVnBr+MybPuMXqtQ==");

            IngressController tc          = new IngressController(keystore, influxLib);
            ActionResult      webResponse = tc.PostRealTimeTelemetry(
                new RealTimeTelemetry
            {
                NodeId  = "node-3",
                Payload = new RealTimeTelemetryPayload
                {
                    Client        = "ClieParity v123",
                    BlockNum      = 12342256,
                    BlockHash     = "123efd",
                    BlockTS       = 1465839830100400200,
                    BlockReceived = 1465839830100400200,
                    NumPeers      = 12,
                    NumTxInBlock  = 23,
                    GasLimit      = 20,
                    GasUsed       = 12
                },
                Signature = "KI8EGFW4acwQc5V7C3MPzmGjHSguXCkE3YxRrQFlZ+G2PrFWkhno9g9NzPSq7H8wxmZMmcZcGdwWNcX0vxLM+vunp3EboHhKxe3p3FFeij6z6GcX0GCJpjyGtaS+VqIGnGKFdzPA3bNZ9QLJwROS/SQA1hjTVm8lhpWR1CQ55oc="
            });


            Assert.NotNull(webResponse);
            var result = Assert.IsType <StatusCodeResult>(webResponse);

            Assert.Equal((int)HttpStatusCode.Forbidden, result.StatusCode);
            Assert.Equal(0, influxLib.LastInsertCount);
        }
        public void UnRegisteredPublicKeyShouldNotRecord()
        {
            var conobj    = LineProtocolConfiguration.InitConfiguration();
            var influxLib = new InfluxClient(conobj);
            var keystore  = new MockKeystore();

            keystore.AddKey("node-3", "BgIAAACkAABSU0ExAAQAAAEAAQBXZXt7QOileknWzBH2Sg+Yk4INDTbKA5XUUfUe23zUmr6eM1USCNHX3lidZfjk5Emuui1m8k0KnghxcJfOau8iPRpLg/lubMNojpLGe2MXn5GsyjgEpVdE+Cf0pLBAYHcBuBYHj99muMsJrJW1/InbKFa24JuVnBr+MybPuMXqtQ==");

            IngressController tc          = new IngressController(keystore, influxLib);
            ActionResult      webResponse = tc.PostRealTimeTelemetry(
                new RealTimeTelemetry
            {
                NodeId  = "0x00000",
                Payload = new RealTimeTelemetryPayload
                {
                    Client        = "Parity v123",
                    BlockNum      = 123456,
                    BlockHash     = "123efd",
                    BlockTS       = 1465839830100400200,
                    BlockReceived = 1465839830100400200,
                    NumPeers      = 12,
                    NumTxInBlock  = 23,
                    GasLimit      = 20,
                    GasUsed       = 12
                },
                Signature = "B8udYvuWJ4hioMt6SJ/WxOMS7hY75QrUEKgQ+vlrt2+AblTpJwVba7TB43GvyHjimwbvvZPenJLWsS+r6j48ySGv7rM7DTYsA7SGMfwhx58gQxV2SxOx8klsiDjRPRC1e5AdrL0e1Lko/9o7OWIOdS1CUeuzfa8QhB2o41UmyuU="
            });

            Assert.NotNull(webResponse);
            var result = Assert.IsType <StatusCodeResult>(webResponse);

            Assert.Equal((int)HttpStatusCode.Forbidden, result.StatusCode);
        }
Exemple #3
0
        public void FirstBufferShouldNotFlushBeforeItemSize(bool useListEnqueue)
        {
            var conobj = LineProtocolConfiguration.InitConfiguration();

            conobj.FlushBufferItemsSize = 2;
            conobj.FlushBufferSeconds   = 300;
            //InfluxCon(conobj, "DELETE FROM \"datameasurementA\"");
            InfluxCon(conobj, "DROP MEASUREMENT \"datameasurementA\"");

            List <string> data = new List <string>();

            data.Add("datameasurementA,location=us-midwest temperature=82 1465839830100400200");

            var influxLib = new InfluxClient(conobj);

            if (useListEnqueue)
            {
                influxLib.Enqueue(data, true);
            }
            else
            {
                influxLib.Enqueue(data[0], true);
            }


            JObject pobj    = JObject.Parse(InfluxCon(conobj, "SELECT * FROM \"datameasurementA\""));
            var     rows    = pobj.SelectTokens("['results'][0].['series'][0].['values']");
            var     inCount = rows.Children().Count();

            Assert.Equal(0, inCount);//Check if row count is now 0
        }
        public void NullTelemetryShouldNotRecord()
        {
            var conobj    = LineProtocolConfiguration.InitConfiguration();
            var influxLib = new InfluxClient(conobj);
            var keystore  = new MockKeystore();

            keystore.AddKey("node-3", "BgIAAACkAABSU0ExAAQAAAEAAQBXZXt7QOileknWzBH2Sg+Yk4INDTbKA5XUUfUe23zUmr6eM1USCNHX3lidZfjk5Emuui1m8k0KnghxcJfOau8iPRpLg/lubMNojpLGe2MXn5GsyjgEpVdE+Cf0pLBAYHcBuBYHj99muMsJrJW1/InbKFa24JuVnBr+MybPuMXqtQ==");

            IngressController tc          = new IngressController(keystore, influxLib);
            ActionResult      webResponse = tc.PostRealTimeTelemetry(
                new RealTimeTelemetry
            {
                NodeId  = null,
                Payload = new RealTimeTelemetryPayload
                {
                    Client        = null,
                    BlockNum      = 9,
                    BlockHash     = "",
                    BlockTS       = 123,
                    BlockReceived = 123,
                    NumPeers      = 123,
                    NumTxInBlock  = 12
                },
                Signature = ""
            });

            Assert.NotNull(webResponse);
            var result = Assert.IsType <BadRequestResult>(webResponse);

            Assert.Equal((int)HttpStatusCode.BadRequest, result.StatusCode);
            Assert.Equal(0, influxLib.LastInsertCount);
        }
        public void EmptyTelemetryShouldNotRecord()
        {
            var conobj    = LineProtocolConfiguration.InitConfiguration();
            var influxLib = new InfluxClient(conobj);
            var keystore  = new MockKeystore();

            keystore.AddKey("node-1", "BgIAAACkAABSU0ExAAQAAAEAAQBdUkRrF0SA3a+QtGv6y97DFa79Z/IDHtCHehoj/LADUJxXsI1k6GBqdyE7MkF9uX2j8FbAMlxpmIKrMcRTWj9wZ5gIhbntiCF61IFsQJ5af23WsTg82u9A7mepxSXrfgfu6Bzq1nB+pUGeWlATaLiOT+wm5uCYjYH8MiTMfDLu4g==");


            IngressController tc          = new IngressController(keystore, influxLib);
            ActionResult      webResponse = tc.PostInfluxTelemetry(new InfluxTelemetry
            {
                NodeId    = "",
                Signature = "",
                Payload   = new List <string>()
            });

            //Assert.IsType<BadRequestResult>(webResponse);
            Assert.NotNull(webResponse);
            var result = Assert.IsType <BadRequestResult>(webResponse);

            Assert.Equal((int)HttpStatusCode.BadRequest, result.StatusCode);
            Assert.Equal(0, influxLib.LastInsertCount);

            /* JObject pobj = JObject.Parse(InfluxCon(conobj));
             * var rows = pobj.SelectTokens("['results'][0].['series'][0].['values']");
             * var in_count = rows.Children().Count();
             * //Assert.Equal(2, in_count);//Check if row count have not increased after first test case
             */
        }
        public void InvalidSignatureShouldNotRecord()
        {
            var conobj    = LineProtocolConfiguration.InitConfiguration();
            var influxLib = new InfluxClient(conobj);
            var keystore  = new MockKeystore();

            keystore.AddKey("node-1", "BgIAAACkAABSU0ExAAQAAAEAAQBdUkRrF0SA3a+QtGv6y97DFa79Z/IDHtCHehoj/LADUJxXsI1k6GBqdyE7MkF9uX2j8FbAMlxpmIKrMcRTWj9wZ5gIhbntiCF61IFsQJ5af23WsTg82u9A7mepxSXrfgfu6Bzq1nB+pUGeWlATaLiOT+wm5uCYjYH8MiTMfDLu4g==");


            IngressController tc          = new IngressController(keystore, influxLib);
            ActionResult      webResponse = tc.PostInfluxTelemetry(new InfluxTelemetry
            {
                NodeId    = "node-1",
                Signature = "GT+8qiTNx2X2jtE0YQOBH6EE6Pu+a6DUFMK//LU+wiIwp/OPvaO7h2SDlU40/MAt83R4ZzVT2IBrl37phKUhbiBN0sMmvgxGJdJAOkAjKtgtacqUUxuVGim4PE6pAIAEIRoETQMe7ZlsALcoyA1p5M8Y1481bM1ykNcKQ23QPuM=",
                Payload   = new List <string>
                {
                    "weather,location=us-midwest temperature=82 1465839830100400200"
                }
            });

            //Assert.IsType<ForbidResult>(webResponse);
            Assert.NotNull(webResponse);
            var result = Assert.IsType <StatusCodeResult>(webResponse);

            Assert.Equal((int)HttpStatusCode.Forbidden, result.StatusCode);
            Assert.Equal(0, influxLib.LastInsertCount);

            /* JObject pobj = JObject.Parse(InfluxCon(conobj));
             * var rows = pobj.SelectTokens("['results'][0].['series'][0].['values']");
             * var in_count = rows.Children().Count();
             * Assert.Equal(2, in_count);//Check if row count have not increased after first test case
             */
        }
Exemple #7
0
        public void InfluxClientDisposeTestShouldPass()  //first buffer failure test
        {
            //for coverage
            InfluxClient ic = new InfluxClient(LineProtocolConfiguration.InitConfiguration());

            ic.Dispose();
        }
Exemple #8
0
        public void SecondBufferShouldNotFlushBeforeItemSize()  //first buffer failure test
        {
            var conobjBufferA = LineProtocolConfiguration.InitConfiguration();

            conobjBufferA.FlushBufferItemsSize       = 1;
            conobjBufferA.FlushBufferSeconds         = 300;
            conobjBufferA.FlushSecondBufferSeconds   = 50;
            conobjBufferA.FlushSecondBufferItemsSize = 42;
            InfluxCon(conobjBufferA, "DROP MEASUREMENT \"datameasurementE\"");
            InfluxCon(conobjBufferA, "DROP DATABASE " + conobjBufferA.DBName);  // dropping db so first buffer fail

            List <string> data = new List <string>();

            data.Add("datameasurementE,location=us-midwest temperature=32 1465839830100400200");

            var influxLib = new InfluxClient(conobjBufferA);

            influxLib.Enqueue(data, true);
            Thread.Sleep(1000); //wait before flush call and db creation so flush dnt pass to influx but to 2nd buffer
            InfluxCon(conobjBufferA, "CREATE DATABASE \"" + conobjBufferA.DBName + "\"");
            Thread.Sleep(2000); //wait for NW latency to Influx

            influxLib.Enqueue("datameasurementE,location=us-east temperature=15 1465839830100400203", false);


            Thread.Sleep(3000); //wait for 2nd buffer to flush

            JObject pobj    = JObject.Parse(InfluxCon(conobjBufferA, "SELECT * FROM \"datameasurementE\""));
            var     rows    = pobj.SelectTokens("['results'][0].['series'][0].['values']");
            var     inCount = rows.Children().Count();

            Assert.Equal(0, inCount);//Check if row count is now 4
        }
Exemple #9
0
        public void SecondBufferFlushTimeInterval(bool notFlushBeforeTimeInterval)  //first buffer failure test
        {
            var conobjBufferA = LineProtocolConfiguration.InitConfiguration();

            conobjBufferA.FlushBufferItemsSize       = 2;
            conobjBufferA.FlushBufferSeconds         = 300;
            conobjBufferA.FlushSecondBufferSeconds   = 5;
            conobjBufferA.FlushSecondBufferItemsSize = 5;
            //InfluxCon(conobjBufferA, "DELETE FROM \"datameasurementD\"");
            InfluxCon(conobjBufferA, "DROP MEASUREMENT \"datameasurementD\"");
            InfluxCon(conobjBufferA, "DROP DATABASE \"" + conobjBufferA.DBName + "\""); // dropping db so first buffer fail

            List <string> data = new List <string>();

            data.Add("datameasurementD,location=us-midwest temperature=82 1465839830100400200");
            data.Add("datameasurementD,location=us-east temperature=75 1465839830100400200");

            var influxLib = new InfluxClient(conobjBufferA);

            influxLib.Enqueue(data, true);
            Thread.Sleep(2000);
            InfluxCon(conobjBufferA, "CREATE DATABASE \"" + conobjBufferA.DBName + "\"");

            if (!notFlushBeforeTimeInterval)
            {
                Thread.Sleep((conobjBufferA.FlushSecondBufferSeconds + 1) * 1000); //wait for 2nd buffer to flush
            }

            JObject pobj    = JObject.Parse(InfluxCon(conobjBufferA, "SELECT * FROM \"datameasurementD\""));
            var     rows    = pobj.SelectTokens("['results'][0].['series'][0].['values']");
            var     inCount = rows.Children().Count();

            Assert.Equal((notFlushBeforeTimeInterval ? 0 : 2), inCount);//Check if row count is now 2
        }
Exemple #10
0
        public void FirstBufferShouldFlushAfterTimeInterval()
        {
            var conobj = LineProtocolConfiguration.InitConfiguration();

            conobj.FlushBufferItemsSize = 100;
            conobj.FlushBufferSeconds   = 1;
            //InfluxCon(conobj, "DELETE FROM \"datameasurementB\"");
            InfluxCon(conobj, "DROP MEASUREMENT \"datameasurementB\"");

            List <string> data = new List <string>();

            data.Add("datameasurementB,location=us-midwest temperature=82 1465839830100400200");

            var influxLib = new InfluxClient(conobj);

            influxLib.Enqueue(data, true);
            Thread.Sleep(2000); //wait for TIME flush & NW latency to Influx


            JObject pobj    = JObject.Parse(InfluxCon(conobj, "SELECT * FROM \"datameasurementB\""));
            var     rows    = pobj.SelectTokens("['results'][0].['series'][0].['values']");
            var     inCount = rows.Children().Count();

            Assert.Equal(1, inCount);//Check if row count is now 1
        }
        public void PostCallShouldFailForNullData()
        {
            var conobj    = LineProtocolConfiguration.InitConfiguration();
            var influxLib = new InfluxClient(conobj);
            var keystore  = new MockKeystore();

            keystore.AddKey("node-3", "BgIAAACkAABSU0ExAAQAAAEAAQBXZXt7QOileknWzBH2Sg+Yk4INDTbKA5XUUfUe23zUmr6eM1USCNHX3lidZfjk5Emuui1m8k0KnghxcJfOau8iPRpLg/lubMNojpLGe2MXn5GsyjgEpVdE+Cf0pLBAYHcBuBYHj99muMsJrJW1/InbKFa24JuVnBr+MybPuMXqtQ==");

            IngressController tc          = new IngressController(keystore, influxLib);
            ActionResult      webResponse = tc.PostRealTimeTelemetry(null);

            Assert.NotNull(webResponse);
            var result = Assert.IsType <BadRequestResult>(webResponse);

            Assert.Equal((int)HttpStatusCode.BadRequest, result.StatusCode);
            Assert.Equal(0, influxLib.LastInsertCount);
        }
        public void ValidTelemetryShouldRecord()
        {
            var conobj = LineProtocolConfiguration.InitConfiguration();

            conobj.FlushBufferItemsSize = 1;
            conobj.FlushBufferSeconds   = 1;
            var influxLib = new InfluxClient(conobj);
            var keystore  = new MockKeystore();

            keystore.AddKey("node-3", "BgIAAACkAABSU0ExAAQAAAEAAQBXZXt7QOileknWzBH2Sg+Yk4INDTbKA5XUUfUe23zUmr6eM1USCNHX3lidZfjk5Emuui1m8k0KnghxcJfOau8iPRpLg/lubMNojpLGe2MXn5GsyjgEpVdE+Cf0pLBAYHcBuBYHj99muMsJrJW1/InbKFa24JuVnBr+MybPuMXqtQ==");

            IngressController tc          = new IngressController(keystore, influxLib);
            ActionResult      webResponse = tc.PostRealTimeTelemetry(
                new RealTimeTelemetry
            {
                NodeId  = "node-3",
                Payload = new RealTimeTelemetryPayload
                {
                    Client        = "Parityv123",
                    BlockNum      = 123456,
                    BlockHash     = "123efd",
                    BlockTS       = 1465839830100400200,
                    BlockReceived = 1465839830100400200,
                    NumPeers      = 12,
                    NumTxInBlock  = 23,
                    GasLimit      = 20,
                    GasUsed       = 12
                },
                Signature = "SDZL5noFP5XQK9rj9SqHPqCm9uEPq9rrQi0lU1SUIhjCI+UU3J3CdYIVG/XnUAf8NFFrHHwA52njhGbnxb+76q4vCruaoAFmmFqigL1MvVHj4XdENhJd5yq3URQMU+8tN9FXosOzNxmqaINKJIfvhfjN4CND4bOXzNdiQ5QrdEU="
            });

            Assert.NotNull(webResponse);
            var result = Assert.IsType <AcceptedResult>(webResponse);

            Assert.Equal((int)HttpStatusCode.Accepted, result.StatusCode);

            //System.Threading.Thread.Sleep(conobj.FlushBufferSeconds * 1000 * 4); //wait for Queue to flush with some extra time for NW latency
            //Assert.Equal(1, influxLib.LastInsertCount);
        }
        public void InvalidPublicKeyOfNodeShouldFail()
        {
            var conobj    = LineProtocolConfiguration.InitConfiguration();
            var influxLib = new InfluxClient(conobj);
            var keystore  = new MockKeystore();

            keystore.AddKey("0x000000000000001", "BgIAAACkAABSU0ExAAQAAAEAAQBdUkRrF0SA3a+QtGv6y97DFa79Z/IDHtCHehoj/LADUJxXsI1k6GBqdyE7MkF9uX2j8FbAMlxpmIKrMcRTWj9wZ5gIhbntiCF61IFsQJ5af23WsTg82u9A7mepxSXrfgfu6Bzq1nB+pUGeWlATaLiOT+wm5uCYjYH8MiTMfDLu4g==");

            IngressController tc          = new IngressController(keystore, influxLib);
            ActionResult      webResponse = tc.PostInfluxTelemetry(new InfluxTelemetry
            {
                NodeId    = "node-1",
                Signature = "GT+8qiTNx2X2jtE0YQOBH6EE6Pu+a6DUFMK//LU+wiIwp/OPvaO7h2SDlU40/MAt83R4ZzVT2IBrl37phKUhbiBN0sMmvgxGJdJAOkAjKtgtacqUUxuVGim4PE6pAIAEIRoETQMe7ZlsALcoyA1p5M8Y1481bM1ykNcKQ23QPuM=",
                Payload   = new List <string>
                {
                    "weather,location=us-midwest temperature=82 1465839830100400200"
                }
            });

            Assert.NotNull(webResponse);
            var result = Assert.IsType <StatusCodeResult>(webResponse);

            Assert.Equal((int)HttpStatusCode.Forbidden, result.StatusCode);
        }
        public void EnqueueShouldFailForInvalidPoint()
        {
            var conobj    = LineProtocolConfiguration.InitConfiguration();
            var influxLib = new InfluxClient(conobj);
            var keystore  = new MockKeystore();

            keystore.AddKey("node-3", "BgIAAACkAABSU0ExAAQAAAEAAQBXZXt7QOileknWzBH2Sg+Yk4INDTbKA5XUUfUe23zUmr6eM1USCNHX3lidZfjk5Emuui1m8k0KnghxcJfOau8iPRpLg/lubMNojpLGe2MXn5GsyjgEpVdE+Cf0pLBAYHcBuBYHj99muMsJrJW1/InbKFa24JuVnBr+MybPuMXqtQ==");

            IngressController tc          = new IngressController(keystore, influxLib);
            ActionResult      webResponse = tc.PostInfluxTelemetry(new InfluxTelemetry
            {
                NodeId    = "node-3",
                Signature = "h9tYfyqrRjq5yrx/7G9zyFHA5YHxr3gUondveKxLhNJevbyj5ozVOoKU2U7VCdHnm2WwO+Jr0fl2xuVqAt1DItIqbZX+7phDufMLown0DgqnzY0YLfW8pEt7xVop9CkGuqXTRZoGzpUiFidqtonwRB9uJXR/x9O3YQheoZ/Wz00=",
                Payload   = new List <string>
                {
                    "weather,location=us-midwest another key=another value temperature=82 1465839830100400200"
                }
            });

            Assert.NotNull(webResponse);
            var result = Assert.IsType <StatusCodeResult>(webResponse);

            Assert.Equal((int)HttpStatusCode.BadRequest, result.StatusCode);
        }
Exemple #15
0
        public void FirstBufferShouldFlushOnItemSize(bool useListEnqueue)
        {
            var conobj = LineProtocolConfiguration.InitConfiguration();

            conobj.FlushBufferItemsSize = 2;
            conobj.FlushBufferSeconds   = 30000;
            InfluxCon(conobj, "DROP MEASUREMENT \"datameasurement\"");

            List <string> data = new List <string>();

            data.Add("datameasurement,location=us-midwest temperature=82 1465839830100400200");
            data.Add("datameasurement,location=us-east temperature=75 1465839830100400200");

            var influxLib = new InfluxClient(conobj);

            if (useListEnqueue)
            {
                influxLib.Enqueue(data, true);
            }
            else
            {
                foreach (string point in data)
                {
                    influxLib.Enqueue(point, true);
                }
            }

            Thread.Sleep(1000); //wait for NW latency to Influx


            JObject pobj    = JObject.Parse(InfluxCon(conobj, "SELECT * FROM \"datameasurement\""));
            var     rows    = pobj.SelectTokens("['results'][0].['series'][0].['values']");
            var     inCount = rows.Children().Count();

            Assert.Equal(2, inCount);//Check if row count is now 2
        }