Skip to content

Commit b612870

Browse files
committed
okay ?
1 parent 84804bb commit b612870

File tree

12 files changed

+71
-39
lines changed

12 files changed

+71
-39
lines changed

clients/algoliasearch-client-csharp/algoliasearch/Utils/SearchClientExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ public async Task<ReplaceAllObjectsResponse> ReplaceAllObjectsAsync<T>(string in
498498
{
499499
var copyResponse = await OperationIndexAsync(indexName,
500500
new OperationIndexParams(OperationType.Copy, tmpIndexName)
501-
{ Scope = [ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms] }, options, cancellationToken)
501+
{ Scope = [ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms] }, options, cancellationToken)
502502
.ConfigureAwait(false);
503503

504504
var batchResponse = await ChunkedBatchAsync(tmpIndexName, objects, Action.AddObject, true, batchSize,
@@ -509,7 +509,7 @@ await WaitForTaskAsync(tmpIndexName, copyResponse.TaskID, requestOptions: option
509509

510510
copyResponse = await OperationIndexAsync(indexName,
511511
new OperationIndexParams(OperationType.Copy, tmpIndexName)
512-
{ Scope = [ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms] }, options, cancellationToken)
512+
{ Scope = [ScopeType.Settings, ScopeType.Rules, ScopeType.Synonyms] }, options, cancellationToken)
513513
.ConfigureAwait(false);
514514
await WaitForTaskAsync(tmpIndexName, copyResponse.TaskID, requestOptions: options, ct: cancellationToken)
515515
.ConfigureAwait(false);

clients/algoliasearch-client-swift/Sources/Search/Extra/SearchClientExtension.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,8 @@ public extension SearchClient {
610610

611611
throw error
612612
}
613+
614+
_ = try? await deleteIndex(indexName: tmpIndexName)
613615
}
614616

615617
/// Generate a secured API key

scripts/cts/testServer/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export async function setupServer(name: string, port: number, addRoutes: (app: E
5959

6060
// 404 handler
6161
app.use((req, res) => {
62-
console.error('endpoint not implemented for', req.method, req.url);
62+
console.error(`[PORT ${port}] endpoint not implemented for`, req.method, req.url);
6363
res.status(404).json({ message: 'not found' });
6464
});
6565

scripts/cts/testServer/replaceAllObjects.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ const raoState: Record<
1414
waitTaskCount: number;
1515
tmpIndexName: string;
1616
waitingForFinalWaitTask: boolean;
17+
tmpIndexDeleted: boolean;
1718
successful: boolean;
1819
}
1920
> = {};
2021

2122
export function assertValidReplaceAllObjects(expectedCount: number): void {
22-
const count = Object.values(raoState).filter((s) => s.successful).length;
23+
const count = Object.values(raoState).filter((s) => s.successful && s.tmpIndexDeleted).length;
2324
if (count !== expectedCount) {
2425
throw new Error(`Expected ${expectedCount} call to replaceAllObjects, got ${count} instead.`);
2526
}
@@ -50,6 +51,7 @@ function addRoutes(app: Express): void {
5051
waitTaskCount: 0,
5152
tmpIndexName: req.body.destination,
5253
waitingForFinalWaitTask: false,
54+
tmpIndexDeleted: false,
5355
successful: false,
5456
};
5557
} else {
@@ -68,6 +70,7 @@ function addRoutes(app: Express): void {
6870
waitTaskCount: 6,
6971
tmpIndexName: req.params.indexName,
7072
waitingForFinalWaitTask: false,
73+
tmpIndexDeleted: false,
7174
successful: false,
7275
});
7376

@@ -113,6 +116,16 @@ function addRoutes(app: Express): void {
113116

114117
res.json({ status: 'published', updatedAt: '2021-01-01T00:00:00.000Z' });
115118
});
119+
120+
app.delete('/1/indexes/:indexName', (req, res) => {
121+
const lang = req.params.indexName.match(/^cts_e2e_replace_all_objects_(.*)_tmp_\d+$/)?.[1] as string;
122+
expect(raoState).to.include.keys(lang);
123+
expect(raoState[lang].tmpIndexName).to.equal(req.params.indexName);
124+
125+
raoState[lang].tmpIndexDeleted = true;
126+
127+
res.json({ taskID: 456, deletedAt: '2021-01-01T00:00:00.000Z' });
128+
});
116129
}
117130

118131
export function replaceAllObjectsServer(): Promise<Server> {

templates/java/api_helpers.mustache

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -653,24 +653,6 @@ public <T> List<BatchResponse> chunkedBatch(
653653
return chunkedBatch(indexName, objects, action, waitForTasks, 1000, requestOptions);
654654
}
655655
656-
/**
657-
* Push a new set of objects and remove all previous ones. Settings, synonyms and query rules are
658-
* untouched. Replace all records in an index without any downtime. See
659-
* https://api-clients-automation.netlify.app/docs/add-new-api-client#5-helpers for implementation
660-
* details.
661-
*
662-
* @param indexName The `indexName` to replace `objects` in.
663-
* @param objects The array of `objects` to store in the given Algolia `indexName`.
664-
* @param batchSize The size of the chunk of `objects`. The number of `batch` calls will be equal
665-
* to `length(objects) / batchSize`.
666-
* @throws AlgoliaRetryException When the retry has failed on all hosts
667-
* @throws AlgoliaApiException When the API sends an http error code
668-
* @throws AlgoliaRuntimeException When an error occurred during the serialization
669-
*/
670-
public <T> ReplaceAllObjectsResponse replaceAllObjects(String indexName, Iterable<T> objects, int batchSize) {
671-
return replaceAllObjects(indexName, objects, batchSize, null);
672-
}
673-
674656
/**
675657
* Helper: Saves the given array of objects in the given index. The `chunkedBatch` helper is used
676658
* under the hood, which creates a `batch` requests with at most 1000 objects in it.
@@ -891,6 +873,40 @@ public <T> List<BatchResponse> partialUpdateObjects(
891873
);
892874
}
893875
876+
/**
877+
* Push a new set of objects and remove all previous ones. Settings, synonyms and query rules are
878+
* untouched. Replace all records in an index without any downtime. See
879+
* https://api-clients-automation.netlify.app/docs/add-new-api-client#5-helpers for implementation
880+
* details.
881+
*
882+
* @param indexName The `indexName` to replace `objects` in.
883+
* @param objects The array of `objects` to store in the given Algolia `indexName`.
884+
* @throws AlgoliaRetryException When the retry has failed on all hosts
885+
* @throws AlgoliaApiException When the API sends an http error code
886+
* @throws AlgoliaRuntimeException When an error occurred during the serialization
887+
*/
888+
public <T> ReplaceAllObjectsResponse replaceAllObjects(String indexName, Iterable<T> objects) {
889+
return replaceAllObjects(indexName, objects, -1);
890+
}
891+
892+
/**
893+
* Push a new set of objects and remove all previous ones. Settings, synonyms and query rules are
894+
* untouched. Replace all records in an index without any downtime. See
895+
* https://api-clients-automation.netlify.app/docs/add-new-api-client#5-helpers for implementation
896+
* details.
897+
*
898+
* @param indexName The `indexName` to replace `objects` in.
899+
* @param objects The array of `objects` to store in the given Algolia `indexName`.
900+
* @param batchSize The size of the chunk of `objects`. The number of `batch` calls will be equal
901+
* to `length(objects) / batchSize`.
902+
* @throws AlgoliaRetryException When the retry has failed on all hosts
903+
* @throws AlgoliaApiException When the API sends an http error code
904+
* @throws AlgoliaRuntimeException When an error occurred during the serialization
905+
*/
906+
public <T> ReplaceAllObjectsResponse replaceAllObjects(String indexName, Iterable<T> objects, int batchSize) {
907+
return replaceAllObjects(indexName, objects, batchSize, null);
908+
}
909+
894910
/**
895911
* Push a new set of objects and remove all previous ones. Settings, synonyms and query rules are
896912
* untouched. Replace all records in an index without any downtime. See
@@ -916,6 +932,10 @@ public <T> ReplaceAllObjectsResponse replaceAllObjects(
916932
Random rnd = new Random();
917933
String tmpIndexName = indexName + "_tmp_" + rnd.nextInt(100);
918934
935+
if (batchSize == -1) {
936+
batchSize = 1000;
937+
}
938+
919939
try {
920940
// Copy settings, synonyms and rules
921941
UpdatedAtResponse copyOperationResponse = operationIndex(
@@ -958,10 +978,8 @@ public <T> ReplaceAllObjectsResponse replaceAllObjects(
958978
.setCopyOperationResponse(copyOperationResponse)
959979
.setBatchResponses(batchResponses)
960980
.setMoveOperationResponse(moveOperationResponse);
961-
} catch (Exception e) {
981+
} finally {
962982
deleteIndex(tmpIndexName);
963-
964-
throw e;
965983
}
966984
}
967985

tests/CTS/client/ingestion/api.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"go": "API error [429] Too Many Requests",
2929
"java": "Status Code: 429 - Too Many Requests",
3030
"javascript": "Too Many Requests",
31-
"kotlin": "Client request(GET http://%localhost%:6676/1/html-error) invalid: 429 Too Many Requests. Text: \\\"<html><body>429 Too Many Requests</body></html>\\\"",
31+
"kotlin": "Client request\\\\(GET http://%localhost%:6676/1/html-error\\\\) invalid: 429 Too Many Requests. Text: \\\"<html><body>429 Too Many Requests</body></html>\\\"",
3232
"php": "429: Too Many Requests",
3333
"python": "Too Many Requests",
3434
"ruby": "429: Too Many Requests",

tests/CTS/client/search/api.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"go": "failed to do request: all hosts have been contacted unsuccessfully, it can either be a server or a network error or wrong appID/key credentials were used. You can use 'ExposeIntermediateNetworkErrors: true' in the config to investigate.",
138138
"java": "Error(s) while processing the retry strategy\\nCaused by: java.net.SocketTimeoutException: timeout",
139139
"javascript": "Unreachable hosts - your application id may be incorrect. If the error persists, please reach out to the Algolia Support team: https://alg.li/support.",
140-
"kotlin": "Error(s) while processing the retry strategy",
140+
"kotlin": "Error\\\\(s\\\\) while processing the retry strategy",
141141
"php": "Impossible to connect, please check your Algolia Application Id.",
142142
"python": "Unreachable hosts",
143143
"ruby": "Unreachable hosts. Last error for %localhost%: Net::ReadTimeout with #<TCPSocket:(closed)>",

tests/CTS/client/search/indexExists.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"go": "API error [403] Invalid API key",
8686
"java": "Status Code: 403 - {\\\"message\\\":\\\"Invalid API key\\\"}",
8787
"javascript": "Invalid API key",
88-
"kotlin": "Client request(GET http://%localhost%:6681/1/indexes/indexExistsERROR/settings) invalid: 403 Forbidden. Text: \\\"{\\\"message\\\":\\\"Invalid API key\\\"}\\\"",
88+
"kotlin": "Client request\\\\(GET http://%localhost%:6681/1/indexes/indexExistsERROR/settings\\\\) invalid: 403 Forbidden. Text: \\\"\\\\{\\\"message\\\":\\\"Invalid API key\\\"\\\\}\\\"",
8989
"php": "Invalid API key",
9090
"python": "Invalid API key",
9191
"ruby": "403: Invalid API key",

tests/CTS/client/search/replaceAllObjects.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@
123123
"apiKey": "test-api-key",
124124
"customHosts": [
125125
{
126-
"host": "${{localhost}}",
127126
"port": 6684
128127
}
129128
]
@@ -148,13 +147,13 @@
148147
"expected": {
149148
"error": {
150149
"csharp": "{\\\"message\\\":\\\"Record is too big\\\",\\\"status\\\":400}",
151-
"go": "API error [400] {\\\"message\\\":\\\"Record is too big\\\",\\\"status\\\":400}",
150+
"go": "API error [400] Record is too big",
152151
"java": "Status Code: 400 - {\\\"message\\\":\\\"Record is too big\\\",\\\"status\\\":400}",
153152
"javascript": "Record is too big",
154-
"kotlin": "Client request(POST http://${{localhost}}:6684/1/indexes/cts_e2e_replace_all_objects_too_big_${{language}}/batch) invalid: 400 Bad Request. Text: \\\"{\\\"message\\\":\\\"Record is too big\\\",\\\"status\\\":400}\\\"",
153+
"kotlin": "Client request\\\\(POST http://%localhost%:6684/1/indexes/cts_e2e_replace_all_objects_too_big_${{language}}_tmp_\\\\d+/batch\\\\) invalid: 400 Bad Request. Text: \\\"\\\\{\\\"message\\\":\\\"Record is too big\\\",\\\"status\\\":400\\\\}\\\"",
155154
"php": "Record is too big",
156155
"python": "Record is too big",
157-
"ruby": "Record is too big",
156+
"ruby": "400: Record is too big",
158157
"swift": "HTTP error: Status code: 400 Message: Record is too big"
159158
}
160159
}

tests/CTS/client/search/saveObjects.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"go": "API error [403] Invalid Application-ID or API key",
8585
"java": "Status Code: 403 - {\\\"message\\\":\\\"Invalid Application-ID or API key\\\",\\\"status\\\":403}",
8686
"javascript": "Invalid Application-ID or API key",
87-
"kotlin": "Client request(POST http://%localhost%:6680/1/indexes/cts_e2e_saveObjects_kotlin/batch) invalid: 403 Forbidden. Text: \\\"{\\\"message\\\":\\\"Invalid Application-ID or API key\\\",\\\"status\\\":403}\\\"",
87+
"kotlin": "Client request\\\\(POST http://%localhost%:6680/1/indexes/cts_e2e_saveObjects_kotlin/batch\\\\) invalid: 403 Forbidden. Text: \\\"\\\\{\\\"message\\\":\\\"Invalid Application-ID or API key\\\",\\\"status\\\":403\\\\}\\\"",
8888
"php": "Invalid Application-ID or API key",
8989
"python": "Invalid Application-ID or API key",
9090
"ruby": "403: Invalid Application-ID or API key",

0 commit comments

Comments
 (0)