コード例 #1
0
        /// <summary>
        /// Returns a random DELETE command
        /// </summary>
        public DbCommand GetDeleteCommand(Random rnd, TableMetadata table, DataStressConnection conn)
        {
            DbCommand com = CreateCommand(rnd, conn);

            StringBuilder cmdText = new StringBuilder();

            cmdText.Append("DELETE FROM \"");

            List <TableColumn> columns = table.Columns;
            string             pName   = GetParameterName("P0");

            cmdText.Append(table.TableName);
            cmdText.Append("\" WHERE PrimaryKey = ");
            cmdText.Append(pName);

            DbParameter param = DbFactory.CreateParameter();

            param.ParameterName = pName;
            param.Value         = GetRandomPK(rnd, table);
            com.Parameters.Add(param);

            if (ShouldModifySession(rnd))
            {
                cmdText.Append(";").Append(GetRandomSessionModificationStatement(rnd));
            }

            com.CommandText = cmdText.ToString();
            return(com);
        }
コード例 #2
0
ファイル: DataTestGroup.cs プロジェクト: pgovind/runtime
        /// <summary>
        /// Utility method to test Async scenario using await keyword
        /// </summary>
        /// <returns></returns>
        protected virtual async Task TestCommandAndReaderAsyncInternal()
        {
            Random rnd = RandomInstance;

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

                com = Factory.GetInsertCommand(rnd, table, conn);
                await CommandExecuteAsync(rnd, com, false);

                com = Factory.GetDeleteCommand(rnd, table, conn);
                await CommandExecuteAsync(rnd, com, false);

                com = Factory.GetSelectCommand(rnd, table, conn);
                await com.ExecuteScalarAsync();

                com = Factory.GetSelectCommand(rnd, table, conn);
                await CommandExecuteAsync(rnd, com, true);
            }
        }
コード例 #3
0
        /// <summary>
        /// Returns a random command object
        /// </summary>
        public DbCommand GetCommand(Random rnd, TableMetadata table, DataStressConnection conn, bool query, bool isXml = false)
        {
            if (query)
            {
                return(GetSelectCommand(rnd, table, conn, isXml));
            }
            else
            {
                // make sure arguments are correct
                DataStressErrors.Assert(!isXml, "wrong usage of GetCommand: cannot create command with FOR XML that is not query");

                int select = rnd.Next(4);
                switch (select)
                {
                case 0:
                    return(GetUpdateCommand(rnd, table, conn));

                case 1:
                    return(GetInsertCommand(rnd, table, conn));

                case 2:
                    return(GetDeleteCommand(rnd, table, conn));

                default:
                    return(GetSelectCommand(rnd, table, conn));
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Returns a random existing Primary Key value
        /// </summary>
        private int GetRandomPK(Random rnd, TableMetadata table)
        {
            using (DataStressConnection conn = CreateConnection())
            {
                conn.Open();

                // This technique to get a random row comes from http://www.4guysfromrolla.com/webtech/042606-1.shtml
                // When you set rowcount and then select into a scalar value, then the query is optimised so that
                // just the last value is selected. So if n = ROWCOUNT then the query returns the n'th row.

                int rowNumber = rnd.Next(Depth);

                DbCommand com     = conn.CreateCommand();
                string    cmdText = string.Format(
                    @"SET ROWCOUNT {0};
                          DECLARE @PK INT;
                          SELECT @PK = PrimaryKey FROM {1} WITH(NOLOCK)
                          SELECT @PK", rowNumber, table.TableName);

                com.CommandText = cmdText;

                object result = com.ExecuteScalarSyncOrAsync(CancellationToken.None, rnd).Result;
                if (result == DBNull.Value)
                {
                    throw DataStressErrors.TestError(string.Format("Table {0} returned DBNull for primary key", table.TableName));
                }
                else
                {
                    int primaryKey = (int)result;
                    return(primaryKey);
                }
            }
        }
コード例 #5
0
ファイル: DataTestGroup.cs プロジェクト: pgovind/runtime
        public void TestCommandTimeout()
        {
            Random rnd = RandomInstance;
            DataStressConnection conn = null;

            try
            {
                // Use a transaction 50% of the time
                if (rnd.NextBool())
                {
                }

                // Create a select command
                conn = Factory.CreateConnection(rnd);
                if (!OpenConnection(conn))
                {
                    return;
                }
                DataStressFactory.TableMetadata table = Factory.GetRandomTable(rnd);
                DbCommand com = Factory.GetSelectCommand(rnd, table, conn);

                // Setup timeout. We want to see various possibilities of timeout happening before, after, or at the same time as when the result comes in.
                int delay   = rnd.Next(0, 10); // delay is from 0 to 9 seconds inclusive
                int timeout = rnd.Next(1, 10); // timeout is from 1 to 9 seconds inclusive
                com.CommandText   += string.Format("; WAITFOR DELAY '00:00:0{0}'", delay);
                com.CommandTimeout = timeout;

                // Execute command and catch timeout exception
                try
                {
                    CommandExecute(rnd, com, true);
                }
                catch (DbException e)
                {
                    if (e is SqlException && ((SqlException)e).Number == 3989)
                    {
                        throw DataStressErrors.ProductError("Timing issue between OnTimeout and ReadAsyncCallback results in SqlClient's packet parsing going out of sync", e);
                    }
                    else if (!e.Message.ToLower().Contains("timeout"))
                    {
                        throw;
                    }
                }
            }
            finally
            {
                if (conn != null)
                {
                    conn.Dispose();
                }
            }
        }
コード例 #6
0
ファイル: DataTestGroup.cs プロジェクト: pgovind/runtime
        public void TestCommandDelete()
        {
            Random rnd = RandomInstance;

            using (DataStressConnection conn = Factory.CreateConnection(rnd))
            {
                if (!OpenConnection(conn))
                {
                    return;
                }
                DataStressFactory.TableMetadata table = Factory.GetRandomTable(rnd);
                DbCommand com = Factory.GetDeleteCommand(rnd, table, conn);
                CommandExecute(rnd, com, false);
            }
        }
コード例 #7
0
        // method used to delete stress tables in the database
        protected void CleanupUserTables(TableMetadata tableMetadata)
        {
            string DropTable = "drop TABLE " + tableMetadata.TableName + ";";

            using (DataStressConnection conn = CreateConnection(null))
            {
                conn.Open();
                using (DbCommand com = conn.CreateCommand())
                {
                    try
                    {
                        com.CommandText = DropTable;
                        com.ExecuteNonQuery();
                    }
                    catch (Exception) { }
                }
            }
        }
コード例 #8
0
ファイル: DataTestGroup.cs プロジェクト: pgovind/runtime
        /// <summary>
        /// Utility function used by MARS tests
        /// </summary>
        private void TestCommandMARS(Random rnd, bool query)
        {
            if (Source.Type != DataSourceType.SqlServer)
            {
                return; // skip for non-SQL Server databases
            }
            using (DataStressConnection conn = Factory.CreateConnection(rnd, DataStressFactory.ConnectionStringOptions.EnableMars))
            {
                if (!OpenConnection(conn))
                {
                    return;
                }
                DbCommand[] commands = new DbCommand[rnd.Next(5, 10)];
                List <Task> tasks    = new List <Task>();
                // Create commands
                for (int i = 0; i < commands.Length; i++)
                {
                    DataStressFactory.TableMetadata table = Factory.GetRandomTable(rnd);
                    commands[i] = Factory.GetCommand(rnd, table, conn, query);
                }

                try
                {
                    // Execute commands
                    for (int i = 0; i < commands.Length; i++)
                    {
                        if (rnd.NextBool(0.7))
                        {
                            tasks.Add(CommandExecuteAsync(rnd, commands[i], query));
                        }
                        else
                        {
                            CommandExecute(rnd, commands[i], query);
                        }
                    }
                }
                finally
                {
                    // All commands must be complete before closing the connection
                    AsyncUtils.WaitAll(tasks.ToArray());
                }
            }
        }
コード例 #9
0
        private DbCommand CreateCommand(Random rnd, DataStressConnection conn)
        {
            DbCommand cmd;

            if (conn == null)
            {
                cmd = DbFactory.CreateCommand();
            }
            else
            {
                cmd = conn.CreateCommand();
            }

            if (rnd != null)
            {
                cmd.CommandTimeout = rnd.NextBool() ? 30 : 600;
            }

            return(cmd);
        }
コード例 #10
0
ファイル: DataTestGroup.cs プロジェクト: pgovind/runtime
 protected bool OpenConnection(DataStressConnection conn)
 {
     try
     {
         conn.Open();
         return(true);
     }
     catch (Exception e)
     {
         if (IsServerNotAccessibleException(e, conn.DbConnection.ConnectionString, conn.DbConnection.DataSource))
         {
             // Ignore this exception.
             // This exception will fire when using named pipes with MultiSubnetFailover option set to true.
             // MultiSubnetFailover=true only works with TCP/IP protocol and will result in exception when using with named pipes.
             return(false);
         }
         else
         {
             throw e;
         }
     }
 }
コード例 #11
0
        /// <summary>
        /// Returns a random SELECT command
        /// </summary>
        public DbCommand GetSelectCommand(Random rnd, TableMetadata tableMetadata, DataStressConnection conn, bool isXml = false)
        {
            DbCommand     com     = CreateCommand(rnd, conn);
            StringBuilder cmdText = new StringBuilder();

            cmdText.Append(GetSelectCommandForMultipleRows(rnd, com, tableMetadata, isXml));

            // 33% of the time, we also want to add another batch to the select command to allow for
            // multiple result sets.
            if ((!isXml) && (rnd.Next(0, 3) == 0))
            {
                cmdText.Append(";").Append(GetSelectCommandForScalarValue(com));
            }

            if ((!isXml) && ShouldModifySession(rnd))
            {
                cmdText.Append(";").Append(GetRandomSessionModificationStatement(rnd));
            }

            com.CommandText = cmdText.ToString();
            return(com);
        }
コード例 #12
0
ファイル: DataStressFactory.cs プロジェクト: Corillian/corefx
        private DbCommand CreateCommand(Random rnd, DataStressConnection conn)
        {
            DbCommand cmd;
            if (conn == null)
            {
                cmd = DbFactory.CreateCommand();
            }
            else
            {
                cmd = conn.CreateCommand();
            }

            if (rnd != null)
            {
                cmd.CommandTimeout = rnd.NextBool() ? 30 : 600;
            }

            return cmd;
        }
コード例 #13
0
ファイル: DataStressFactory.cs プロジェクト: Corillian/corefx
        /// <summary>
        /// Returns a random command object
        /// </summary>
        public DbCommand GetCommand(Random rnd, TableMetadata table, DataStressConnection conn, bool query, bool isXml = false)
        {
            if (query)
            {
                return GetSelectCommand(rnd, table, conn, isXml);
            }
            else
            {
                // make sure arguments are correct
                DataStressErrors.Assert(!isXml, "wrong usage of GetCommand: cannot create command with FOR XML that is not query");

                int select = rnd.Next(4);
                switch (select)
                {
                    case 0:
                        return GetUpdateCommand(rnd, table, conn);
                    case 1:
                        return GetInsertCommand(rnd, table, conn);
                    case 2:
                        return GetDeleteCommand(rnd, table, conn);
                    default:
                        return GetSelectCommand(rnd, table, conn);
                }
            }
        }
コード例 #14
0
ファイル: DataStressFactory.cs プロジェクト: Corillian/corefx
        /// <summary>
        /// Returns a random SELECT command
        /// </summary>
        public DbCommand GetSelectCommand(Random rnd, TableMetadata tableMetadata, DataStressConnection conn, bool isXml = false)
        {
            DbCommand com = CreateCommand(rnd, conn);
            StringBuilder cmdText = new StringBuilder();
            cmdText.Append(GetSelectCommandForMultipleRows(rnd, com, tableMetadata, isXml));

            // 33% of the time, we also want to add another batch to the select command to allow for
            // multiple result sets.
            if ((!isXml) && (rnd.Next(0, 3) == 0))
            {
                cmdText.Append(";").Append(GetSelectCommandForScalarValue(com));
            }

            if ((!isXml) && ShouldModifySession(rnd))
            {
                cmdText.Append(";").Append(GetRandomSessionModificationStatement(rnd));
            }

            com.CommandText = cmdText.ToString();
            return com;
        }
コード例 #15
0
        // method used to create stress tables in the database
        protected void BuildUserTables(List <TableMetadata> TableMetadataList)
        {
            string CreateTable1 =
                "CREATE TABLE stress_test_table_1 (PrimaryKey int identity(1,1) primary key, int_FLD int, smallint_FLD smallint, real_FLD real, float_FLD float, decimal_FLD decimal(28,4), " +
                "smallmoney_FLD smallmoney, bit_FLD bit, tinyint_FLD tinyint, uniqueidentifier_FLD uniqueidentifier, varbinary_FLD varbinary(756), binary_FLD binary(756), " +
                "image_FLD image, varbinarymax_FLD varbinary(max), timestamp_FLD timestamp, char_FLD char(756), text_FLD text, varcharmax_FLD varchar(max), " +
                "varchar_FLD varchar(756), nchar_FLD nchar(756), ntext_FLD ntext, nvarcharmax_FLD nvarchar(max), nvarchar_FLD nvarchar(756), datetime_FLD datetime, " +
                "smalldatetime_FLD smalldatetime);" +
                "CREATE UNIQUE INDEX stress_test_table_1 on stress_test_table_1 ( PrimaryKey );" +
                "insert into stress_test_table_1(int_FLD, smallint_FLD, real_FLD, float_FLD, decimal_FLD, " +
                "smallmoney_FLD, bit_FLD, tinyint_FLD, uniqueidentifier_FLD, varbinary_FLD, binary_FLD, " +
                "image_FLD, varbinarymax_FLD, char_FLD, text_FLD, varcharmax_FLD, " +
                "varchar_FLD, nchar_FLD, ntext_FLD, nvarcharmax_FLD, nvarchar_FLD, datetime_FLD, " +
                "smalldatetime_FLD) values ( 0, 0, 0, 0, 0, $0, 0, 0, '00000000-0000-0000-0000-000000000000', " +
                "0x00, 0x00, 0x00, 0x00, '0', '0', '0', '0', N'0', N'0', N'0', N'0', '01/11/2000 12:54:01', '01/11/2000 12:54:00' );"
            ;

            string CreateTable2 =
                "CREATE TABLE stress_test_table_2 (PrimaryKey int identity(1,1) primary key, bigint_FLD bigint, money_FLD money, numeric_FLD numeric, " +
                "time_FLD time, date_FLD date, datetimeoffset_FLD datetimeoffset, sql_variant_FLD sql_variant, " +
                "datetime2_FLD datetime2, xml_FLD xml);" +
                "CREATE UNIQUE INDEX stress_test_table_2 on stress_test_table_2 ( PrimaryKey );" +
                "insert into stress_test_table_2(bigint_FLD, money_FLD, numeric_FLD, " +
                "time_FLD, date_FLD, datetimeoffset_FLD, sql_variant_FLD, " +
                "datetime2_FLD, xml_FLD) values ( 0, $0, 0, '01/11/2015 12:54:01', '01/11/2015 12:54:01', '01/11/2000 12:54:01 -08:00', 0, '01/11/2000 12:54:01', '0' );"
            ;

            if (TableMetadataList == null)
            {
                TableMetadataList = new List <TableMetadata>();
            }

            List <TableColumn> tableColumns1 = new List <TableColumn>();

            tableColumns1.Add(new TableColumn("PrimaryKey", -1));
            tableColumns1.Add(new TableColumn("int_FLD", -1));
            tableColumns1.Add(new TableColumn("smallint_FLD", -1));
            tableColumns1.Add(new TableColumn("real_FLD", -1));
            tableColumns1.Add(new TableColumn("float_FLD", -1));
            tableColumns1.Add(new TableColumn("decimal_FLD", -1));
            tableColumns1.Add(new TableColumn("smallmoney_FLD", -1));
            tableColumns1.Add(new TableColumn("bit_FLD", -1));
            tableColumns1.Add(new TableColumn("tinyint_FLD", -1));
            tableColumns1.Add(new TableColumn("uniqueidentifier_FLD", -1));
            tableColumns1.Add(new TableColumn("varbinary_FLD", 756));
            tableColumns1.Add(new TableColumn("binary_FLD", 756));
            tableColumns1.Add(new TableColumn("image_FLD", -1));
            tableColumns1.Add(new TableColumn("varbinarymax_FLD", -1));
            tableColumns1.Add(new TableColumn("timestamp_FLD", -1));
            tableColumns1.Add(new TableColumn("char_FLD", -1));
            tableColumns1.Add(new TableColumn("text_FLD", -1));
            tableColumns1.Add(new TableColumn("varcharmax_FLD", -1));
            tableColumns1.Add(new TableColumn("varchar_FLD", 756));
            tableColumns1.Add(new TableColumn("nchar_FLD", 756));
            tableColumns1.Add(new TableColumn("ntext_FLD", -1));
            tableColumns1.Add(new TableColumn("nvarcharmax_FLD", -1));
            tableColumns1.Add(new TableColumn("nvarchar_FLD", 756));
            tableColumns1.Add(new TableColumn("datetime_FLD", -1));
            tableColumns1.Add(new TableColumn("smalldatetime_FLD", -1));
            TableMetadata tableMeta1 = new TableMetadata("stress_test_table_1", tableColumns1);

            TableMetadataList.Add(tableMeta1);

            List <TableColumn> tableColumns2 = new List <TableColumn>();

            tableColumns2.Add(new TableColumn("PrimaryKey", -1));
            tableColumns2.Add(new TableColumn("bigint_FLD", -1));
            tableColumns2.Add(new TableColumn("money_FLD", -1));
            tableColumns2.Add(new TableColumn("numeric_FLD", -1));
            tableColumns2.Add(new TableColumn("time_FLD", -1));
            tableColumns2.Add(new TableColumn("date_FLD", -1));
            tableColumns2.Add(new TableColumn("datetimeoffset_FLD", -1));
            tableColumns2.Add(new TableColumn("sql_variant_FLD", -1));
            tableColumns2.Add(new TableColumn("datetime2_FLD", -1));
            tableColumns2.Add(new TableColumn("xml_FLD", -1));
            TableMetadata tableMeta2 = new TableMetadata("stress_test_table_2", tableColumns2);

            TableMetadataList.Add(tableMeta2);

            using (DataStressConnection conn = CreateConnection(null))
            {
                conn.Open();
                using (DbCommand com = conn.CreateCommand())
                {
                    try
                    {
                        com.CommandText = CreateTable1;
                        com.ExecuteNonQuery();
                    }
                    catch (DbException de)
                    {
                        // This can be improved by doing a Drop Table if exists.
                        if (de.Message.Contains("There is already an object named \'" + tableMeta1.TableName + "\' in the database."))
                        {
                            CleanupUserTables(tableMeta1);
                            com.ExecuteNonQuery();
                        }
                        else
                        {
                            throw de;
                        }
                    }

                    try
                    {
                        com.CommandText = CreateTable2;
                        com.ExecuteNonQuery();
                    }
                    catch (DbException de)
                    {
                        // This can be improved by doing a Drop Table if exists in the query itself.
                        if (de.Message.Contains("There is already an object named \'" + tableMeta2.TableName + "\' in the database."))
                        {
                            CleanupUserTables(tableMeta2);
                            com.ExecuteNonQuery();
                        }
                        else
                        {
                            throw de;
                        }
                    }

                    for (int i = 0; i < Depth; i++)
                    {
                        TrackedRandom randomInstance = new TrackedRandom();
                        randomInstance.Mark();

                        DbCommand comInsert1 = GetInsertCommand(randomInstance, tableMeta1, conn);
                        comInsert1.ExecuteNonQuery();

                        DbCommand comInsert2 = GetInsertCommand(randomInstance, tableMeta2, conn);
                        comInsert2.ExecuteNonQuery();
                    }
                }
            }
        }
コード例 #16
0
ファイル: DataStressFactory.cs プロジェクト: Corillian/corefx
        /// <summary>
        /// Returns a random INSERT command
        /// </summary> 
        public DbCommand GetInsertCommand(Random rnd, TableMetadata table, DataStressConnection conn)
        {
            DbCommand com = CreateCommand(rnd, conn);

            StringBuilder cmdText = new StringBuilder();
            cmdText.Append("INSERT INTO \"");
            cmdText.Append(table.TableName);
            cmdText.Append("\" (");

            StringBuilder valuesText = new StringBuilder();
            valuesText.Append(") VALUES (");

            List<TableColumn> columns = table.Columns;
            int numColumns = rnd.Next(2, columns.Count);
            bool mostlyNull = rnd.NextBool(0.1); // 10% of rows have 90% chance of each column being null, in order to test nbcrow

            for (int i = 0; i < numColumns; i++)
            {
                if (columns[i].ColumnName.ToUpper() == "PRIMARYKEY") continue;

                if (i > 1)
                {
                    cmdText.Append(", ");
                    valuesText.Append(", ");
                }

                cmdText.Append(columns[i].ColumnName);

                if (columns[i].ColumnName.ToUpper() == "TIMESTAMP_FLD")
                {
                    valuesText.Append("DEFAULT"); // Cannot insert an explicit value in a timestamp field
                }
                else if (mostlyNull && rnd.NextBool(0.9))
                {
                    valuesText.Append("NULL");
                }
                else
                {
                    DbParameter param = CreateRandomParameter(rnd, string.Format("P{0}", i + 1), columns[i]);

                    valuesText.Append(param.ParameterName);
                    com.Parameters.Add(param);
                }
            }

            // To deal databases that do not support auto-incremented columns (Oracle?)
            // if (!columns["PrimaryKey"].AutoIncrement)
            if (PrimaryKeyValueIsRequired)
            {
                DbParameter param = CreateRandomParameter(rnd, "P0", table.GetColumn("PrimaryKey"));
                cmdText.Append(", PrimaryKey");
                valuesText.Append(", ");
                valuesText.Append(param.ParameterName);
                com.Parameters.Add(param);
            }

            valuesText.Append(")");
            cmdText.Append(valuesText);

            if (ShouldModifySession(rnd))
            {
                cmdText.Append(";").Append(GetRandomSessionModificationStatement(rnd));
            }

            com.CommandText = cmdText.ToString();
            return com;
        }
コード例 #17
0
        /// <summary>
        /// Returns a random INSERT command
        /// </summary>
        public DbCommand GetInsertCommand(Random rnd, TableMetadata table, DataStressConnection conn)
        {
            DbCommand com = CreateCommand(rnd, conn);

            StringBuilder cmdText = new StringBuilder();

            cmdText.Append("INSERT INTO \"");
            cmdText.Append(table.TableName);
            cmdText.Append("\" (");

            StringBuilder valuesText = new StringBuilder();

            valuesText.Append(") VALUES (");

            List <TableColumn> columns = table.Columns;
            int  numColumns            = rnd.Next(2, columns.Count);
            bool mostlyNull            = rnd.NextBool(0.1); // 10% of rows have 90% chance of each column being null, in order to test nbcrow

            for (int i = 0; i < numColumns; i++)
            {
                if (columns[i].ColumnName.ToUpper() == "PRIMARYKEY")
                {
                    continue;
                }

                if (i > 1)
                {
                    cmdText.Append(", ");
                    valuesText.Append(", ");
                }

                cmdText.Append(columns[i].ColumnName);

                if (columns[i].ColumnName.ToUpper() == "TIMESTAMP_FLD")
                {
                    valuesText.Append("DEFAULT"); // Cannot insert an explicit value in a timestamp field
                }
                else if (mostlyNull && rnd.NextBool(0.9))
                {
                    valuesText.Append("NULL");
                }
                else
                {
                    DbParameter param = CreateRandomParameter(rnd, string.Format("P{0}", i + 1), columns[i]);

                    valuesText.Append(param.ParameterName);
                    com.Parameters.Add(param);
                }
            }

            // To deal databases that do not support auto-incremented columns (Oracle?)
            // if (!columns["PrimaryKey"].AutoIncrement)
            if (PrimaryKeyValueIsRequired)
            {
                DbParameter param = CreateRandomParameter(rnd, "P0", table.GetColumn("PrimaryKey"));
                cmdText.Append(", PrimaryKey");
                valuesText.Append(", ");
                valuesText.Append(param.ParameterName);
                com.Parameters.Add(param);
            }

            valuesText.Append(")");
            cmdText.Append(valuesText);

            if (ShouldModifySession(rnd))
            {
                cmdText.Append(";").Append(GetRandomSessionModificationStatement(rnd));
            }

            com.CommandText = cmdText.ToString();
            return(com);
        }
コード例 #18
0
ファイル: DataStressFactory.cs プロジェクト: Corillian/corefx
        /// <summary>
        /// Returns a random UPDATE command
        /// </summary>  
        public DbCommand GetUpdateCommand(Random rnd, TableMetadata table, DataStressConnection conn)
        {
            DbCommand com = CreateCommand(rnd, conn);

            StringBuilder cmdText = new StringBuilder();
            cmdText.Append("UPDATE \"");
            cmdText.Append(table.TableName);
            cmdText.Append("\" SET ");

            List<TableColumn> columns = table.Columns;
            int numColumns = rnd.Next(2, columns.Count);
            bool mostlyNull = rnd.NextBool(0.1); // 10% of rows have 90% chance of each column being null, in order to test nbcrow

            for (int i = 0; i < numColumns; i++)
            {
                if (columns[i].ColumnName == "PrimaryKey") continue;
                if (columns[i].ColumnName.ToUpper() == "TIMESTAMP_FLD") continue;

                if (i > 1) cmdText.Append(", ");
                cmdText.Append(columns[i].ColumnName);
                cmdText.Append(" = ");

                if (mostlyNull && rnd.NextBool(0.9))
                {
                    cmdText.Append("NULL");
                }
                else
                {
                    DbParameter param = CreateRandomParameter(rnd, string.Format("P{0}", (i + 1)), columns[i]);
                    cmdText.Append(param.ParameterName);
                    com.Parameters.Add(param);
                }
            }

            cmdText.Append(" WHERE PrimaryKey = ");
            string pName = GetParameterName("P0");
            cmdText.Append(pName);
            DbParameter keyParam = DbFactory.CreateParameter();
            keyParam.ParameterName = pName;
            keyParam.Value = GetRandomPK(rnd, table);
            com.Parameters.Add(keyParam);

            if (ShouldModifySession(rnd))
            {
                cmdText.Append(";").Append(GetRandomSessionModificationStatement(rnd));
            }

            com.CommandText = cmdText.ToString(); ;
            return com;
        }
コード例 #19
0
        /// <summary>
        /// Returns a random UPDATE command
        /// </summary>
        public DbCommand GetUpdateCommand(Random rnd, TableMetadata table, DataStressConnection conn)
        {
            DbCommand com = CreateCommand(rnd, conn);

            StringBuilder cmdText = new StringBuilder();

            cmdText.Append("UPDATE \"");
            cmdText.Append(table.TableName);
            cmdText.Append("\" SET ");

            List <TableColumn> columns = table.Columns;
            int  numColumns            = rnd.Next(2, columns.Count);
            bool mostlyNull            = rnd.NextBool(0.1); // 10% of rows have 90% chance of each column being null, in order to test nbcrow

            for (int i = 0; i < numColumns; i++)
            {
                if (columns[i].ColumnName == "PrimaryKey")
                {
                    continue;
                }
                if (columns[i].ColumnName.ToUpper() == "TIMESTAMP_FLD")
                {
                    continue;
                }

                if (i > 1)
                {
                    cmdText.Append(", ");
                }
                cmdText.Append(columns[i].ColumnName);
                cmdText.Append(" = ");

                if (mostlyNull && rnd.NextBool(0.9))
                {
                    cmdText.Append("NULL");
                }
                else
                {
                    DbParameter param = CreateRandomParameter(rnd, string.Format("P{0}", (i + 1)), columns[i]);
                    cmdText.Append(param.ParameterName);
                    com.Parameters.Add(param);
                }
            }

            cmdText.Append(" WHERE PrimaryKey = ");
            string pName = GetParameterName("P0");

            cmdText.Append(pName);
            DbParameter keyParam = DbFactory.CreateParameter();

            keyParam.ParameterName = pName;
            keyParam.Value         = GetRandomPK(rnd, table);
            com.Parameters.Add(keyParam);

            if (ShouldModifySession(rnd))
            {
                cmdText.Append(";").Append(GetRandomSessionModificationStatement(rnd));
            }

            com.CommandText = cmdText.ToString();;
            return(com);
        }
コード例 #20
0
ファイル: DataStressFactory.cs プロジェクト: Corillian/corefx
        /// <summary>
        /// Returns a random DELETE command
        /// </summary>    
        public DbCommand GetDeleteCommand(Random rnd, TableMetadata table, DataStressConnection conn)
        {
            DbCommand com = CreateCommand(rnd, conn);

            StringBuilder cmdText = new StringBuilder();
            cmdText.Append("DELETE FROM \"");

            List<TableColumn> columns = table.Columns;
            string pName = GetParameterName("P0");
            cmdText.Append(table.TableName);
            cmdText.Append("\" WHERE PrimaryKey = ");
            cmdText.Append(pName);

            DbParameter param = DbFactory.CreateParameter();
            param.ParameterName = pName;
            param.Value = GetRandomPK(rnd, table);
            com.Parameters.Add(param);

            if (ShouldModifySession(rnd))
            {
                cmdText.Append(";").Append(GetRandomSessionModificationStatement(rnd));
            }

            com.CommandText = cmdText.ToString();
            return com;
        }
コード例 #21
0
 protected bool OpenConnection(DataStressConnection conn)
 {
     try
     {
         conn.Open();
         return true;
     }
     catch (Exception e)
     {
         if (IsServerNotAccessibleException(e, conn.DbConnection.ConnectionString, conn.DbConnection.DataSource))
         {
             // Ignore this exception.
             // This exception will fire when using named pipes with MultiSubnetFailover option set to true.
             // MultiSubnetFailover=true only works with TCP/IP protocol and will result in exception when using with named pipes.
             return false;
         }
         else
         {
             throw e;
         }
     }
 }