Exemplo n.º 1
0
        //--------------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <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 = "";
        }
Exemplo n.º 2
0
        //--------------------------------------------------------------------------------------------------------------------------------------------------------------
        /// <summary>
        ///     Generates n search patterns with between 1 and 3 search parameters randomly chosen from 6 of the RedisTestObj attributes
        ///     11-Aug-2016 - updated so that the patterns we are searching for are broader if there are multiple tests ...
        ///     16-Aug-2016 - No longer searching using the TestBool parameter as the query results are far too broad.
        /// </summary>
        public static void GenerateRandomPatterns(List <DatabaseIndexInfo> riis)
        {
            //-----0----- Reset the list of patterns to search for
            PatternsToSearchFor = new List <List <DatabaseSearchPattern> >();

            //     1=PrimaryKey, 2=Integer, 3=Long, 4=Double, 5=String, 6=DateTime (Note we are not using bool searches here as they are far too sloooow)
            int totalNumPatterns = 6;

            //-----1----- Process the number of search pattern groups specified in the global parameter
            for (int i = 0; i < NumSearchPatterns; i++)
            {
                List <DatabaseSearchPattern> rsps = new List <DatabaseSearchPattern>();

                //-----2----- Determine how many tests to run and from which parameters...
                int        numTests  = MGLEncryption.GenerateRandomInt(1, 3);
                List <int> testTypes = new List <int>();
                for (int j = 0; j < numTests; j++)
                {
                    int testType = MGLEncryption.GenerateRandomInt(1, totalNumPatterns);

                    //-----2a----- Reduce the number of PK queries in the multiple search parameter queries and instead choose integer range parameters..
                    if (testType == 1 && j > 0)
                    {
                        testType = 2;
                    }

                    //-----2b----- If this test type already exists, then iterate through and find a test type that has not yet already been chosen
                    while (testTypes.Contains(testType) == true)
                    {
                        testType = MGLEncryption.GenerateRandomInt(1, totalNumPatterns);
                        // Reduce the number of PK queries in the multiple search parameter queries and instead choose integer range parameters..
                        if (testType == 1 && j > 0)
                        {
                            testType = 2;
                        }
                    }
                    testTypes.Add(testType);


                    //-----3----- Now go through and randomly generate the SearchPattern for each of these test types
                    // We now have about six types of test we are processing...
                    if (testType == 1)                     //-----a----- ID - Primary Key - Equivalent - individual result ...
                    {
                        rsps.Add(GenerateSearchPatternPrimaryKey(0, TestParameters.NumIterations));
                    }
                    else if (testType == 2)             //-----b----- TestInt  - Try to ensure that max results returned is 20%
                    {
                        rsps.Add(GenerateSearchPatternInteger(1, TestParameters.MaxIntegerInRange, numTests));
                    }
                    else if (testType == 3)             //-----c----- TestLong - a range of 4 billion and we are searching between for ranges of 10,000,000 (i.e. 0.25%)
                    {
                        rsps.Add(GenerateSearchPatternLong(TestParameters.MinLongInRange, TestParameters.MaxLongInRange, numTests));
                    }
                    else if (testType == 4)            //-----d----- TestDouble - Try to ensure that max results return is 20%
                    {
                        rsps.Add(GenerateSearchPatternDouble(TestParameters.MinDoubleInRange, TestParameters.MaxDoubleInRange, numTests));
                    }
                    else if (testType == 5)           //-----e----- TestStr - max results returned is 1/(40*40) when using a two char search length
                    {
                        rsps.Add(GenerateSearchPatternString());
                    }
                    else if (testType == 6)          //-----f----- TestDT - searching for ranges in hours
                    {
                        rsps.Add(GenerateSearchPatternDateTime(TestParameters.DateMin, TestParameters.DateMax, numTests));
                    }
                }

                // 19-Aug-2016 - if DoDebug == true, we need to sort here so that the views in the MySQL and Redis debug lists are consistent!
                // Otherwise it is difficult to compare the results of the two databases afterwards ..
                if (RedisWrapper.DoDebug == true)
                {
                    rsps.Sort(DatabaseSearchPattern.Sort(riis));
                }

                // add our new search patterns ...
                PatternsToSearchFor.Add(rsps);
            }
        }