//-------------------------------------------------------------------------------------------------------------------------------------------------------------- /// <summary> /// Generates a series of simple integer range searches... useful for more specific testing /// </summary> public static void TestSorting() { List <DatabaseIndexInfo> riis = rw.IndexFindAll(new TestObj()); int randomVal = MGLEncryption.GenerateRandomInt(1, 1000000); long randomVal2 = MGLEncryption.GenerateRandomLong(8000000000, 12000000000); double randomVal3 = MGLEncryption.GenerateRandomDouble(0, 1); DateTime randomVal4 = MGLEncryption.GenerateRandomDateTime(TestParameters.DateMin, TestParameters.DateMax); List <DatabaseSearchPattern> testPatterns = new List <DatabaseSearchPattern>() { // Bool new DatabaseSearchPattern("TestBool", MGLEncryption.GenerateRandomBool()), // Score - equivalent (int) new DatabaseSearchPattern("TestInt", randomVal), // Score - greater than new DatabaseSearchPattern("TestInt", randomVal, true), // Score - less than new DatabaseSearchPattern("TestInt", randomVal, false), // Score - between new DatabaseSearchPattern("TestInt", randomVal, randomVal + TestParameters.SearchRangeSize), // Text - Starts with new DatabaseSearchPattern("TestStr", MGLEncryption.GetSalt(RedisWrapper.TextIndexLength).ToString().ToLower()), // Score - between (long) new DatabaseSearchPattern("TestLong", randomVal2, randomVal2 + (4000000000 * TestParameters.SearchRangeSize / 1000000)), // Primary key new DatabaseSearchPattern((long)randomVal), // Score - between new DatabaseSearchPattern("TestDouble", randomVal3, randomVal3 + ((double)TestParameters.SearchRangeSize / 1000000.0)), // Date time - betwen new DatabaseSearchPattern("TestDT", randomVal4, randomVal4.AddDays(1)), // Date time - less than new DatabaseSearchPattern("TestDT", randomVal4, false), // Date time - greater than new DatabaseSearchPattern("TestDT", randomVal4, true), // Date time - equivalent new DatabaseSearchPattern("TestDT", randomVal4) }; // sort it testPatterns.Sort(DatabaseSearchPattern.Sort(riis)); string isItGucci = ""; }
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- /// <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); }