Esempio n. 1
0
        public static void RecordScalingChange(ThroughputConfiguration context, int scale)
        {
            lock (FileLock)
            {
                if (!String.IsNullOrEmpty(context.LogDirectory))
                {
                    if (!System.IO.Directory.Exists(context.LogDirectory))
                    {
                        System.IO.Directory.CreateDirectory(context.LogDirectory);
                    }

                    String header = "Time,Scale";
                    String path   = System.IO.Path.Combine(context.LogDirectory, "scaling.csv");

                    bool exists = System.IO.File.Exists(path);
                    using (System.IO.StreamWriter writer = new System.IO.StreamWriter(path, true))
                    {
                        if (!exists)
                        {
                            writer.WriteLine(header);
                        }

                        writer.WriteLine(String.Format("{0},{1}", DateTime.Now.ToUniversalTime().ToString("O"), scale));
                    }
                }
            }
        }
Esempio n. 2
0
        public static void RecordHistory(ThroughputConfiguration context, string content)
        {
            lock (FileLock)
            {
                if (!String.IsNullOrEmpty(context.LogDirectory))
                {
                    if (!System.IO.Directory.Exists(context.LogDirectory))
                    {
                        System.IO.Directory.CreateDirectory(context.LogDirectory);
                    }

                    String header = "TestNo,TestCountTotal,ThreadCount,Records,Failures,AITime,TotalTime,RPS,MaxRecords,MinRecords";
                    String path   = System.IO.Path.Combine(context.LogDirectory, "history.csv");

                    bool exists = System.IO.File.Exists(path);
                    using (System.IO.StreamWriter writer = new System.IO.StreamWriter(path, true))
                    {
                        if (!exists)
                        {
                            writer.WriteLine(header);
                        }

                        writer.WriteLine(content);
                    }
                }
            }
        }
Esempio n. 3
0
        public static void RecordTiming(ThroughputConfiguration context, string content)
        {
            lock (FileLock)
            {
                if (!String.IsNullOrEmpty(context.LogDirectory))
                {
                    if (!System.IO.Directory.Exists(context.LogDirectory))
                    {
                        System.IO.Directory.CreateDirectory(context.LogDirectory);
                    }
                    String header = "Time,Record,PayloadSize,Success,Attempts,Response,TotalTime,AiTime";
                    String path   = System.IO.Path.Combine(context.LogDirectory, "timing.csv");

                    bool exists = System.IO.File.Exists(path);
                    using (System.IO.StreamWriter writer = new System.IO.StreamWriter(path, true))
                    {
                        if (!exists)
                        {
                            writer.WriteLine(header);
                        }

                        content = String.Format("{0},{1}", DateTime.Now.ToString("HH:mm:ss:fff"), content);
                        writer.WriteLine(content);
                    }
                }
            }
        }
Esempio n. 4
0
 public ThreadRecordSupplier(ThroughputConfiguration configuration,
                             IRecordProvider context,
                             OnStatusUpdate onStatus = null)
 {
     this.Configuration = configuration;
     this.Provider      = context;
     this.OnStatus      = onStatus;
     PopulateRecordList();
 }
Esempio n. 5
0
        public DefaultRecordProvider(ThroughputConfiguration context)
        {
            if (!context.DefaultProvider.IsValid())
            {
                throw new Exception("Default provider is invalid");
            }

            this.EndpointUrl = context.DefaultProvider.Url;
            this.EndpointKey = context.DefaultProvider.Key;
            this.FileInput   = context.DefaultProvider.File;
        }
Esempio n. 6
0
 public JobManager(
     IRecordProvider recordProvider,
     ThroughputConfiguration context,
     OnRecordCompleted jobComplete,
     OnStatusUpdate update,
     OnAllJobsCompleted allCompleted)
     : this()
 {
     this.RecordProvider       = recordProvider;
     this.Context              = context;
     this.RecordCompleted     += jobComplete;
     this.StatusUpdate        += update;
     this.AllThreadsCompleted += allCompleted;
 }
Esempio n. 7
0
        static void Main(string[] args)
        {
            try
            {
                // Event triggered when everythign has completed
                Program.ResetEvent = new ManualResetEvent(false);

                // Load the context for the run
                Program.Context = ThroughputConfiguration.LoadConfiguration();

                // Load the record and default record providers, then select one
                Program.RecordProviders  = ProviderLocationUtility.LoadRecordProviders(Program.Context);
                Program.SelectedProvider = ProviderLocationUtility.SelectProvider(Program.RecordProviders);

                if (Program.SelectedProvider != null)
                {
                    // Determine the number of records being sent
                    if (Program.SelectedProvider.GetType().IsAssignableFrom(typeof(DefaultRecordProvider)))
                    {
                        Program.Context.SelectedRecordCount = Program.Context.DefaultProvider.RecordCount;
                    }
                    else
                    {
                        Program.Context.SelectedRecordCount = Program.Context.RecordConfiguration.RecordCount;
                    }

                    // Display a summary of what is about to happen
                    Program.ShowSummary();

                    // Run the jobs then wait until complete.
                    Console.WriteLine("Starting Jobs");
                    Program.StartJobs();
                    while (!WaitHandle.WaitAll(new WaitHandle[] { Program.ResetEvent }, 1000))
                    {
                        ;
                    }
                    Console.WriteLine("Test Complete");
                }
            }
            catch (Exception ex)
            {
                String msg = String.Format("Exception Caught During Execution{0}{1}",
                                           Environment.NewLine,
                                           ex.Message);
                Console.WriteLine(msg);
            }

            Console.ReadLine();
        }
Esempio n. 8
0
        /// <summary>
        /// Loads instances of IRecordProvider using the location on disk identified
        /// in the configuration.
        /// </summary>
        /// <param name="context">App context containing disk location to look for</param>
        /// <returns>Collection of IRecordProviders</returns>
        public static List <IRecordProvider> LoadRecordProviders(ThroughputConfiguration context)
        {
            Type   type             = typeof(IRecordProvider);
            String providerLocation = context.RecordProviderDiskLocation;

            List <IRecordProvider> returnSelections = new List <IRecordProvider>();

            if (!String.IsNullOrEmpty(providerLocation))
            {
                if (!System.IO.Directory.Exists(providerLocation))
                {
                    throw new Exception(String.Format("Provider location in configuration '{0}' is not a valid directory", providerLocation));
                }

                // Load all assemblies in the location looking for the interface IRecordProvider
                System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(providerLocation);
                System.IO.FileInfo[]    files     = directory.GetFiles("*.dll", System.IO.SearchOption.TopDirectoryOnly);

                List <Assembly> assemblies = new List <Assembly>();
                foreach (System.IO.FileInfo file in files)
                {
                    AssemblyName assemblyName = AssemblyName.GetAssemblyName(file.FullName);
                    assemblies.Add(AppDomain.CurrentDomain.Load(assemblyName));
                }

                IEnumerable <Type> types = assemblies
                                           .SelectMany(s => s.GetTypes())
                                           .Where(p => type.IsAssignableFrom(p) && p.IsClass);

                // Create any record providers found
                foreach (Type t in types)
                {
                    returnSelections.Add(Activator.CreateInstance(t) as IRecordProvider);
                }
            }

            // Is there a default provider? If so add that to the list as well.
            if (context.DefaultProvider.IsValid())
            {
                returnSelections.Add(new DefaultRecordProvider(context));
            }

            return(returnSelections);
        }