Ejemplo n.º 1
0
        public void TestSqlAsyncMARS()
        {
            const int MaxCmds = 11;
            Random    rnd     = RandomInstance;

            using (DataStressConnection conn = Factory.CreateConnection(rnd, DataStressFactory.ConnectionStringOptions.EnableMars))
            {
                if (!OpenConnection(conn))
                {
                    return;
                }
                DataStressFactory.TableMetadata table = Factory.GetRandomTable(rnd);

                // MARS session cache is by default 10.
                // This is documented here: http://msdn.microsoft.com/en-us/library/h32h3abf.aspx
                // We want to stress test this by allowing 11 concurrent commands. Hence the max in rnd.Next below is 12.
                MARSCommand[] cmds = new MARSCommand[rnd.Next(5, MaxCmds + 1)];

                for (int i = 0; i < cmds.Length; i++)
                {
                    cmds[i] = new MARSCommand();

                    // Make every 3rd query xml reader
                    if (i % 3 == 0)
                    {
                        cmds[i].query = true;
                        cmds[i].xml   = true;
                    }
                    else
                    {
                        cmds[i].query = rnd.NextBool();
                        cmds[i].xml   = false;
                    }

                    cmds[i].cmd    = (SqlCommand)Factory.GetCommand(rnd, table, conn, cmds[i].query, cmds[i].xml);
                    cmds[i].result = SqlCommandBeginExecute(cmds[i].cmd, cmds[i].query, cmds[i].xml, rnd.NextBool());
                    if (cmds[i].result != null)
                    {
                        WaitForAsyncOpToComplete(rnd, cmds[i].result, true, false);
                    }
                }

                // After all commands have been launched, wait for them to complete now.
                for (int i = 0; i < cmds.Length; i++)
                {
                    SqlCommandEndExecute(rnd, cmds[i].result, cmds[i].cmd, cmds[i].query, cmds[i].xml, false);
                }
            }
        }
Ejemplo n.º 2
0
        public void TestSqlAsyncMARS()
        {
            const int MaxCmds = 11;
            Random rnd = RandomInstance;

            using (DataStressConnection conn = Factory.CreateConnection(rnd, DataStressFactory.ConnectionStringOptions.EnableMars))
            {
                if (!OpenConnection(conn)) return;
                DataStressFactory.TableMetadata table = Factory.GetRandomTable(rnd);

                // MARS session cache is by default 10. 
                // This is documented here: http://msdn.microsoft.com/en-us/library/h32h3abf.aspx
                // We want to stress test this by allowing 11 concurrent commands. Hence the max in rnd.Next below is 12.
                MARSCommand[] cmds = new MARSCommand[rnd.Next(5, MaxCmds + 1)];

                for (int i = 0; i < cmds.Length; i++)
                {
                    cmds[i] = new MARSCommand();

                    // Make every 3rd query xml reader
                    if (i % 3 == 0)
                    {
                        cmds[i].query = true;
                        cmds[i].xml = true;
                    }
                    else
                    {
                        cmds[i].query = rnd.NextBool();
                        cmds[i].xml = false;
                    }

                    cmds[i].cmd = (SqlCommand)Factory.GetCommand(rnd, table, conn, cmds[i].query, cmds[i].xml);
                    cmds[i].result = SqlCommandBeginExecute(cmds[i].cmd, cmds[i].query, cmds[i].xml, rnd.NextBool());
                    if (cmds[i].result != null)
                        WaitForAsyncOpToComplete(rnd, cmds[i].result, true, false);
                }

                // After all commands have been launched, wait for them to complete now.
                for (int i = 0; i < cmds.Length; i++)
                {
                    SqlCommandEndExecute(rnd, cmds[i].result, cmds[i].cmd, cmds[i].query, cmds[i].xml, false);
                }
            }
        }