Пример #1
0
        public void DatabaseDeletedWhenCalledFromClient()
        {
            // arrange
            var uniqueName = BuildUniqueName();

            VerifyDatabase(uniqueName, false);

            var client = BuildHCatalogClient();

            var createDatabaseRequest = new CreateDatabaseRequest { Database = uniqueName, Location = DatabaseLocation };

            var createDbTask = client.CreateDatabase(createDatabaseRequest);
            createDbTask.Wait();
            Assert.IsTrue(createDbTask.Result);

            var getDbsTask = client.GetDatabases();
            getDbsTask.Wait();

            VerifyDatabase(uniqueName, true);

            // act
            var resultTask = client.DeleteDatabase(uniqueName);
            resultTask.Wait();

            // assert
            Assert.IsTrue(resultTask.Result);
            VerifyDatabase(uniqueName, false);
        }
        protected void CreateDatabaseIfNotExists()
        {
            var client = BuildHCatalogClient();
            var task = client.GetDatabases();
            task.Wait();

            if (task.Result.Databases.Any(s => DatabaseName == s))
            {
                return;
            }

            var createDatabase = new CreateDatabaseRequest { Database = DatabaseName, Location = DatabaseLocation };

            client.CreateDatabase(createDatabase).Wait();
        }
Пример #3
0
        public Task<bool> CreateDatabase(CreateDatabaseRequest createDatabaseRequest)
        {
            createDatabaseRequest.CheckWhetherArgumentIsNull("createDatabaseRequest");

            var createDatabaseUrl = this.urlBuilder.CreateDatabaseUrl(createDatabaseRequest.Database);

            return Task<bool>.Factory.StartNew(
                () =>
                {
                    using (var restService = this.webClientBuilder.BuildWebClient())
                    {
                        var response = restService.PutJson<Dictionary<string, string>>(createDatabaseUrl, createDatabaseRequest.ToJson());

                        // project response to true/false
                        return response.ContainsKey("database") && response.ContainsValue(createDatabaseRequest.Database);
                    }
                });
        }