/// <summary> /// Helper that sets up a proxy server for us and points it at our local host, 1433 SQL Server. /// </summary> /// <returns> /// The newly created proxy server for our local sql server host. /// </returns> /// <remarks> /// Note that we are not inducing any network delay (the first arg). We coul dchange this if desired. /// </remarks> private ProxyServer GetProxyServer() { ProxyServer proxy = new ProxyServer(simulatedPacketDelay: 0, simulatedInDelay: true, simulatedOutDelay: true, bufferSize: 8192); proxy.RemoteEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1433); return proxy; }
/// <summary> /// Helper that provides us with ShardConnections based on the shard map (for the database), but routed through the proxy. /// </summary> /// <param name="proxy">The proxy to route the connections through.</param> /// <returns> /// The List of {ShardLocation, DbConnection} tuples that we can use to instantiate our multi-shard connection. /// </returns> /// <remarks> /// Since our shards all reside in the local instance we can just point them at a single proxy server. If we were using /// actual physically distributed shards, then I think we would need a separate proxy for each shard. We could /// augment these tests to use a separate proxy per shard, if we wanted, in order to be able to simulate /// a richer variety of failures. For now, we just simulate total failures of all shards. /// </remarks> private List<Tuple<ShardLocation, DbConnection>> GetProxyShardConnections(ProxyServer proxy) { // We'll do this by looking at our pre-existing connections and working from that. // string baseConnString = MultiShardTestUtils.ShardConnectionString.ToString(); List<Tuple<ShardLocation, DbConnection>> rVal = new List<Tuple<ShardLocation, DbConnection>>(); foreach (Shard shard in _shardMap.GetShards()) { // Location doesn't really matter, so just use the same one. // ShardLocation curLoc = shard.Location; // The connection, however, does matter, so set up a connection SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(baseConnString); builder.DataSource = "localhost," + proxy.LocalPort; builder.InitialCatalog = curLoc.Database; SqlConnection curConn = new SqlConnection(builder.ToString()); Tuple<ShardLocation, DbConnection> curTuple = new Tuple<ShardLocation, DbConnection>(curLoc, curConn); rVal.Add(curTuple); } return rVal; }
/// <summary> /// Standard constructor /// </summary> public ProxyServerConnection(TcpClient incomingConnection, ProxyServer server) { IncomingConnection = incomingConnection; Server = server; }