mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-30 01:25:45 -05:00
3278 Kusto Unit Tests - Part 1 (#1057)
* 3278 Added unit tests in MetadataFactoryTests and Microsoft.Kusto.ServiceLayer.UnitTests project * 3278 Removed todo and changed unit test to validate megabytes * 3278 Added file and unit tests in AutoCompleteHelperTests.cs * 3278 Removed unused functions from Kusto > ScriptAsScriptingOperation * 3278 Added unit tests for DataSourceFactory * 3278 Refactored AdminService to pass in ConnectionService rather than through instance variable. Added unit test for AdminServiceTests * 3278 Refactored DataSourceFactory to not have static functions for future unit tests * 3278 Re-added properties that were flagged as unused but are being used by ADS in ReliableDataSourceConnection.cs * 3278 Re-added properties that were flagged as unused but are being used by ADS in ReliableDataSourceConnection.cs * adding pipeline to execute tests (#1062) * 3278 Converted GetDefaultAutoComplete and GetDefaultSemanticMarkers to static functions in DataSourceFactory. Removed unused constructor in ScriptFile. Added positive unit tests for both functions * undoing release version bump * adding additional configs * adressing feedback * Correcting path in csproj Co-authored-by: Jorge Berumen <52225468+joberume@users.noreply.github.com> Co-authored-by: joberume <jberumen3@miners.utep.edu>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Composition;
|
||||
using Microsoft.Kusto.ServiceLayer.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
||||
using Microsoft.Kusto.ServiceLayer.DataSource.DataSourceIntellisense;
|
||||
@@ -9,9 +10,10 @@ using Microsoft.Kusto.ServiceLayer.LanguageServices.Completion;
|
||||
|
||||
namespace Microsoft.Kusto.ServiceLayer.DataSource
|
||||
{
|
||||
public class DataSourceFactory
|
||||
[Export(typeof(IDataSourceFactory))]
|
||||
public class DataSourceFactory : IDataSourceFactory
|
||||
{
|
||||
public static IDataSource Create(DataSourceType dataSourceType, string connectionString, string azureAccountToken)
|
||||
public IDataSource Create(DataSourceType dataSourceType, string connectionString, string azureAccountToken)
|
||||
{
|
||||
ValidationUtils.IsArgumentNotNullOrWhiteSpace(connectionString, nameof(connectionString));
|
||||
ValidationUtils.IsArgumentNotNullOrWhiteSpace(azureAccountToken, nameof(azureAccountToken));
|
||||
@@ -57,15 +59,16 @@ namespace Microsoft.Kusto.ServiceLayer.DataSource
|
||||
}
|
||||
}
|
||||
|
||||
public static ReliableConnectionHelper.ServerInfo ConvertToServerinfoFormat(DataSourceType dataSourceType, DiagnosticsInfo clusterDiagnostics)
|
||||
public static ReliableConnectionHelper.ServerInfo ConvertToServerInfoFormat(DataSourceType dataSourceType, DiagnosticsInfo clusterDiagnostics)
|
||||
{
|
||||
switch (dataSourceType)
|
||||
{
|
||||
case DataSourceType.Kusto:
|
||||
{
|
||||
ReliableConnectionHelper.ServerInfo serverInfo = new ReliableConnectionHelper.ServerInfo();
|
||||
serverInfo.Options = new Dictionary<string, object>(clusterDiagnostics.Options);
|
||||
return serverInfo;
|
||||
return new ReliableConnectionHelper.ServerInfo
|
||||
{
|
||||
Options = new Dictionary<string, object>(clusterDiagnostics.Options)
|
||||
};
|
||||
}
|
||||
|
||||
default:
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Microsoft.Kusto.ServiceLayer.DataSource
|
||||
{
|
||||
public interface IDataSourceFactory
|
||||
{
|
||||
IDataSource Create(DataSourceType dataSourceType, string connectionString, string azureAccountToken);
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@ namespace Microsoft.Kusto.ServiceLayer.Connection
|
||||
|
||||
private readonly string _connectionString;
|
||||
private readonly string _azureAccountToken;
|
||||
private readonly IDataSourceFactory _dataSourceFactory;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the ReliableKustoClient class with a given connection string
|
||||
@@ -52,11 +53,15 @@ namespace Microsoft.Kusto.ServiceLayer.Connection
|
||||
/// <param name="connectionString">The connection string used to open the SQL Azure database.</param>
|
||||
/// <param name="connectionRetryPolicy">The retry policy defining whether to retry a request if a connection fails to be established.</param>
|
||||
/// <param name="commandRetryPolicy">The retry policy defining whether to retry a request if a command fails to be executed.</param>
|
||||
public ReliableDataSourceConnection(string connectionString, RetryPolicy connectionRetryPolicy, RetryPolicy commandRetryPolicy, string azureAccountToken)
|
||||
/// <param name="azureAccountToken"></param>
|
||||
/// <param name="dataSourceFactory"></param>
|
||||
public ReliableDataSourceConnection(string connectionString, RetryPolicy connectionRetryPolicy,
|
||||
RetryPolicy commandRetryPolicy, string azureAccountToken, IDataSourceFactory dataSourceFactory)
|
||||
{
|
||||
_connectionString = connectionString;
|
||||
_azureAccountToken = azureAccountToken;
|
||||
_dataSource = DataSourceFactory.Create(DataSourceType.Kusto, connectionString, azureAccountToken);
|
||||
_dataSourceFactory = dataSourceFactory;
|
||||
_dataSource = dataSourceFactory.Create(DataSourceType.Kusto, connectionString, azureAccountToken);
|
||||
|
||||
_connectionRetryPolicy = connectionRetryPolicy ?? RetryPolicyFactory.CreateNoRetryPolicy();
|
||||
_commandRetryPolicy = commandRetryPolicy ?? RetryPolicyFactory.CreateNoRetryPolicy();
|
||||
@@ -112,42 +117,45 @@ namespace Microsoft.Kusto.ServiceLayer.Connection
|
||||
/// </summary>
|
||||
public string ConnectionString { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the policy which decides whether to retry a connection request, based on how many
|
||||
/// times the request has been made and the reason for the last failure.
|
||||
/// <summary>
|
||||
/// Gets the policy which decides whether to retry a connection request, based on how many
|
||||
/// times the request has been made and the reason for the last failure.
|
||||
/// </summary>
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
public RetryPolicy ConnectionRetryPolicy
|
||||
{
|
||||
get { return _connectionRetryPolicy; }
|
||||
}
|
||||
{
|
||||
get { return _connectionRetryPolicy; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the policy which decides whether to retry a command, based on how many
|
||||
/// times the request has been made and the reason for the last failure.
|
||||
/// <summary>
|
||||
/// Gets the policy which decides whether to retry a command, based on how many
|
||||
/// times the request has been made and the reason for the last failure.
|
||||
/// </summary>
|
||||
public RetryPolicy CommandRetryPolicy
|
||||
{
|
||||
get { return _commandRetryPolicy; }
|
||||
set
|
||||
{
|
||||
Validate.IsNotNull(nameof(value), value);
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
public RetryPolicy CommandRetryPolicy
|
||||
{
|
||||
get { return _commandRetryPolicy; }
|
||||
set
|
||||
{
|
||||
Validate.IsNotNull(nameof(value), value);
|
||||
|
||||
if (_commandRetryPolicy != null)
|
||||
{
|
||||
_commandRetryPolicy.RetryOccurred -= RetryCommandCallback;
|
||||
}
|
||||
if (_commandRetryPolicy != null)
|
||||
{
|
||||
_commandRetryPolicy.RetryOccurred -= RetryCommandCallback;
|
||||
}
|
||||
|
||||
_commandRetryPolicy = value;
|
||||
_commandRetryPolicy.RetryOccurred += RetryCommandCallback;
|
||||
}
|
||||
}
|
||||
_commandRetryPolicy = value;
|
||||
_commandRetryPolicy.RetryOccurred += RetryCommandCallback;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the server name from the underlying connection.
|
||||
/// </summary>
|
||||
public string ClusterName
|
||||
{
|
||||
get { return _dataSource.ClusterName; }
|
||||
/// <summary>
|
||||
/// Gets the server name from the underlying connection.
|
||||
/// </summary>
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
public string ClusterName
|
||||
{
|
||||
get { return _dataSource.ClusterName; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -182,7 +190,7 @@ namespace Microsoft.Kusto.ServiceLayer.Connection
|
||||
{
|
||||
_connectionRetryPolicy.ExecuteAction(() =>
|
||||
{
|
||||
_dataSource = DataSourceFactory.Create(DataSourceType.Kusto, _connectionString, _azureAccountToken);
|
||||
_dataSource = _dataSourceFactory.Create(DataSourceType.Kusto, _connectionString, _azureAccountToken);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -219,14 +227,15 @@ namespace Microsoft.Kusto.ServiceLayer.Connection
|
||||
public void Close()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the time to wait while trying to establish a connection before terminating
|
||||
/// the attempt and generating an error.
|
||||
/// </summary>
|
||||
|
||||
/// <summary>
|
||||
/// Gets the time to wait while trying to establish a connection before terminating
|
||||
/// the attempt and generating an error.
|
||||
/// </summary>
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
public int ConnectionTimeout
|
||||
{
|
||||
get { return 30; }
|
||||
{
|
||||
get { return 30; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -237,14 +246,6 @@ namespace Microsoft.Kusto.ServiceLayer.Connection
|
||||
{
|
||||
get { return _dataSource.DatabaseName; }
|
||||
}
|
||||
|
||||
private void VerifyConnectionOpen(ReliableDataSourceConnection conn)
|
||||
{
|
||||
if(conn.GetUnderlyingConnection() == null)
|
||||
{
|
||||
conn.Open();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user