/// <summary>
        /// Runs a query by calling the services directly (not using the test driver)
        /// </summary>
        public async Task RunQueryAsync(TestServerType serverType, string databaseName, string queryText, bool throwOnError = false)
        {
            string uri = "";

            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                uri = queryTempFile.FilePath;

                ConnectionInfo connInfo = InitLiveConnectionInfo(serverType, databaseName, uri);
                Query          query    = new Query(queryText, connInfo, new QueryExecutionSettings(), MemoryFileSystem.GetFileStreamFactory());
                query.Execute();
                await query.ExecutionTask;

                if (throwOnError)
                {
                    IEnumerable <Batch> errorBatches = query.Batches.Where(b => b.HasError);
                    if (errorBatches.Count() > 0)
                    {
                        throw new InvalidOperationException(
                                  string.Format(
                                      "The query encountered and error. The batches with errors: {0}",
                                      string.Join(Environment.NewLine, errorBatches.Select(b => b.BatchText))));
                    }
                }
                DisconnectConnection(uri);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Create the test db if not already exists
        /// </summary>
        public static async Task <SqlTestDb> CreateNewAsync(
            TestServerType serverType,
            bool doNotCleanupDb = false,
            string databaseName = null,
            string query        = null,
            string dbNamePrefix = null)
        {
            SqlTestDb testDb = new SqlTestDb();

            databaseName = databaseName ?? GetUniqueDBName(dbNamePrefix);
            string createDatabaseQuery = Scripts.CreateDatabaseQuery.Replace("#DatabaseName#", databaseName);
            await TestServiceProvider.Instance.RunQueryAsync(serverType, MasterDatabaseName, createDatabaseQuery);

            Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test database '{0}' is created", databaseName));
            if (!string.IsNullOrEmpty(query))
            {
                query = string.Format(CultureInfo.InvariantCulture, query, databaseName);
                await TestServiceProvider.Instance.RunQueryAsync(serverType, databaseName, query);

                Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test database '{0}' SQL types are created", databaseName));
            }
            testDb.DatabaseName   = databaseName;
            testDb.ServerType     = serverType;
            testDb.DoNotCleanupDb = doNotCleanupDb;

            return(testDb);
        }
Beispiel #3
0
        private async Task QueryResultFirstOnPremTest(TestServerType serverType, string query, [CallerMemberName] string testName = "")
        {
            await TestServiceDriverProvider.RunTestIterations(async (timer) =>
            {
                using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                    using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                    {
                        await testService.ConnectForQuery(serverType, query, queryTempFile.FilePath, SqlTestDb.MasterDatabaseName);
                        testService.WriteToFile(queryTempFile.FilePath, query);
                        await testService.RunQueryAndWaitToStart(queryTempFile.FilePath, 50000);
                        await testService.ExecuteWithTimeout(timer, 500000, async() =>
                        {
                            var queryResult = await testService.ExecuteSubset(queryTempFile.FilePath, 0, 0, 0, 50);
                            if (queryResult != null)
                            {
                                Assert.NotNull(queryResult);
                                Assert.NotNull(queryResult.ResultSubset);
                                Assert.True(queryResult.ResultSubset.Rows.Any());
                            }
                            return(queryResult != null);
                        }, TimeSpan.FromMilliseconds(10));

                        await testService.Disconnect(queryTempFile.FilePath);
                    }
            }, testName);
        }
        public async Task ConnectOnPremTest()
        {
            TestServerType serverType = TestServerType.OnPrem;

            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    const string query = Scripts.TestDbSimpleSelectQuery;
                    testService.WriteToFile(queryTempFile.FilePath, query);

                    DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
                    {
                        TextDocument = new TextDocumentItem
                        {
                            Uri        = queryTempFile.FilePath,
                            LanguageId = "enu",
                            Version    = 1,
                            Text       = query
                        }
                    };

                    await testService.RequestOpenDocumentNotification(openParams);

                    Thread.Sleep(500);
                    var connected = await testService.CalculateRunTime(async() =>
                    {
                        var connectParams = testService.GetConnectionParameters(serverType, Common.PerfTestDatabaseName);
                        return(await testService.Connect(queryTempFile.FilePath, connectParams));
                    }, true);

                    Assert.True(connected, "Connection was not successful");
                }
        }
Beispiel #5
0
        internal static async Task <bool> ConnectAsync(TestHelper testHelper, TestServerType serverType, string query, string ownerUri, string databaseName)
        {
            testHelper.WriteToFile(ownerUri, query);

            DidOpenTextDocumentNotification openParams = new DidOpenTextDocumentNotification
            {
                TextDocument = new TextDocumentItem
                {
                    Uri        = ownerUri,
                    LanguageId = "enu",
                    Version    = 1,
                    Text       = query
                }
            };

            await testHelper.RequestOpenDocumentNotification(openParams);

            Thread.Sleep(500);
            var connectParams = await testHelper.GetDatabaseConnectionAsync(serverType, databaseName);

            bool connected = await testHelper.Connect(ownerUri, connectParams);

            Assert.True(connected, "Connection is successful");
            Console.WriteLine($"Connection to {connectParams.Connection.ServerName} is successful");

            return(connected);
        }
Beispiel #6
0
        private readonly OneServer _v4Sv; //サーバ

        public TestServer(TestServerType type, String iniSubDir, String iniFileName)
        {
            var confName = type == TestServerType.Pop ? "Pop3" : "Smtp";

            //設定ファイルの退避と上書き
            _op = new TmpOption(iniSubDir, iniFileName);
            var kernel = new Kernel();
            var option = kernel.ListOption.Get(confName);
            var conf   = new Conf(option);


            //サーバ起動
            if (type == TestServerType.Pop)
            {
                _v4Sv = new Pop3Server.Server(kernel, conf, new OneBind(new Ip(IpKind.V4Localhost), ProtocolKind.Tcp));
                _v6Sv = new Pop3Server.Server(kernel, conf, new OneBind(new Ip(IpKind.V6Localhost), ProtocolKind.Tcp));
            }
            else
            {
                _v4Sv = new SmtpServer.Server(kernel, conf, new OneBind(new Ip(IpKind.V4Localhost), ProtocolKind.Tcp));
                _v6Sv = new SmtpServer.Server(kernel, conf, new OneBind(new Ip(IpKind.V6Localhost), ProtocolKind.Tcp));
            }
            _v4Sv.Start();
            _v6Sv.Start();

            Thread.Sleep(100); //少し余裕がないと多重でテストした場合に、サーバが起動しきらないうちにクライアントからの接続が始まってしまう。
        }
Beispiel #7
0
        public static async Task DropDatabase(string databaseName, TestServerType serverType = TestServerType.OnPrem)
        {
            string dropDatabaseQuery = string.Format(CultureInfo.InvariantCulture,
                                                     (serverType == TestServerType.Azure ? Scripts.DropDatabaseIfExistAzure : Scripts.DropDatabaseIfExist), databaseName);

            Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Cleaning up database {0}", databaseName));
            await TestServiceProvider.Instance.RunQueryAsync(serverType, MasterDatabaseName, dropDatabaseQuery);
        }
Beispiel #8
0
        public async Task BindingCacheColdOnPremComplexQuery()
        {
            TestServerType serverType = TestServerType.OnPrem;

            using (TestHelper testHelper = new TestHelper())
            {
                await VerifyBindingLoadScenario(testHelper, serverType, Scripts.TestDbComplexSelectQueries, false);
            }
        }
Beispiel #9
0
        public async Task BindingCacheColdAzureSimpleQuery()
        {
            TestServerType serverType = TestServerType.Azure;

            using (TestHelper testHelper = new TestHelper())
            {
                await VerifyBindingLoadScenario(testHelper, serverType, Scripts.TestDbSimpleSelectQuery, false);
            }
        }
Beispiel #10
0
 /// <summary>
 /// Create the test db if not already exists
 /// </summary>
 public static SqlTestDb CreateNew(
     TestServerType serverType,
     bool doNotCleanupDb = false,
     string databaseName = null,
     string query        = null,
     string dbNamePrefix = null)
 {
     return(CreateNewAsync(serverType, doNotCleanupDb, databaseName, query, dbNamePrefix).Result);
 }
        /// <summary>
        ///  Request a new connection to be created for given query
        /// </summary>
        public async Task <bool> ConnectForQuery(TestServerType serverType, string query, string ownerUri, string databaseName = null, int timeout = 15000)
        {
            if (!string.IsNullOrEmpty(query))
            {
                WriteToFile(ownerUri, query);
            }

            return(await Connect(serverType, ownerUri, databaseName, timeout));
        }
Beispiel #12
0
        public async Task BindingCacheColdAzureComplexQuery()
        {
            TestServerType serverType = TestServerType.Azure;

            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
            {
                await VerifyBindingLoadScenario(testService, serverType, Scripts.TestDbComplexSelectQueries, false);
            }
        }
Beispiel #13
0
        public async Task BindingCacheColdOnPremSimpleQuery()
        {
            TestServerType serverType = TestServerType.OnPrem;

            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
            {
                await VerifyBindingLoadScenario(testService, serverType, Scripts.TestDbSimpleSelectQuery, false);
            }
        }
Beispiel #14
0
        public async Task DiagnosticsTests()
        {
            TestServerType serverType = TestServerType.OnPrem;

            SqlTestDb.CreateNew(serverType, doNotCleanupDb: true, databaseName: Common.PerfTestDatabaseName, query: Scripts.CreateDatabaseObjectsQuery);

            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                {
                    await testService.ConnectForQuery(serverType, Scripts.TestDbSimpleSelectQuery, queryTempFile.FilePath, Common.PerfTestDatabaseName);

                    Thread.Sleep(500);
                    var contentChanges = new TextDocumentChangeEvent[1];
                    contentChanges[0] = new TextDocumentChangeEvent()
                    {
                        Range = new Range
                        {
                            Start = new Position
                            {
                                Line      = 0,
                                Character = 5
                            },
                            End = new Position
                            {
                                Line      = 0,
                                Character = 6
                            }
                        },
                        RangeLength = 1,
                        Text        = "z"
                    };
                    DidChangeTextDocumentParams changeParams = new DidChangeTextDocumentParams
                    {
                        ContentChanges = contentChanges,
                        TextDocument   = new VersionedTextDocumentIdentifier
                        {
                            Version = 2,
                            Uri     = queryTempFile.FilePath
                        }
                    };

                    TestTimer timer = new TestTimer()
                    {
                        PrintResult = true
                    };
                    await testService.RequestChangeTextDocumentNotification(changeParams);

                    await testService.ExecuteWithTimeout(timer, 60000, async() =>
                    {
                        var completeEvent = await testService.Driver.WaitForEvent(PublishDiagnosticsNotification.Type, 15000);
                        return(completeEvent?.Diagnostics != null && completeEvent.Diagnostics.Length > 0);
                    });

                    await testService.Disconnect(queryTempFile.FilePath);
                }
        }
Beispiel #15
0
 public async Task BindingCacheWarmAzureComplexQuery()
 {
     using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
         using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
         {
             string query = Scripts.TestDbComplexSelectQueries;
             const TestServerType serverType = TestServerType.Azure;
             await VerifyBindingLoadScenario(testService, serverType, query, true);
         }
 }
Beispiel #16
0
 public async Task BindingCacheWarmOnPremComplexQuery()
 {
     using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
         using (TestHelper testHelper = new TestHelper())
         {
             string query = Scripts.TestDbComplexSelectQueries;
             const TestServerType serverType = TestServerType.OnPrem;
             await VerifyBindingLoadScenario(testHelper, serverType, query, true);
         }
 }
Beispiel #17
0
 /// <summary>
 /// Runs a query by calling the services directly (not using the test driver)
 /// </summary>
 public void RunQuery(TestServerType serverType, string databaseName, string queryText)
 {
     using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
     {
         ConnectionInfo connInfo = InitLiveConnectionInfo(serverType, databaseName, queryTempFile.FilePath);
         Query          query    = new Query(queryText, connInfo, new QueryExecutionSettings(), GetFileStreamFactory(new Dictionary <string, byte[]>()));
         query.Execute();
         query.ExecutionTask.Wait();
     }
 }
Beispiel #18
0
        internal static async Task RunQuery(TestHelper testHelper, TestServerType serverType, string databaseName, string query)
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, databaseName);

                var queryResult = await Common.CalculateRunTime(() => testHelper.RunQuery(queryTempFile.FilePath, query, 50000), false);

                await testHelper.Disconnect(queryTempFile.FilePath);
            }
        }
        /// <summary>
        ///  Request a new connection to be created for url
        /// </summary>
        public async Task <bool> Connect(TestServerType serverType, string ownerUri, string databaseName = null, int timeout = 15000)
        {
            var connectParams = GetConnectionParameters(serverType, databaseName);

            bool connected = await Connect(ownerUri, connectParams, timeout);

            Assert.True(connected, "Connection is successful");
            Console.WriteLine($"Connection to {connectParams.Connection.ServerName} is successful");

            return(connected);
        }
 public async Task BindingCacheColdOnPremComplexQuery()
 {
     await TestServiceDriverProvider.RunTestIterations(async (timer) =>
     {
         TestServerType serverType = TestServerType.OnPrem;
         using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
         {
             await VerifyBindingLoadScenario(testService, serverType, Scripts.TestDbComplexSelectQueries, false, timer);
         }
     });
 }
Beispiel #21
0
        public async Task BindingCacheWarmAzureSimpleQuery()
        {
            TestServerType serverType = TestServerType.Azure;

            using (TestHelper testHelper = new TestHelper())
                using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                {
                    const string query = Scripts.TestDbSimpleSelectQuery;
                    await VerifyBindingLoadScenario(testHelper, serverType, query, true);
                }
        }
Beispiel #22
0
        public async Task BindingCacheWarmOnPremSimpleQuery()
        {
            TestServerType serverType = TestServerType.OnPrem;

            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                {
                    const string query = Scripts.TestDbSimpleSelectQuery;
                    await VerifyBindingLoadScenario(testService, serverType, query, true);
                }
        }
 public async Task BindingCacheWarmAzureSimpleQuery()
 {
     await TestServiceDriverProvider.RunTestIterations(async (timer) =>
     {
         TestServerType serverType = TestServerType.Azure;
         using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
             using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
             {
                 const string query = Scripts.TestDbSimpleSelectQuery;
                 await VerifyBindingLoadScenario(testService, serverType, query, true, timer);
             }
     });
 }
 public async Task BindingCacheWarmOnPremComplexQuery()
 {
     await TestServiceDriverProvider.RunTestIterations(async (timer) =>
     {
         using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
             using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
             {
                 string query = Scripts.TestDbComplexSelectQueries;
                 const TestServerType serverType = TestServerType.OnPrem;
                 await VerifyBindingLoadScenario(testService, serverType, query, true, timer);
             }
     });
 }
        public async Task RunQuery(TestServerType serverType, string databaseName, string query)
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                await ConnectForQuery(serverType, query, queryTempFile.FilePath, databaseName);

                var queryResult = await CalculateRunTime(() => RunQueryAndWaitToComplete(queryTempFile.FilePath, query, 50000));

                Assert.NotNull(queryResult);
                Assert.NotNull(queryResult.BatchSummaries);

                await Disconnect(queryTempFile.FilePath);
            }
        }
        public async Task DisconnectTest()
        {
            TestServerType serverType = TestServerType.OnPrem;

            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                {
                    await testService.ConnectForQuery(serverType, Scripts.TestDbSimpleSelectQuery, queryTempFile.FilePath, Common.PerfTestDatabaseName);

                    Thread.Sleep(1000);
                    var connected = await testService.CalculateRunTime(() => testService.Disconnect(queryTempFile.FilePath), true);

                    Assert.True(connected);
                }
        }
Beispiel #27
0
        /// <summary>
        /// Create the test db if not already exists
        /// </summary>
        internal static async Task CreateTestDatabase(TestServerType serverType)
        {
            using (TestHelper testHelper = new TestHelper())
                using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                {
                    string databaseName        = Common.PerfTestDatabaseName;
                    string createDatabaseQuery = Scripts.CreateDatabaseQuery.Replace("#DatabaseName#", databaseName);
                    await RunQuery(testHelper, serverType, Common.MasterDatabaseName, createDatabaseQuery);

                    Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Verified test database '{0}' is created", databaseName));
                    await RunQuery(testHelper, serverType, databaseName, Scripts.CreateDatabaseObjectsQuery);

                    Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Verified test database '{0}' SQL types are created", databaseName));
                }
        }
Beispiel #28
0
        public async Task SuggestionsTest()
        {
            TestServerType serverType = TestServerType.OnPrem;

            using (TestHelper testHelper = new TestHelper())
                using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                {
                    const string query = Scripts.TestDbSimpleSelectQuery;
                    await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.PerfTestDatabaseName);
                    await ValidateCompletionResponse(testHelper, queryTempFile.FilePath, false, Common.PerfTestDatabaseName, true);
                    await ValidateCompletionResponse(testHelper, queryTempFile.FilePath, true, Common.PerfTestDatabaseName, false);

                    await testHelper.Disconnect(queryTempFile.FilePath);
                }
        }
 public async Task SuggestionsTest()
 {
     await TestServiceDriverProvider.RunTestIterations(async (timer) =>
     {
         TestServerType serverType = TestServerType.OnPrem;
         using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
             using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
             {
                 const string query = Scripts.TestDbSimpleSelectQuery;
                 await testService.ConnectForQuery(serverType, query, queryTempFile.FilePath, Common.PerfTestDatabaseName);
                 await ValidateCompletionResponse(testService, queryTempFile.FilePath, Common.PerfTestDatabaseName, timer: null, waitForIntelliSense: true);
                 await ValidateCompletionResponse(testService, queryTempFile.FilePath, Common.PerfTestDatabaseName, timer: timer, waitForIntelliSense: false);
                 await testService.Disconnect(queryTempFile.FilePath);
             }
     });
 }
Beispiel #30
0
        public async Task HoverTestOnPrem()
        {
            TestServerType serverType = TestServerType.OnPrem;

            using (TestHelper testHelper = new TestHelper())
                using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                {
                    const string query = Scripts.TestDbSimpleSelectQuery;
                    await Common.ConnectAsync(testHelper, serverType, query, queryTempFile.FilePath, Common.PerfTestDatabaseName);

                    Hover hover = await Common.CalculateRunTime(() => testHelper.RequestHover(queryTempFile.FilePath, query, 0, Scripts.TestDbComplexSelectQueries.Length + 1), true);

                    Assert.NotNull(hover);
                    await testHelper.Disconnect(queryTempFile.FilePath);
                }
        }
Beispiel #31
0
        private readonly OneServer _v6Sv; //サーバ

        #endregion Fields

        #region Constructors

        public TestServer(TestServerType type,String iniSubDir,String iniFileName)
        {
            var confName = type == TestServerType.Pop ? "Pop3" : "Smtp";

            //設定ファイルの退避と上書き
            _op = new TmpOption(iniSubDir,iniFileName);
            var kernel = new Kernel();
            var option = kernel.ListOption.Get(confName);
            var conf = new Conf(option);

            //サーバ起動
            if (type == TestServerType.Pop){
                _v4Sv = new Pop3Server.Server(kernel, conf, new OneBind(new Ip(IpKind.V4Localhost), ProtocolKind.Tcp));
                _v6Sv = new Pop3Server.Server(kernel, conf, new OneBind(new Ip(IpKind.V6Localhost), ProtocolKind.Tcp));
            } else {
                _v4Sv = new SmtpServer.Server(kernel, conf, new OneBind(new Ip(IpKind.V4Localhost), ProtocolKind.Tcp));
                _v6Sv = new SmtpServer.Server(kernel, conf, new OneBind(new Ip(IpKind.V6Localhost), ProtocolKind.Tcp));
            }
            _v4Sv.Start();
            _v6Sv.Start();

            Thread.Sleep(100); //少し余裕がないと多重でテストした場合に、サーバが起動しきらないうちにクライアントからの接続が始まってしまう。
        }