Example #1
0
        private T SendDataOverWire <T>(ICollectorWire wire, string method, params object[] data)
        {
            try
            {
                var serializedData = _serializer.Serialize(data);
                var responseBody   = wire.SendData(method, _connectionInfo, serializedData);
                return(ParseResponse <T>(responseBody));
            }
            catch (Exceptions.HttpException ex)
            {
                Log.DebugFormat("Received a {0} {1} response invoking method \"{2}\"", (int)ex.StatusCode, ex.StatusCode, method);

                if (ex.StatusCode == HttpStatusCode.Gone)
                {
                    Log.Info("The server has requested that the agent disconnect. The agent is shutting down.");
                }

                throw;
            }
            catch (Exception ex)
            {
                Log.DebugFormat("An error occurred invoking method \"{0}\": {1}", method, ex);
                throw;
            }
        }
Example #2
0
        private void ConnectRespondsWithEventHarvestConfig(EventHarvestConfig eventHarvestConfig)
        {
            if (eventHarvestConfig != null)
            {
                _compositeTestAgent.ServerConfiguration.EventHarvestConfig = eventHarvestConfig;
            }

            var serverConfigJson = Newtonsoft.Json.JsonConvert.SerializeObject(_compositeTestAgent.ServerConfiguration);

            Mock.Arrange(() => _collectorWire.SendData("connect", Arg.IsAny <ConnectionInfo>(), Arg.IsAny <string>()))
            .Returns($"{{'return_value': {serverConfigJson} }}");
        }
Example #3
0
        public void SetUp()
        {
            _compositeTestAgent = new CompositeTestAgent();
            var environment          = _compositeTestAgent.Container.Resolve <IEnvironment>();
            var collectorWireFactory = Mock.Create <ICollectorWireFactory>();

            _collectorWire = Mock.Create <ICollectorWire>();
            var systemInfo       = Mock.Create <ISystemInfo>();
            var processStatic    = Mock.Create <IProcessStatic>();
            var agentEnvironment = new NewRelic.Agent.Core.Environment(systemInfo, processStatic);

            Mock.Arrange(() => collectorWireFactory.GetCollectorWire(null, Arg.IsAny <IAgentHealthReporter>())).IgnoreArguments().Returns(_collectorWire);
            Mock.Arrange(() => _collectorWire.SendData("preconnect", Arg.IsAny <ConnectionInfo>(), Arg.IsAny <string>()))
            .Returns("{'return_value': { 'redirect_host': ''}}");

            _agentHealthReporter = Mock.Create <IAgentHealthReporter>();

            _connectionHandler = new ConnectionHandler(new JsonSerializer(), collectorWireFactory, Mock.Create <IProcessStatic>(), Mock.Create <IDnsStatic>(),
                                                       Mock.Create <ILabelsService>(), agentEnvironment, systemInfo, _agentHealthReporter, Mock.Create <IEnvironment>());
        }