public IEnumerable <string> IndexDocuments(SearchIndexClient client, int totalDocCount) { int existingDocumentCount = TestDocuments.Length; IEnumerable <string> hotelIds = Enumerable.Range(existingDocumentCount + 1, totalDocCount - existingDocumentCount) .Select(id => id.ToString()); var hotels = hotelIds.Select(id => new Hotel() { HotelId = id }).ToList(); for (int i = 0; i < hotels.Count; i += 1000) { IEnumerable <Hotel> nextHotels = hotels.Skip(i).Take(1000); if (!nextHotels.Any()) { break; } var batch = IndexBatch.Upload(nextHotels); client.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); } return(hotelIds); }
public SearchServiceFixture() { SearchManagementClient client = TestBase.GetServiceClient <SearchManagementClient>(new CSMTestEnvironmentFactory()); SearchServiceName = SearchTestUtilities.GenerateServiceName(); var createServiceParameters = new SearchServiceCreateOrUpdateParameters() { Location = Location, Properties = new SearchServiceProperties() { Sku = new Sku(SkuType.Free) } }; SearchServiceCreateOrUpdateResponse createServiceResponse = client.Services.CreateOrUpdate(ResourceGroupName, SearchServiceName, createServiceParameters); Assert.Equal(HttpStatusCode.Created, createServiceResponse.StatusCode); AdminKeyResponse adminKeyResponse = client.AdminKeys.List(ResourceGroupName, SearchServiceName); Assert.Equal(HttpStatusCode.OK, adminKeyResponse.StatusCode); PrimaryApiKey = adminKeyResponse.PrimaryKey; ListQueryKeysResponse queryKeyResponse = client.QueryKeys.List(ResourceGroupName, SearchServiceName); Assert.Equal(HttpStatusCode.OK, queryKeyResponse.StatusCode); Assert.Equal(1, queryKeyResponse.QueryKeys.Count); QueryApiKey = queryKeyResponse.QueryKeys[0].Key; }
public Indexer CreateTestIndexerWithSkillset(string skillsetName, IList <FieldMapping> outputFieldMapping) { return(new Indexer(name: SearchTestUtilities.GenerateName(), dataSourceName: DataSourceName, targetIndexName: TargetIndexName, skillsetName: skillsetName) { // We can't test startTime because it's an absolute time that must be within 24 hours of the current // time. That doesn't play well with recorded mock payloads. Schedule = new IndexingSchedule(interval: TimeSpan.FromDays(1)), OutputFieldMappings = outputFieldMapping }); }
public DocumentsFixture() { SearchIndexClient indexClient = this.GetSearchIndexClient(); var batch = IndexBatch.Create(TestDocuments.Select(d => IndexAction.Create(d))); indexClient.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); }
public override void Initialize(MockContext context) { base.Initialize(context); SearchServiceClient searchClient = this.GetSearchServiceClient(); TargetIndexName = SearchTestUtilities.GenerateName(); DataSourceName = SearchTestUtilities.GenerateName(); var index = new Index( TargetIndexName, new[] { new Field("feature_id", DataType.String) { IsKey = true }, new Field("feature_name", DataType.String) { IsFilterable = true, IsSearchable = true }, new Field("feature_class", DataType.String), new Field("state", DataType.String) { IsFilterable = true, IsSearchable = true }, new Field("county_name", DataType.String) { IsFilterable = true, IsSearchable = true }, new Field("elevation", DataType.Int32) { IsFilterable = true }, new Field("map_name", DataType.String) { IsFilterable = true, IsSearchable = true }, new Field("history", DataType.Collection(DataType.String)) { IsSearchable = true } }); searchClient.Indexes.Create(index); var dataSource = DataSource.AzureSql( name: DataSourceName, sqlConnectionString: AzureSqlReadOnlyConnectionString, tableOrViewName: AzureSqlTestTableName); searchClient.DataSources.Create(dataSource); }
private string EnsureSearchService(SearchManagementClient client) { // Ensuring a search service involves creating it, and then waiting until its DNS resolves. The approach // we take depends on what kind of test run this is. If it's a Record or Playback run, we need determinism // since the mock server has no clue how many times we retried DNS lookup in the original test run. In // this case, we can't just delete and re-create the search service if DNS doesn't resolve in a timely // manner. However, we do fail fast in the interests of speeding up interactive dev cycles. // // If we're in None mode (i.e. -- no mock recording or playback), we assume we're running automated tests // in batch. In this case, non-determinism is not a problem (because mocks aren't involved), and // reliability is paramount. For this reason, we retry the entire sequence several times, deleting and // trying to re-create the service each time. int maxAttempts = (HttpMockServer.Mode == HttpRecorderMode.None) ? 10 : 1; for (int attempt = 0; attempt < maxAttempts; attempt++) { string searchServiceName = SearchTestUtilities.GenerateServiceName(); var createServiceParameters = new SearchServiceCreateOrUpdateParameters() { Location = Location, Properties = new SearchServiceProperties() { Sku = new Sku() { Name = SkuType.Free } } }; client.Services.CreateOrUpdate(ResourceGroupName, searchServiceName, createServiceParameters); // In the common case, DNS propagation happens in less than 15 seconds. In the uncommon case, it can // take many minutes. The timeout we use depends on the mock mode. If we're in Playback, the delay is // irrelevant. If we're in Record mode, we can't delete and re-create the service, so we get more // reliable results if we wait longer. In "None" mode, we can delete and re-create, which is often // faster than waiting a long time for DNS propagation. In that case, rather than force all tests to // wait several minutes, we fail fast here. TimeSpan maxDelay = (HttpMockServer.Mode == HttpRecorderMode.Record) ? TimeSpan.FromMinutes(1) : TimeSpan.FromSeconds(15); if (SearchTestUtilities.WaitForSearchServiceDns(searchServiceName, maxDelay)) { return(searchServiceName); } // If the service DNS isn't resolvable in a timely manner, delete it and try to create another one. // We need to delete it since there can be only one free service per subscription. client.Services.Delete(ResourceGroupName, searchServiceName); } throw new InvalidOperationException("Failed to provision a search service in a timely manner."); }
public override void Initialize(MockContext context) { base.Initialize(context); SearchIndexClient indexClient = this.GetSearchIndexClient(); var batch = IndexBatch.Upload(TestDocuments); indexClient.Documents.Index(batch); SearchTestUtilities.WaitForIndexing(); }
public override void Initialize(MockContext context) { base.Initialize(context); SearchServiceClient searchClient = this.GetSearchServiceClient(); IndexName = SearchTestUtilities.GenerateName(); var index = CreateTestIndex(IndexName); searchClient.Indexes.Create(index); // Give the index time to stabilize before running tests. // TODO: Remove this workaround once the retry hang bug is fixed. TestUtilities.Wait(TimeSpan.FromSeconds(20)); }
public Indexer CreateTestIndexer() => new Indexer(SearchTestUtilities.GenerateName(), DataSourceName, TargetIndexName) { // We can't test startTime because it's an absolute time that must be within 24 hours of the current // time. That doesn't play well with recorded mock payloads. Schedule = new IndexingSchedule(interval: TimeSpan.FromDays(1)), FieldMappings = new[] { // Try all the field mapping functions (even if they don't make sense in the context of the test DB). new FieldMapping("feature_class", FieldMappingFunction.Base64Encode()), new FieldMapping("state_alpha", "state"), new FieldMapping("county_name", FieldMappingFunction.ExtractTokenAtPosition(" ", 0)), new FieldMapping("elev_in_m", "elevation"), new FieldMapping("map_name", FieldMappingFunction.Base64Decode()), new FieldMapping("history", FieldMappingFunction.JsonArrayToStringCollection()) } };
public virtual void Initialize(MockContext context) { ResourceManagementClient client = context.GetServiceClient <ResourceManagementClient>(); // Register subscription and get a valid location for search services. Provider provider = client.Providers.Register(SearchNamespace); Assert.NotNull(provider); // We only support one resource type. Location = provider.ResourceTypes.First().Locations.First(); // Create resource group ResourceGroupName = SearchTestUtilities.GenerateName(); ResourceGroup resourceGroup = client.ResourceGroups.CreateOrUpdate(ResourceGroupName, new ResourceGroup() { Location = Location }); Assert.NotNull(resourceGroup); }
public override void Initialize(MockContext context) { base.Initialize(context); MockContext = context; ResourceManagementClient rmClient = context.GetServiceClient <ResourceManagementClient>(); // Register subscription for storage and networking Provider provider = rmClient.Providers.Register("Microsoft.Storage"); Assert.NotNull(provider); provider = rmClient.Providers.Register("Microsoft.Network"); Assert.NotNull(provider); StorageAccountName = SearchTestUtilities.GenerateStorageAccountName(); StorageManagementClient client = MockContext.GetServiceClient <StorageManagementClient>(); StorageAccount account = client.StorageAccounts.Create( ResourceGroupName, StorageAccountName, new StorageAccountCreateParameters( new Sku("Standard_LRS"), kind: "StorageV2", location: "eastus2euap")); Assert.NotNull(account); StorageAccountId = account.Id; SearchManagementClient searchMgmt = context.GetServiceClient <SearchManagementClient>(); ServiceName = SearchTestUtilities.GenerateServiceName(); SearchService service = DefineServiceWithSku(Management.Search.Models.SkuName.Basic); searchMgmt.Services.CreateOrUpdate(ResourceGroupName, ServiceName, service); }
public override void Initialize(MockContext context) { base.Initialize(context); SearchServiceClient searchClient = this.GetSearchServiceClient(); IndexName = SearchTestUtilities.GenerateName(); // This is intentionally a different index definition than the one returned by IndexTests.CreateTestIndex(). // That index is meant to exercise serialization of the index definition itself, while this one is tuned // more for exercising document serialization, indexing, and querying operations. var index = new Index() { Name = IndexName, Fields = new[] { new Field("hotelId", DataType.String) { IsKey = true, IsFilterable = true, IsSortable = true, IsFacetable = true }, new Field("baseRate", DataType.Double) { IsFilterable = true, IsSortable = true, IsFacetable = true }, new Field("description", DataType.String) { IsSearchable = true }, new Field("descriptionFr", AnalyzerName.FrLucene), new Field("hotelName", DataType.String) { IsSearchable = true, IsFilterable = true, IsSortable = true, IsFacetable = true }, new Field("category", DataType.String) { IsSearchable = true, IsFilterable = true, IsSortable = true, IsFacetable = true }, new Field("tags", DataType.Collection(DataType.String)) { IsSearchable = true, IsFilterable = true, IsFacetable = true }, new Field("parkingIncluded", DataType.Boolean) { IsFilterable = true, IsSortable = true, IsFacetable = true }, new Field("smokingAllowed", DataType.Boolean) { IsFilterable = true, IsSortable = true, IsFacetable = true }, new Field("lastRenovationDate", DataType.DateTimeOffset) { IsFilterable = true, IsSortable = true, IsFacetable = true }, new Field("rating", DataType.Int32) { IsFilterable = true, IsSortable = true, IsFacetable = true }, new Field("location", DataType.GeographyPoint) { IsFilterable = true, IsSortable = true } }, Suggesters = new[] { new Suggester( name: "sg", searchMode: SuggesterSearchMode.AnalyzingInfixMatching, sourceFields: new[] { "description", "hotelName" }) }, ScoringProfiles = new[] { new ScoringProfile("nearest") { FunctionAggregation = ScoringFunctionAggregation.Sum, Functions = new[] { new DistanceScoringFunction("location", 2, new DistanceScoringParameters("myloc", 100)) } } } }; searchClient.Indexes.Create(index); // Give the index time to stabilize before running tests. // TODO: Remove this workaround once the retry hang bug is fixed. TestUtilities.Wait(TimeSpan.FromSeconds(20)); }