//-------------------------------------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Generates a number of randomly generated RedisTestObj objects, with each parameter between a range... /// These are ONLY used for writing, so we can ignore if the readonly flag is enabled /// </summary> public static void GenerateRandomObjects() { // These are ONLY used for writing, so we can ignore if the readonly flag is enabled if (TestParameters.DoWrite == false) { Logger.Log("Skipping generating the random objects as the global TestParameter.JustDoRead parameter is set to read only."); return; } RandomObjects = new List <object>(); // Generate some random data! Logger.LogSubHeading("Generating " + NumIterations + " randomly generated TestObj objects..."); int i = 0; for (i = 0; i < NumIterations; i++) { RandomObjects.Add( // The primary key new TestObj((ulong)i, // A random int MGLEncryption.GenerateRandomInt(1, MaxIntegerInRange), // longs ... MGLEncryption.GenerateRandomLong(TestParameters.MinLongInRange, TestParameters.MaxLongInRange), // doubles ... MGLEncryption.GenerateRandomDouble(TestParameters.MinDoubleInRange, TestParameters.MaxDoubleInRange), // bools ... MGLEncryption.GenerateRandomBool(), // strings ... MGLEncryption.GetSalt(20).ToString(), // DateTime - Standardise the dates to the nearest second so that the MySQL vs Redis comparison is consistent // Otherwise Redis is stored to the nearest MS while MySQL only stores to the nearest second DatabaseSearchPattern.StandardiseDateToStartOfSecond(MGLEncryption.GenerateRandomDateTime(TestParameters.DateMin, TestParameters.DateMax), false))); // Log the progress ... Logger.Log(i, 1000, NumIterations); } Logger.Log(i, 1, NumIterations); Logger.Log("\n"); }
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- public static DatabaseSearchPattern GenerateSearchPatternDateTime(DateTime min, DateTime max, int numTestsInGroup) { DatabaseSearchPattern rsp = null; //-----a----- Get the expression type (==, <=, >= or between) int randomET = GenerateExpressionType(numTestsInGroup); //-----b----- The default range in HOURS - note that we calculate this in the same manner as the other ranges from the integer parameter (approx 3.6 hrs) int range = (int)Math.Round(TestParameters.DateMax.Subtract(TestParameters.DateMin).TotalHours *TestParameters.SearchRangeSize / TestParameters.MaxIntegerInRange); //----c----- so we want to generalise for multiple tests --- so if numTests > 0, then increase the range and bring in the min and max to ensure a larger range ..... if (numTestsInGroup > 1) { range = range * 18; // becomes roughly three days // 8; // For >= or <= lets also tweak the min and max to ensure the range is larger if (randomET == 2) { min = min.AddHours(range); max = max.AddHours(-range); } } //-----d----- Generate the random value DateTime randomVal = DatabaseSearchPattern.StandardiseDateToStartOfSecond(MGLEncryption.GenerateRandomDateTime(min, max), false); //-----e----- And generate the search pattern as well... if (randomET == 1) //_____ == _____ // Note that for dates equal to - would result in all the results for a specific date and time being returned - which is only very rarely going to return results { rsp = new DatabaseSearchPattern("TestDT", randomVal); } else if (randomET == 2) //_____ >= or <= range search _____ // We need a random bool to determine if this is a >= or a <= search ... { bool randomBool = MGLEncryption.GenerateRandomBool(); // Generate ranges between the temporarily defined max and min above and a range's width above or below these parameters // depending on whether this is greater than or less than ... if (randomBool == true) { randomVal = DatabaseSearchPattern.StandardiseDateToStartOfSecond(MGLEncryption.GenerateRandomDateTime(max.AddHours(-range), max), false); } else { randomVal = DatabaseSearchPattern.StandardiseDateToStartOfSecond(MGLEncryption.GenerateRandomDateTime(min, min.AddHours(range)), false); } // Now add this randomVal as a range query rsp = new DatabaseSearchPattern("TestDT", randomVal, randomBool); } else //_____ Between _____ // Between our randomly generated date and a range's width above this ... { rsp = new DatabaseSearchPattern("TestDT", randomVal, randomVal.AddHours(range)); } return(rsp); }