public void TestExceptionSerialization()
        {
            ShardLocation sl1 = new ShardLocation("dataSource1", "database1");
            ShardLocation sl2 = new ShardLocation("dataSource2", "database2");

            MultiShardException innerEx1 = new MultiShardException(sl1);
            MultiShardException innerEx2 = new MultiShardException(sl2);

            List <Exception> exList = new List <Exception>();

            exList.Add(innerEx1);
            exList.Add(innerEx2);

            MultiShardAggregateException aggEx = new MultiShardAggregateException(exList);

            MultiShardException deserialized1 = CommonTestUtils.SerializeDeserialize(innerEx1);

            CompareForEquality(innerEx1, deserialized1);

            MultiShardException deserialized2 = CommonTestUtils.SerializeDeserialize(innerEx2);

            CompareForEquality(innerEx2, deserialized2);

            MultiShardAggregateException deserialized3 = CommonTestUtils.SerializeDeserialize(aggEx);

            CompareForEquality(aggEx, deserialized3);
        }
Ejemplo n.º 2
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);
                }
            }
        }
 private void DoExceptionComparison(MultiShardAggregateException first, MultiShardAggregateException second)
 {
     Assert.AreEqual(first.InnerExceptions.Count, second.InnerExceptions.Count);
     for (int i = 0; i < first.InnerExceptions.Count; i++)
     {
         CompareForEquality((MultiShardException)(first.InnerExceptions[i]), (MultiShardException)(second.InnerExceptions[i]));
     }
 }
Ejemplo n.º 4
0
        public void TestSelect_PartialFailure_CompleteResults()
        {
            string query = GetPartialFailureQuery();
            MultiShardAggregateException e = TestSelectFailure(query, MultiShardExecutionPolicy.CompleteResults);

            // Exactly one should have failed
            Assert.AreEqual(1, e.InnerExceptions.Count);
        }
Ejemplo n.º 5
0
        public void TestSelect_Failure_PartialResults()
        {
            MultiShardAggregateException e = TestSelectFailure(
                "raiserror('blah', 16, 0)",
                MultiShardExecutionPolicy.PartialResults);

            // All children should have failed
            Assert.AreEqual(_shardMap.GetShards().Count(), e.InnerExceptions.Count);
        }
Ejemplo n.º 6
0
        public void TestSelect_Failure_CompleteResults()
        {
            MultiShardAggregateException e = TestSelectFailure(
                "raiserror('blah', 16, 0)",
                MultiShardExecutionPolicy.CompleteResults);

            // We don't know exactly how many child exceptions will happen, because the
            // first exception that is seen will cause the children to be canceled.
            AssertExtensions.AssertGreaterThanOrEqualTo(1, e.InnerExceptions.Count);
            AssertExtensions.AssertLessThanOrEqualTo(_shardMap.GetShards().Count(), e.InnerExceptions.Count);
        }
        public void TestExceptionSerialization()
        {
            ShardLocation sl1 = new ShardLocation("dataSource1", "database1");
            ShardLocation sl2 = new ShardLocation("dataSource2", "database2");

            MultiShardException innerEx1 = new MultiShardException(sl1);
            MultiShardException innerEx2 = new MultiShardException(sl2);

            List <Exception> exList = new List <Exception>();

            exList.Add(innerEx1);
            exList.Add(innerEx2);

            MultiShardAggregateException aggEx = new MultiShardAggregateException(exList);

            TestSerialization <MultiShardException>(innerEx1);
            TestSerialization <MultiShardException>(innerEx2);
            TestSerialization <MultiShardAggregateException>(aggEx);
        }