Exemplo n.º 1
0
 public ConnectionMetrics(ServerConnection serverConnection, GenericSqlProxy proxy)
 {
     this.proxy           = proxy;
     ServerConnection     = serverConnection;
     proxy.OnConnect     += Proxy_OnConnect;
     proxy.OnWriteHost   += Proxy_OnWriteHost;
     proxy.OnWriteClient += Proxy_OnWriteClient;
     serverConnection.StatementExecuted += ServerConnection_StatementExecuted;
 }
Exemplo n.º 2
0
        public static ConnectionMetrics SetupMeasuredConnection(TestContext testContext, int latencyPaddingMs = 0)
        {
            var connectionString = testContext.GetConnectionString();
            var proxy            = new GenericSqlProxy(connectionString);

            if (latencyPaddingMs > 0)
            {
                proxy.OnWriteClient += (o, e) => DelayWrite(latencyPaddingMs, e);
            }
            // If running these tests in a container you may need to set a specific port
            // and expose that port in the dockerfile
            var port = testContext.Properties.ContainsKey("proxyPort")
                ? Convert.ToInt32(testContext.Properties["proxyPort"])
                : 0;
            var sqlConnection    = new SqlConnection(proxy.Initialize(port));
            var serverConnection = new ServerConnection(sqlConnection);

            return(new ConnectionMetrics(serverConnection, proxy));
        }