Beispiel #1
0
        public MultiShardAggregateException TestSelectFailure(string commandText, MultiShardExecutionPolicy policy)
        {
            using (MultiShardConnection conn = new MultiShardConnection(_shardMap.GetShards(), MultiShardTestUtils.ShardConnectionString))
            {
                using (MultiShardCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText     = commandText;
                    cmd.ExecutionPolicy = policy;

                    // ExecuteReader should fail
                    MultiShardAggregateException aggregateException =
                        AssertExtensions.AssertThrows <MultiShardAggregateException>(() => cmd.ExecuteReader());

                    // Sanity check the exceptions are the correct type
                    foreach (Exception e in aggregateException.InnerExceptions)
                    {
                        Assert.IsInstanceOfType(e, typeof(MultiShardException));
                        Assert.IsInstanceOfType(e.InnerException, typeof(SqlException));
                    }

                    // Return the exception so that the caller can do additional validation
                    return(aggregateException);
                }
            }
        }
Beispiel #2
0
        public void TestSelectNoRows(string commandText, MultiShardExecutionPolicy policy)
        {
            using (MultiShardConnection conn = new MultiShardConnection(_shardMap.GetShards(), MultiShardTestUtils.ShardConnectionString))
            {
                using (MultiShardCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText     = commandText;
                    cmd.ExecutionPolicy = policy;

                    // Read first
                    using (MultiShardDataReader sdr = cmd.ExecuteReader())
                    {
                        Assert.AreEqual(0, sdr.MultiShardExceptions.Count);
                        while (sdr.Read())
                        {
                            Assert.Fail("Should not have gotten any records.");
                        }
                        Assert.IsFalse(sdr.HasRows);
                    }

                    // HasRows first
                    using (MultiShardDataReader sdr = cmd.ExecuteReader())
                    {
                        Assert.AreEqual(0, sdr.MultiShardExceptions.Count);
                        Assert.IsFalse(sdr.HasRows);
                        while (sdr.Read())
                        {
                            Assert.Fail("Should not have gotten any records.");
                        }
                    }
                }
            }
        }
Beispiel #3
0
        public void TestSimpleSelect(MultiShardExecutionPolicy policy)
        {
            // What we're doing:
            // Grab all rows from each test database.
            // Load them into a MultiShardDataReader.
            // Iterate through the rows and make sure that we have 9 total.
            //
            using (MultiShardConnection conn = new MultiShardConnection(_shardMap.GetShards(), MultiShardTestUtils.ShardConnectionString))
            {
                using (MultiShardCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText      = "SELECT dbNameField, Test_int_Field, Test_bigint_Field FROM ConsistentShardedTable";
                    cmd.ExecutionOptions = MultiShardExecutionOptions.IncludeShardNameColumn;
                    cmd.ExecutionPolicy  = policy;

                    using (MultiShardDataReader sdr = cmd.ExecuteReader())
                    {
                        int recordsRetrieved = 0;
                        Logger.Log("Starting to get records");
                        while (sdr.Read())
                        {
                            recordsRetrieved++;
                            string dbNameField         = sdr.GetString(0);
                            int    testIntField        = sdr.GetFieldValue <int>(1);
                            Int64  testBigIntField     = sdr.GetFieldValue <Int64>(2);
                            string shardIdPseudoColumn = sdr.GetFieldValue <string>(3);
                            string logRecord           =
                                string.Format(
                                    "RecordRetrieved: dbNameField: {0}, TestIntField: {1}, TestBigIntField: {2}, shardIdPseudoColumnField: {3}, RecordCount: {4}",
                                    dbNameField, testIntField, testBigIntField, shardIdPseudoColumn, recordsRetrieved);
                            Logger.Log(logRecord);
                            Debug.WriteLine(logRecord);
                        }

                        sdr.Close();

                        Assert.AreEqual(recordsRetrieved, 9);
                    }
                }
            }
        }
Beispiel #4
0
        public void TestSelectNonQuery(string commandText, MultiShardExecutionPolicy policy)
        {
            using (MultiShardConnection conn = new MultiShardConnection(_shardMap.GetShards(), MultiShardTestUtils.ShardConnectionString))
            {
                using (MultiShardCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText     = commandText;
                    cmd.ExecutionPolicy = policy;

                    using (MultiShardDataReader sdr = cmd.ExecuteReader())
                    {
                        Assert.AreEqual(0, sdr.MultiShardExceptions.Count);

                        // TODO: This is a weird error message, but it's good enough for now
                        // Fixing this will require significant refactoring of MultiShardDataReader,
                        // we should fix it when we finish implementing async adding of child readers
                        AssertExtensions.AssertThrows <MultiShardDataReaderClosedException>(() => sdr.Read());
                    }
                }
            }
        }
        public MultiShardAggregateException TestSelectFailure(string commandText, MultiShardExecutionPolicy policy)
        {
            using (MultiShardConnection conn = new MultiShardConnection(_shardMap.GetShards(), MultiShardTestUtils.ShardConnectionString))
            {
                using (MultiShardCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = commandText;
                    cmd.ExecutionPolicy = policy;

                    // ExecuteReader should fail
                    MultiShardAggregateException aggregateException =
                        AssertExtensions.AssertThrows<MultiShardAggregateException>(() => cmd.ExecuteReader());

                    // Sanity check the exceptions are the correct type
                    foreach (Exception e in aggregateException.InnerExceptions)
                    {
                        Assert.IsInstanceOfType(e, typeof(MultiShardException));
                        Assert.IsInstanceOfType(e.InnerException, typeof(SqlException));
                    }

                    // Return the exception so that the caller can do additional validation
                    return aggregateException;
                }
            }
        }
        public void TestSelectNonQuery(string commandText, MultiShardExecutionPolicy policy)
        {
            using (MultiShardConnection conn = new MultiShardConnection(_shardMap.GetShards(), MultiShardTestUtils.ShardConnectionString))
            {
                using (MultiShardCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = commandText;
                    cmd.ExecutionPolicy = policy;

                    using (MultiShardDataReader sdr = cmd.ExecuteReader())
                    {
                        Assert.AreEqual(0, sdr.MultiShardExceptions.Count);

                        // TODO: This is a weird error message, but it's good enough for now
                        // Fixing this will require significant refactoring of MultiShardDataReader,
                        // we should fix it when we finish implementing async adding of child readers
                        AssertExtensions.AssertThrows<MultiShardDataReaderClosedException>(() => sdr.Read());
                    }
                }
            }
        }
        public void TestSelectNoRows(string commandText, MultiShardExecutionPolicy policy)
        {
            using (MultiShardConnection conn = new MultiShardConnection(_shardMap.GetShards(), MultiShardTestUtils.ShardConnectionString))
            {
                using (MultiShardCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = commandText;
                    cmd.ExecutionPolicy = policy;

                    // Read first
                    using (MultiShardDataReader sdr = cmd.ExecuteReader())
                    {
                        Assert.AreEqual(0, sdr.MultiShardExceptions.Count);
                        while (sdr.Read())
                        {
                            Assert.Fail("Should not have gotten any records.");
                        }
                        Assert.IsFalse(sdr.HasRows);
                    }

                    // HasRows first
                    using (MultiShardDataReader sdr = cmd.ExecuteReader())
                    {
                        Assert.AreEqual(0, sdr.MultiShardExceptions.Count);
                        Assert.IsFalse(sdr.HasRows);
                        while (sdr.Read())
                        {
                            Assert.Fail("Should not have gotten any records.");
                        }
                    }
                }
            }
        }
        public void TestSimpleSelect(MultiShardExecutionPolicy policy)
        {
            // What we're doing:
            // Grab all rows from each test database.
            // Load them into a MultiShardDataReader.
            // Iterate through the rows and make sure that we have 9 total.
            //
            using (MultiShardConnection conn = new MultiShardConnection(_shardMap.GetShards(), MultiShardTestUtils.ShardConnectionString))
            {
                using (MultiShardCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "SELECT dbNameField, Test_int_Field, Test_bigint_Field FROM ConsistentShardedTable";
                    cmd.ExecutionOptions = MultiShardExecutionOptions.IncludeShardNameColumn;
                    cmd.ExecutionPolicy = policy;

                    using (MultiShardDataReader sdr = cmd.ExecuteReader())
                    {
                        int recordsRetrieved = 0;
                        Logger.Log("Starting to get records");
                        while (sdr.Read())
                        {
                            recordsRetrieved++;
                            string dbNameField = sdr.GetString(0);
                            int testIntField = sdr.GetFieldValue<int>(1);
                            Int64 testBigIntField = sdr.GetFieldValue<Int64>(2);
                            string shardIdPseudoColumn = sdr.GetFieldValue<string>(3);
                            string logRecord =
                                string.Format(
                                    "RecordRetrieved: dbNameField: {0}, TestIntField: {1}, TestBigIntField: {2}, shardIdPseudoColumnField: {3}, RecordCount: {4}",
                                    dbNameField, testIntField, testBigIntField, shardIdPseudoColumn, recordsRetrieved);
                            Logger.Log(logRecord);
                            Debug.WriteLine(logRecord);
                        }

                        sdr.Close();

                        Assert.AreEqual(recordsRetrieved, 9);
                    }
                }
            }
        }