Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » General » Downloads
 
Add your own
alternative version

Identifying NHibernate-Related Bottlenecks through Performance Monitoring

, 10 Jun 2007
A distilled methodology for detecting and isolating NHibernate-related performance and scalability issues
namespace ShipCompliant.WebServices.Samples
{
	public class TestDataGenerator
	{
		/*
		#region members
		private Random random;
		private Address [] addressBook;
		private static TestDataGenerator instance = null;
		#endregion
		#region singleton logic
		public static TestDataGenerator GetInstance()
		{
			if(instance==null) instance = new TestDataGenerator();
			return instance;
		}
		private TestDataGenerator()
		{
			random = new Random();
			BuildAddressBook();
		}
		#endregion
		#region methods
		#region address-valid
		private Address GetValidAddress()
		{
			return addressBook[random.Next(0,addressBook.Length-1)];
		}
		private void BuildAddressBook()
		{
			addressBook = new Address[5];

			addressBook[0] = new Address();
			addressBook[0].FirstName = "Randy";
			addressBook[0].LastName = "Hunt";
			addressBook[0].Street1 = "2883 5th Ave";
			addressBook[0].Street2 = "Premier Financial Bancorp";
			addressBook[0].City = "Huntington";
			addressBook[0].State = "WV";
			addressBook[0].Zip1 = "25702";
			addressBook[0].Zip2 = "1435";
			//addressBook[0].Country = "US";

			addressBook[1] = new Address();
			addressBook[1].FirstName = "Alan";
			addressBook[1].LastName = "Turing";
			addressBook[1].Street1 = "389 5th ave";
			addressBook[1].Street2 = "";
			addressBook[1].City = "New York";
			addressBook[1].State = "NY";
			addressBook[1].Zip1 = "10016";
			addressBook[1].Zip2 = "";
			//addressBook[1].Country = "US";

			addressBook[2] = new Address();
			addressBook[2].FirstName = "Connie";
			addressBook[2].LastName = "Nyland";
			addressBook[2].Street1 = "509 5th st";
			addressBook[2].Street2 = "";
			addressBook[2].City = "Boulder City";
			addressBook[2].State = "NV";
			addressBook[2].Zip1 = "89005";
			addressBook[2].Zip2 = "";
			//addressBook[2].Country = "US";

			addressBook[3] = new Address();
			addressBook[3].FirstName = "Rod";
			addressBook[3].LastName = "Jones";
			addressBook[3].Street1 = "1503 Baywood Dr";
			addressBook[3].Street2 = "";
			addressBook[3].City = "West Fargo";
			addressBook[3].State = "ND";
			addressBook[3].Zip1 = "58078";
			addressBook[3].Zip2 = "";
			//addressBook[3].Country = "US";

			addressBook[4] = new Address();
			addressBook[4].FirstName = "Ian";
			addressBook[4].LastName = "Barry";
			addressBook[4].Street1 = "6217 N 150th st";
			addressBook[4].Street2 = "";
			addressBook[4].City = "Omaha";
			addressBook[4].State = "NE";
			addressBook[4].Zip1 = "68116";
			addressBook[4].Zip2 = "";
			//addressBook[4].Country = "US";
		}
		#endregion
		#region address-random
		private Address GetRandomAddress()
		{
			Address address = new Address();
			address.FirstName = GetName();
			address.LastName = GetName();
			address.Street1 = GetAddress();
			address.Street2 = "";
			address.City = GetCity();
			address.State = GetState();
			address.Zip1 = GetZip();
			address.Zip2 = "";
			address.Phone = GetPhoneNumber();
			address.Fax = GetPhoneNumber();
			address.Country = "US";
			address.Company = "";
			address.County = "";
			//address.Website = "";
			//address.AlternatePhone="";
			address.DateOfBirth = DateTime.Now.AddYears(-random.Next(MINAGE,MAXAGE));
			return address;
		}
		private  string GetName()
		{
			string[] WordList = { "joe", "john", "wayne", "johnson", "jones", " sally", "christiansen","jeremy","jameson",
									"mary", "christian", "spence", "dorothy", "daniels", "westra","anderson","andy","cheryl","wolfgang"};
			return WordList[random.Next(0,WordList.Length)];
		}
		private  string GetAddress()
		{
			string[] WordList = { "11 Wallaby Way", "12 North Ridge Drive", "13 Dusty Lane", "52 Jone Ave", "123 Main St", " 200 University ave suite 12", 
									"32 Stillwater pl", "1 Grand Ave", "23 pearl st", "23 NW 55th st","260 N 12th street","11 Sunshine Boulevard"};
			return WordList[random.Next(0,WordList.Length)];
		}
		private  string GetCity()
		{
			string[] WordList = { "SpringField", "Lincoln", "StandardTown", "Capital City", "ParkTown", "WineTown", 
									"GenericsVille", "Central City","Sunny View","Mountain View", "Reunion", "Nowhere","Anywhere"};
			return WordList[random.Next(0,WordList.Length)];
		}
		private  string GetState()
		{
			string[] WordList = { "AL", "AK", "NY", "CA", "CO", "WY", 
									"NM", "AZ", "FL","MA","NH","VT","ME","CT","RI","TN","GA","OK","KA","HI","LA","TX","WA","OR","MI",
									"MT","MI","IA","ND","SD","NC","SC","VA","WV","PA","DE","KS"};
			return WordList[random.Next(0,WordList.Length)];
		}
		private  string GetZip()
		{
			return random.Next(00000,99999).ToString();
		}
		private  string GetPhoneNumber()
		{
			return random.Next(222,999).ToString() + "-"+ random.Next(222,999).ToString() + "-" + random.Next(2222,9999).ToString();
		}
		#endregion
		#region salesorder
		public SalesOrderRequest GetSampleRequest() 
		{
			SalesOrderRequest request = new SalesOrderRequest();
			request.SalesOrder = new SalesOrder();
			request.SalesOrder.BillTo = GetValidAddress();
			request.SalesOrder.CustomerKey = GetRandomCustomerKey();
			request.SalesOrder.OrderType = OrderType.Internet;
			request.SalesOrder.PurchaseDate = GetRandomRecentDate();
			request.SalesOrder.SalesOrderKey = GetRandomSalesOrderKey();
			request.SalesOrder.Shipments = new Shipment[random.Next(MINSHIPMENTSPERSALESORDER,MAXSHIPMENTSPERSALESORDER)];
			for(int i = 0; i < request.SalesOrder.Shipments.Length; i++)
			{
				request.SalesOrder.Shipments[i] = GetRandomShipment(LicenseRelationship.SupplierToConsumer);
			}
			return request;
		}
		private string GetRandomCustomerKey()
		{
			return "WSTestCustomerKey"+random.Next(1000000);
		}
		private string GetRandomSalesOrderKey()
		{
			return "WSTestSalesOrderKey"+random.Next(1000000);
		}
		private DateTime GetRandomRecentDate()
		{
			return DateTime.Now.AddDays(-random.Next(MINPASTRECENTDAYS,MAXPASTRECENTDAYS));
		}
		#endregion
		#region shipments
		private  Shipment GetRandomShipment(LicenseRelationship licenseType)
		{
			Shipment shipment = new Shipment();
			shipment.Freight = random.Next(MINFREIGHTCOST,MAXFREIGHTCOST);
			shipment.ShipDate = DateTime.Today.AddDays(-random.Next(MINDAYSPASTSHIPDATE,MAXDAYSPASTSHIPDATE));
			shipment.ShipmentItems = new ShipmentItem[random.Next(MINITEMSPERSHIPMENT,MAXITEMSPERSHIPMENT)];
			for(int i = 0; i < shipment.ShipmentItems.Length; i++)
			{
				shipment.ShipmentItems[i] = GetRandomShipmentItem();
			}
			shipment.Packages = new Package[random.Next(MINPACKAGESPERSHIPMENT,MAXPACKAGESPERSHIPMENT)];
			for(int i = 0; i < shipment.Packages.Length; i++)
			{
				shipment.Packages[i] = GetRandomPackage();
			}
			shipment.ShipmentKey = GetRandomShipmentKey();
			shipment.ShipTo = GetValidAddress();
			shipment.LicenseRelationship = licenseType;
			shipment.ShipmentStatus = GetRandomShipmentStatusType();
			shipment.ShippingService = GetRandomShipmentServiceType();
			return shipment;
		}
		private string GetRandomShipmentKey()
		{
			return "WSTestShipmentKey"+random.Next(1000000); 
		}
		private ShipmentStatus GetRandomShipmentStatusType()
		{
			Array shipmentStatusTypes = Enum.GetValues(typeof(ShipmentStatus));
			ShipmentStatus status = (ShipmentStatus)shipmentStatusTypes.GetValue(random.Next(0,shipmentStatusTypes.Length));
			while(status == ShipmentStatus.Voided || status ==ShipmentStatus.Null)
				status = (ShipmentStatus)shipmentStatusTypes.GetValue(random.Next(0,shipmentStatusTypes.Length));
			return status;
		}
		private ShippingService GetRandomShipmentServiceType()
		{
			Array shippingServiceTypes = Enum.GetValues(typeof(ShippingService));
			ShippingService service = (ShippingService)shippingServiceTypes.GetValue(random.Next(0,shippingServiceTypes.Length));
			while(service==ShippingService.Null)
				service = (ShippingService)shippingServiceTypes.GetValue(random.Next(0,shippingServiceTypes.Length));
			return service;
		}
		#endregion
		#region Packages
		private Package GetRandomPackage()
		{
			Package package = new Package();
			package.TrackingNumber = GetRandomTrackingNumber();
			return package;
		}
		private string GetRandomTrackingNumber()
		{
			return random.Next(10000000,999999999).ToString();
		}
		#endregion
		#region shipmentitems
		private  ShipmentItem GetRandomShipmentItem()
		{
			ShipmentItem shipmentItem = new ShipmentItem();
			shipmentItem.ProductUnitPrice = random.Next(MINUNITPRICE,MAXUNITPRICE);
			shipmentItem.ProductKey = GetRandomProductKey();
			shipmentItem.ProductQuantity = random.Next(MINQUANTITY,MAXQUANTITY);
			return shipmentItem;
		}
		#endregion
		#region products
		private string GetRandomProductKey()
		{
			return "SprkMG04";
		}
		#endregion
		#endregion
		#region settings
		private  readonly int MAXQUANTITY = 20;
		private  readonly int MINQUANTITY = 1;
		private  readonly int MINUNITPRICE = 5;
		private  readonly int MAXUNITPRICE = 200;
		private  readonly int MINAGE = 22;
		private  readonly int MAXAGE = 99;
		private  readonly int MINFREIGHTCOST = 5;
		private  readonly int MAXFREIGHTCOST = 200;
		private  readonly int MINDAYSPASTSHIPDATE = 0;
		private  readonly int MAXDAYSPASTSHIPDATE = 0;
		private  readonly int MINITEMSPERSHIPMENT = 1;
		private  readonly int MAXITEMSPERSHIPMENT = 10;
		private  readonly int MAXSHIPMENTSPERSALESORDER = 3;
		private  readonly int MINSHIPMENTSPERSALESORDER = 1;
		private  readonly int MINPASTRECENTDAYS = 0;
		private  readonly int MAXPASTRECENTDAYS = 30;
		private  readonly int MINPACKAGESPERSHIPMENT = 1;
		private  readonly int MAXPACKAGESPERSHIPMENT = 8;
		#endregion
		*/
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Peter Weissbrod
Web Developer
United States United States
Independent contract developer for .NET data-oriented systems.
 
not much to say about myself but feel free to contact me for any inquiries and comments!

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 10 Jun 2007
Article Copyright 2007 by Peter Weissbrod
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid