diff --git a/Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolIT.cs index 2a403521e..4f5020538 100644 --- a/Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFConnectionPoolIT.cs @@ -333,7 +333,7 @@ void ThreadProcess2(string connstr) Thread.Sleep(5000); SFStatement statement = new SFStatement(conn1.SfSession); - SFBaseResultSet resultSet = statement.Execute(0, "select 1", null, false); + SFBaseResultSet resultSet = statement.Execute(0, "select 1", null, false, false); Assert.AreEqual(true, resultSet.Next()); Assert.AreEqual("1", resultSet.GetString(0)); SnowflakeDbConnectionPool.ClearAllPools(); diff --git a/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs b/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs index 6e92c0aac..59b39a764 100755 --- a/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs +++ b/Snowflake.Data.Tests/IntegrationTests/SFDbCommandIT.cs @@ -175,6 +175,375 @@ public void TestExecuteAsyncWithMaxRetryReached() Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 30 * 1000); } } + + [Test] + public void TestAsyncExecQueryAsync() + { + string queryId; + var expectedWaitTime = 5; + Task task; + + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + task = conn.OpenAsync(CancellationToken.None); + task.Wait(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Arrange + cmd.CommandText = $"CALL SYSTEM$WAIT({expectedWaitTime}, \'SECONDS\');"; + + // Act + var queryTask = cmd.ExecuteAsyncInAsyncMode(CancellationToken.None); + queryTask.Wait(); + queryId = queryTask.Result; + + var statusTask = cmd.GetQueryStatusAsync(queryId, CancellationToken.None); + statusTask.Wait(); + var queryStatus = statusTask.Result; + + // Assert + Assert.IsTrue(QueryStatuses.IsStillRunning(queryStatus)); + + // Act + var readerTask = cmd.GetResultsFromQueryIdAsync(queryId, CancellationToken.None); + readerTask.Wait(); + DbDataReader reader = readerTask.Result; + + statusTask = cmd.GetQueryStatusAsync(queryId, CancellationToken.None); + statusTask.Wait(); + queryStatus = statusTask.Result; + + // Assert + Assert.IsTrue(reader.Read()); + Assert.AreEqual($"waited {expectedWaitTime} seconds", reader.GetString(0)); + Assert.AreEqual(QueryStatus.SUCCESS, queryStatus); + } + + task = conn.CloseAsync(CancellationToken.None); + task.Wait(); + } + } + + [Test] + public void TestMixedSyncAndAsyncQueryAsync() + { + string queryId; + var expectedWaitTime = 5; + Task task; + + // Start the async exec query + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + task = conn.OpenAsync(CancellationToken.None); + task.Wait(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Arrange + cmd.CommandText = $"CALL SYSTEM$WAIT({expectedWaitTime}, \'SECONDS\');"; + + // Act + var queryTask = cmd.ExecuteAsyncInAsyncMode(CancellationToken.None); + queryTask.Wait(); + queryId = queryTask.Result; + + var statusTask = cmd.GetQueryStatusAsync(queryId, CancellationToken.None); + statusTask.Wait(); + var queryStatus = statusTask.Result; + + // Assert + Assert.IsTrue(QueryStatuses.IsStillRunning(queryStatus)); + } + + task = conn.CloseAsync(CancellationToken.None); + task.Wait(); + } + + // Execute a normal query + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + conn.Open(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Arrange + cmd.CommandText = $"select 1;"; + + // Act + var row = cmd.ExecuteScalar(); + + // Assert + Assert.AreEqual(1, row); + } + + conn.Close(); + } + + // Get results of the async exec query + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + task = conn.OpenAsync(CancellationToken.None); + task.Wait(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Act + var readerTask = cmd.GetResultsFromQueryIdAsync(queryId, CancellationToken.None); + readerTask.Wait(); + DbDataReader reader = readerTask.Result; + + var statusTask = cmd.GetQueryStatusAsync(queryId, CancellationToken.None); + statusTask.Wait(); + var queryStatus = statusTask.Result; + + // Assert + Assert.IsTrue(reader.Read()); + Assert.AreEqual($"waited {expectedWaitTime} seconds", reader.GetString(0)); + Assert.AreEqual(QueryStatus.SUCCESS, queryStatus); + } + + task = conn.CloseAsync(CancellationToken.None); + task.Wait(); + } + } + + [Test] + public void TestStillRunningAsyncQueriesAsync() + { + string queryIdOne, queryIdTwo; + Task task; + + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + task = conn.OpenAsync(CancellationToken.None); + task.Wait(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Arrange + cmd.CommandText = $"CALL SYSTEM$WAIT({3}, \'SECONDS\');"; + + // Act + var queryTask = cmd.ExecuteAsyncInAsyncMode(CancellationToken.None); + queryTask.Wait(); + queryIdOne = queryTask.Result; + + // Arrange + cmd.CommandText = $"CALL SYSTEM$WAIT({10}, \'SECONDS\');"; + + // Act + queryTask = cmd.ExecuteAsyncInAsyncMode(CancellationToken.None); + queryTask.Wait(); + queryIdTwo = queryTask.Result; + var stillRunningTask = conn.SfSession.StillRunningAsyncQueriesAsync(CancellationToken.None); + stillRunningTask.Wait(); + var statusTask = cmd.GetQueryStatusAsync(queryIdOne, CancellationToken.None); + statusTask.Wait(); + + // Assert + Assert.IsTrue(QueryStatuses.IsStillRunning(statusTask.Result)); + Assert.IsTrue(stillRunningTask.Result); + + // Act + var readerTask = cmd.GetResultsFromQueryIdAsync(queryIdOne, CancellationToken.None); + readerTask.Wait(); + statusTask = cmd.GetQueryStatusAsync(queryIdOne, CancellationToken.None); + statusTask.Wait(); + stillRunningTask = conn.SfSession.StillRunningAsyncQueriesAsync(CancellationToken.None); + stillRunningTask.Wait(); + + // Assert + Assert.IsFalse(QueryStatuses.IsStillRunning(statusTask.Result)); + Assert.IsTrue(QueryStatuses.IsStillRunning(cmd.GetQueryStatus(queryIdTwo))); + Assert.IsTrue(stillRunningTask.Result); + + // Act + readerTask = cmd.GetResultsFromQueryIdAsync(queryIdTwo, CancellationToken.None); + readerTask.Wait(); + statusTask = cmd.GetQueryStatusAsync(queryIdTwo, CancellationToken.None); + statusTask.Wait(); + stillRunningTask = conn.SfSession.StillRunningAsyncQueriesAsync(CancellationToken.None); + stillRunningTask.Wait(); + + // Assert + Assert.IsFalse(QueryStatuses.IsStillRunning(statusTask.Result)); + Assert.IsFalse(stillRunningTask.Result); + } + + task = conn.CloseAsync(CancellationToken.None); + task.Wait(); + } + } + + [Test] + public void TestFailedAsyncExecQueryThrowsErrorAsync() + { + string queryId; + Task task; + + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + task = conn.OpenAsync(CancellationToken.None); + task.Wait(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Arrange + cmd.CommandText = $"SELECT * FROM FAKE_TABLE;"; + + // Act + var queryTask = cmd.ExecuteAsyncInAsyncMode(CancellationToken.None); + queryTask.Wait(); + queryId = queryTask.Result; + + var statusTask = cmd.GetQueryStatusAsync(queryId, CancellationToken.None); + statusTask.Wait(); + var queryStatus = statusTask.Result; + + while (QueryStatuses.IsStillRunning(queryStatus)) + { + Thread.Sleep(1000); + statusTask = cmd.GetQueryStatusAsync(queryId, CancellationToken.None); + statusTask.Wait(); + queryStatus = statusTask.Result; + } + + // Assert + Assert.AreEqual(QueryStatus.FAILED_WITH_ERROR, queryStatus); + + // Act + var readerTask = cmd.GetResultsFromQueryIdAsync(queryId, CancellationToken.None); + var thrown = Assert.Throws(() => readerTask.Wait()); + + // Assert + Assert.IsTrue(thrown.InnerException.Message.Contains("'FAKE_TABLE' does not exist")); + } + + task = conn.CloseAsync(CancellationToken.None); + task.Wait(); + } + } + + [Test] + public void TestGetStatusOfInvalidQueryIdAsync() + { + string fakeQueryId = "fakeQueryId"; + Task task; + + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + task = conn.OpenAsync(CancellationToken.None); + task.Wait(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Arrange + var statusTask = cmd.GetQueryStatusAsync(fakeQueryId, CancellationToken.None); + + // Act + var thrown = Assert.Throws(() => statusTask.Wait()); + + // Assert + Assert.IsTrue(thrown.InnerException.Message.Contains($"The given query id {fakeQueryId} is not valid uuid")); + } + + task = conn.CloseAsync(CancellationToken.None); + task.Wait(); + } + } + + [Test] + public void TestGetResultsOfInvalidQueryIdAsync() + { + string fakeQueryId = "fakeQueryId"; + Task task; + + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + task = conn.OpenAsync(CancellationToken.None); + task.Wait(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Arrange + var readerTask = cmd.GetResultsFromQueryIdAsync(fakeQueryId, CancellationToken.None); + + // Act + var thrown = Assert.Throws(() => readerTask.Wait()); + + // Assert + Assert.IsTrue(thrown.InnerException.Message.Contains($"The given query id {fakeQueryId} is not valid uuid")); + } + + task = conn.CloseAsync(CancellationToken.None); + task.Wait(); + } + } + + [Test, NonParallelizable] + public void TestGetStatusOfUnknownQueryIdAsync() + { + string unknownQueryId = "ba321edc-1abc-123e-987f-1234a56b789c"; + Task task; + + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + task = conn.OpenAsync(CancellationToken.None); + task.Wait(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Act + var statusTask = cmd.GetQueryStatusAsync(unknownQueryId, CancellationToken.None); + statusTask.Wait(); + + // Assert + Assert.AreEqual(QueryStatus.NO_DATA, statusTask.Result); + } + + task = conn.CloseAsync(CancellationToken.None); + task.Wait(); + } + } + + [Test] + public void TestGetResultsOfUnknownQueryIdAsync() + { + string unknownQueryId = "ab123fed-1abc-987f-987f-1234a56b789c"; + Task task; + + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + task = conn.OpenAsync(CancellationToken.None); + task.Wait(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Arrange + var readerTask = cmd.GetResultsFromQueryIdAsync(unknownQueryId, CancellationToken.None); + + // Act + var thrown = Assert.Throws(() => readerTask.Wait()); + + // Assert + Assert.IsTrue(thrown.Message.Contains($"Max retry for no data is reached")); + } + + task = conn.CloseAsync(CancellationToken.None); + task.Wait(); + } + } } [TestFixture] @@ -1040,5 +1409,287 @@ public void TestGetQueryId() conn.Close(); } } + + [Test] + public void TestAsyncExecQuery() + { + string queryId; + var expectedWaitTime = 5; + + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + conn.Open(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Arrange + cmd.CommandText = $"CALL SYSTEM$WAIT({expectedWaitTime}, \'SECONDS\');"; + + // Act + queryId = cmd.ExecuteInAsyncMode(); + + // Assert + Assert.IsTrue(QueryStatuses.IsStillRunning(cmd.GetQueryStatus(queryId))); + + // Act + DbDataReader reader = cmd.GetResultsFromQueryId(queryId); + + // Assert + Assert.IsTrue(reader.Read()); + Assert.AreEqual($"waited {expectedWaitTime} seconds", reader.GetString(0)); + Assert.AreEqual(QueryStatus.SUCCESS, cmd.GetQueryStatus(queryId)); + } + + conn.Close(); + } + } + + [Test] + public void TestMixedSyncAndAsyncQuery() + { + string queryId; + var expectedWaitTime = 5; + + // Start the async exec query + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + conn.Open(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Arrange + cmd.CommandText = $"CALL SYSTEM$WAIT({expectedWaitTime}, \'SECONDS\');"; + + // Act + queryId = cmd.ExecuteInAsyncMode(); + + // Assert + Assert.IsTrue(QueryStatuses.IsStillRunning(cmd.GetQueryStatus(queryId))); + } + + conn.Close(); + } + + // Execute a normal query + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + conn.Open(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Arrange + cmd.CommandText = $"select 1;"; + + // Act + var row = cmd.ExecuteScalar(); + + // Assert + Assert.AreEqual(1, row); + } + + conn.Close(); + } + + // Get results of the async exec query + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + conn.Open(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Act + DbDataReader reader = cmd.GetResultsFromQueryId(queryId); + + // Assert + Assert.IsTrue(reader.Read()); + Assert.AreEqual($"waited {expectedWaitTime} seconds", reader.GetString(0)); + Assert.AreEqual(QueryStatus.SUCCESS, cmd.GetQueryStatus(queryId)); + } + + conn.Close(); + } + } + + + [Test] + public void TestStillRunningAsyncQueries() + { + string queryIdOne, queryIdTwo; + + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + conn.Open(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Arrange + cmd.CommandText = $"CALL SYSTEM$WAIT({3}, \'SECONDS\');"; + + // Act + queryIdOne = cmd.ExecuteInAsyncMode(); + + // Arrange + cmd.CommandText = $"CALL SYSTEM$WAIT({10}, \'SECONDS\');"; + + // Act + queryIdTwo = cmd.ExecuteInAsyncMode(); + + // Assert + Assert.IsTrue(QueryStatuses.IsStillRunning(cmd.GetQueryStatus(queryIdOne))); + Assert.IsTrue(conn.SfSession.StillRunningAsyncQueries()); + + // Act + cmd.GetResultsFromQueryId(queryIdOne); + + // Assert + Assert.IsFalse(QueryStatuses.IsStillRunning(cmd.GetQueryStatus(queryIdOne))); + Assert.IsTrue(QueryStatuses.IsStillRunning(cmd.GetQueryStatus(queryIdTwo))); + Assert.IsTrue(conn.SfSession.StillRunningAsyncQueries()); + + // Act + cmd.GetResultsFromQueryId(queryIdTwo); + + // Assert + Assert.IsFalse(QueryStatuses.IsStillRunning(cmd.GetQueryStatus(queryIdTwo))); + Assert.AreEqual(QueryStatus.SUCCESS, cmd.GetQueryStatus(queryIdTwo)); + Assert.IsFalse(conn.SfSession.StillRunningAsyncQueries()); + } + + conn.Close(); + } + } + + [Test] + public void TestFailedAsyncExecQueryThrowsError() + { + string queryId; + + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + conn.Open(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Arrange + cmd.CommandText = $"SELECT * FROM FAKE_TABLE;"; + + // Act + queryId = cmd.ExecuteInAsyncMode(); + while (QueryStatuses.IsStillRunning(cmd.GetQueryStatus(queryId))) + { + Thread.Sleep(1000); + } + + // Assert + Assert.AreEqual(QueryStatus.FAILED_WITH_ERROR, cmd.GetQueryStatus(queryId)); + + // Act + var thrown = Assert.Throws(() => cmd.GetResultsFromQueryId(queryId)); + + // Assert + Assert.IsTrue(thrown.Message.Contains("'FAKE_TABLE' does not exist")); + } + + conn.Close(); + } + } + + [Test] + public void TestGetStatusOfInvalidQueryId() + { + string fakeQueryId = "fakeQueryId"; + + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + conn.Open(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Act + var thrown = Assert.Throws(() => cmd.GetQueryStatus(fakeQueryId)); + + // Assert + Assert.IsTrue(thrown.Message.Contains($"The given query id {fakeQueryId} is not valid uuid")); + } + + conn.Close(); + } + } + + [Test] + public void TestGetResultsOfInvalidQueryId() + { + string fakeQueryId = "fakeQueryId"; + + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + conn.Open(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Act + var thrown = Assert.Throws(() => cmd.GetResultsFromQueryId(fakeQueryId)); + + // Assert + Assert.IsTrue(thrown.Message.Contains($"The given query id {fakeQueryId} is not valid uuid")); + } + + conn.Close(); + } + } + + [Test, NonParallelizable] + public void TestGetStatusOfUnknownQueryId() + { + string unknownQueryId = "ab123cde-1cba-789a-987f-1234a56b789c"; + + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + conn.Open(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Act + var queryStatus = cmd.GetQueryStatus(unknownQueryId); + + // Assert + Assert.AreEqual(QueryStatus.NO_DATA, queryStatus); + } + + conn.Close(); + } + } + + [Test] + public void TestGetResultsOfUnknownQueryId() + { + string unknownQueryId = "ba987def-1abc-987f-987f-1234a56b789c"; + + using (SnowflakeDbConnection conn = new SnowflakeDbConnection()) + { + conn.ConnectionString = ConnectionString; + conn.Open(); + + using (SnowflakeDbCommand cmd = (SnowflakeDbCommand)conn.CreateCommand()) + { + // Act + var thrown = Assert.Throws(() => cmd.GetResultsFromQueryId(unknownQueryId)); + + // Assert + Assert.IsTrue(thrown.Message.Contains($"Max retry for no data is reached")); + } + + conn.Close(); + } + } } } diff --git a/Snowflake.Data.Tests/UnitTests/SFStatementTest.cs b/Snowflake.Data.Tests/UnitTests/SFStatementTest.cs index 330b19f96..e1a8b3042 100755 --- a/Snowflake.Data.Tests/UnitTests/SFStatementTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFStatementTest.cs @@ -21,7 +21,7 @@ public void TestSessionRenew() SFSession sfSession = new SFSession("account=test;user=test;password=test", null, restRequester); sfSession.Open(); SFStatement statement = new SFStatement(sfSession); - SFBaseResultSet resultSet = statement.Execute(0, "select 1", null, false); + SFBaseResultSet resultSet = statement.Execute(0, "select 1", null, false, false); Assert.AreEqual(true, resultSet.Next()); Assert.AreEqual("1", resultSet.GetString(0)); Assert.AreEqual("new_session_token", sfSession.sessionToken); @@ -37,7 +37,7 @@ public void TestSessionRenewDuringQueryExec() SFSession sfSession = new SFSession("account=test;user=test;password=test", null, restRequester); sfSession.Open(); SFStatement statement = new SFStatement(sfSession); - SFBaseResultSet resultSet = statement.Execute(0, "select 1", null, false); + SFBaseResultSet resultSet = statement.Execute(0, "select 1", null, false, false); Assert.AreEqual(true, resultSet.Next()); Assert.AreEqual("1", resultSet.GetString(0)); } @@ -57,7 +57,7 @@ public void TestServiceName() for (int i = 0; i < 5; i++) { SFStatement statement = new SFStatement(sfSession); - SFBaseResultSet resultSet = statement.Execute(0, "SELECT 1", null, false); + SFBaseResultSet resultSet = statement.Execute(0, "SELECT 1", null, false, false); expectServiceName += "a"; Assert.AreEqual(expectServiceName, sfSession.ParameterMap[SFSessionParameter.SERVICE_NAME]); } @@ -73,7 +73,7 @@ public void TestTrimSqlBlockComment() SFSession sfSession = new SFSession("account=test;user=test;password=test", null, restRequester); sfSession.Open(); SFStatement statement = new SFStatement(sfSession); - SFBaseResultSet resultSet = statement.Execute(0, "/*comment*/select 1/*comment*/", null, false); + SFBaseResultSet resultSet = statement.Execute(0, "/*comment*/select 1/*comment*/", null, false, false); Assert.AreEqual(true, resultSet.Next()); Assert.AreEqual("1", resultSet.GetString(0)); } @@ -88,7 +88,7 @@ public void TestTrimSqlBlockCommentMultiline() SFSession sfSession = new SFSession("account=test;user=test;password=test", null, restRequester); sfSession.Open(); SFStatement statement = new SFStatement(sfSession); - SFBaseResultSet resultSet = statement.Execute(0, "/*comment\r\ncomment*/select 1/*comment\r\ncomment*/", null, false); + SFBaseResultSet resultSet = statement.Execute(0, "/*comment\r\ncomment*/select 1/*comment\r\ncomment*/", null, false, false); Assert.AreEqual(true, resultSet.Next()); Assert.AreEqual("1", resultSet.GetString(0)); } @@ -103,7 +103,7 @@ public void TestTrimSqlLineComment() SFSession sfSession = new SFSession("account=test;user=test;password=test", null, restRequester); sfSession.Open(); SFStatement statement = new SFStatement(sfSession); - SFBaseResultSet resultSet = statement.Execute(0, "--comment\r\nselect 1\r\n--comment", null, false); + SFBaseResultSet resultSet = statement.Execute(0, "--comment\r\nselect 1\r\n--comment", null, false, false); Assert.AreEqual(true, resultSet.Next()); Assert.AreEqual("1", resultSet.GetString(0)); } @@ -118,9 +118,47 @@ public void TestTrimSqlLineCommentWithClosingNewline() SFSession sfSession = new SFSession("account=test;user=test;password=test", null, restRequester); sfSession.Open(); SFStatement statement = new SFStatement(sfSession); - SFBaseResultSet resultSet = statement.Execute(0, "--comment\r\nselect 1\r\n--comment\r\n", null, false); + SFBaseResultSet resultSet = statement.Execute(0, "--comment\r\nselect 1\r\n--comment\r\n", null, false, false); Assert.AreEqual(true, resultSet.Next()); Assert.AreEqual("1", resultSet.GetString(0)); } + + [Test] + [TestCase(QueryStatus.RUNNING, true)] + [TestCase(QueryStatus.RESUMING_WAREHOUSE, true)] + [TestCase(QueryStatus.QUEUED, true)] + [TestCase(QueryStatus.QUEUED_REPARING_WAREHOUSE, true)] + [TestCase(QueryStatus.NO_DATA, true)] + [TestCase(QueryStatus.ABORTING, false)] + [TestCase(QueryStatus.SUCCESS, false)] + [TestCase(QueryStatus.FAILED_WITH_ERROR, false)] + [TestCase(QueryStatus.ABORTED, false)] + [TestCase(QueryStatus.FAILED_WITH_INCIDENT, false)] + [TestCase(QueryStatus.DISCONNECTED, false)] + [TestCase(QueryStatus.RESTARTED, false)] + [TestCase(QueryStatus.BLOCKED, false)] + public void TestIsStillRunning(QueryStatus status, bool expectedResult) + { + Assert.AreEqual(expectedResult, QueryStatuses.IsStillRunning(status)); + } + + [Test] + [TestCase(QueryStatus.ABORTING, true)] + [TestCase(QueryStatus.FAILED_WITH_ERROR, true)] + [TestCase(QueryStatus.ABORTED, true)] + [TestCase(QueryStatus.FAILED_WITH_INCIDENT, true)] + [TestCase(QueryStatus.DISCONNECTED, true)] + [TestCase(QueryStatus.BLOCKED, true)] + [TestCase(QueryStatus.RUNNING, false)] + [TestCase(QueryStatus.RESUMING_WAREHOUSE, false)] + [TestCase(QueryStatus.QUEUED, false)] + [TestCase(QueryStatus.QUEUED_REPARING_WAREHOUSE, false)] + [TestCase(QueryStatus.NO_DATA, false)] + [TestCase(QueryStatus.SUCCESS, false)] + [TestCase(QueryStatus.RESTARTED, false)] + public void TestIsAnError(QueryStatus status, bool expectedResult) + { + Assert.AreEqual(expectedResult, QueryStatuses.IsAnError(status)); + } } }