diff --git a/ballerina/client.bal b/ballerina/client.bal index bdf255f2..62470d43 100644 --- a/ballerina/client.bal +++ b/ballerina/client.bal @@ -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]); } @@ -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; diff --git a/ballerina/tests/bulk_csv_query.bal b/ballerina/tests/bulk_csv_query.bal index 263a8a44..1f4e2bbf 100644 --- a/ballerina/tests/bulk_csv_query.bal +++ b/ballerina/tests/bulk_csv_query.bal @@ -61,7 +61,6 @@ function queryCsv() returns error? { } } } - } @@ -69,7 +68,7 @@ function queryCsv() returns error? { 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'"; @@ -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]