//-------------------------------------------------------------------------------------------------------------------------------------------------------------- public static DatabaseSearchPattern GenerateSearchPatternLong(long min, long max, int numTestsInGroup) { DatabaseSearchPattern rsp = null; //-----a----- Get the expression type (==, <=, >= or between) int randomET = GenerateExpressionType(numTestsInGroup); //-----b----- The range is 20m by default long range = ((max - min) * TestParameters.SearchRangeSize / TestParameters.MaxIntegerInRange); //-----c----- So we want to generalise for multiple tests --- so if numTests > 0, then increase the range ..... if (numTestsInGroup > 1) { // increase the range by a factor of 10 ... range = range * 10; // For >= or <= lets also tweak the min and max to ensure the range is larger if (randomET == 2) { min = min + range; max = max - range; } } //-----d----- Generate the random value long randomVal = MGLEncryption.GenerateRandomLong(min, max); //-----e----- Generate the search expression if (randomET == 1) //_____ == _____ { rsp = new DatabaseSearchPattern("TestLong", randomVal); } else if (randomET == 2) //_____ >= or <= range search _____ // Work out if this is a <= or >= query { bool randomBool = MGLEncryption.GenerateRandomBool(); if (randomBool == true) { rsp = new DatabaseSearchPattern("TestLong", MGLEncryption.GenerateRandomLong(max - range, max), randomBool); } else { rsp = new DatabaseSearchPattern("TestLong", MGLEncryption.GenerateRandomLong(min, min + range), randomBool); } } else //_____ Between _____ { rsp = new DatabaseSearchPattern("TestLong", randomVal, randomVal + range); } return(rsp); }
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- /// <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 GenerateSearchPatternPrimaryKey(long start, long end) { // We just generate a random number between the start and the end return(new DatabaseSearchPattern(MGLEncryption.GenerateRandomLong(start, end))); }