From ca315133c99a91e269021e53818e57c0ee622204 Mon Sep 17 00:00:00 2001 From: algolia-bot Date: Wed, 14 Feb 2024 16:49:29 +0000 Subject: [PATCH] chore: generated code for commit 65bd154879fdf13cb0e8dc79f73b0f478b9af971. [skip ci] Co-authored-by: Pierre Millot --- .../client_core/lib/src/config/host.dart | 17 +- .../lib/Configuration/Configuration.php | 13 + .../lib/Configuration/SearchConfig.php | 1 + .../algoliasearch/http/transporter.py | 6 +- .../algoliasearch/recommend/config.py | 15 +- .../algoliasearch/search/config.py | 15 +- .../lib/algolia/transport/transport.rb | 2 +- .../src/generated/client/Abtesting.test.cs | 3 + .../src/generated/client/Analytics.test.cs | 3 + .../src/generated/client/Ingestion.test.cs | 3 + .../src/generated/client/Insights.test.cs | 3 + .../src/generated/client/Monitoring.test.cs | 3 + .../generated/client/Personalization.test.cs | 3 + .../generated/client/QuerySuggestions.test.cs | 3 + .../src/generated/client/Recommend.test.cs | 3 + .../src/generated/client/Search.test.cs | 41 +++ .../dart/test/client/insights_test.dart | 159 ++++++----- .../dart/test/client/recommend_test.dart | 138 +++++----- .../output/dart/test/client/search_test.dart | 255 ++++++++++-------- tests/output/go/tests/client/search_test.go | 28 ++ .../com/algolia/client/Abtesting.test.java | 24 +- .../com/algolia/client/Analytics.test.java | 24 +- .../com/algolia/client/Ingestion.test.java | 22 +- .../com/algolia/client/Insights.test.java | 24 +- .../com/algolia/client/Monitoring.test.java | 20 +- .../algolia/client/Personalization.test.java | 24 +- .../algolia/client/QuerySuggestions.test.java | 24 +- .../com/algolia/client/Recommend.test.java | 22 +- .../java/com/algolia/client/Search.test.java | 51 +++- .../javascript/src/client/search.test.ts | 13 + .../kotlin/com/algolia/client/SearchTest.kt | 17 ++ tests/output/php/src/client/SearchTest.php | 16 ++ .../python/tests/client/abtesting_test.py | 45 +++- .../python/tests/client/analytics_test.py | 48 +++- .../python/tests/client/ingestion_test.py | 36 ++- .../python/tests/client/insights_test.py | 43 ++- .../python/tests/client/monitoring_test.py | 23 +- .../tests/client/personalization_test.py | 47 ++-- .../tests/client/query_suggestions_test.py | 47 ++-- .../python/tests/client/recommend_test.py | 32 ++- .../output/python/tests/client/search_test.py | 76 +++++- .../output/ruby/test/client/abtesting_test.rb | 6 + .../output/ruby/test/client/analytics_test.rb | 7 + .../output/ruby/test/client/ingestion_test.rb | 5 + .../output/ruby/test/client/insights_test.rb | 6 + .../ruby/test/client/monitoring_test.rb | 4 + .../ruby/test/client/personalization_test.rb | 6 + .../test/client/query_suggestions_test.rb | 6 + .../output/ruby/test/client/recommend_test.rb | 5 + tests/output/ruby/test/client/search_test.rb | 35 +++ .../algoliasearch/client/AbtestingTest.scala | 2 + .../algoliasearch/client/AnalyticsTest.scala | 2 + .../algoliasearch/client/IngestionTest.scala | 2 + .../algoliasearch/client/InsightsTest.scala | 2 + .../algoliasearch/client/MonitoringTest.scala | 2 + .../client/PersonalizationTest.scala | 2 + .../client/QuerySuggestionsTest.scala | 2 + .../algoliasearch/client/RecommendTest.scala | 2 + .../algoliasearch/client/SearchTest.scala | 27 ++ .../swift/Tests/client/SearchTests.swift | 18 ++ 60 files changed, 1112 insertions(+), 421 deletions(-) diff --git a/clients/algoliasearch-client-dart/packages/client_core/lib/src/config/host.dart b/clients/algoliasearch-client-dart/packages/client_core/lib/src/config/host.dart index 662cd9e763..9dbe6ad08b 100644 --- a/clients/algoliasearch-client-dart/packages/client_core/lib/src/config/host.dart +++ b/clients/algoliasearch-client-dart/packages/client_core/lib/src/config/host.dart @@ -13,14 +13,20 @@ final class Host { final CallType? callType; /// Constructs a [Host] instance with the provided parameters. - const Host({required this.url, this.port, this.scheme = 'https', this.callType}); + const Host( + {required this.url, this.port, this.scheme = 'https', this.callType}); - factory Host.create({required String url, String scheme = 'https', CallType? callType}) { + factory Host.create( + {required String url, String scheme = 'https', CallType? callType}) { if (url.contains(':')) { final parts = url.split(':'); - return Host(url: parts[0], port: int.parse(parts[1]), scheme: scheme, callType: callType); + return Host( + url: parts[0], + port: int.parse(parts[1]), + scheme: scheme, + callType: callType); } - + return Host(url: url, scheme: scheme, callType: callType); } @@ -35,7 +41,8 @@ final class Host { callType == other.callType; @override - int get hashCode => url.hashCode ^ (port ?? 1) ^ scheme.hashCode ^ callType.hashCode; + int get hashCode => + url.hashCode ^ (port ?? 1) ^ scheme.hashCode ^ callType.hashCode; @override String toString() { diff --git a/clients/algoliasearch-client-php/lib/Configuration/Configuration.php b/clients/algoliasearch-client-php/lib/Configuration/Configuration.php index 880f153307..6dce367fd6 100644 --- a/clients/algoliasearch-client-php/lib/Configuration/Configuration.php +++ b/clients/algoliasearch-client-php/lib/Configuration/Configuration.php @@ -170,6 +170,7 @@ public function getDefaultConfiguration() 'appId' => '', 'apiKey' => '', 'hosts' => null, + 'hasFullHosts' => false, 'readTimeout' => $this->defaultReadTimeout, 'writeTimeout' => $this->defaultWriteTimeout, 'connectTimeout' => $this->defaultConnectTimeout, @@ -213,6 +214,18 @@ public function setHosts($hosts) return $this; } + public function setFullHosts($hosts) + { + $this->config['hasFullHosts'] = true; + + return $this->setHosts($hosts); + } + + public function getHasFullHosts() + { + return $this->config['hasFullHosts']; + } + public function getReadTimeout() { return $this->config['readTimeout']; diff --git a/clients/algoliasearch-client-php/lib/Configuration/SearchConfig.php b/clients/algoliasearch-client-php/lib/Configuration/SearchConfig.php index 85e6bf8f4c..b5fb2c29da 100644 --- a/clients/algoliasearch-client-php/lib/Configuration/SearchConfig.php +++ b/clients/algoliasearch-client-php/lib/Configuration/SearchConfig.php @@ -26,6 +26,7 @@ public function getDefaultConfiguration() 'appId' => '', 'apiKey' => '', 'hosts' => null, + 'hasFullHosts' => false, 'readTimeout' => $this->defaultReadTimeout, 'writeTimeout' => $this->defaultWriteTimeout, 'connectTimeout' => $this->defaultConnectTimeout, diff --git a/clients/algoliasearch-client-python/algoliasearch/http/transporter.py b/clients/algoliasearch-client-python/algoliasearch/http/transporter.py index 7cca872bf3..832e326153 100644 --- a/clients/algoliasearch-client-python/algoliasearch/http/transporter.py +++ b/clients/algoliasearch-client-python/algoliasearch/http/transporter.py @@ -93,7 +93,11 @@ async def request( ) for host in self._retry_strategy.valid_hosts(self._hosts): - url = "{}://{}{}".format(host.scheme, host.url + (":{}".format(host.port) if host.port else ""), path) + url = "{}://{}{}".format( + host.scheme, + host.url + (":{}".format(host.port) if host.port else ""), + path, + ) proxy = None if url.startswith("https"): diff --git a/clients/algoliasearch-client-python/algoliasearch/recommend/config.py b/clients/algoliasearch-client-python/algoliasearch/recommend/config.py index 2612a12a0a..23d3398d22 100644 --- a/clients/algoliasearch-client-python/algoliasearch/recommend/config.py +++ b/clients/algoliasearch-client-python/algoliasearch/recommend/config.py @@ -32,10 +32,19 @@ def __init__( self.hosts = HostsCollection( [ - Host("{}-dsn.algolia.net".format(self.app_id), 10, CallType.READ), - Host("{}.algolia.net".format(self.app_id), 10, CallType.WRITE), + Host( + url="{}-dsn.algolia.net".format(self.app_id), + priority=10, + accept=CallType.READ, + ), + Host( + url="{}.algolia.net".format(self.app_id), + priority=10, + accept=CallType.WRITE, + ), Host("{}-1.algolianet.com".format(self.app_id)), Host("{}-2.algolianet.com".format(self.app_id)), Host("{}-3.algolianet.com".format(self.app_id)), - ] + ], + reorder_hosts=True, ) diff --git a/clients/algoliasearch-client-python/algoliasearch/search/config.py b/clients/algoliasearch-client-python/algoliasearch/search/config.py index 97106b3893..db619ceef8 100644 --- a/clients/algoliasearch-client-python/algoliasearch/search/config.py +++ b/clients/algoliasearch-client-python/algoliasearch/search/config.py @@ -32,10 +32,19 @@ def __init__( self.hosts = HostsCollection( [ - Host("{}-dsn.algolia.net".format(self.app_id), 10, CallType.READ), - Host("{}.algolia.net".format(self.app_id), 10, CallType.WRITE), + Host( + url="{}-dsn.algolia.net".format(self.app_id), + priority=10, + accept=CallType.READ, + ), + Host( + url="{}.algolia.net".format(self.app_id), + priority=10, + accept=CallType.WRITE, + ), Host("{}-1.algolianet.com".format(self.app_id)), Host("{}-2.algolianet.com".format(self.app_id)), Host("{}-3.algolianet.com".format(self.app_id)), - ] + ], + reorder_hosts=True, ) diff --git a/clients/algoliasearch-client-ruby/lib/algolia/transport/transport.rb b/clients/algoliasearch-client-ruby/lib/algolia/transport/transport.rb index 61c6516047..4e812e2f4d 100644 --- a/clients/algoliasearch-client-ruby/lib/algolia/transport/transport.rb +++ b/clients/algoliasearch-client-ruby/lib/algolia/transport/transport.rb @@ -59,7 +59,7 @@ def request(call_type, method, path, body, opts = {}) return response unless outcome == RETRY end - raise Algolia::AlgoliaUnreachableHostError.new('Unreachable hosts') + raise Algolia::AlgoliaUnreachableHostError, 'Unreachable hosts' end private diff --git a/tests/output/csharp/src/generated/client/Abtesting.test.cs b/tests/output/csharp/src/generated/client/Abtesting.test.cs index e0a60832dd..13aa522b19 100644 --- a/tests/output/csharp/src/generated/client/Abtesting.test.cs +++ b/tests/output/csharp/src/generated/client/Abtesting.test.cs @@ -2,6 +2,9 @@ using Algolia.Search.Clients; using Algolia.Search.Http; using Algolia.Search.Models.Abtesting; +using Algolia.Search.Transport; +using Newtonsoft.Json; +using Quibble.Xunit; using Xunit; public class AbtestingClientTests diff --git a/tests/output/csharp/src/generated/client/Analytics.test.cs b/tests/output/csharp/src/generated/client/Analytics.test.cs index d6f8402404..b1d83b435b 100644 --- a/tests/output/csharp/src/generated/client/Analytics.test.cs +++ b/tests/output/csharp/src/generated/client/Analytics.test.cs @@ -2,6 +2,9 @@ using Algolia.Search.Clients; using Algolia.Search.Http; using Algolia.Search.Models.Analytics; +using Algolia.Search.Transport; +using Newtonsoft.Json; +using Quibble.Xunit; using Xunit; public class AnalyticsClientTests diff --git a/tests/output/csharp/src/generated/client/Ingestion.test.cs b/tests/output/csharp/src/generated/client/Ingestion.test.cs index 9d8b22e648..60c3809034 100644 --- a/tests/output/csharp/src/generated/client/Ingestion.test.cs +++ b/tests/output/csharp/src/generated/client/Ingestion.test.cs @@ -2,6 +2,9 @@ using Algolia.Search.Clients; using Algolia.Search.Http; using Algolia.Search.Models.Ingestion; +using Algolia.Search.Transport; +using Newtonsoft.Json; +using Quibble.Xunit; using Xunit; public class IngestionClientTests diff --git a/tests/output/csharp/src/generated/client/Insights.test.cs b/tests/output/csharp/src/generated/client/Insights.test.cs index dc09fff1f1..7c440e6ed4 100644 --- a/tests/output/csharp/src/generated/client/Insights.test.cs +++ b/tests/output/csharp/src/generated/client/Insights.test.cs @@ -2,6 +2,9 @@ using Algolia.Search.Clients; using Algolia.Search.Http; using Algolia.Search.Models.Insights; +using Algolia.Search.Transport; +using Newtonsoft.Json; +using Quibble.Xunit; using Xunit; public class InsightsClientTests diff --git a/tests/output/csharp/src/generated/client/Monitoring.test.cs b/tests/output/csharp/src/generated/client/Monitoring.test.cs index 82a6216ee0..3a17c123ec 100644 --- a/tests/output/csharp/src/generated/client/Monitoring.test.cs +++ b/tests/output/csharp/src/generated/client/Monitoring.test.cs @@ -2,6 +2,9 @@ using Algolia.Search.Clients; using Algolia.Search.Http; using Algolia.Search.Models.Monitoring; +using Algolia.Search.Transport; +using Newtonsoft.Json; +using Quibble.Xunit; using Xunit; public class MonitoringClientTests diff --git a/tests/output/csharp/src/generated/client/Personalization.test.cs b/tests/output/csharp/src/generated/client/Personalization.test.cs index 67bdb52e6d..438c728c66 100644 --- a/tests/output/csharp/src/generated/client/Personalization.test.cs +++ b/tests/output/csharp/src/generated/client/Personalization.test.cs @@ -2,6 +2,9 @@ using Algolia.Search.Clients; using Algolia.Search.Http; using Algolia.Search.Models.Personalization; +using Algolia.Search.Transport; +using Newtonsoft.Json; +using Quibble.Xunit; using Xunit; public class PersonalizationClientTests diff --git a/tests/output/csharp/src/generated/client/QuerySuggestions.test.cs b/tests/output/csharp/src/generated/client/QuerySuggestions.test.cs index 165219e5df..2e9ecfc6d0 100644 --- a/tests/output/csharp/src/generated/client/QuerySuggestions.test.cs +++ b/tests/output/csharp/src/generated/client/QuerySuggestions.test.cs @@ -2,6 +2,9 @@ using Algolia.Search.Clients; using Algolia.Search.Http; using Algolia.Search.Models.QuerySuggestions; +using Algolia.Search.Transport; +using Newtonsoft.Json; +using Quibble.Xunit; using Xunit; public class QuerySuggestionsClientTests diff --git a/tests/output/csharp/src/generated/client/Recommend.test.cs b/tests/output/csharp/src/generated/client/Recommend.test.cs index dd48dc61e5..c1f744ba76 100644 --- a/tests/output/csharp/src/generated/client/Recommend.test.cs +++ b/tests/output/csharp/src/generated/client/Recommend.test.cs @@ -2,6 +2,9 @@ using Algolia.Search.Clients; using Algolia.Search.Http; using Algolia.Search.Models.Recommend; +using Algolia.Search.Transport; +using Newtonsoft.Json; +using Quibble.Xunit; using Xunit; public class RecommendClientTests diff --git a/tests/output/csharp/src/generated/client/Search.test.cs b/tests/output/csharp/src/generated/client/Search.test.cs index 9198a1f747..f36753850d 100644 --- a/tests/output/csharp/src/generated/client/Search.test.cs +++ b/tests/output/csharp/src/generated/client/Search.test.cs @@ -2,6 +2,9 @@ using Algolia.Search.Clients; using Algolia.Search.Http; using Algolia.Search.Models.Search; +using Algolia.Search.Transport; +using Newtonsoft.Json; +using Quibble.Xunit; using Xunit; public class SearchClientTests @@ -37,6 +40,44 @@ public async Task ApiTest1() Assert.Equal("test-app-id.algolia.net", result.Host); } + [Fact(DisplayName = "tests the retry strategy")] + public async Task ApiTest2() + { + SearchConfig _config = new SearchConfig("test-app-id", "test-api-key") + { + CustomHosts = new List + { + new() + { + Scheme = HttpScheme.Http, + Url = "localhost", + Port = 6677, + Up = true, + LastUse = DateTime.UtcNow, + Accept = CallType.Read | CallType.Write, + }, + new() + { + Scheme = HttpScheme.Http, + Url = "localhost", + Port = 6678, + Up = true, + LastUse = DateTime.UtcNow, + Accept = CallType.Read | CallType.Write, + } + } + }; + var client = new SearchClient(_config); + + var res = await client.CustomGetAsync("/test"); + + JsonAssert.EqualOverrideDefault( + "{\"message\":\"ok test server response\"}", + JsonConvert.SerializeObject(res), + new JsonDiffConfig(false) + ); + } + [Fact(DisplayName = "calls api with correct user agent")] public async Task CommonApiTest0() { diff --git a/tests/output/dart/test/client/insights_test.dart b/tests/output/dart/test/client/insights_test.dart index a6fe11e4a2..85841ddc47 100644 --- a/tests/output/dart/test/client/insights_test.dart +++ b/tests/output/dart/test/client/insights_test.dart @@ -4,83 +4,77 @@ import 'package:test/test.dart'; import 'package:test_api/hooks.dart'; void main() { - test('calls api with correct user agent', () { + test('calls api with correct user agent', () async { + final requester = RequestInterceptor(); final client = InsightsClient( appId: 'appId', apiKey: 'apiKey', region: 'us', + options: ClientOptions(requester: requester), ); - runTest( - builder: (requester) => InsightsClient( - appId: client.appId, - apiKey: client.apiKey, - region: client.region, - options: ClientOptions(requester: requester), - ), - call: (client) => client.customPost( + requester.setOnRequest((request) { + TestHandle.current.markSkipped('User agent added using an interceptor'); + }); + try { + final res = await client.customPost( path: "/test", - ), - intercept: (request) { - TestHandle.current.markSkipped('User agent added using an interceptor'); - }, - ); + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }); - test('calls api with default read timeouts', () { + + test('calls api with default read timeouts', () async { + final requester = RequestInterceptor(); final client = InsightsClient( appId: 'appId', apiKey: 'apiKey', region: 'us', + options: ClientOptions(requester: requester), ); - runTest( - builder: (requester) => InsightsClient( - appId: client.appId, - apiKey: client.apiKey, - region: client.region, - options: ClientOptions(requester: requester), - ), - call: (client) => client.customGet( + requester.setOnRequest((request) { + expect(5000, request.timeout.inMilliseconds); + }); + try { + final res = await client.customGet( path: "/test", - ), - intercept: (request) { - expect(5000, request.timeout.inMilliseconds); - }, - ); + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }); - test('calls api with default write timeouts', () { + + test('calls api with default write timeouts', () async { + final requester = RequestInterceptor(); final client = InsightsClient( appId: 'appId', apiKey: 'apiKey', region: 'us', + options: ClientOptions(requester: requester), ); - runTest( - builder: (requester) => InsightsClient( - appId: client.appId, - apiKey: client.apiKey, - region: client.region, - options: ClientOptions(requester: requester), - ), - call: (client) => client.customPost( + requester.setOnRequest((request) { + expect(30000, request.timeout.inMilliseconds); + }); + try { + final res = await client.customPost( path: "/test", - ), - intercept: (request) { - expect(30000, request.timeout.inMilliseconds); - }, - ); + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }); - test('fallbacks to the alias when region is not given', () { + test('fallbacks to the alias when region is not given', () async { + final requester = RequestInterceptor(); final client = InsightsClient( - appId: "my-app-id", - apiKey: "my-api-key", - ); - runTest( - builder: (requester) => InsightsClient( - appId: client.appId, - apiKey: client.apiKey, - region: client.region, - options: ClientOptions(requester: requester), - ), - call: (client) => client.pushEvents( + appId: "my-app-id", + apiKey: "my-api-key", + options: ClientOptions(requester: requester)); + requester.setOnRequest((request) { + expect(request.host.url, 'insights.algolia.io'); + }); + try { + final res = await client.pushEvents( insightsEvents: InsightsEvents( events: [ ClickedObjectIDsAfterSearch( @@ -102,42 +96,41 @@ void main() { ), ], ), - ), - intercept: (request) { - expect(request.host.url, 'insights.algolia.io'); - }, - ); + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }); - test('uses the correct region', () { + + test('uses the correct region', () async { + final requester = RequestInterceptor(); final client = InsightsClient( - appId: "my-app-id", - apiKey: "my-api-key", - region: 'us', - ); - runTest( - builder: (requester) => InsightsClient( - appId: client.appId, - apiKey: client.apiKey, - region: client.region, - options: ClientOptions(requester: requester), - ), - call: (client) => client.customDelete( + appId: "my-app-id", + apiKey: "my-api-key", + region: 'us', + options: ClientOptions(requester: requester)); + requester.setOnRequest((request) { + expect(request.host.url, 'insights.us.algolia.io'); + }); + try { + final res = await client.customDelete( path: "/test", - ), - intercept: (request) { - expect(request.host.url, 'insights.us.algolia.io'); - }, - ); + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }); - test('throws when incorrect region is given', () { + + test('throws when incorrect region is given', () async { + final requester = RequestInterceptor(); expectError( '`region` must be one of the following: de, us', - () { + () async { final client = InsightsClient( - appId: "my-app-id", - apiKey: "my-api-key", - region: 'not_a_region', - ); + appId: "my-app-id", + apiKey: "my-api-key", + region: 'not_a_region', + options: ClientOptions(requester: requester)); }, ); }); diff --git a/tests/output/dart/test/client/recommend_test.dart b/tests/output/dart/test/client/recommend_test.dart index 7a8c1caa1f..dd8fa1c2e4 100644 --- a/tests/output/dart/test/client/recommend_test.dart +++ b/tests/output/dart/test/client/recommend_test.dart @@ -4,100 +4,96 @@ import 'package:test/test.dart'; import 'package:test_api/hooks.dart'; void main() { - test('calls api with correct read host', () { + test('calls api with correct read host', () async { + final requester = RequestInterceptor(); final client = RecommendClient( - appId: "test-app-id", - apiKey: "test-api-key", - ); - runTest( - builder: (requester) => RecommendClient( - appId: client.appId, - apiKey: client.apiKey, - options: ClientOptions(requester: requester), - ), - call: (client) => client.customGet( + appId: "test-app-id", + apiKey: "test-api-key", + options: ClientOptions(requester: requester)); + requester.setOnRequest((request) { + expect(request.host.url, 'test-app-id-dsn.algolia.net'); + }); + try { + final res = await client.customGet( path: "/test", - ), - intercept: (request) { - expect(request.host.url, 'test-app-id-dsn.algolia.net'); - }, - ); + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }); - test('calls api with correct write host', () { + + test('calls api with correct write host', () async { + final requester = RequestInterceptor(); final client = RecommendClient( - appId: "test-app-id", - apiKey: "test-api-key", - ); - runTest( - builder: (requester) => RecommendClient( - appId: client.appId, - apiKey: client.apiKey, - options: ClientOptions(requester: requester), - ), - call: (client) => client.customPost( + appId: "test-app-id", + apiKey: "test-api-key", + options: ClientOptions(requester: requester)); + requester.setOnRequest((request) { + expect(request.host.url, 'test-app-id.algolia.net'); + }); + try { + final res = await client.customPost( path: "/test", - ), - intercept: (request) { - expect(request.host.url, 'test-app-id.algolia.net'); - }, - ); + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }); - test('calls api with correct user agent', () { + test('calls api with correct user agent', () async { + final requester = RequestInterceptor(); final client = RecommendClient( appId: 'appId', apiKey: 'apiKey', + options: ClientOptions(requester: requester), ); - runTest( - builder: (requester) => RecommendClient( - appId: client.appId, - apiKey: client.apiKey, - options: ClientOptions(requester: requester), - ), - call: (client) => client.customPost( + requester.setOnRequest((request) { + TestHandle.current.markSkipped('User agent added using an interceptor'); + }); + try { + final res = await client.customPost( path: "/test", - ), - intercept: (request) { - TestHandle.current.markSkipped('User agent added using an interceptor'); - }, - ); + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }); - test('calls api with default read timeouts', () { + + test('calls api with default read timeouts', () async { + final requester = RequestInterceptor(); final client = RecommendClient( appId: 'appId', apiKey: 'apiKey', + options: ClientOptions(requester: requester), ); - runTest( - builder: (requester) => RecommendClient( - appId: client.appId, - apiKey: client.apiKey, - options: ClientOptions(requester: requester), - ), - call: (client) => client.customGet( + requester.setOnRequest((request) { + expect(5000, request.timeout.inMilliseconds); + }); + try { + final res = await client.customGet( path: "/test", - ), - intercept: (request) { - expect(5000, request.timeout.inMilliseconds); - }, - ); + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }); - test('calls api with default write timeouts', () { + + test('calls api with default write timeouts', () async { + final requester = RequestInterceptor(); final client = RecommendClient( appId: 'appId', apiKey: 'apiKey', + options: ClientOptions(requester: requester), ); - runTest( - builder: (requester) => RecommendClient( - appId: client.appId, - apiKey: client.apiKey, - options: ClientOptions(requester: requester), - ), - call: (client) => client.customPost( + requester.setOnRequest((request) { + expect(30000, request.timeout.inMilliseconds); + }); + try { + final res = await client.customPost( path: "/test", - ), - intercept: (request) { - expect(30000, request.timeout.inMilliseconds); - }, - ); + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }); } diff --git a/tests/output/dart/test/client/search_test.dart b/tests/output/dart/test/client/search_test.dart index 1f2b5bbf02..b80b663e51 100644 --- a/tests/output/dart/test/client/search_test.dart +++ b/tests/output/dart/test/client/search_test.dart @@ -4,179 +4,218 @@ import 'package:test/test.dart'; import 'package:test_api/hooks.dart'; void main() { - test('calls api with correct read host', () { + test('calls api with correct read host', () async { + final requester = RequestInterceptor(); final client = SearchClient( - appId: "test-app-id", - apiKey: "test-api-key", - ); - runTest( - builder: (requester) => SearchClient( - appId: client.appId, - apiKey: client.apiKey, - options: ClientOptions(requester: requester), - ), - call: (client) => client.customGet( + appId: "test-app-id", + apiKey: "test-api-key", + options: ClientOptions(requester: requester)); + requester.setOnRequest((request) { + expect(request.host.url, 'test-app-id-dsn.algolia.net'); + }); + try { + final res = await client.customGet( path: "/test", - ), - intercept: (request) { - expect(request.host.url, 'test-app-id-dsn.algolia.net'); - }, - ); + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }); - test('calls api with correct write host', () { + + test('calls api with correct write host', () async { + final requester = RequestInterceptor(); final client = SearchClient( - appId: "test-app-id", - apiKey: "test-api-key", - ); - runTest( - builder: (requester) => SearchClient( - appId: client.appId, - apiKey: client.apiKey, - options: ClientOptions(requester: requester), - ), - call: (client) => client.customPost( + appId: "test-app-id", + apiKey: "test-api-key", + options: ClientOptions(requester: requester)); + requester.setOnRequest((request) { + expect(request.host.url, 'test-app-id.algolia.net'); + }); + try { + final res = await client.customPost( path: "/test", - ), - intercept: (request) { - expect(request.host.url, 'test-app-id.algolia.net'); - }, - ); + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } + }); + + test('tests the retry strategy', () async { + final requester = RequestInterceptor(); + final client = SearchClient( + appId: "test-app-id", + apiKey: "test-api-key", + options: ClientOptions(hosts: [ + Host.create(url: 'localhost:6677', scheme: 'http'), + Host.create(url: 'localhost:6678', scheme: 'http'), + ])); + requester.setOnRequest((request) {}); + try { + final res = await client.customGet( + path: "/test", + ); + expectBody(res, """{"message":"ok test server response"}"""); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }); - test('calls api with correct user agent', () { + test('calls api with correct user agent', () async { + final requester = RequestInterceptor(); final client = SearchClient( appId: 'appId', apiKey: 'apiKey', + options: ClientOptions(requester: requester), ); - runTest( - builder: (requester) => SearchClient( - appId: client.appId, - apiKey: client.apiKey, - options: ClientOptions(requester: requester), - ), - call: (client) => client.customPost( + requester.setOnRequest((request) { + TestHandle.current.markSkipped('User agent added using an interceptor'); + }); + try { + final res = await client.customPost( path: "/test", - ), - intercept: (request) { - TestHandle.current.markSkipped('User agent added using an interceptor'); - }, - ); + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }); - test('calls api with default read timeouts', () { + + test('calls api with default read timeouts', () async { + final requester = RequestInterceptor(); final client = SearchClient( appId: 'appId', apiKey: 'apiKey', + options: ClientOptions(requester: requester), ); - runTest( - builder: (requester) => SearchClient( - appId: client.appId, - apiKey: client.apiKey, - options: ClientOptions(requester: requester), - ), - call: (client) => client.customGet( + requester.setOnRequest((request) { + expect(5000, request.timeout.inMilliseconds); + }); + try { + final res = await client.customGet( path: "/test", - ), - intercept: (request) { - expect(5000, request.timeout.inMilliseconds); - }, - ); + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }); - test('calls api with default write timeouts', () { + + test('calls api with default write timeouts', () async { + final requester = RequestInterceptor(); final client = SearchClient( appId: 'appId', apiKey: 'apiKey', + options: ClientOptions(requester: requester), ); - runTest( - builder: (requester) => SearchClient( - appId: client.appId, - apiKey: client.apiKey, - options: ClientOptions(requester: requester), - ), - call: (client) => client.customPost( + requester.setOnRequest((request) { + expect(30000, request.timeout.inMilliseconds); + }); + try { + final res = await client.customPost( path: "/test", - ), - intercept: (request) { - expect(30000, request.timeout.inMilliseconds); - }, - ); + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }); - test('client throws with invalid parameters', () { + test('client throws with invalid parameters', () async { + final requester = RequestInterceptor(); expectError( '`appId` is missing.', - () { + () async { final client = SearchClient( - appId: "", - apiKey: "", - ); + appId: "", + apiKey: "", + options: ClientOptions(requester: requester)); }, ); expectError( '`appId` is missing.', - () { + () async { final client = SearchClient( - appId: "", - apiKey: "my-api-key", - ); + appId: "", + apiKey: "my-api-key", + options: ClientOptions(requester: requester)); }, ); expectError( '`apiKey` is missing.', - () { + () async { final client = SearchClient( - appId: "my-app-id", - apiKey: "", - ); + appId: "my-app-id", + apiKey: "", + options: ClientOptions(requester: requester)); }, ); }); - test('`addApiKey` throws with invalid parameters', () { + + test('`addApiKey` throws with invalid parameters', () async { + final requester = RequestInterceptor(); final client = SearchClient( appId: 'appId', apiKey: 'apiKey', + options: ClientOptions(requester: requester), ); expectError( 'Parameter `apiKey` is required when calling `addApiKey`.', - () { - return client.addApiKey( - apiKey: empty(), - ); + () async { + try { + final res = await client.addApiKey( + apiKey: empty(), + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }, ); }); - test('`addOrUpdateObject` throws with invalid parameters', () { + + test('`addOrUpdateObject` throws with invalid parameters', () async { + final requester = RequestInterceptor(); final client = SearchClient( appId: 'appId', apiKey: 'apiKey', + options: ClientOptions(requester: requester), ); expectError( 'Parameter `indexName` is required when calling `addOrUpdateObject`.', - () { - return client.addOrUpdateObject( - indexName: empty(), - objectID: "my-object-id", - body: {}, - ); + () async { + try { + final res = await client.addOrUpdateObject( + indexName: empty(), + objectID: "my-object-id", + body: {}, + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }, ); expectError( 'Parameter `objectID` is required when calling `addOrUpdateObject`.', - () { - return client.addOrUpdateObject( - indexName: "my-index-name", - objectID: empty(), - body: {}, - ); + () async { + try { + final res = await client.addOrUpdateObject( + indexName: "my-index-name", + objectID: empty(), + body: {}, + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }, ); expectError( 'Parameter `body` is required when calling `addOrUpdateObject`.', - () { - return client.addOrUpdateObject( - indexName: "my-index-name", - objectID: "my-object-id", - body: empty(), - ); + () async { + try { + final res = await client.addOrUpdateObject( + indexName: "my-index-name", + objectID: "my-object-id", + body: empty(), + ); + } on InterceptionException catch (_) { + // Ignore InterceptionException + } }, ); }); diff --git a/tests/output/go/tests/client/search_test.go b/tests/output/go/tests/client/search_test.go index 5a627c2df6..23e6e93e02 100644 --- a/tests/output/go/tests/client/search_test.go +++ b/tests/output/go/tests/client/search_test.go @@ -1,6 +1,7 @@ package client import ( + "encoding/json" "regexp" "testing" @@ -8,6 +9,7 @@ import ( "gotests/tests" + "github.com/algolia/algoliasearch-client-go/v4/algolia/call" "github.com/algolia/algoliasearch-client-go/v4/algolia/search" "github.com/algolia/algoliasearch-client-go/v4/algolia/transport" ) @@ -75,6 +77,32 @@ func TestSearchapi1(t *testing.T) { require.Equal(t, "test-app-id.algolia.net", echo.Host) } +// tests the retry strategy +func TestSearchapi2(t *testing.T) { + var err error + echo := &tests.EchoRequester{} + var client *search.APIClient + var cfg search.Configuration + _ = client + _ = echo + cfg = search.Configuration{ + Configuration: transport.Configuration{ + AppID: "test-app-id", + ApiKey: "test-api-key", + Hosts: []transport.StatefulHost{transport.NewStatefulHost("http", "localhost:6677", call.IsReadWrite), transport.NewStatefulHost("http", "localhost:6678", call.IsReadWrite)}, + }, + } + client, err = search.NewClientWithConfig(cfg) + require.NoError(t, err) + res, err := client.CustomGet(client.NewApiCustomGetRequest( + "/test", + )) + require.NoError(t, err) + rawBody, err := json.Marshal(res) + require.NoError(t, err) + require.JSONEq(t, `{"message":"ok test server response"}`, string(rawBody)) +} + // calls api with correct user agent func TestSearchcommonApi0(t *testing.T) { var err error diff --git a/tests/output/java/src/test/java/com/algolia/client/Abtesting.test.java b/tests/output/java/src/test/java/com/algolia/client/Abtesting.test.java index 4be1fcf13a..e01e69e163 100644 --- a/tests/output/java/src/test/java/com/algolia/client/Abtesting.test.java +++ b/tests/output/java/src/test/java/com/algolia/client/Abtesting.test.java @@ -9,7 +9,11 @@ import com.algolia.api.AbtestingClient; import com.algolia.config.*; import com.algolia.model.abtesting.*; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import java.util.*; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -18,15 +22,25 @@ class AbtestingClientClientTests { private EchoInterceptor echo = new EchoInterceptor(); + private ObjectMapper json; + + @BeforeAll + void init() { + this.json = JsonMapper.builder().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build(); + } AbtestingClient createClient() { - return new AbtestingClient("appId", "apiKey", "us", buildClientOptions()); + return new AbtestingClient("appId", "apiKey", "us", withEchoRequester()); } - private ClientOptions buildClientOptions() { + private ClientOptions withEchoRequester() { return ClientOptions.builder().setRequesterConfig(requester -> requester.addInterceptor(echo)).build(); } + private ClientOptions withCustomHosts(List hosts) { + return ClientOptions.builder().setHosts(hosts).build(); + } + @Test @DisplayName("calls api with correct user agent") void commonApiTest0() { @@ -74,7 +88,7 @@ void commonApiTest2() { @Test @DisplayName("fallbacks to the alias when region is not given") void parametersTest0() { - AbtestingClient client = new AbtestingClient("my-app-id", "my-api-key", buildClientOptions()); + AbtestingClient client = new AbtestingClient("my-app-id", "my-api-key", withEchoRequester()); client.getABTest(123); EchoResponse result = echo.getLastResponse(); @@ -84,7 +98,7 @@ void parametersTest0() { @Test @DisplayName("uses the correct region") void parametersTest1() { - AbtestingClient client = new AbtestingClient("my-app-id", "my-api-key", "us", buildClientOptions()); + AbtestingClient client = new AbtestingClient("my-app-id", "my-api-key", "us", withEchoRequester()); client.getABTest(123); EchoResponse result = echo.getLastResponse(); @@ -98,7 +112,7 @@ void parametersTest2() { Exception exception = assertThrows( Exception.class, () -> { - AbtestingClient client = new AbtestingClient("my-app-id", "my-api-key", "not_a_region", buildClientOptions()); + AbtestingClient client = new AbtestingClient("my-app-id", "my-api-key", "not_a_region", withEchoRequester()); } ); assertEquals("`region` must be one of the following: de, us", exception.getMessage()); diff --git a/tests/output/java/src/test/java/com/algolia/client/Analytics.test.java b/tests/output/java/src/test/java/com/algolia/client/Analytics.test.java index 6bef44b7b1..12f391f283 100644 --- a/tests/output/java/src/test/java/com/algolia/client/Analytics.test.java +++ b/tests/output/java/src/test/java/com/algolia/client/Analytics.test.java @@ -9,7 +9,11 @@ import com.algolia.api.AnalyticsClient; import com.algolia.config.*; import com.algolia.model.analytics.*; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import java.util.*; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -18,15 +22,25 @@ class AnalyticsClientClientTests { private EchoInterceptor echo = new EchoInterceptor(); + private ObjectMapper json; + + @BeforeAll + void init() { + this.json = JsonMapper.builder().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build(); + } AnalyticsClient createClient() { - return new AnalyticsClient("appId", "apiKey", "us", buildClientOptions()); + return new AnalyticsClient("appId", "apiKey", "us", withEchoRequester()); } - private ClientOptions buildClientOptions() { + private ClientOptions withEchoRequester() { return ClientOptions.builder().setRequesterConfig(requester -> requester.addInterceptor(echo)).build(); } + private ClientOptions withCustomHosts(List hosts) { + return ClientOptions.builder().setHosts(hosts).build(); + } + @Test @DisplayName("calls api with correct user agent") void commonApiTest0() { @@ -74,7 +88,7 @@ void commonApiTest2() { @Test @DisplayName("fallbacks to the alias when region is not given") void parametersTest0() { - AnalyticsClient client = new AnalyticsClient("my-app-id", "my-api-key", buildClientOptions()); + AnalyticsClient client = new AnalyticsClient("my-app-id", "my-api-key", withEchoRequester()); client.getAverageClickPosition("my-index"); EchoResponse result = echo.getLastResponse(); @@ -84,7 +98,7 @@ void parametersTest0() { @Test @DisplayName("uses the correct region") void parametersTest1() { - AnalyticsClient client = new AnalyticsClient("my-app-id", "my-api-key", "de", buildClientOptions()); + AnalyticsClient client = new AnalyticsClient("my-app-id", "my-api-key", "de", withEchoRequester()); client.customPost("/test"); EchoResponse result = echo.getLastResponse(); @@ -98,7 +112,7 @@ void parametersTest2() { Exception exception = assertThrows( Exception.class, () -> { - AnalyticsClient client = new AnalyticsClient("my-app-id", "my-api-key", "not_a_region", buildClientOptions()); + AnalyticsClient client = new AnalyticsClient("my-app-id", "my-api-key", "not_a_region", withEchoRequester()); } ); assertEquals("`region` must be one of the following: de, us", exception.getMessage()); diff --git a/tests/output/java/src/test/java/com/algolia/client/Ingestion.test.java b/tests/output/java/src/test/java/com/algolia/client/Ingestion.test.java index 8bf335d777..9feb5929f7 100644 --- a/tests/output/java/src/test/java/com/algolia/client/Ingestion.test.java +++ b/tests/output/java/src/test/java/com/algolia/client/Ingestion.test.java @@ -9,7 +9,11 @@ import com.algolia.api.IngestionClient; import com.algolia.config.*; import com.algolia.model.ingestion.*; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import java.util.*; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -18,15 +22,25 @@ class IngestionClientClientTests { private EchoInterceptor echo = new EchoInterceptor(); + private ObjectMapper json; + + @BeforeAll + void init() { + this.json = JsonMapper.builder().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build(); + } IngestionClient createClient() { - return new IngestionClient("appId", "apiKey", "us", buildClientOptions()); + return new IngestionClient("appId", "apiKey", "us", withEchoRequester()); } - private ClientOptions buildClientOptions() { + private ClientOptions withEchoRequester() { return ClientOptions.builder().setRequesterConfig(requester -> requester.addInterceptor(echo)).build(); } + private ClientOptions withCustomHosts(List hosts) { + return ClientOptions.builder().setHosts(hosts).build(); + } + @Test @DisplayName("calls api with correct user agent") void commonApiTest0() { @@ -74,7 +88,7 @@ void commonApiTest2() { @Test @DisplayName("uses the correct region") void parametersTest0() { - IngestionClient client = new IngestionClient("my-app-id", "my-api-key", "us", buildClientOptions()); + IngestionClient client = new IngestionClient("my-app-id", "my-api-key", "us", withEchoRequester()); client.getSource("6c02aeb1-775e-418e-870b-1faccd4b2c0f"); EchoResponse result = echo.getLastResponse(); @@ -88,7 +102,7 @@ void parametersTest1() { Exception exception = assertThrows( Exception.class, () -> { - IngestionClient client = new IngestionClient("my-app-id", "my-api-key", "not_a_region", buildClientOptions()); + IngestionClient client = new IngestionClient("my-app-id", "my-api-key", "not_a_region", withEchoRequester()); } ); assertEquals("`region` is required and must be one of the following: eu, us", exception.getMessage()); diff --git a/tests/output/java/src/test/java/com/algolia/client/Insights.test.java b/tests/output/java/src/test/java/com/algolia/client/Insights.test.java index 75b9e2a01a..c30989652a 100644 --- a/tests/output/java/src/test/java/com/algolia/client/Insights.test.java +++ b/tests/output/java/src/test/java/com/algolia/client/Insights.test.java @@ -9,7 +9,11 @@ import com.algolia.api.InsightsClient; import com.algolia.config.*; import com.algolia.model.insights.*; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import java.util.*; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -18,15 +22,25 @@ class InsightsClientClientTests { private EchoInterceptor echo = new EchoInterceptor(); + private ObjectMapper json; + + @BeforeAll + void init() { + this.json = JsonMapper.builder().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build(); + } InsightsClient createClient() { - return new InsightsClient("appId", "apiKey", "us", buildClientOptions()); + return new InsightsClient("appId", "apiKey", "us", withEchoRequester()); } - private ClientOptions buildClientOptions() { + private ClientOptions withEchoRequester() { return ClientOptions.builder().setRequesterConfig(requester -> requester.addInterceptor(echo)).build(); } + private ClientOptions withCustomHosts(List hosts) { + return ClientOptions.builder().setHosts(hosts).build(); + } + @Test @DisplayName("calls api with correct user agent") void commonApiTest0() { @@ -74,7 +88,7 @@ void commonApiTest2() { @Test @DisplayName("fallbacks to the alias when region is not given") void parametersTest0() { - InsightsClient client = new InsightsClient("my-app-id", "my-api-key", buildClientOptions()); + InsightsClient client = new InsightsClient("my-app-id", "my-api-key", withEchoRequester()); client.pushEvents( new InsightsEvents() .setEvents( @@ -100,7 +114,7 @@ void parametersTest0() { @Test @DisplayName("uses the correct region") void parametersTest1() { - InsightsClient client = new InsightsClient("my-app-id", "my-api-key", "us", buildClientOptions()); + InsightsClient client = new InsightsClient("my-app-id", "my-api-key", "us", withEchoRequester()); client.customDelete("/test"); EchoResponse result = echo.getLastResponse(); @@ -114,7 +128,7 @@ void parametersTest2() { Exception exception = assertThrows( Exception.class, () -> { - InsightsClient client = new InsightsClient("my-app-id", "my-api-key", "not_a_region", buildClientOptions()); + InsightsClient client = new InsightsClient("my-app-id", "my-api-key", "not_a_region", withEchoRequester()); } ); assertEquals("`region` must be one of the following: de, us", exception.getMessage()); diff --git a/tests/output/java/src/test/java/com/algolia/client/Monitoring.test.java b/tests/output/java/src/test/java/com/algolia/client/Monitoring.test.java index 87526f9826..7f42f09406 100644 --- a/tests/output/java/src/test/java/com/algolia/client/Monitoring.test.java +++ b/tests/output/java/src/test/java/com/algolia/client/Monitoring.test.java @@ -8,7 +8,11 @@ import com.algolia.api.MonitoringClient; import com.algolia.config.*; import com.algolia.model.monitoring.*; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import java.util.*; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -17,15 +21,25 @@ class MonitoringClientClientTests { private EchoInterceptor echo = new EchoInterceptor(); + private ObjectMapper json; + + @BeforeAll + void init() { + this.json = JsonMapper.builder().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build(); + } MonitoringClient createClient() { - return new MonitoringClient("appId", "apiKey", buildClientOptions()); + return new MonitoringClient("appId", "apiKey", withEchoRequester()); } - private ClientOptions buildClientOptions() { + private ClientOptions withEchoRequester() { return ClientOptions.builder().setRequesterConfig(requester -> requester.addInterceptor(echo)).build(); } + private ClientOptions withCustomHosts(List hosts) { + return ClientOptions.builder().setHosts(hosts).build(); + } + @Test @DisplayName("calls api with correct user agent") void commonApiTest0() { @@ -73,7 +87,7 @@ void commonApiTest2() { @Test @DisplayName("use the correct host") void parametersTest0() { - MonitoringClient client = new MonitoringClient("my-app-id", "my-api-key", buildClientOptions()); + MonitoringClient client = new MonitoringClient("my-app-id", "my-api-key", withEchoRequester()); client.customDelete("/test"); EchoResponse result = echo.getLastResponse(); diff --git a/tests/output/java/src/test/java/com/algolia/client/Personalization.test.java b/tests/output/java/src/test/java/com/algolia/client/Personalization.test.java index c32f9f0444..5132bfc8f0 100644 --- a/tests/output/java/src/test/java/com/algolia/client/Personalization.test.java +++ b/tests/output/java/src/test/java/com/algolia/client/Personalization.test.java @@ -9,7 +9,11 @@ import com.algolia.api.PersonalizationClient; import com.algolia.config.*; import com.algolia.model.personalization.*; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import java.util.*; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -18,15 +22,25 @@ class PersonalizationClientClientTests { private EchoInterceptor echo = new EchoInterceptor(); + private ObjectMapper json; + + @BeforeAll + void init() { + this.json = JsonMapper.builder().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build(); + } PersonalizationClient createClient() { - return new PersonalizationClient("appId", "apiKey", "us", buildClientOptions()); + return new PersonalizationClient("appId", "apiKey", "us", withEchoRequester()); } - private ClientOptions buildClientOptions() { + private ClientOptions withEchoRequester() { return ClientOptions.builder().setRequesterConfig(requester -> requester.addInterceptor(echo)).build(); } + private ClientOptions withCustomHosts(List hosts) { + return ClientOptions.builder().setHosts(hosts).build(); + } + @Test @DisplayName("calls api with correct user agent") void commonApiTest0() { @@ -78,7 +92,7 @@ void parametersTest0() { Exception exception = assertThrows( Exception.class, () -> { - PersonalizationClient client = new PersonalizationClient("my-app-id", "my-api-key", "", buildClientOptions()); + PersonalizationClient client = new PersonalizationClient("my-app-id", "my-api-key", "", withEchoRequester()); } ); assertEquals("`region` is required and must be one of the following: eu, us", exception.getMessage()); @@ -92,7 +106,7 @@ void parametersTest1() { Exception exception = assertThrows( Exception.class, () -> { - PersonalizationClient client = new PersonalizationClient("my-app-id", "my-api-key", "not_a_region", buildClientOptions()); + PersonalizationClient client = new PersonalizationClient("my-app-id", "my-api-key", "not_a_region", withEchoRequester()); } ); assertEquals("`region` is required and must be one of the following: eu, us", exception.getMessage()); @@ -102,6 +116,6 @@ void parametersTest1() { @Test @DisplayName("does not throw when region is given") void parametersTest2() { - PersonalizationClient client = new PersonalizationClient("my-app-id", "my-api-key", "us", buildClientOptions()); + PersonalizationClient client = new PersonalizationClient("my-app-id", "my-api-key", "us", withEchoRequester()); } } diff --git a/tests/output/java/src/test/java/com/algolia/client/QuerySuggestions.test.java b/tests/output/java/src/test/java/com/algolia/client/QuerySuggestions.test.java index c974bdb317..3651731db3 100644 --- a/tests/output/java/src/test/java/com/algolia/client/QuerySuggestions.test.java +++ b/tests/output/java/src/test/java/com/algolia/client/QuerySuggestions.test.java @@ -9,7 +9,11 @@ import com.algolia.api.QuerySuggestionsClient; import com.algolia.config.*; import com.algolia.model.querysuggestions.*; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import java.util.*; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -18,15 +22,25 @@ class QuerySuggestionsClientClientTests { private EchoInterceptor echo = new EchoInterceptor(); + private ObjectMapper json; + + @BeforeAll + void init() { + this.json = JsonMapper.builder().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build(); + } QuerySuggestionsClient createClient() { - return new QuerySuggestionsClient("appId", "apiKey", "us", buildClientOptions()); + return new QuerySuggestionsClient("appId", "apiKey", "us", withEchoRequester()); } - private ClientOptions buildClientOptions() { + private ClientOptions withEchoRequester() { return ClientOptions.builder().setRequesterConfig(requester -> requester.addInterceptor(echo)).build(); } + private ClientOptions withCustomHosts(List hosts) { + return ClientOptions.builder().setHosts(hosts).build(); + } + @Test @DisplayName("calls api with correct user agent") void commonApiTest0() { @@ -78,7 +92,7 @@ void parametersTest0() { Exception exception = assertThrows( Exception.class, () -> { - QuerySuggestionsClient client = new QuerySuggestionsClient("my-app-id", "my-api-key", "", buildClientOptions()); + QuerySuggestionsClient client = new QuerySuggestionsClient("my-app-id", "my-api-key", "", withEchoRequester()); } ); assertEquals("`region` is required and must be one of the following: eu, us", exception.getMessage()); @@ -92,7 +106,7 @@ void parametersTest1() { Exception exception = assertThrows( Exception.class, () -> { - QuerySuggestionsClient client = new QuerySuggestionsClient("my-app-id", "my-api-key", "not_a_region", buildClientOptions()); + QuerySuggestionsClient client = new QuerySuggestionsClient("my-app-id", "my-api-key", "not_a_region", withEchoRequester()); } ); assertEquals("`region` is required and must be one of the following: eu, us", exception.getMessage()); @@ -102,6 +116,6 @@ void parametersTest1() { @Test @DisplayName("does not throw when region is given") void parametersTest2() { - QuerySuggestionsClient client = new QuerySuggestionsClient("my-app-id", "my-api-key", "us", buildClientOptions()); + QuerySuggestionsClient client = new QuerySuggestionsClient("my-app-id", "my-api-key", "us", withEchoRequester()); } } diff --git a/tests/output/java/src/test/java/com/algolia/client/Recommend.test.java b/tests/output/java/src/test/java/com/algolia/client/Recommend.test.java index ccaa14f002..effbf16c48 100644 --- a/tests/output/java/src/test/java/com/algolia/client/Recommend.test.java +++ b/tests/output/java/src/test/java/com/algolia/client/Recommend.test.java @@ -8,7 +8,11 @@ import com.algolia.api.RecommendClient; import com.algolia.config.*; import com.algolia.model.recommend.*; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import java.util.*; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -17,19 +21,29 @@ class RecommendClientClientTests { private EchoInterceptor echo = new EchoInterceptor(); + private ObjectMapper json; + + @BeforeAll + void init() { + this.json = JsonMapper.builder().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build(); + } RecommendClient createClient() { - return new RecommendClient("appId", "apiKey", buildClientOptions()); + return new RecommendClient("appId", "apiKey", withEchoRequester()); } - private ClientOptions buildClientOptions() { + private ClientOptions withEchoRequester() { return ClientOptions.builder().setRequesterConfig(requester -> requester.addInterceptor(echo)).build(); } + private ClientOptions withCustomHosts(List hosts) { + return ClientOptions.builder().setHosts(hosts).build(); + } + @Test @DisplayName("calls api with correct read host") void apiTest0() { - RecommendClient client = new RecommendClient("test-app-id", "test-api-key", buildClientOptions()); + RecommendClient client = new RecommendClient("test-app-id", "test-api-key", withEchoRequester()); client.customGet("/test"); EchoResponse result = echo.getLastResponse(); @@ -39,7 +53,7 @@ void apiTest0() { @Test @DisplayName("calls api with correct write host") void apiTest1() { - RecommendClient client = new RecommendClient("test-app-id", "test-api-key", buildClientOptions()); + RecommendClient client = new RecommendClient("test-app-id", "test-api-key", withEchoRequester()); client.customPost("/test"); EchoResponse result = echo.getLastResponse(); diff --git a/tests/output/java/src/test/java/com/algolia/client/Search.test.java b/tests/output/java/src/test/java/com/algolia/client/Search.test.java index 8101e8dcd9..4b7d43b0e3 100644 --- a/tests/output/java/src/test/java/com/algolia/client/Search.test.java +++ b/tests/output/java/src/test/java/com/algolia/client/Search.test.java @@ -1,5 +1,6 @@ package com.algolia.client; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -9,28 +10,44 @@ import com.algolia.api.SearchClient; import com.algolia.config.*; import com.algolia.model.search.*; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; import java.util.*; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; @TestInstance(TestInstance.Lifecycle.PER_CLASS) class SearchClientClientTests { private EchoInterceptor echo = new EchoInterceptor(); + private ObjectMapper json; + + @BeforeAll + void init() { + this.json = JsonMapper.builder().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).build(); + } SearchClient createClient() { - return new SearchClient("appId", "apiKey", buildClientOptions()); + return new SearchClient("appId", "apiKey", withEchoRequester()); } - private ClientOptions buildClientOptions() { + private ClientOptions withEchoRequester() { return ClientOptions.builder().setRequesterConfig(requester -> requester.addInterceptor(echo)).build(); } + private ClientOptions withCustomHosts(List hosts) { + return ClientOptions.builder().setHosts(hosts).build(); + } + @Test @DisplayName("calls api with correct read host") void apiTest0() { - SearchClient client = new SearchClient("test-app-id", "test-api-key", buildClientOptions()); + SearchClient client = new SearchClient("test-app-id", "test-api-key", withEchoRequester()); client.customGet("/test"); EchoResponse result = echo.getLastResponse(); @@ -40,13 +57,33 @@ void apiTest0() { @Test @DisplayName("calls api with correct write host") void apiTest1() { - SearchClient client = new SearchClient("test-app-id", "test-api-key", buildClientOptions()); + SearchClient client = new SearchClient("test-app-id", "test-api-key", withEchoRequester()); client.customPost("/test"); EchoResponse result = echo.getLastResponse(); assertEquals("test-app-id.algolia.net", result.host); } + @Test + @DisplayName("tests the retry strategy") + void apiTest2() { + SearchClient client = new SearchClient( + "test-app-id", + "test-api-key", + withCustomHosts( + Arrays.asList( + new Host("localhost", EnumSet.of(CallType.READ, CallType.WRITE), "http", 6677), + new Host("localhost", EnumSet.of(CallType.READ, CallType.WRITE), "http", 6678) + ) + ) + ); + var res = client.customGet("/test"); + + assertDoesNotThrow(() -> + JSONAssert.assertEquals("{\"message\":\"ok test server response\"}", json.writeValueAsString(res), JSONCompareMode.STRICT) + ); + } + @Test @DisplayName("calls api with correct user agent") void commonApiTest0() { @@ -98,7 +135,7 @@ void parametersTest0() { Exception exception = assertThrows( Exception.class, () -> { - SearchClient client = new SearchClient("", "", buildClientOptions()); + SearchClient client = new SearchClient("", "", withEchoRequester()); } ); assertEquals("`appId` is missing.", exception.getMessage()); @@ -107,7 +144,7 @@ void parametersTest0() { Exception exception = assertThrows( Exception.class, () -> { - SearchClient client = new SearchClient("", "my-api-key", buildClientOptions()); + SearchClient client = new SearchClient("", "my-api-key", withEchoRequester()); } ); assertEquals("`appId` is missing.", exception.getMessage()); @@ -116,7 +153,7 @@ void parametersTest0() { Exception exception = assertThrows( Exception.class, () -> { - SearchClient client = new SearchClient("my-app-id", "", buildClientOptions()); + SearchClient client = new SearchClient("my-app-id", "", withEchoRequester()); } ); assertEquals("`apiKey` is missing.", exception.getMessage()); diff --git a/tests/output/javascript/src/client/search.test.ts b/tests/output/javascript/src/client/search.test.ts index 89c9895c36..119a400eff 100644 --- a/tests/output/javascript/src/client/search.test.ts +++ b/tests/output/javascript/src/client/search.test.ts @@ -36,6 +36,19 @@ describe('api', () => { expect(result.host).toEqual('test-app-id.algolia.net'); }); + + test('tests the retry strategy', async () => { + const $client = searchClient('test-app-id', 'test-api-key', { + hosts: [ + { url: 'localhost', port: 6677, accept: 'readWrite', protocol: 'http' }, + { url: 'localhost', port: 6678, accept: 'readWrite', protocol: 'http' }, + ], + }); + + const result = await $client.customGet({ path: '/test' }); + + expect(result).toEqual({ message: 'ok test server response' }); + }); }); describe('commonApi', () => { diff --git a/tests/output/kotlin/src/commonTest/kotlin/com/algolia/client/SearchTest.kt b/tests/output/kotlin/src/commonTest/kotlin/com/algolia/client/SearchTest.kt index c963ca6162..7676a15751 100644 --- a/tests/output/kotlin/src/commonTest/kotlin/com/algolia/client/SearchTest.kt +++ b/tests/output/kotlin/src/commonTest/kotlin/com/algolia/client/SearchTest.kt @@ -7,6 +7,7 @@ import com.algolia.client.transport.* import com.algolia.utils.* import io.ktor.http.* import kotlinx.coroutines.test.* +import kotlinx.serialization.encodeToString import kotlinx.serialization.json.* import kotlin.test.* @@ -42,6 +43,22 @@ class SearchTest { ) } + @Test + fun `tests the retry strategy`() = runTest { + val client = SearchClient(appId = "test-app-id", apiKey = "test-api-key", options = ClientOptions(hosts = listOf(Host(url = "localhost", protocol = "http", port = 6677), Host(url = "localhost", protocol = "http", port = 6678)))) + client.runTest( + call = { + customGet( + path = "/test", + ) + }, + response = { + val response = Json.encodeToString(it) + assertEquals("{\"message\":\"ok test server response\"}", response) + }, + ) + } + @Test fun `calls api with correct user agent`() = runTest { val client = SearchClient(appId = "appId", apiKey = "apiKey") diff --git a/tests/output/php/src/client/SearchTest.php b/tests/output/php/src/client/SearchTest.php index 59701f18c1..655e13eb20 100644 --- a/tests/output/php/src/client/SearchTest.php +++ b/tests/output/php/src/client/SearchTest.php @@ -77,6 +77,22 @@ public function test1api() ); } + /** + * Test case : tests the retry strategy. + */ + public function test2api() + { + $client = SearchClient::createWithConfig(SearchConfig::create('test-app-id', 'test-api-key')->setFullHosts(['http://localhost:6677', 'http://localhost:6678'])); + + $res = $client->customGet( + '/test', + ); + $this->assertEquals( + '{"message":"ok test server response"}', + json_encode($res) + ); + } + /** * Test case : calls api with correct user agent. */ diff --git a/tests/output/python/tests/client/abtesting_test.py b/tests/output/python/tests/client/abtesting_test.py index ca21b4af8e..4524a984b3 100644 --- a/tests/output/python/tests/client/abtesting_test.py +++ b/tests/output/python/tests/client/abtesting_test.py @@ -6,16 +6,18 @@ class TestAbtestingClient: - _config: AbtestingConfig _client: AbtestingClient def create_client(self) -> AbtestingClient: - self._config = AbtestingConfig("appId", "apiKey", "us") + _config = AbtestingConfig("appId", "apiKey", "us") self._client = AbtestingClient.create_with_config( - config=self._config, transporter=EchoTransporter(self._config) + config=_config, transporter=EchoTransporter(_config) ) async def test_common_api_0(self): + """ + calls api with correct user agent + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -27,6 +29,9 @@ async def test_common_api_0(self): assert regex_user_agent.match(_req.headers.get("user-agent")) is not None async def test_common_api_1(self): + """ + calls api with default read timeouts + """ self.create_client() _req = await self._client.custom_get_with_http_info( @@ -36,6 +41,9 @@ async def test_common_api_1(self): assert _req.timeouts.get("response") == 5000 async def test_common_api_2(self): + """ + calls api with default write timeouts + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -45,8 +53,13 @@ async def test_common_api_2(self): assert _req.timeouts.get("response") == 30000 async def test_parameters_0(self): - self._client = AbtestingClient( - transporter=EchoTransporter(AbtestingConfig("my-app-id", "my-api-key")) + """ + fallbacks to the alias when region is not given + """ + + _config = AbtestingConfig("my-app-id", "my-api-key") + self._client = AbtestingClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) _req = await self._client.get_ab_test_with_http_info( id=123, @@ -54,10 +67,13 @@ async def test_parameters_0(self): assert _req.host == "analytics.algolia.com" async def test_parameters_1(self): - self._client = AbtestingClient( - transporter=EchoTransporter( - AbtestingConfig("my-app-id", "my-api-key", "us") - ) + """ + uses the correct region + """ + + _config = AbtestingConfig("my-app-id", "my-api-key", "us") + self._client = AbtestingClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) _req = await self._client.get_ab_test_with_http_info( id=123, @@ -65,11 +81,14 @@ async def test_parameters_1(self): assert _req.host == "analytics.us.algolia.com" async def test_parameters_2(self): + """ + throws when incorrect region is given + """ + try: - self._client = AbtestingClient( - transporter=EchoTransporter( - AbtestingConfig("my-app-id", "my-api-key", "not_a_region") - ) + _config = AbtestingConfig("my-app-id", "my-api-key", "not_a_region") + self._client = AbtestingClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) except (ValueError, Exception) as e: assert str(e) == "`region` must be one of the following: de, us" diff --git a/tests/output/python/tests/client/analytics_test.py b/tests/output/python/tests/client/analytics_test.py index 9ec6902e6d..eb381e020a 100644 --- a/tests/output/python/tests/client/analytics_test.py +++ b/tests/output/python/tests/client/analytics_test.py @@ -6,16 +6,18 @@ class TestAnalyticsClient: - _config: AnalyticsConfig _client: AnalyticsClient def create_client(self) -> AnalyticsClient: - self._config = AnalyticsConfig("appId", "apiKey", "us") + _config = AnalyticsConfig("appId", "apiKey", "us") self._client = AnalyticsClient.create_with_config( - config=self._config, transporter=EchoTransporter(self._config) + config=_config, transporter=EchoTransporter(_config) ) async def test_common_api_0(self): + """ + calls api with correct user agent + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -27,6 +29,9 @@ async def test_common_api_0(self): assert regex_user_agent.match(_req.headers.get("user-agent")) is not None async def test_common_api_1(self): + """ + calls api with default read timeouts + """ self.create_client() _req = await self._client.custom_get_with_http_info( @@ -36,6 +41,9 @@ async def test_common_api_1(self): assert _req.timeouts.get("response") == 5000 async def test_common_api_2(self): + """ + calls api with default write timeouts + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -45,8 +53,13 @@ async def test_common_api_2(self): assert _req.timeouts.get("response") == 30000 async def test_parameters_0(self): - self._client = AnalyticsClient( - transporter=EchoTransporter(AnalyticsConfig("my-app-id", "my-api-key")) + """ + fallbacks to the alias when region is not given + """ + + _config = AnalyticsConfig("my-app-id", "my-api-key") + self._client = AnalyticsClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) _req = await self._client.get_average_click_position_with_http_info( index="my-index", @@ -54,10 +67,13 @@ async def test_parameters_0(self): assert _req.host == "analytics.algolia.com" async def test_parameters_1(self): - self._client = AnalyticsClient( - transporter=EchoTransporter( - AnalyticsConfig("my-app-id", "my-api-key", "de") - ) + """ + uses the correct region + """ + + _config = AnalyticsConfig("my-app-id", "my-api-key", "de") + self._client = AnalyticsClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) _req = await self._client.custom_post_with_http_info( path="/test", @@ -65,16 +81,22 @@ async def test_parameters_1(self): assert _req.host == "analytics.de.algolia.com" async def test_parameters_2(self): + """ + throws when incorrect region is given + """ + try: - self._client = AnalyticsClient( - transporter=EchoTransporter( - AnalyticsConfig("my-app-id", "my-api-key", "not_a_region") - ) + _config = AnalyticsConfig("my-app-id", "my-api-key", "not_a_region") + self._client = AnalyticsClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) except (ValueError, Exception) as e: assert str(e) == "`region` must be one of the following: de, us" async def test_parameters_3(self): + """ + getAverageClickPosition throws without index + """ self.create_client() try: diff --git a/tests/output/python/tests/client/ingestion_test.py b/tests/output/python/tests/client/ingestion_test.py index b0b4740b57..d0855ba71c 100644 --- a/tests/output/python/tests/client/ingestion_test.py +++ b/tests/output/python/tests/client/ingestion_test.py @@ -6,16 +6,18 @@ class TestIngestionClient: - _config: IngestionConfig _client: IngestionClient def create_client(self) -> IngestionClient: - self._config = IngestionConfig("appId", "apiKey", "us") + _config = IngestionConfig("appId", "apiKey", "us") self._client = IngestionClient.create_with_config( - config=self._config, transporter=EchoTransporter(self._config) + config=_config, transporter=EchoTransporter(_config) ) async def test_common_api_0(self): + """ + calls api with correct user agent + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -27,6 +29,9 @@ async def test_common_api_0(self): assert regex_user_agent.match(_req.headers.get("user-agent")) is not None async def test_common_api_1(self): + """ + calls api with default read timeouts + """ self.create_client() _req = await self._client.custom_get_with_http_info( @@ -36,6 +41,9 @@ async def test_common_api_1(self): assert _req.timeouts.get("response") == 5000 async def test_common_api_2(self): + """ + calls api with default write timeouts + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -45,10 +53,13 @@ async def test_common_api_2(self): assert _req.timeouts.get("response") == 30000 async def test_parameters_0(self): - self._client = IngestionClient( - transporter=EchoTransporter( - IngestionConfig("my-app-id", "my-api-key", "us") - ) + """ + uses the correct region + """ + + _config = IngestionConfig("my-app-id", "my-api-key", "us") + self._client = IngestionClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) _req = await self._client.get_source_with_http_info( source_id="6c02aeb1-775e-418e-870b-1faccd4b2c0f", @@ -56,11 +67,14 @@ async def test_parameters_0(self): assert _req.host == "data.us.algolia.com" async def test_parameters_1(self): + """ + throws when incorrect region is given + """ + try: - self._client = IngestionClient( - transporter=EchoTransporter( - IngestionConfig("my-app-id", "my-api-key", "not_a_region") - ) + _config = IngestionConfig("my-app-id", "my-api-key", "not_a_region") + self._client = IngestionClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) except (ValueError, Exception) as e: assert ( diff --git a/tests/output/python/tests/client/insights_test.py b/tests/output/python/tests/client/insights_test.py index 0bb6996ecd..528fd17d80 100644 --- a/tests/output/python/tests/client/insights_test.py +++ b/tests/output/python/tests/client/insights_test.py @@ -6,16 +6,18 @@ class TestInsightsClient: - _config: InsightsConfig _client: InsightsClient def create_client(self) -> InsightsClient: - self._config = InsightsConfig("appId", "apiKey", "us") + _config = InsightsConfig("appId", "apiKey", "us") self._client = InsightsClient.create_with_config( - config=self._config, transporter=EchoTransporter(self._config) + config=_config, transporter=EchoTransporter(_config) ) async def test_common_api_0(self): + """ + calls api with correct user agent + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -27,6 +29,9 @@ async def test_common_api_0(self): assert regex_user_agent.match(_req.headers.get("user-agent")) is not None async def test_common_api_1(self): + """ + calls api with default read timeouts + """ self.create_client() _req = await self._client.custom_get_with_http_info( @@ -36,6 +41,9 @@ async def test_common_api_1(self): assert _req.timeouts.get("response") == 5000 async def test_common_api_2(self): + """ + calls api with default write timeouts + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -45,8 +53,13 @@ async def test_common_api_2(self): assert _req.timeouts.get("response") == 30000 async def test_parameters_0(self): - self._client = InsightsClient( - transporter=EchoTransporter(InsightsConfig("my-app-id", "my-api-key")) + """ + fallbacks to the alias when region is not given + """ + + _config = InsightsConfig("my-app-id", "my-api-key") + self._client = InsightsClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) _req = await self._client.push_events_with_http_info( insights_events={ @@ -74,8 +87,13 @@ async def test_parameters_0(self): assert _req.host == "insights.algolia.io" async def test_parameters_1(self): - self._client = InsightsClient( - transporter=EchoTransporter(InsightsConfig("my-app-id", "my-api-key", "us")) + """ + uses the correct region + """ + + _config = InsightsConfig("my-app-id", "my-api-key", "us") + self._client = InsightsClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) _req = await self._client.custom_delete_with_http_info( path="/test", @@ -83,11 +101,14 @@ async def test_parameters_1(self): assert _req.host == "insights.us.algolia.io" async def test_parameters_2(self): + """ + throws when incorrect region is given + """ + try: - self._client = InsightsClient( - transporter=EchoTransporter( - InsightsConfig("my-app-id", "my-api-key", "not_a_region") - ) + _config = InsightsConfig("my-app-id", "my-api-key", "not_a_region") + self._client = InsightsClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) except (ValueError, Exception) as e: assert str(e) == "`region` must be one of the following: de, us" diff --git a/tests/output/python/tests/client/monitoring_test.py b/tests/output/python/tests/client/monitoring_test.py index 7880cf9070..ce7b66b19e 100644 --- a/tests/output/python/tests/client/monitoring_test.py +++ b/tests/output/python/tests/client/monitoring_test.py @@ -6,16 +6,18 @@ class TestMonitoringClient: - _config: MonitoringConfig _client: MonitoringClient def create_client(self) -> MonitoringClient: - self._config = MonitoringConfig("appId", "apiKey") + _config = MonitoringConfig("appId", "apiKey") self._client = MonitoringClient.create_with_config( - config=self._config, transporter=EchoTransporter(self._config) + config=_config, transporter=EchoTransporter(_config) ) async def test_common_api_0(self): + """ + calls api with correct user agent + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -27,6 +29,9 @@ async def test_common_api_0(self): assert regex_user_agent.match(_req.headers.get("user-agent")) is not None async def test_common_api_1(self): + """ + calls api with default read timeouts + """ self.create_client() _req = await self._client.custom_get_with_http_info( @@ -36,6 +41,9 @@ async def test_common_api_1(self): assert _req.timeouts.get("response") == 5000 async def test_common_api_2(self): + """ + calls api with default write timeouts + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -45,8 +53,13 @@ async def test_common_api_2(self): assert _req.timeouts.get("response") == 30000 async def test_parameters_0(self): - self._client = MonitoringClient( - transporter=EchoTransporter(MonitoringConfig("my-app-id", "my-api-key")) + """ + use the correct host + """ + + _config = MonitoringConfig("my-app-id", "my-api-key") + self._client = MonitoringClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) _req = await self._client.custom_delete_with_http_info( path="/test", diff --git a/tests/output/python/tests/client/personalization_test.py b/tests/output/python/tests/client/personalization_test.py index 33a0d705f7..c5e62b311d 100644 --- a/tests/output/python/tests/client/personalization_test.py +++ b/tests/output/python/tests/client/personalization_test.py @@ -6,16 +6,18 @@ class TestPersonalizationClient: - _config: PersonalizationConfig _client: PersonalizationClient def create_client(self) -> PersonalizationClient: - self._config = PersonalizationConfig("appId", "apiKey", "us") + _config = PersonalizationConfig("appId", "apiKey", "us") self._client = PersonalizationClient.create_with_config( - config=self._config, transporter=EchoTransporter(self._config) + config=_config, transporter=EchoTransporter(_config) ) async def test_common_api_0(self): + """ + calls api with correct user agent + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -27,6 +29,9 @@ async def test_common_api_0(self): assert regex_user_agent.match(_req.headers.get("user-agent")) is not None async def test_common_api_1(self): + """ + calls api with default read timeouts + """ self.create_client() _req = await self._client.custom_get_with_http_info( @@ -36,6 +41,9 @@ async def test_common_api_1(self): assert _req.timeouts.get("response") == 5000 async def test_common_api_2(self): + """ + calls api with default write timeouts + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -45,11 +53,14 @@ async def test_common_api_2(self): assert _req.timeouts.get("response") == 30000 async def test_parameters_0(self): + """ + throws when region is not given + """ + try: - self._client = PersonalizationClient( - transporter=EchoTransporter( - PersonalizationConfig("my-app-id", "my-api-key", "") - ) + _config = PersonalizationConfig("my-app-id", "my-api-key", "") + self._client = PersonalizationClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) except (ValueError, Exception) as e: assert ( @@ -58,11 +69,14 @@ async def test_parameters_0(self): ) async def test_parameters_1(self): + """ + throws when incorrect region is given + """ + try: - self._client = PersonalizationClient( - transporter=EchoTransporter( - PersonalizationConfig("my-app-id", "my-api-key", "not_a_region") - ) + _config = PersonalizationConfig("my-app-id", "my-api-key", "not_a_region") + self._client = PersonalizationClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) except (ValueError, Exception) as e: assert ( @@ -71,8 +85,11 @@ async def test_parameters_1(self): ) async def test_parameters_2(self): - self._client = PersonalizationClient( - transporter=EchoTransporter( - PersonalizationConfig("my-app-id", "my-api-key", "us") - ) + """ + does not throw when region is given + """ + + _config = PersonalizationConfig("my-app-id", "my-api-key", "us") + self._client = PersonalizationClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) diff --git a/tests/output/python/tests/client/query_suggestions_test.py b/tests/output/python/tests/client/query_suggestions_test.py index 6ba47ede73..28c75796cf 100644 --- a/tests/output/python/tests/client/query_suggestions_test.py +++ b/tests/output/python/tests/client/query_suggestions_test.py @@ -6,16 +6,18 @@ class TestQuerySuggestionsClient: - _config: QuerySuggestionsConfig _client: QuerySuggestionsClient def create_client(self) -> QuerySuggestionsClient: - self._config = QuerySuggestionsConfig("appId", "apiKey", "us") + _config = QuerySuggestionsConfig("appId", "apiKey", "us") self._client = QuerySuggestionsClient.create_with_config( - config=self._config, transporter=EchoTransporter(self._config) + config=_config, transporter=EchoTransporter(_config) ) async def test_common_api_0(self): + """ + calls api with correct user agent + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -27,6 +29,9 @@ async def test_common_api_0(self): assert regex_user_agent.match(_req.headers.get("user-agent")) is not None async def test_common_api_1(self): + """ + calls api with default read timeouts + """ self.create_client() _req = await self._client.custom_get_with_http_info( @@ -36,6 +41,9 @@ async def test_common_api_1(self): assert _req.timeouts.get("response") == 5000 async def test_common_api_2(self): + """ + calls api with default write timeouts + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -45,11 +53,14 @@ async def test_common_api_2(self): assert _req.timeouts.get("response") == 30000 async def test_parameters_0(self): + """ + throws when region is not given + """ + try: - self._client = QuerySuggestionsClient( - transporter=EchoTransporter( - QuerySuggestionsConfig("my-app-id", "my-api-key", "") - ) + _config = QuerySuggestionsConfig("my-app-id", "my-api-key", "") + self._client = QuerySuggestionsClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) except (ValueError, Exception) as e: assert ( @@ -58,11 +69,14 @@ async def test_parameters_0(self): ) async def test_parameters_1(self): + """ + throws when incorrect region is given + """ + try: - self._client = QuerySuggestionsClient( - transporter=EchoTransporter( - QuerySuggestionsConfig("my-app-id", "my-api-key", "not_a_region") - ) + _config = QuerySuggestionsConfig("my-app-id", "my-api-key", "not_a_region") + self._client = QuerySuggestionsClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) except (ValueError, Exception) as e: assert ( @@ -71,8 +85,11 @@ async def test_parameters_1(self): ) async def test_parameters_2(self): - self._client = QuerySuggestionsClient( - transporter=EchoTransporter( - QuerySuggestionsConfig("my-app-id", "my-api-key", "us") - ) + """ + does not throw when region is given + """ + + _config = QuerySuggestionsConfig("my-app-id", "my-api-key", "us") + self._client = QuerySuggestionsClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) diff --git a/tests/output/python/tests/client/recommend_test.py b/tests/output/python/tests/client/recommend_test.py index 8b33ad0aa4..01a44b27f9 100644 --- a/tests/output/python/tests/client/recommend_test.py +++ b/tests/output/python/tests/client/recommend_test.py @@ -6,18 +6,22 @@ class TestRecommendClient: - _config: RecommendConfig _client: RecommendClient def create_client(self) -> RecommendClient: - self._config = RecommendConfig("appId", "apiKey") + _config = RecommendConfig("appId", "apiKey") self._client = RecommendClient.create_with_config( - config=self._config, transporter=EchoTransporter(self._config) + config=_config, transporter=EchoTransporter(_config) ) async def test_api_0(self): - self._client = RecommendClient( - transporter=EchoTransporter(RecommendConfig("test-app-id", "test-api-key")) + """ + calls api with correct read host + """ + + _config = RecommendConfig("test-app-id", "test-api-key") + self._client = RecommendClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) _req = await self._client.custom_get_with_http_info( path="/test", @@ -25,8 +29,13 @@ async def test_api_0(self): assert _req.host == "test-app-id-dsn.algolia.net" async def test_api_1(self): - self._client = RecommendClient( - transporter=EchoTransporter(RecommendConfig("test-app-id", "test-api-key")) + """ + calls api with correct write host + """ + + _config = RecommendConfig("test-app-id", "test-api-key") + self._client = RecommendClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) _req = await self._client.custom_post_with_http_info( path="/test", @@ -34,6 +43,9 @@ async def test_api_1(self): assert _req.host == "test-app-id.algolia.net" async def test_common_api_0(self): + """ + calls api with correct user agent + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -45,6 +57,9 @@ async def test_common_api_0(self): assert regex_user_agent.match(_req.headers.get("user-agent")) is not None async def test_common_api_1(self): + """ + calls api with default read timeouts + """ self.create_client() _req = await self._client.custom_get_with_http_info( @@ -54,6 +69,9 @@ async def test_common_api_1(self): assert _req.timeouts.get("response") == 5000 async def test_common_api_2(self): + """ + calls api with default write timeouts + """ self.create_client() _req = await self._client.custom_post_with_http_info( diff --git a/tests/output/python/tests/client/search_test.py b/tests/output/python/tests/client/search_test.py index 5f3f98031f..3ab7bf8a68 100644 --- a/tests/output/python/tests/client/search_test.py +++ b/tests/output/python/tests/client/search_test.py @@ -1,23 +1,28 @@ from re import compile +from algoliasearch.http.hosts import Host, HostsCollection from algoliasearch.http.transporter import EchoTransporter from algoliasearch.search.client import SearchClient from algoliasearch.search.config import SearchConfig class TestSearchClient: - _config: SearchConfig _client: SearchClient def create_client(self) -> SearchClient: - self._config = SearchConfig("appId", "apiKey") + _config = SearchConfig("appId", "apiKey") self._client = SearchClient.create_with_config( - config=self._config, transporter=EchoTransporter(self._config) + config=_config, transporter=EchoTransporter(_config) ) async def test_api_0(self): - self._client = SearchClient( - transporter=EchoTransporter(SearchConfig("test-app-id", "test-api-key")) + """ + calls api with correct read host + """ + + _config = SearchConfig("test-app-id", "test-api-key") + self._client = SearchClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) _req = await self._client.custom_get_with_http_info( path="/test", @@ -25,15 +30,41 @@ async def test_api_0(self): assert _req.host == "test-app-id-dsn.algolia.net" async def test_api_1(self): - self._client = SearchClient( - transporter=EchoTransporter(SearchConfig("test-app-id", "test-api-key")) + """ + calls api with correct write host + """ + + _config = SearchConfig("test-app-id", "test-api-key") + self._client = SearchClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) _req = await self._client.custom_post_with_http_info( path="/test", ) assert _req.host == "test-app-id.algolia.net" + async def test_api_2(self): + """ + tests the retry strategy + """ + + _config = SearchConfig("test-app-id", "test-api-key") + _config.hosts = HostsCollection( + [ + Host(url="localhost", scheme="http", port=6677), + Host(url="localhost", scheme="http", port=6678), + ] + ) + self._client = SearchClient.create_with_config(config=_config) + _req = await self._client.custom_get( + path="/test", + ) + assert _req == """{"message":"ok test server response"}""" + async def test_common_api_0(self): + """ + calls api with correct user agent + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -45,6 +76,9 @@ async def test_common_api_0(self): assert regex_user_agent.match(_req.headers.get("user-agent")) is not None async def test_common_api_1(self): + """ + calls api with default read timeouts + """ self.create_client() _req = await self._client.custom_get_with_http_info( @@ -54,6 +88,9 @@ async def test_common_api_1(self): assert _req.timeouts.get("response") == 5000 async def test_common_api_2(self): + """ + calls api with default write timeouts + """ self.create_client() _req = await self._client.custom_post_with_http_info( @@ -63,26 +100,36 @@ async def test_common_api_2(self): assert _req.timeouts.get("response") == 30000 async def test_parameters_0(self): + """ + client throws with invalid parameters + """ + try: - self._client = SearchClient( - transporter=EchoTransporter(SearchConfig("", "")) + _config = SearchConfig("", "") + self._client = SearchClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) except (ValueError, Exception) as e: assert str(e) == "`app_id` is missing." try: - self._client = SearchClient( - transporter=EchoTransporter(SearchConfig("", "my-api-key")) + _config = SearchConfig("", "my-api-key") + self._client = SearchClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) except (ValueError, Exception) as e: assert str(e) == "`app_id` is missing." try: - self._client = SearchClient( - transporter=EchoTransporter(SearchConfig("my-app-id", "")) + _config = SearchConfig("my-app-id", "") + self._client = SearchClient.create_with_config( + config=_config, transporter=EchoTransporter(_config) ) except (ValueError, Exception) as e: assert str(e) == "`api_key` is missing." async def test_parameters_1(self): + """ + `addApiKey` throws with invalid parameters + """ self.create_client() try: @@ -95,6 +142,9 @@ async def test_parameters_1(self): ) async def test_parameters_2(self): + """ + `addOrUpdateObject` throws with invalid parameters + """ self.create_client() try: diff --git a/tests/output/ruby/test/client/abtesting_test.rb b/tests/output/ruby/test/client/abtesting_test.rb index fe446f2b52..e871d12ed4 100644 --- a/tests/output/ruby/test/client/abtesting_test.rb +++ b/tests/output/ruby/test/client/abtesting_test.rb @@ -3,6 +3,7 @@ class TestClientAbtestingClient < Test::Unit::TestCase include Algolia::Abtesting + # calls api with correct user agent def test_common_api0 client = Algolia::AbtestingClient.create( 'APP_ID', @@ -14,6 +15,7 @@ def test_common_api0 assert(req.headers['user-agent'].match(/^Algolia for Ruby \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; Abtesting (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$/)) end + # calls api with default read timeouts def test_common_api1 client = Algolia::AbtestingClient.create( 'APP_ID', @@ -26,6 +28,7 @@ def test_common_api1 assert_equal(5000, req.timeout) end + # calls api with default write timeouts def test_common_api2 client = Algolia::AbtestingClient.create( 'APP_ID', @@ -38,6 +41,7 @@ def test_common_api2 assert_equal(30_000, req.timeout) end + # fallbacks to the alias when region is not given def test_parameters0 client = Algolia::AbtestingClient.create( 'my-app-id', @@ -48,6 +52,7 @@ def test_parameters0 assert_equal('analytics.algolia.com', req.host.url) end + # uses the correct region def test_parameters1 client = Algolia::AbtestingClient.create( 'my-app-id', @@ -59,6 +64,7 @@ def test_parameters1 assert_equal('analytics.us.algolia.com', req.host.url) end + # throws when incorrect region is given def test_parameters2 Algolia::AbtestingClient.create( 'my-app-id', diff --git a/tests/output/ruby/test/client/analytics_test.rb b/tests/output/ruby/test/client/analytics_test.rb index 37127ac185..f229fc314d 100644 --- a/tests/output/ruby/test/client/analytics_test.rb +++ b/tests/output/ruby/test/client/analytics_test.rb @@ -3,6 +3,7 @@ class TestClientAnalyticsClient < Test::Unit::TestCase include Algolia::Analytics + # calls api with correct user agent def test_common_api0 client = Algolia::AnalyticsClient.create( 'APP_ID', @@ -14,6 +15,7 @@ def test_common_api0 assert(req.headers['user-agent'].match(/^Algolia for Ruby \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; Analytics (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$/)) end + # calls api with default read timeouts def test_common_api1 client = Algolia::AnalyticsClient.create( 'APP_ID', @@ -26,6 +28,7 @@ def test_common_api1 assert_equal(5000, req.timeout) end + # calls api with default write timeouts def test_common_api2 client = Algolia::AnalyticsClient.create( 'APP_ID', @@ -38,6 +41,7 @@ def test_common_api2 assert_equal(30_000, req.timeout) end + # fallbacks to the alias when region is not given def test_parameters0 client = Algolia::AnalyticsClient.create( 'my-app-id', @@ -48,6 +52,7 @@ def test_parameters0 assert_equal('analytics.algolia.com', req.host.url) end + # uses the correct region def test_parameters1 client = Algolia::AnalyticsClient.create( 'my-app-id', @@ -59,6 +64,7 @@ def test_parameters1 assert_equal('analytics.de.algolia.com', req.host.url) end + # throws when incorrect region is given def test_parameters2 Algolia::AnalyticsClient.create( 'my-app-id', @@ -70,6 +76,7 @@ def test_parameters2 assert_equal('`region` must be one of the following: de, us', e.message) end + # getAverageClickPosition throws without index def test_parameters3 client = Algolia::AnalyticsClient.create( 'APP_ID', diff --git a/tests/output/ruby/test/client/ingestion_test.rb b/tests/output/ruby/test/client/ingestion_test.rb index 4409322871..2cb6c12be6 100644 --- a/tests/output/ruby/test/client/ingestion_test.rb +++ b/tests/output/ruby/test/client/ingestion_test.rb @@ -3,6 +3,7 @@ class TestClientIngestionClient < Test::Unit::TestCase include Algolia::Ingestion + # calls api with correct user agent def test_common_api0 client = Algolia::IngestionClient.create( 'APP_ID', @@ -14,6 +15,7 @@ def test_common_api0 assert(req.headers['user-agent'].match(/^Algolia for Ruby \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; Ingestion (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$/)) end + # calls api with default read timeouts def test_common_api1 client = Algolia::IngestionClient.create( 'APP_ID', @@ -26,6 +28,7 @@ def test_common_api1 assert_equal(5000, req.timeout) end + # calls api with default write timeouts def test_common_api2 client = Algolia::IngestionClient.create( 'APP_ID', @@ -38,6 +41,7 @@ def test_common_api2 assert_equal(30_000, req.timeout) end + # uses the correct region def test_parameters0 client = Algolia::IngestionClient.create( 'my-app-id', @@ -49,6 +53,7 @@ def test_parameters0 assert_equal('data.us.algolia.com', req.host.url) end + # throws when incorrect region is given def test_parameters1 Algolia::IngestionClient.create( 'my-app-id', diff --git a/tests/output/ruby/test/client/insights_test.rb b/tests/output/ruby/test/client/insights_test.rb index d9fcc04fca..1c8c1ec5d6 100644 --- a/tests/output/ruby/test/client/insights_test.rb +++ b/tests/output/ruby/test/client/insights_test.rb @@ -3,6 +3,7 @@ class TestClientInsightsClient < Test::Unit::TestCase include Algolia::Insights + # calls api with correct user agent def test_common_api0 client = Algolia::InsightsClient.create( 'APP_ID', @@ -14,6 +15,7 @@ def test_common_api0 assert(req.headers['user-agent'].match(/^Algolia for Ruby \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; Insights (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$/)) end + # calls api with default read timeouts def test_common_api1 client = Algolia::InsightsClient.create( 'APP_ID', @@ -26,6 +28,7 @@ def test_common_api1 assert_equal(5000, req.timeout) end + # calls api with default write timeouts def test_common_api2 client = Algolia::InsightsClient.create( 'APP_ID', @@ -38,6 +41,7 @@ def test_common_api2 assert_equal(30_000, req.timeout) end + # fallbacks to the alias when region is not given def test_parameters0 client = Algolia::InsightsClient.create( 'my-app-id', @@ -64,6 +68,7 @@ def test_parameters0 assert_equal('insights.algolia.io', req.host.url) end + # uses the correct region def test_parameters1 client = Algolia::InsightsClient.create( 'my-app-id', @@ -75,6 +80,7 @@ def test_parameters1 assert_equal('insights.us.algolia.io', req.host.url) end + # throws when incorrect region is given def test_parameters2 Algolia::InsightsClient.create( 'my-app-id', diff --git a/tests/output/ruby/test/client/monitoring_test.rb b/tests/output/ruby/test/client/monitoring_test.rb index 32ead9b241..0100dc9503 100644 --- a/tests/output/ruby/test/client/monitoring_test.rb +++ b/tests/output/ruby/test/client/monitoring_test.rb @@ -3,6 +3,7 @@ class TestClientMonitoringClient < Test::Unit::TestCase include Algolia::Monitoring + # calls api with correct user agent def test_common_api0 client = Algolia::MonitoringClient.create( 'APP_ID', @@ -13,6 +14,7 @@ def test_common_api0 assert(req.headers['user-agent'].match(/^Algolia for Ruby \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; Monitoring (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$/)) end + # calls api with default read timeouts def test_common_api1 client = Algolia::MonitoringClient.create( 'APP_ID', @@ -24,6 +26,7 @@ def test_common_api1 assert_equal(5000, req.timeout) end + # calls api with default write timeouts def test_common_api2 client = Algolia::MonitoringClient.create( 'APP_ID', @@ -35,6 +38,7 @@ def test_common_api2 assert_equal(30_000, req.timeout) end + # use the correct host def test_parameters0 client = Algolia::MonitoringClient.create( 'my-app-id', diff --git a/tests/output/ruby/test/client/personalization_test.rb b/tests/output/ruby/test/client/personalization_test.rb index 80262faf54..dfc7ac6854 100644 --- a/tests/output/ruby/test/client/personalization_test.rb +++ b/tests/output/ruby/test/client/personalization_test.rb @@ -3,6 +3,7 @@ class TestClientPersonalizationClient < Test::Unit::TestCase include Algolia::Personalization + # calls api with correct user agent def test_common_api0 client = Algolia::PersonalizationClient.create( 'APP_ID', @@ -14,6 +15,7 @@ def test_common_api0 assert(req.headers['user-agent'].match(/^Algolia for Ruby \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; Personalization (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$/)) end + # calls api with default read timeouts def test_common_api1 client = Algolia::PersonalizationClient.create( 'APP_ID', @@ -26,6 +28,7 @@ def test_common_api1 assert_equal(5000, req.timeout) end + # calls api with default write timeouts def test_common_api2 client = Algolia::PersonalizationClient.create( 'APP_ID', @@ -38,6 +41,7 @@ def test_common_api2 assert_equal(30_000, req.timeout) end + # throws when region is not given def test_parameters0 Algolia::PersonalizationClient.create( 'my-app-id', @@ -49,6 +53,7 @@ def test_parameters0 assert_equal('`region` is required and must be one of the following: eu, us', e.message) end + # throws when incorrect region is given def test_parameters1 Algolia::PersonalizationClient.create( 'my-app-id', @@ -60,6 +65,7 @@ def test_parameters1 assert_equal('`region` is required and must be one of the following: eu, us', e.message) end + # does not throw when region is given def test_parameters2 client = Algolia::PersonalizationClient.create( 'my-app-id', diff --git a/tests/output/ruby/test/client/query_suggestions_test.rb b/tests/output/ruby/test/client/query_suggestions_test.rb index d8f056d0ac..5943b48ae4 100644 --- a/tests/output/ruby/test/client/query_suggestions_test.rb +++ b/tests/output/ruby/test/client/query_suggestions_test.rb @@ -3,6 +3,7 @@ class TestClientQuerySuggestionsClient < Test::Unit::TestCase include Algolia::QuerySuggestions + # calls api with correct user agent def test_common_api0 client = Algolia::QuerySuggestionsClient.create( 'APP_ID', @@ -14,6 +15,7 @@ def test_common_api0 assert(req.headers['user-agent'].match(/^Algolia for Ruby \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; QuerySuggestions (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$/)) end + # calls api with default read timeouts def test_common_api1 client = Algolia::QuerySuggestionsClient.create( 'APP_ID', @@ -26,6 +28,7 @@ def test_common_api1 assert_equal(5000, req.timeout) end + # calls api with default write timeouts def test_common_api2 client = Algolia::QuerySuggestionsClient.create( 'APP_ID', @@ -38,6 +41,7 @@ def test_common_api2 assert_equal(30_000, req.timeout) end + # throws when region is not given def test_parameters0 Algolia::QuerySuggestionsClient.create( 'my-app-id', @@ -49,6 +53,7 @@ def test_parameters0 assert_equal('`region` is required and must be one of the following: eu, us', e.message) end + # throws when incorrect region is given def test_parameters1 Algolia::QuerySuggestionsClient.create( 'my-app-id', @@ -60,6 +65,7 @@ def test_parameters1 assert_equal('`region` is required and must be one of the following: eu, us', e.message) end + # does not throw when region is given def test_parameters2 client = Algolia::QuerySuggestionsClient.create( 'my-app-id', diff --git a/tests/output/ruby/test/client/recommend_test.rb b/tests/output/ruby/test/client/recommend_test.rb index e48cc62f79..8a4962fc7e 100644 --- a/tests/output/ruby/test/client/recommend_test.rb +++ b/tests/output/ruby/test/client/recommend_test.rb @@ -3,6 +3,7 @@ class TestClientRecommendClient < Test::Unit::TestCase include Algolia::Recommend + # calls api with correct read host def test_api0 client = Algolia::RecommendClient.create( 'test-app-id', @@ -13,6 +14,7 @@ def test_api0 assert_equal('test-app-id-dsn.algolia.net', req.host.url) end + # calls api with correct write host def test_api1 client = Algolia::RecommendClient.create( 'test-app-id', @@ -23,6 +25,7 @@ def test_api1 assert_equal('test-app-id.algolia.net', req.host.url) end + # calls api with correct user agent def test_common_api0 client = Algolia::RecommendClient.create( 'APP_ID', @@ -33,6 +36,7 @@ def test_common_api0 assert(req.headers['user-agent'].match(/^Algolia for Ruby \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; Recommend (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$/)) end + # calls api with default read timeouts def test_common_api1 client = Algolia::RecommendClient.create( 'APP_ID', @@ -44,6 +48,7 @@ def test_common_api1 assert_equal(5000, req.timeout) end + # calls api with default write timeouts def test_common_api2 client = Algolia::RecommendClient.create( 'APP_ID', diff --git a/tests/output/ruby/test/client/search_test.rb b/tests/output/ruby/test/client/search_test.rb index 0884cdfe43..66b5585ee1 100644 --- a/tests/output/ruby/test/client/search_test.rb +++ b/tests/output/ruby/test/client/search_test.rb @@ -3,6 +3,7 @@ class TestClientSearchClient < Test::Unit::TestCase include Algolia::Search + # calls api with correct read host def test_api0 client = Algolia::SearchClient.create( 'test-app-id', @@ -13,6 +14,7 @@ def test_api0 assert_equal('test-app-id-dsn.algolia.net', req.host.url) end + # calls api with correct write host def test_api1 client = Algolia::SearchClient.create( 'test-app-id', @@ -23,6 +25,34 @@ def test_api1 assert_equal('test-app-id.algolia.net', req.host.url) end + # tests the retry strategy + def test_api2 + client = Algolia::SearchClient.create_with_config( + Algolia::Configuration.new( + 'test-app-id', + 'test-api-key', + [ + Algolia::Transport::StatefulHost.new( + 'localhost', + protocol: 'http://', + port: 6677, + accept: CallType::READ | CallType::WRITE + ), + Algolia::Transport::StatefulHost.new( + 'localhost', + protocol: 'http://', + port: 6678, + accept: CallType::READ | CallType::WRITE + ) + ], + 'searchClient' + ) + ) + req = client.custom_get("/test") + assert_equal({ 'message': "ok test server response" }, req) + end + + # calls api with correct user agent def test_common_api0 client = Algolia::SearchClient.create( 'APP_ID', @@ -33,6 +63,7 @@ def test_common_api0 assert(req.headers['user-agent'].match(/^Algolia for Ruby \(\d+\.\d+\.\d+(-?.*)?\)(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*(; Search (\(\d+\.\d+\.\d+(-?.*)?\)))(; [a-zA-Z. ]+ (\(\d+((\.\d+)?\.\d+)?(-?.*)?\))?)*$/)) end + # calls api with default read timeouts def test_common_api1 client = Algolia::SearchClient.create( 'APP_ID', @@ -44,6 +75,7 @@ def test_common_api1 assert_equal(5000, req.timeout) end + # calls api with default write timeouts def test_common_api2 client = Algolia::SearchClient.create( 'APP_ID', @@ -55,6 +87,7 @@ def test_common_api2 assert_equal(30_000, req.timeout) end + # client throws with invalid parameters def test_parameters0 begin Algolia::SearchClient.create( @@ -85,6 +118,7 @@ def test_parameters0 end end + # `addApiKey` throws with invalid parameters def test_parameters1 client = Algolia::SearchClient.create( 'APP_ID', @@ -98,6 +132,7 @@ def test_parameters1 end end + # `addOrUpdateObject` throws with invalid parameters def test_parameters2 client = Algolia::SearchClient.create( 'APP_ID', diff --git a/tests/output/scala/src/test/scala/algoliasearch/client/AbtestingTest.scala b/tests/output/scala/src/test/scala/algoliasearch/client/AbtestingTest.scala index 601fb36081..3ae83dbd61 100644 --- a/tests/output/scala/src/test/scala/algoliasearch/client/AbtestingTest.scala +++ b/tests/output/scala/src/test/scala/algoliasearch/client/AbtestingTest.scala @@ -7,6 +7,8 @@ import algoliasearch.abtesting.* import algoliasearch.exception.* import org.json4s.* import org.json4s.native.JsonParser.* +import org.json4s.native.Serialization +import org.json4s.native.Serialization.write import org.scalatest.funsuite.AnyFunSuite import scala.concurrent.duration.Duration diff --git a/tests/output/scala/src/test/scala/algoliasearch/client/AnalyticsTest.scala b/tests/output/scala/src/test/scala/algoliasearch/client/AnalyticsTest.scala index 7f19eafb64..7fcab655dd 100644 --- a/tests/output/scala/src/test/scala/algoliasearch/client/AnalyticsTest.scala +++ b/tests/output/scala/src/test/scala/algoliasearch/client/AnalyticsTest.scala @@ -7,6 +7,8 @@ import algoliasearch.analytics.* import algoliasearch.exception.* import org.json4s.* import org.json4s.native.JsonParser.* +import org.json4s.native.Serialization +import org.json4s.native.Serialization.write import org.scalatest.funsuite.AnyFunSuite import scala.concurrent.duration.Duration diff --git a/tests/output/scala/src/test/scala/algoliasearch/client/IngestionTest.scala b/tests/output/scala/src/test/scala/algoliasearch/client/IngestionTest.scala index 3b70caab55..3c0370512a 100644 --- a/tests/output/scala/src/test/scala/algoliasearch/client/IngestionTest.scala +++ b/tests/output/scala/src/test/scala/algoliasearch/client/IngestionTest.scala @@ -7,6 +7,8 @@ import algoliasearch.ingestion.* import algoliasearch.exception.* import org.json4s.* import org.json4s.native.JsonParser.* +import org.json4s.native.Serialization +import org.json4s.native.Serialization.write import org.scalatest.funsuite.AnyFunSuite import scala.concurrent.duration.Duration diff --git a/tests/output/scala/src/test/scala/algoliasearch/client/InsightsTest.scala b/tests/output/scala/src/test/scala/algoliasearch/client/InsightsTest.scala index 8a4b534e09..e815bab8ff 100644 --- a/tests/output/scala/src/test/scala/algoliasearch/client/InsightsTest.scala +++ b/tests/output/scala/src/test/scala/algoliasearch/client/InsightsTest.scala @@ -7,6 +7,8 @@ import algoliasearch.insights.* import algoliasearch.exception.* import org.json4s.* import org.json4s.native.JsonParser.* +import org.json4s.native.Serialization +import org.json4s.native.Serialization.write import org.scalatest.funsuite.AnyFunSuite import scala.concurrent.duration.Duration diff --git a/tests/output/scala/src/test/scala/algoliasearch/client/MonitoringTest.scala b/tests/output/scala/src/test/scala/algoliasearch/client/MonitoringTest.scala index a22f81b33c..c5569f39a3 100644 --- a/tests/output/scala/src/test/scala/algoliasearch/client/MonitoringTest.scala +++ b/tests/output/scala/src/test/scala/algoliasearch/client/MonitoringTest.scala @@ -7,6 +7,8 @@ import algoliasearch.monitoring.* import algoliasearch.exception.* import org.json4s.* import org.json4s.native.JsonParser.* +import org.json4s.native.Serialization +import org.json4s.native.Serialization.write import org.scalatest.funsuite.AnyFunSuite import scala.concurrent.duration.Duration diff --git a/tests/output/scala/src/test/scala/algoliasearch/client/PersonalizationTest.scala b/tests/output/scala/src/test/scala/algoliasearch/client/PersonalizationTest.scala index 7ee43169bf..cbe3cf0c63 100644 --- a/tests/output/scala/src/test/scala/algoliasearch/client/PersonalizationTest.scala +++ b/tests/output/scala/src/test/scala/algoliasearch/client/PersonalizationTest.scala @@ -7,6 +7,8 @@ import algoliasearch.personalization.* import algoliasearch.exception.* import org.json4s.* import org.json4s.native.JsonParser.* +import org.json4s.native.Serialization +import org.json4s.native.Serialization.write import org.scalatest.funsuite.AnyFunSuite import scala.concurrent.duration.Duration diff --git a/tests/output/scala/src/test/scala/algoliasearch/client/QuerySuggestionsTest.scala b/tests/output/scala/src/test/scala/algoliasearch/client/QuerySuggestionsTest.scala index 6a64f3f311..e481699ded 100644 --- a/tests/output/scala/src/test/scala/algoliasearch/client/QuerySuggestionsTest.scala +++ b/tests/output/scala/src/test/scala/algoliasearch/client/QuerySuggestionsTest.scala @@ -7,6 +7,8 @@ import algoliasearch.querysuggestions.* import algoliasearch.exception.* import org.json4s.* import org.json4s.native.JsonParser.* +import org.json4s.native.Serialization +import org.json4s.native.Serialization.write import org.scalatest.funsuite.AnyFunSuite import scala.concurrent.duration.Duration diff --git a/tests/output/scala/src/test/scala/algoliasearch/client/RecommendTest.scala b/tests/output/scala/src/test/scala/algoliasearch/client/RecommendTest.scala index 951dceb386..49084df97f 100644 --- a/tests/output/scala/src/test/scala/algoliasearch/client/RecommendTest.scala +++ b/tests/output/scala/src/test/scala/algoliasearch/client/RecommendTest.scala @@ -7,6 +7,8 @@ import algoliasearch.recommend.* import algoliasearch.exception.* import org.json4s.* import org.json4s.native.JsonParser.* +import org.json4s.native.Serialization +import org.json4s.native.Serialization.write import org.scalatest.funsuite.AnyFunSuite import scala.concurrent.duration.Duration diff --git a/tests/output/scala/src/test/scala/algoliasearch/client/SearchTest.scala b/tests/output/scala/src/test/scala/algoliasearch/client/SearchTest.scala index 8e30aea989..90641b5681 100644 --- a/tests/output/scala/src/test/scala/algoliasearch/client/SearchTest.scala +++ b/tests/output/scala/src/test/scala/algoliasearch/client/SearchTest.scala @@ -7,6 +7,8 @@ import algoliasearch.search.* import algoliasearch.exception.* import org.json4s.* import org.json4s.native.JsonParser.* +import org.json4s.native.Serialization +import org.json4s.native.Serialization.write import org.scalatest.funsuite.AnyFunSuite import scala.concurrent.duration.Duration @@ -57,6 +59,31 @@ class SearchTest extends AnyFunSuite { assert(echo.lastResponse.get.host == "test-app-id.algolia.net") } + test("tests the retry strategy") { + + val client = SearchClient( + appId = "test-app-id", + apiKey = "test-api-key", + clientOptions = ClientOptions + .builder() + .withHosts( + List( + Host("localhost", Set(CallType.Read, CallType.Write), "http", Option(6677)), + Host("localhost", Set(CallType.Read, CallType.Write), "http", Option(6678)) + ) + ) + .build() + ) + + var res = Await.result( + client.customGet[Any]( + path = "/test" + ), + Duration.Inf + ) + assert(write(res) == "{\"message\":\"ok test server response\"}") + } + test("calls api with correct user agent") { val (client, echo) = testClient() diff --git a/tests/output/swift/Tests/client/SearchTests.swift b/tests/output/swift/Tests/client/SearchTests.swift index 8e5088a501..81275021b2 100644 --- a/tests/output/swift/Tests/client/SearchTests.swift +++ b/tests/output/swift/Tests/client/SearchTests.swift @@ -44,6 +44,24 @@ final class SearchClientClientTests: XCTestCase { XCTAssertEqual("test-app-id.algolia.net", echoResponse.host) } + /** + tests the retry strategy + */ + func testApiTest2() async throws { + let configuration: Search.Configuration = try Search.Configuration(appId: "test-app-id", apiKey: "test-api-key", hosts: [RetryableHost(url: URL(string: "http://localhost:6677")!), RetryableHost(url: URL(string: "http://localhost:6678")!)]) + let transporter = Transporter(configuration: configuration) + let client = SearchClient(configuration: configuration, transporter: transporter) + let response = try await client.customGetWithHTTPInfo( + path: "/test" + ) + let responseBodyData = try XCTUnwrap(response.bodyData) + let responseBodyJSON = try XCTUnwrap(responseBodyData.jsonString) + let comparableData = "{\"message\":\"ok test server response\"}".data(using: .utf8) + let comparableJSON = try XCTUnwrap(comparableData?.jsonString) + + XCTAssertEqual(comparableJSON, responseBodyJSON) + } + /** calls api with correct user agent */