public async Task OpenCloseShouldChangeState() { // Arrange await using var conn = new SparkConnection(Config.ConnectionString); conn.Open(); Assert.Equal(ConnectionState.Open, conn.State); // Assert and Act conn.Close(); Assert.Equal(ConnectionState.Closed, conn.State); // Assert and Act conn.Open(); Assert.Equal(ConnectionState.Open, conn.State); }
public async Task WhenAtParameterWithinQuotesShouldNotReplace() { // Arrange await using var conn = new SparkConnection(Config.ConnectionString); conn.Open(); var cmd = DataFactory.CreateCommand(conn, $@"SELECT ""This is \"" @MyValue \"" string"" as `@MyValue string`, 'This is also \' @MyValue \' string' as `also @MyValue string`, @MyValue+3 as MyValue"); var param = cmd.CreateParameter(); param.ParameterName = "MyValue"; param.Value = 12; cmd.Parameters.Add(param); // Act using var resultReader = cmd.ExecuteReader(); using var resultReaderAsync = await cmd.ExecuteReaderAsync(); // Assert Assert.True(await resultReader.ReadAsync()); Assert.Equal("This is \" @MyValue \" string", resultReader["@MyValue string"]); Assert.Equal("This is also \' @MyValue \' string", resultReader["also @MyValue string"]); Assert.Equal(15, resultReader["MyValue"]); Assert.False(await resultReader.ReadAsync()); Assert.True(await resultReaderAsync.ReadAsync()); Assert.Equal("This is \" @MyValue \" string", resultReaderAsync["@MyValue string"]); Assert.Equal("This is also \' @MyValue \' string", resultReaderAsync["also @MyValue string"]); Assert.Equal(15, resultReaderAsync["MyValue"]); Assert.False(await resultReaderAsync.ReadAsync()); }
public async Task ShouldAcceptAccessToken() { var httpClient = new HttpClient(); var response = await httpClient.PostAsync($"https://login.microsoftonline.com/{Config.AccessTokenCredentials.Tenant}/oauth2/v2.0/token", new FormUrlEncodedContent(new Dictionary <string, string>() { { "grant_type", "client_credentials" }, { "scope", "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default" }, { "client_id", Config.AccessTokenCredentials.ClientId }, { "client_secret", Config.AccessTokenCredentials.ClientSecret }, })); response.EnsureSuccessStatusCode(); var accessToken = JsonConvert.DeserializeObject <JObject>(await response.Content.ReadAsStringAsync())["access_token"].ToString(); // Arrange var connectionStringBuilder = new SparkConnectionStringBuilder(Config.ConnectionString); await using var conn = new SparkConnection($"Data Source={connectionStringBuilder.DataSource}"); conn.AccessToken = accessToken; // Assert and Act conn.Open(); Assert.Equal(ConnectionState.Open, conn.State); }
public async Task InitializeAsync() { var timeoutTokenSource = CancellationTokenSource.CreateLinkedTokenSource(CancellationToken.None); timeoutTokenSource.CancelAfter(TimeSpan.FromMinutes(10)); var cancellationToken = timeoutTokenSource.Token; while (true) { using (var connection = new SparkConnection(ConnectionString)) { try { // cluster will start, but fail until it finishing initilizaing // so we are going to keep trying until it works connection.Open(); return; } catch (TTransportException ex) when(ex.Message.Contains("503 (Service Unavailable)")) { await Task.Delay(5000, cancellationToken); } } } }