Skip to content
Snippets Groups Projects
Commit 926b43f3 authored by Zhibin Mai's avatar Zhibin Mai
Browse files

Fix the unit test

parent 56b2d043
No related branches found
No related tags found
1 merge request!597Make sure that the indexing message sent to Azure service bus is not over-size
Pipeline #204299 failed
......@@ -21,6 +21,7 @@ import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.microsoft.azure.servicebus.Message;
import lombok.extern.java.Log;
import org.apache.commons.collections.CollectionUtils;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.azure.servicebus.ITopicClientFactory;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
......@@ -105,13 +106,18 @@ public class IndexerQueueTaskBuilderAzure extends IndexerQueueTaskBuilder {
RecordChangedMessages receivedPayload = gson.fromJson(payload, RecordChangedMessages.class);
List<RecordInfo> recordInfos = parseRecordsAsJSON(receivedPayload.getData());
Map<String, String> attributes = receivedPayload.getAttributes();
List<List<RecordInfo>> batch = Lists.partition(recordInfos, publisherConfig.getPubSubBatchSize());
for (List<RecordInfo> recordsBatch : batch) {
RecordChangedMessages recordChangedMessages = RecordChangedMessages.builder().data(gson.toJson(recordsBatch)).attributes(attributes).build();
String recordChangedMessagePayload = gson.toJson(recordChangedMessages);
createTask(recordChangedMessagePayload, headers);
if(!CollectionUtils.isEmpty(recordInfos)) {
Map<String, String> attributes = receivedPayload.getAttributes();
if (attributes == null) {
attributes = new HashMap<>();
}
List<List<RecordInfo>> batch = Lists.partition(recordInfos, publisherConfig.getPubSubBatchSize());
for (List<RecordInfo> recordsBatch : batch) {
RecordChangedMessages recordChangedMessages = RecordChangedMessages.builder().data(gson.toJson(recordsBatch)).attributes(attributes).build();
String recordChangedMessagePayload = gson.toJson(recordChangedMessages);
createTask(recordChangedMessagePayload, headers);
}
}
}
......
......@@ -31,7 +31,12 @@ import static org.opengroup.osdu.core.common.model.http.DpsHeaders.AUTHORIZATION
@RunWith(MockitoJUnitRunner.class)
public class IndexerQueueTaskBuilderAzureTest {
private String payload = "{payload : value }";
private String payload = "{\n" +
" \"data\": \"[{\\\"id\\\":\\\"opendes:work-product-component--WellLog:566edebc-1a9f-4f4d-9a30-ed458e959ac7\\\",\\\"kind\\\":\\\"osdu:wks:work-product-component--WellLog:1.2.0\\\",\\\"op\\\":\\\"create\\\"},{\\\"id\\\":\\\"opendes:work-product-component--WellLog:84958febe54e4908a1703778e1918dae\\\",\\\"kind\\\":\\\"osdu:wks:work-product-component--WellLog:1.2.0\\\",\\\"op\\\":\\\"create\\\"}]\",\n" +
" \"attributes\": {\n" +
" \"data-partition-id\": \"opendes\"\n" +
" }\n" +
"}";
private static String partitionId = "opendes";
private static String correlationId = "correlationId";
private static String serviceBusReindexTopicNameField = "serviceBusReindexTopicName";
......@@ -78,7 +83,7 @@ public class IndexerQueueTaskBuilderAzureTest {
verify(dpsHeaders, times(4)).getPartitionIdWithFallbackToAccountId();
verify(dpsHeaders, times(2)).getCorrelationId();
verify(dpsHeaders, times(1)).addCorrelationIdIfMissing();
verify(dpsHeaders, times(2)).addCorrelationIdIfMissing();
verify(topicClientFactory, times(1)).getClient(partitionId, serviceBusReindexTopicNameValue);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment