Example #1
0
        public void TestRecieveMessagesFromSocketDevice( )
        {
            const int MESSAGES_TO_SEND_BY_SOCKET = 5;

            try
            {
                IList <string> sources = Loader.GetSources( )
                                         .Where(m => m.Contains("Socket")).ToList( );
                IList <SensorEndpoint> endpoints = Loader.GetEndpoints( )
                                                   .Where(m => m.Name.Contains("Socket")).ToList( );

                if (endpoints.Count == 0)
                {
                    throw new Exception("Need to specify local ip host for Socket interations " +
                                        "and name of endpoint should contain \"Socket\"");
                }

                GatewayService service = PrepareGatewayService( );

                SensorEndpoint         endpoint = endpoints.First( );
                SocketClientTestDevice device   = new SocketClientTestDevice(_logger);
                device.Start(endpoint, MESSAGES_TO_SEND_BY_SOCKET);

                DeviceAdapterLoader dataIntakeLoader = new DeviceAdapterLoader(
                    sources,
                    endpoints,
                    _logger);

                _totalMessagesToSend += MESSAGES_TO_SEND_BY_SOCKET;

                dataIntakeLoader.StartAll(service.Enqueue, DataArrived);

                _completed.WaitOne( );

                dataIntakeLoader.StopAll( );

                _batchSenderThread.Stop(STOP_TIMEOUT_MS);
            }
            catch (Exception ex)
            {
                _logger.LogError("exception caught: " + ex.StackTrace);
            }
            finally
            {
                _batchSenderThread.Stop(STOP_TIMEOUT_MS);
                _sender.Close( );
            }
        }
        public void TestRealTimeData( )
        {
            const int INITIAL_MESSAGES_BOUND = 5;
            const int STOP_TIMEOUT_MS        = 5000; // ms

            try
            {
                ////IList<string> sources = Loader.GetSources( ).Where(
                ////    m => !m.Contains( "Mock" )
                ////        && ( m.Contains( "Socket" ) || m.Contains( "SerialPort" ) )
                ////    ).ToList( );

                ////IList<SensorEndpoint> endpoints = Loader.GetEndpoints( );

                ////if( !endpoints.Any( m => m.Name.Contains( "Socket" ) ) )
                ////{
                ////    Console.Out.WriteLine( "Need to specify local ip host for Socket interations " +
                ////                        "and name of endpoint should contain \"Socket\"" );
                ////}

                GatewayService service = PrepareGatewayService( );

                ////DeviceAdapterLoader dataIntakeLoader = new DeviceAdapterLoader(
                ////    sources,
                ////    endpoints,
                ////    _logger );

                _totalMessagesToSend += INITIAL_MESSAGES_BOUND;

                ////dataIntakeLoader.StartAll( service.Enqueue, DataArrived );

                _completed.WaitOne( );

                ////dataIntakeLoader.StopAll( );

                _batchSenderThread.Stop(STOP_TIMEOUT_MS);
            }
            catch (Exception ex)
            {
                _logger.LogError("exception caught: " + ex.StackTrace);
            }
            finally
            {
                _batchSenderThread.Stop(STOP_TIMEOUT_MS);
                _sender.Close( );
            }
        }
Example #3
0
 public void Dispose()
 {
     _batchSenderThread.Stop(STOP_TIMEOUT_MS);
     _sender.Close();
 }
Example #4
0
        public void TestRepeatSend( )
        {
            try
            {
                GatewayService service = PrepareGatewayService( );

                // Send a flurry of messages, repeat a few times

                // script message sequence
                int[] sequence = new int[TEST_ITERATIONS];
                for (int iteration = 0; iteration < TEST_ITERATIONS; ++iteration)
                {
                    int count = _rand.Next(MAX_TEST_MESSAGES);

                    sequence[iteration] = count;

                    _totalMessagesToSend += count;
                }

                const float mean  = 39.6001f;
                const int   range = 10;

                Random rand = new Random(( int )(DateTime.Now.Ticks >> 32));

                // send the messages
                for (int iteration = 0; iteration < TEST_ITERATIONS; ++iteration)
                {
                    int count = sequence[iteration];

                    while (--count >= 0)
                    {
                        //
                        // Build a message.
                        // It will look something like this:
                        // "{\"unitofmeasure\":\"%\",\"location\":\"Olivier's office\",\"measurename\":\"Humidity\",\"timecreated\":\"2/26/2015 12:50:29 AM\",\"organization\":\"MSOpenTech\",\"guid\":\"00000000-0000-0000-0000-000000000000\",\"value\":39.600000000000001,\"displayname\":\"NETMF\"}"
                        //

                        bool  add     = (rand.Next( ) % 2) == 0;
                        int   variant = rand.Next( ) % range;
                        float value   = mean;

                        StringBuilder sb = new StringBuilder( );
                        sb.Append("{\"unitofmeasure\":\"%\",\"location\":\"Olivier's office\",\"measurename\":\"Humidity\",");
                        sb.Append("\"timecreated\":\"");
                        sb.Append(DateTime.UtcNow.ToString( ));   // this should look like "2015-02-25T23:07:47.159Z"
                        sb.Append("\",\"organization\":\"MSOpenTech\",\"guid\":\"");
                        sb.Append(new Guid( ).ToString( ));
                        sb.Append("\",\"value\":");
                        sb.Append((value += add ? variant : -variant).ToString( ));
                        sb.Append(",\"displayname\":\"NETMF\"}");

                        string message = sb.ToString( );

                        service.Enqueue(message);

                        DataArrived(message);
                    }
                }

                Debug.Assert(_totalMessagesSent == _totalMessagesToSend);

                _completed.WaitOne( );

                _batchSenderThread.Stop(STOP_TIMEOUT_MS);
            }
            catch (Exception ex)
            {
                _logger.LogError("exception caught: " + ex.StackTrace);
            }
            finally
            {
                _batchSenderThread.Stop(STOP_TIMEOUT_MS);
                _sender.Close( );
            }
        }