public void Setup()
 {
     config               = new TestConfiguration();
     clientProvider       = Substitute.For <IHTTPClientProvider>();
     timingProvider       = Substitute.For <ITimingProvider>();
     nonTerminalStateMock = Substitute.For <AbstractBeaconSendingState>(false);
 }
 public void Setup()
 {
     logger         = Substitute.For <ILogger>();
     config         = new TestConfiguration();
     clientProvider = Substitute.For <IHTTPClientProvider>();
     timingProvider = Substitute.For <ITimingProvider>();
 }
        public OpenKitInitializer(IOpenKitBuilder builder)
        {
            logger = builder.Logger;
            privacyConfiguration = PrivacyConfiguration.From(builder);
            openKitConfiguration = OpenKitConfiguration.From(builder);

            timingProvider    = new DefaultTimingProvider();
            threadIdProvider  = new DefaultThreadIdProvider();
            sessionIdProvider = new DefaultSessionIdProvider();

            beaconCache        = new BeaconCache(logger);
            beaconCacheEvictor = new BeaconCacheEvictor(logger, beaconCache, BeaconCacheConfiguration.From(builder),
                                                        timingProvider);

            var httpClientConfig = HttpClientConfiguration.From(openKitConfiguration);
            // shared thread suspender between BeaconSender and HttpClient. HttpClient will be woken up when
            // BeaconSender shuts down
            var beaconSenderThreadSuspender = new InterruptibleThreadSuspender();

            beaconSender = new BeaconSender(
                logger,
                httpClientConfig,
                new DefaultHttpClientProvider(logger, beaconSenderThreadSuspender),
                timingProvider,
                beaconSenderThreadSuspender);
            var watchdogThreadSuspender = new InterruptibleThreadSuspender();

            sessionWatchdog = new SessionWatchdog(
                logger,
                new SessionWatchdogContext(timingProvider, watchdogThreadSuspender));
        }
Example #4
0
        protected OpenKit(ILogger logger,
                          OpenKitConfiguration configuration,
                          IHTTPClientProvider httpClientProvider,
                          ITimingProvider timingProvider,
                          IThreadIDProvider threadIDProvider)
        {
            if (logger.IsInfoEnabled)
            {
                //TODO: Use proper version information (incl. the build number)
                logger.Info(configuration.OpenKitType + " " + GetType().Name + " " + OpenKitConstants.DEFAULT_APPLICATION_VERSION + " instantiated");
            }
            if (logger.IsDebugEnabled)
            {
                logger.Debug(
                    "applicationName=" + configuration.ApplicationName + ", applicationID=" + configuration.ApplicationID
                    + ", deviceID=" + configuration.DeviceID + ", endpointURL=" + configuration.EndpointURL
                    );
            }
            this.configuration    = configuration;
            this.logger           = logger;
            this.timingProvider   = timingProvider;
            this.threadIDProvider = threadIDProvider;

            beaconCache        = new BeaconCache(logger);
            beaconSender       = new BeaconSender(logger, configuration, httpClientProvider, timingProvider);
            beaconCacheEvictor = new BeaconCacheEvictor(logger, beaconCache, configuration.BeaconCacheConfig, timingProvider);
        }
Example #5
0
        // *** constructor ***

        /// <summary>
        /// Creates a new instance of type Beacon
        /// </summary>
        /// <param name="logger">Logger for logging messages</param>
        /// <param name="cache">Cache storing beacon related data</param>
        /// <param name="configuration">OpenKit related configuration</param>
        /// <param name="clientIPAddress">The client's IP address</param>
        /// <param name="threadIdProvider">Provider for retrieving thread id</param>
        /// <param name="timingProvider">Provider for time related methods</param>
        public Beacon(ILogger logger, BeaconCache beaconCache, OpenKitConfiguration configuration, string clientIPAddress,
                      IThreadIDProvider threadIDProvider, ITimingProvider timingProvider)
        {
            this.logger         = logger;
            this.beaconCache    = beaconCache;
            this.sessionNumber  = configuration.NextSessionNumber;
            this.timingProvider = timingProvider;

            this.configuration    = configuration;
            this.threadIDProvider = threadIDProvider;
            this.sessionStartTime = timingProvider.ProvideTimestampInMilliseconds();

            if (InetAddressValidator.IsValidIP(clientIPAddress))
            {
                this.clientIPAddress = clientIPAddress;
            }
            else
            {
                this.clientIPAddress = string.Empty;
            }

            // store the current http configuration
            this.httpConfiguration = configuration.HTTPClientConfig;

            basicBeaconData = CreateBasicBeaconData();
        }
Example #6
0
        /// <summary>
        /// Constructor
        ///
        /// Current state is initialized to <see cref="Dynatrace.OpenKit.Core.Communication."/>
        ///
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="configuration"></param>
        /// <param name="httpClientProvider"></param>
        /// <param name="timingProvider"></param>
        public BeaconSendingContext(ILogger logger, OpenKitConfiguration configuration, IHTTPClientProvider httpClientProvider, ITimingProvider timingProvider)
        {
            this.logger        = logger;
            Configuration      = configuration;
            HTTPClientProvider = httpClientProvider;
            TimingProvider     = timingProvider;

            // set current state to init state
            CurrentState = new BeaconSendingInitState();
        }
 public void SetUp()
 {
     mockTimingProvider = Substitute.For <ITimingProvider>();
     testConfiguration  = new TestConfiguration();
     beacon             = new Beacon(Substitute.For <ILogger>(),
                                     new BeaconCache(),
                                     testConfiguration,
                                     "127.0.0.1",
                                     Substitute.For <IThreadIDProvider>(),
                                     mockTimingProvider);
 }
 public void SetUp()
 {
     mockTimingProvider = Substitute.For <ITimingProvider>();
     testConfiguration  = new TestConfiguration();
     beacon             = new Beacon(Substitute.For <ILogger>(),
                                     new BeaconCache(),
                                     testConfiguration,
                                     "127.0.0.1",
                                     Substitute.For <IThreadIDProvider>(),
                                     mockTimingProvider);
     action = new RootAction(beacon, "ActionName", new SynchronizedQueue <IAction>());
 }
        public void SetUp()
        {
            logger             = Substitute.For <ILogger>();
            mockTimingProvider = Substitute.For <ITimingProvider>();
            var beaconConfig = new BeaconConfiguration(1, DataCollectionLevel.USER_BEHAVIOR, CrashReportingLevel.OPT_IN_CRASHES);

            testConfiguration = new TestConfiguration("1", beaconConfig);
            beacon            = new Beacon(logger,
                                           new BeaconCache(logger),
                                           testConfiguration,
                                           "127.0.0.1",
                                           Substitute.For <IThreadIDProvider>(),
                                           mockTimingProvider);
        }
Example #10
0
        /// <summary>
        /// Constructor
        ///
        /// Current state is initialized to <see cref="Dynatrace.OpenKit.Core.Communication."/>
        ///
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="httpClientProvider"></param>
        /// <param name="timingProvider"></param>
        public BeaconSendingContext(OpenKitConfiguration configuration, IHTTPClientProvider httpClientProvider, ITimingProvider timingProvider)
        {
            Configuration      = configuration;
            HTTPClientProvider = httpClientProvider;
            TimingProvider     = timingProvider;

            // set time sync supported to true
            IsTimeSyncSupported = true;
            // set last time sync time to -1
            LastTimeSyncTime = -1;

            // set current state to init state
            CurrentState = new BeaconSendingInitState();
        }
Example #11
0
        protected OpenKit(ILogger logger,
                          OpenKitConfiguration configuration,
                          IHTTPClientProvider httpClientProvider,
                          ITimingProvider timingProvider,
                          IThreadIDProvider threadIDProvider)
        {
            this.configuration    = configuration;
            this.logger           = logger;
            this.timingProvider   = timingProvider;
            this.threadIDProvider = threadIDProvider;

            beaconCache        = new BeaconCache();
            beaconSender       = new BeaconSender(configuration, httpClientProvider, timingProvider);
            beaconCacheEvictor = new BeaconCacheEvictor(logger, beaconCache, configuration.BeaconCacheConfig, timingProvider);
        }
        private void VerifyDefaultsAreSet(OpenKitConfiguration configuration)
        {
            // default values
            Assert.That(configuration.ApplicationVersion, Is.EqualTo(OpenKitConstants.DEFAULT_APPLICATION_VERSION));
            Assert.That(configuration.Device.Manufacturer, Is.EqualTo(OpenKitConstants.DEFAULT_MANUFACTURER));
            Assert.That(configuration.Device.OperatingSystem, Is.EqualTo(OpenKitConstants.DEFAULT_OPERATING_SYSTEM));
            Assert.That(configuration.Device.ModelID, Is.EqualTo(OpenKitConstants.DEFAULT_MODEL_ID));

            // default trust manager
            Assert.That(configuration.HTTPClientConfig.SSLTrustManager, Is.InstanceOf <SSLStrictTrustManager>());

            // default values for beacon cache configuration
            Assert.That(configuration.BeaconCacheConfig, Is.Not.Null);
            Assert.That(configuration.BeaconCacheConfig.MaxRecordAge, Is.EqualTo(BeaconCacheConfiguration.DEFAULT_MAX_RECORD_AGE_IN_MILLIS));
            Assert.That(configuration.BeaconCacheConfig.CacheSizeUpperBound, Is.EqualTo(BeaconCacheConfiguration.DEFAULT_UPPER_MEMORY_BOUNDARY_IN_BYTES));
            Assert.That(configuration.BeaconCacheConfig.CacheSizeLowerBound, Is.EqualTo(BeaconCacheConfiguration.DEFAULT_LOWER_MEMORY_BOUNDARY_IN_BYTES));
        }
Example #13
0
        /// <summary>
        /// Creates a new instance of type Beacon
        /// </summary>
        /// <param name="logger">Logger for logging messages</param>
        /// <param name="cache">Cache storing beacon related data</param>
        /// <param name="configuration">OpenKit related configuration</param>
        /// <param name="clientIPAddress">The client's IP address</param>
        /// <param name="threadIdProvider">Provider for retrieving thread id</param>
        /// <param name="timingProvider">Provider for time related methods</param>
        /// <param name="randomNumberGenerator">Random number generator</param>
        internal Beacon(ILogger logger, BeaconCache beaconCache, OpenKitConfiguration configuration, string clientIPAddress,
                        IThreadIDProvider threadIDProvider, ITimingProvider timingProvider, IPRNGenerator randomNumberGenerator)
        {
            this.logger         = logger;
            this.beaconCache    = beaconCache;
            BeaconConfiguration = configuration.BeaconConfig;

            if (beaconConfiguration.DataCollectionLevel == DataCollectionLevel.USER_BEHAVIOR)
            {
                SessionNumber = configuration.NextSessionNumber;
                DeviceID      = Truncate(configuration.DeviceID);
            }
            else
            {
                SessionNumber = 1;
                DeviceID      = randomNumberGenerator.NextLong(long.MaxValue)
                                .ToString(CultureInfo.InvariantCulture);
            }

            this.timingProvider = timingProvider;

            this.configuration         = configuration;
            this.threadIDProvider      = threadIDProvider;
            this.randomNumberGenerator = randomNumberGenerator;
            sessionStartTime           = timingProvider.ProvideTimestampInMilliseconds();

            if (InetAddressValidator.IsValidIP(clientIPAddress))
            {
                this.clientIPAddress = clientIPAddress;
            }
            else
            {
                this.clientIPAddress = string.Empty;
            }
            // store the current http configuration
            httpConfiguration = configuration.HTTPClientConfig;
            basicBeaconData   = CreateBasicBeaconData();
        }
Example #14
0
 public BeaconSender(ILogger logger, OpenKitConfiguration configuration, IHTTPClientProvider clientProvider, ITimingProvider provider)
     : this(logger, new BeaconSendingContext(logger, configuration, clientProvider, provider))
 {
 }
Example #15
0
        // *** constructors ***

        public OpenKit(ILogger logger, OpenKitConfiguration configuration)
            : this(logger, configuration, new DefaultHTTPClientProvider(logger), new DefaultTimingProvider(), new DefaultThreadIDProvider())
        {
        }
Example #16
0
 public BeaconSender(OpenKitConfiguration configuration, IHTTPClientProvider clientProvider, ITimingProvider provider)
     : this(new BeaconSendingContext(configuration, clientProvider, provider))
 {
 }
Example #17
0
        // *** constructor ***

        /// <summary>
        /// Creates a new instance of type Beacon
        /// </summary>
        /// <param name="logger">Logger for logging messages</param>
        /// <param name="cache">Cache storing beacon related data</param>
        /// <param name="configuration">OpenKit related configuration</param>
        /// <param name="clientIPAddress">The client's IP address</param>
        /// <param name="threadIdProvider">Provider for retrieving thread id</param>
        /// <param name="timingProvider">Provider for time related methods</param>
        public Beacon(ILogger logger, BeaconCache beaconCache, OpenKitConfiguration configuration, string clientIPAddress,
                      IThreadIDProvider threadIDProvider, ITimingProvider timingProvider)
            : this(logger, beaconCache, configuration, clientIPAddress, threadIDProvider, timingProvider, new DefaultPRNGenerator())
        {
        }