public static void MyClassCleanup() { // We need to clear the connection pools so that we don't get a database still in use error // resulting from our attenpt to drop the databases below. // SqlConnection.ClearAllPools(); MultiShardTestUtils.DropDatabases(); }
public void TestMultiShardConnectionConstructorEvaluatesShards() { MultiShardTestUtils.DropAndCreateDatabases(); ShardMap shardMap = MultiShardTestUtils.CreateAndGetTestShardMap(); List <Shard> shards = shardMap.GetShards().ToList(); MultiShardConnection conn = new MultiShardConnection(shards.ToConsumable(), dummyConnectionString); AssertExtensions.AssertSequenceEqual(shards, conn.Shards); }
public void TestSchemaMismatchErrorPropagation() { // First we need to alter the schema on one of the shards - we'll choose the last one. // string origColName = "Test_bigint_Field"; string newColName = "ModifiedName"; MultiShardTestUtils.ChangeColumnNameOnShardedTable(2, origColName, newColName); // Then create new sharded connection so we can test the error handling logic. // We'll wrap this all in a try-catch-finally block so that we can change the schema back // to what the other tests will expect it to be in the finally. // try { using (MultiShardConnection conn = new MultiShardConnection(_shardMap.GetShards(), MultiShardTestUtils.ShardConnectionString)) { using (MultiShardCommand cmd = conn.CreateCommand()) { // Need to do a SELECT * in order to get the column name error as a schema mismatcherror. If we name it explicitly // we will get a command execution error instead. // cmd.CommandText = "SELECT * FROM ConsistentShardedTable"; cmd.CommandType = CommandType.Text; using (MultiShardDataReader sdr = ExecAsync(conn, cmd).Result) { // The number of errors we have depends on which shard executed first. // So, we know it should be 1 OR 2. // Assert.IsTrue( ((sdr.MultiShardExceptions.Count == 1) || (sdr.MultiShardExceptions.Count == 2)), string.Format("Expected 1 or 2 execution erros, but saw {0}", sdr.MultiShardExceptions.Count)); int recordsRetrieved = 0; while (sdr.Read()) { recordsRetrieved++; var dbNameField = sdr.GetString(0); } // We should see 9 records less 3 for each one that had a schema error. int expectedRecords = ((9 - (3 * sdr.MultiShardExceptions.Count))); Assert.AreEqual(recordsRetrieved, expectedRecords); } } } } finally { MultiShardTestUtils.ChangeColumnNameOnShardedTable(2, newColName, origColName); } }
public static void MyClassInitialize(TestContext testContext) { // Drop and recreate the test databases, tables, and data that we will use to verify // the functionality. // For now I have hardcoded the server location and database names. A better approach would be // to make the server location configurable and the database names be guids. // Not the top priority right now, though. // SqlConnection.ClearAllPools(); MultiShardTestUtils.DropAndCreateDatabases(); MultiShardTestUtils.CreateAndPopulateTables(); }
public void MyTestInitialize() { _shardMap = MultiShardTestUtils.CreateAndGetTestShardMap(); _shardConnection = new MultiShardConnection(_shardMap.GetShards(), MultiShardTestUtils.ShardConnectionString); }