Skip to content

Commit ab13852

Browse files
algolia-botmillotp
andcommitted
fix(clients): use the dsn with the read transporter (#3781) (generated) [skip ci]
Co-authored-by: Pierre Millot <[email protected]>
1 parent 4f64d5f commit ab13852

File tree

14 files changed

+206
-35
lines changed

14 files changed

+206
-35
lines changed

clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/api/RecommendClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ private static List<Host> getDefaultHosts(String appId) {
3737
hosts.add(new Host(appId + ".algolia.net", EnumSet.of(CallType.WRITE)));
3838

3939
List<Host> commonHosts = new ArrayList<>();
40-
hosts.add(new Host(appId + "-1.algolianet.net", EnumSet.of(CallType.READ, CallType.WRITE)));
41-
hosts.add(new Host(appId + "-2.algolianet.net", EnumSet.of(CallType.READ, CallType.WRITE)));
42-
hosts.add(new Host(appId + "-3.algolianet.net", EnumSet.of(CallType.READ, CallType.WRITE)));
40+
commonHosts.add(new Host(appId + "-1.algolianet.net", EnumSet.of(CallType.READ, CallType.WRITE)));
41+
commonHosts.add(new Host(appId + "-2.algolianet.net", EnumSet.of(CallType.READ, CallType.WRITE)));
42+
commonHosts.add(new Host(appId + "-3.algolianet.net", EnumSet.of(CallType.READ, CallType.WRITE)));
4343

4444
Collections.shuffle(commonHosts, new Random());
4545

clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/api/SearchClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ private static List<Host> getDefaultHosts(String appId) {
4949
hosts.add(new Host(appId + ".algolia.net", EnumSet.of(CallType.WRITE)));
5050

5151
List<Host> commonHosts = new ArrayList<>();
52-
hosts.add(new Host(appId + "-1.algolianet.net", EnumSet.of(CallType.READ, CallType.WRITE)));
53-
hosts.add(new Host(appId + "-2.algolianet.net", EnumSet.of(CallType.READ, CallType.WRITE)));
54-
hosts.add(new Host(appId + "-3.algolianet.net", EnumSet.of(CallType.READ, CallType.WRITE)));
52+
commonHosts.add(new Host(appId + "-1.algolianet.net", EnumSet.of(CallType.READ, CallType.WRITE)));
53+
commonHosts.add(new Host(appId + "-2.algolianet.net", EnumSet.of(CallType.READ, CallType.WRITE)));
54+
commonHosts.add(new Host(appId + "-3.algolianet.net", EnumSet.of(CallType.READ, CallType.WRITE)));
5555

5656
Collections.shuffle(commonHosts, new Random());
5757

clients/algoliasearch-client-java/algoliasearch/src/main/java/com/algolia/internal/HttpRequester.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.algolia.internal.interceptors.GzipRequestInterceptor;
77
import com.algolia.internal.interceptors.HeaderInterceptor;
88
import com.algolia.internal.interceptors.LogInterceptor;
9+
import com.algolia.utils.UseReadTransporter;
910
import com.fasterxml.jackson.core.type.TypeReference;
1011
import com.fasterxml.jackson.databind.JavaType;
1112
import java.io.IOException;
@@ -18,7 +19,6 @@
1819
import okhttp3.*;
1920
import okhttp3.internal.http.HttpMethod;
2021
import okio.BufferedSink;
21-
import com.algolia.utils.UseReadTransporter;
2222

2323
/**
2424
* HttpRequester is responsible for making HTTP requests using the OkHttp client. It provides a
@@ -77,7 +77,7 @@ private <T> T execute(@Nonnull HttpRequest httpRequest, RequestOptions requestOp
7777
if (httpRequest.isRead()) {
7878
requestBuilder.tag(new UseReadTransporter());
7979
}
80-
80+
8181
Request request = requestBuilder.build();
8282

8383
// Get or adjust the HTTP client according to request options.

tests/output/csharp/src/generated/client/Search.test.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,30 @@ public async Task ApiTest0()
3737
Assert.Equal("test-app-id-dsn.algolia.net", result.Host);
3838
}
3939

40-
[Fact(DisplayName = "calls api with correct write host")]
40+
[Fact(DisplayName = "read transporter with POST method")]
4141
public async Task ApiTest1()
4242
{
4343
var client = new SearchClient(new SearchConfig("test-app-id", "test-api-key"), _echo);
4444

45+
await client.SearchSingleIndexAsync<Hit>("indexName");
46+
EchoResponse result = _echo.LastResponse;
47+
48+
Assert.Equal("test-app-id-dsn.algolia.net", result.Host);
49+
}
50+
51+
[Fact(DisplayName = "calls api with correct write host")]
52+
public async Task ApiTest2()
53+
{
54+
var client = new SearchClient(new SearchConfig("test-app-id", "test-api-key"), _echo);
55+
4556
await client.CustomPostAsync("test");
4657
EchoResponse result = _echo.LastResponse;
4758

4859
Assert.Equal("test-app-id.algolia.net", result.Host);
4960
}
5061

5162
[Fact(DisplayName = "tests the retry strategy")]
52-
public async Task ApiTest2()
63+
public async Task ApiTest3()
5364
{
5465
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
5566
{
@@ -96,7 +107,7 @@ public async Task ApiTest2()
96107
}
97108

98109
[Fact(DisplayName = "tests the retry strategy error")]
99-
public async Task ApiTest3()
110+
public async Task ApiTest4()
100111
{
101112
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
102113
{
@@ -126,7 +137,7 @@ public async Task ApiTest3()
126137
}
127138

128139
[Fact(DisplayName = "test the compression strategy")]
129-
public async Task ApiTest4()
140+
public async Task ApiTest5()
130141
{
131142
SearchConfig _config = new SearchConfig("test-app-id", "test-api-key")
132143
{

tests/output/dart/test/client/search_test.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,24 @@ void main() {
2323
}
2424
});
2525

26+
test('read transporter with POST method', () async {
27+
final requester = RequestInterceptor();
28+
final client = SearchClient(
29+
appId: "test-app-id",
30+
apiKey: "test-api-key",
31+
options: ClientOptions(requester: requester));
32+
requester.setOnRequest((request) {
33+
expect(request.host.url, "test-app-id-dsn.algolia.net");
34+
});
35+
try {
36+
final res = await client.searchSingleIndex(
37+
indexName: "indexName",
38+
);
39+
} on InterceptionException catch (_) {
40+
// Ignore InterceptionException
41+
}
42+
});
43+
2644
test('calls api with correct write host', () async {
2745
final requester = RequestInterceptor();
2846
final client = SearchClient(

tests/output/go/tests/client/search_test.go

Lines changed: 30 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/output/java/src/test/java/com/algolia/client/Search.test.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,17 @@ void apiTest0() {
5858
}
5959

6060
@Test
61-
@DisplayName("calls api with correct write host")
61+
@DisplayName("read transporter with POST method")
6262
void apiTest1() {
63+
SearchClient client = new SearchClient("test-app-id", "test-api-key", withEchoRequester());
64+
client.searchSingleIndex("indexName", Hit.class);
65+
EchoResponse result = echo.getLastResponse();
66+
assertEquals("test-app-id-dsn.algolia.net", result.host);
67+
}
68+
69+
@Test
70+
@DisplayName("calls api with correct write host")
71+
void apiTest2() {
6372
SearchClient client = new SearchClient("test-app-id", "test-api-key", withEchoRequester());
6473
client.customPost("test");
6574
EchoResponse result = echo.getLastResponse();
@@ -68,7 +77,7 @@ void apiTest1() {
6877

6978
@Test
7079
@DisplayName("tests the retry strategy")
71-
void apiTest2() {
80+
void apiTest3() {
7281
SearchClient client = new SearchClient(
7382
"test-app-id",
7483
"test-api-key",
@@ -90,7 +99,7 @@ void apiTest2() {
9099

91100
@Test
92101
@DisplayName("tests the retry strategy error")
93-
void apiTest3() {
102+
void apiTest4() {
94103
SearchClient client = new SearchClient(
95104
"test-app-id",
96105
"test-api-key",
@@ -109,7 +118,7 @@ void apiTest3() {
109118

110119
@Test
111120
@DisplayName("test the compression strategy")
112-
void apiTest4() {
121+
void apiTest5() {
113122
SearchClient client = new SearchClient(
114123
"test-app-id",
115124
"test-api-key",

tests/output/javascript/src/client/search.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ describe('api', () => {
2424
expect(result.host).toEqual('test-app-id-dsn.algolia.net');
2525
}, 15000);
2626

27+
test('read transporter with POST method', async () => {
28+
const client = searchClient('test-app-id', 'test-api-key', { requester: nodeEchoRequester() });
29+
30+
const result = (await client.searchSingleIndex({ indexName: 'indexName' })) as unknown as EchoResponse;
31+
32+
expect(result.host).toEqual('test-app-id-dsn.algolia.net');
33+
}, 15000);
34+
2735
test('calls api with correct write host', async () => {
2836
const client = searchClient('test-app-id', 'test-api-key', { requester: nodeEchoRequester() });
2937

tests/output/kotlin/src/commonTest/kotlin/com/algolia/client/SearchTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ class SearchTest {
3232
)
3333
}
3434

35+
@Test
36+
fun `read transporter with POST method`() = runTest {
37+
val client = SearchClient(appId = "test-app-id", apiKey = "test-api-key")
38+
client.runTest(
39+
call = {
40+
searchSingleIndex(
41+
indexName = "indexName",
42+
)
43+
},
44+
intercept = {
45+
assertEquals("test-app-id-dsn.algolia.net", it.url.host)
46+
},
47+
)
48+
}
49+
3550
@Test
3651
fun `calls api with correct write host`() = runTest {
3752
val client = SearchClient(appId = "test-app-id", apiKey = "test-api-key")

tests/output/php/src/client/SearchTest.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,25 @@ public function test0api(): void
5555
);
5656
}
5757

58-
#[TestDox('calls api with correct write host')]
58+
#[TestDox('read transporter with POST method')]
5959
public function test1api(): void
60+
{
61+
$client = $this->createClient(
62+
'test-app-id',
63+
'test-api-key'
64+
);
65+
$this->assertIsObject($client);
66+
$client->searchSingleIndex(
67+
'indexName',
68+
);
69+
$this->assertEquals(
70+
'test-app-id-dsn.algolia.net',
71+
$this->recordedRequest['request']->getUri()->getHost()
72+
);
73+
}
74+
75+
#[TestDox('calls api with correct write host')]
76+
public function test2api(): void
6077
{
6178
$client = $this->createClient(
6279
'test-app-id',
@@ -73,7 +90,7 @@ public function test1api(): void
7390
}
7491

7592
#[TestDox('tests the retry strategy')]
76-
public function test2api(): void
93+
public function test3api(): void
7794
{
7895
$client = SearchClient::createWithConfig(SearchConfig::create('test-app-id', 'test-api-key')->setFullHosts(['http://localhost:6676', 'http://localhost:6677', 'http://localhost:6678']));
7996

@@ -87,7 +104,7 @@ public function test2api(): void
87104
}
88105

89106
#[TestDox('tests the retry strategy error')]
90-
public function test3api(): void
107+
public function test4api(): void
91108
{
92109
$client = SearchClient::createWithConfig(SearchConfig::create('test-app-id', 'test-api-key')->setFullHosts(['http://localhost:6676']));
93110

tests/output/python/tests/client/search_test.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ async def test_api_0(self):
3232
assert _req.host == "test-app-id-dsn.algolia.net"
3333

3434
async def test_api_1(self):
35+
"""
36+
read transporter with POST method
37+
"""
38+
39+
_config = SearchConfig("test-app-id", "test-api-key")
40+
_client = SearchClient.create_with_config(
41+
config=_config, transporter=EchoTransporter(_config)
42+
)
43+
_req = await _client.search_single_index_with_http_info(
44+
index_name="indexName",
45+
)
46+
assert _req.host == "test-app-id-dsn.algolia.net"
47+
48+
async def test_api_2(self):
3549
"""
3650
calls api with correct write host
3751
"""
@@ -45,7 +59,7 @@ async def test_api_1(self):
4559
)
4660
assert _req.host == "test-app-id.algolia.net"
4761

48-
async def test_api_2(self):
62+
async def test_api_3(self):
4963
"""
5064
tests the retry strategy
5165
"""
@@ -70,7 +84,7 @@ async def test_api_2(self):
7084
else _req.to_dict()
7185
) == loads("""{"message":"ok test server response"}""")
7286

73-
async def test_api_3(self):
87+
async def test_api_4(self):
7488
"""
7589
tests the retry strategy error
7690
"""
@@ -727,6 +741,20 @@ def test_api_0(self):
727741
assert _req.host == "test-app-id-dsn.algolia.net"
728742

729743
def test_api_1(self):
744+
"""
745+
read transporter with POST method
746+
"""
747+
748+
_config = SearchConfig("test-app-id", "test-api-key")
749+
_client = SearchClientSync.create_with_config(
750+
config=_config, transporter=EchoTransporterSync(_config)
751+
)
752+
_req = _client.search_single_index_with_http_info(
753+
index_name="indexName",
754+
)
755+
assert _req.host == "test-app-id-dsn.algolia.net"
756+
757+
def test_api_2(self):
730758
"""
731759
calls api with correct write host
732760
"""
@@ -740,7 +768,7 @@ def test_api_1(self):
740768
)
741769
assert _req.host == "test-app-id.algolia.net"
742770

743-
def test_api_2(self):
771+
def test_api_3(self):
744772
"""
745773
tests the retry strategy
746774
"""
@@ -765,7 +793,7 @@ def test_api_2(self):
765793
else _req.to_dict()
766794
) == loads("""{"message":"ok test server response"}""")
767795

768-
def test_api_3(self):
796+
def test_api_4(self):
769797
"""
770798
tests the retry strategy error
771799
"""

0 commit comments

Comments
 (0)