Skip to content

Commit

Permalink
Add changes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
aashikam committed Jun 6, 2024
1 parent 96f3846 commit c9a5b83
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
6 changes: 5 additions & 1 deletion ballerina/client.bal
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ public isolated client class Client {
return [];
}
batchingParams = string `results?locator=${locator}`;
path = utils:prepareUrl([API_BASE_PATH, JOBS, QUERY, bulkJobId, batchingParams]);
} else {
path = utils:prepareUrl([API_BASE_PATH, JOBS, QUERY, bulkJobId, RESULT]);
}
Expand All @@ -698,7 +699,10 @@ public isolated client class Client {
return [];
}
lock {
self.sfLocators[bulkJobId] = check response.getHeader("sforce-locator");
string|http:HeaderNotFoundError locatorValue = response.getHeader("sforce-locator");
if locatorValue is string {
self.sfLocators[bulkJobId] = locatorValue;
} // header not found error ignored
}
string[][] result = check parseCsvString(textPayload);
return result;
Expand Down
60 changes: 58 additions & 2 deletions ballerina/tests/bulk_csv_query.bal
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,14 @@ function queryCsv() returns error? {
}
}
}

}


@test:Config {
enable: true,
dependsOn: [insertCsvFromFile, insertCsv, insertCsvStringArrayFromFile, insertCsvStreamFromFile]
}
function queryCsvWithMaxRecords() returns error? {
function queryWithLowerMaxRecordsValue() returns error? {
runtime:sleep(delayInSecs);
log:printInfo("baseClient -> queryCsv");
string queryStr = "SELECT Id, Name FROM Contact WHERE Title='Professor Level 02'";
Expand Down Expand Up @@ -123,6 +122,63 @@ function queryCsvWithMaxRecords() returns error? {
}


@test:Config {
enable: true,
dependsOn: [insertCsvFromFile, insertCsv, insertCsvStringArrayFromFile, insertCsvStreamFromFile]
}
function queryWithHigherMaxRecordsValue() returns error? {
runtime:sleep(delayInSecs);
log:printInfo("baseClient -> queryCsv");
string queryStr = "SELECT Id, Name FROM Contact WHERE Title='Professor Level 02'";

BulkCreatePayload payloadq = {
operation : "query",
query : queryStr
};

//create job
BulkJob queryJob = check baseClient->createQueryJob(payloadq);
int totalRecordsReceived = 0;
int totalIterationsOfGetResult = 0;
string[][]|error batchResult = [];

//get batch result
foreach int currentRetry in 1 ..< maxIterations + 1 {
while true {
batchResult = baseClient->getQueryResult(queryJob.id, 10);
if batchResult is error || batchResult.length() == 0 {
break;
} else {
totalRecordsReceived += batchResult.length();
totalIterationsOfGetResult += 1;
}
}

if totalIterationsOfGetResult != 0 {
if totalRecordsReceived == 7 {
test:assertTrue(totalRecordsReceived == 7, msg = "Retrieving batch result failed.");
test:assertTrue(totalIterationsOfGetResult == 1, msg = "Retrieving batch result failed.");
break;
} else {
if currentRetry != maxIterations {
log:printWarn("getBatchResult Operation Failed! Retrying...");
runtime:sleep(delayInSecs);
} else {
log:printWarn("getBatchResult Operation Failed! Giving up after 5 tries.");
}
}
} else if batchResult is error {
if currentRetry != maxIterations {
log:printWarn("getBatchResult Operation Failed! Retrying...");
runtime:sleep(delayInSecs);
} else {
log:printWarn("getBatchResult Operation Failed! Giving up after 5 tries.");
test:assertFail(msg = batchResult.message());
}
}
}
}

@test:Config {
enable: true,
dependsOn: [insertCsvFromFile, insertCsv, insertCsvStringArrayFromFile, insertCsvStreamFromFile]
Expand Down

0 comments on commit c9a5b83

Please sign in to comment.