Skip to content

Commit

Permalink
chore: generated code for commit 65bd154. [skip ci]
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Millot <pierre.millot@algolia.com>
  • Loading branch information
algolia-bot and millotp committed Feb 14, 2024
1 parent 65bd154 commit ca31513
Show file tree
Hide file tree
Showing 60 changed files with 1,112 additions and 421 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public function getDefaultConfiguration()
'appId' => '',
'apiKey' => '',
'hosts' => null,
'hasFullHosts' => false,
'readTimeout' => $this->defaultReadTimeout,
'writeTimeout' => $this->defaultWriteTimeout,
'connectTimeout' => $this->defaultConnectTimeout,
Expand Down Expand Up @@ -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'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function getDefaultConfiguration()
'appId' => '',
'apiKey' => '',
'hosts' => null,
'hasFullHosts' => false,
'readTimeout' => $this->defaultReadTimeout,
'writeTimeout' => $this->defaultWriteTimeout,
'connectTimeout' => $this->defaultConnectTimeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
15 changes: 12 additions & 3 deletions clients/algoliasearch-client-python/algoliasearch/search/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/output/csharp/src/generated/client/Abtesting.test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/output/csharp/src/generated/client/Analytics.test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/output/csharp/src/generated/client/Ingestion.test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/output/csharp/src/generated/client/Insights.test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/output/csharp/src/generated/client/Monitoring.test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/output/csharp/src/generated/client/Recommend.test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions tests/output/csharp/src/generated/client/Search.test.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<StatefulHost>
{
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()
{
Expand Down
Loading

0 comments on commit ca31513

Please sign in to comment.