Skip to content

Commit

Permalink
Merge pull request #82 from adobe/dev
Browse files Browse the repository at this point in the history
Merge `dev` into `staging` for 2.2.1 release
  • Loading branch information
prudrabhat authored Jan 29, 2024
2 parents 728b30f + b045b31 commit 44e07cd
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Assurance {

public static final Class<? extends Extension> EXTENSION = AssuranceExtension.class;
public static final String LOG_TAG = "Assurance";
public static final String EXTENSION_VERSION = "2.2.0";
public static final String EXTENSION_VERSION = "2.2.1";
public static final String EXTENSION_NAME = "com.adobe.assurance";
public static final String EXTENSION_FRIENDLY_NAME = "Assurance";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,12 @@ public List<AssuranceEvent> chunk(final AssuranceEvent event) {
final String chunkId = UUID.randomUUID().toString();
int chunkNumber = 0;

while (byteArrayInputStream.read(buffer) != -1) {
int bytesRead;
while ((bytesRead = byteArrayInputStream.read(buffer)) != -1) {
final HashMap<String, Object> payload = new HashMap<>();
payload.put(
AssuranceConstants.AssuranceEventKeys.CHUNK_DATA,
new String(buffer, Charset.forName("UTF-8")));
new String(buffer, 0, bytesRead, Charset.forName("UTF-8")));

final HashMap<String, Object> metadata = new HashMap<>();
metadata.put(AssuranceConstants.AssuranceEventKeys.CHUNK_ID, chunkId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;

import com.adobe.marketing.mobile.util.JSONUtils;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -304,7 +305,7 @@ public void test_sendEvent_payloadOverMaxPayloadSize_20KB() {
try {
// Prepare & read large payload from resources.
final String expectedPayloadKeyValue =
readPayloadFromResource("assurance_large_event_payload_key_value_20KB.txt");
readFromResource("assurance_large_event_payload_key_value_20KB.txt");

// Construct expected event payload
final HashMap<String, Object> expectedEventPayload = new HashMap<>();
Expand Down Expand Up @@ -344,7 +345,7 @@ public void test_sendEvent_payloadOverMaxPayloadSize_40KB() {
try {
// Prepare & read large payload from resources.
final String expectedPayloadKeyValue =
readPayloadFromResource("assurance_large_event_payload_key_value_40KB.txt");
readFromResource("assurance_large_event_payload_key_value_40KB.txt");

// Construct expected event payload
final HashMap<String, Object> expectedEventPayload = new HashMap<>();
Expand Down Expand Up @@ -419,7 +420,7 @@ public void test_sendEvent_payloadOverMaxPayloadSize_HTML() {
try {
// Prepare & read large payload from resources.
final String expectedPayloadKeyValue =
readPayloadFromResource("assurance_large_event_payload_key_value_html.txt");
readFromResource("assurance_large_event_payload_key_value_html.txt");

// Construct expected event payload
final HashMap<String, Object> expectedEventPayload = new HashMap<>();
Expand Down Expand Up @@ -486,7 +487,78 @@ public void test_sendEvent_payloadOverMaxPayloadSize_HTML() {
}
}

private String readPayloadFromResource(final String resourceName) throws IOException {
@Test
public void test_sendEvent_overflow_clientInfo() {
when(mockAssuranceWebViewSocket.getState())
.thenReturn(AssuranceWebViewSocket.SocketReadyState.OPEN);
try {
final String payloadString =
readFromResource("assurance_large_full_event_outbound_flow.txt");

// Construct event from payload
final AssuranceEvent largeAssuranceEvent = new AssuranceEvent(payloadString);

// Simulate event enqueueing into outbound queue.
outboundEventQueueWorker.offer(largeAssuranceEvent);
outboundEventQueueWorker.start();
outboundEventQueueWorker.unblock();

// Capture data being sent through the socket and Verify 8 events trigger in total.
// 1 client info event and 7 chunked Assurance events.
ArgumentCaptor<byte[]> socketDataCaptor = ArgumentCaptor.forClass(byte[].class);
verify(mockAssuranceWebViewSocket, times(8)).sendData(socketDataCaptor.capture());
final List<byte[]> capturedEventData = socketDataCaptor.getAllValues();
assertEquals(8, capturedEventData.size());

final StringBuilder actualPayloadValue = new StringBuilder();
final Set<String> chunkIds = new HashSet<>();

// Start from 1 because 0th event is mock client info event.
for (int i = 1; i < capturedEventData.size(); i++) {
// Verify that the chunked bytes sent is below the permitted limit.
final byte[] capturedChunkedEventBytes = capturedEventData.get(i);
assertTrue(
capturedChunkedEventBytes.length < OutboundEventQueueWorker.MAX_EVENT_SIZE);

final String assuranceEventString =
new String(capturedEventData.get(i), Charset.forName("UTF-8"));
final AssuranceEvent actualEvent = new AssuranceEvent(assuranceEventString);
final String chunkData =
(String)
actualEvent
.getPayload()
.get(AssuranceConstants.AssuranceEventKeys.CHUNK_DATA);
// Construct the actual de-chunked event payload from chunked events.
actualPayloadValue.append(chunkData);

// Validate metadata keys - chunkId, sequence number, total chunks per event.
final Map<String, Object> metadata = actualEvent.getMetadata();
// collect chunkId's for verifying similarity.
chunkIds.add((String) metadata.get(AssuranceConstants.AssuranceEventKeys.CHUNK_ID));
assertEquals(
i - 1,
metadata.get(AssuranceConstants.AssuranceEventKeys.CHUNK_SEQUENCE_NUMBER));
assertEquals(7, metadata.get(AssuranceConstants.AssuranceEventKeys.CHUNK_TOTAL));

// Verify that the other event values are same as the original event
assertEquals(largeAssuranceEvent.vendor, actualEvent.vendor);
assertEquals(largeAssuranceEvent.type, actualEvent.type);
assertEquals(largeAssuranceEvent.timestamp, actualEvent.timestamp);
}

// Validate that the chunkId is same across events.
assertEquals(1, chunkIds.size());

// Validate that the de-chunked payload matches the combined chunks.
final JSONObject actualPayloadJson = new JSONObject(actualPayloadValue.toString());
final Map<String, Object> actualPayloadMap = JSONUtils.toMap(actualPayloadJson);
assertEquals(largeAssuranceEvent.payload, actualPayloadMap);
} catch (JSONException | IOException e) {
fail();
}
}

private String readFromResource(final String resourceName) throws IOException {
final InputStream payloadValueStream =
this.getClass().getClassLoader().getResourceAsStream(resourceName);
final BufferedReader bufferedReader =
Expand All @@ -497,7 +569,6 @@ private String readPayloadFromResource(final String resourceName) throws IOExcep

while ((curentLine = bufferedReader.readLine()) != null) {
resourceContent.append(curentLine);
resourceContent.append("\n");
}

return resourceContent.toString();
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion code/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ org.gradle.configureondemand = false
moduleProjectName=assurance
moduleName=assurance
moduleAARName=assurance-phone-release.aar
moduleVersion=2.2.0
moduleVersion=2.2.1
mavenRepoName=AdobeMobileAssurance
mavenRepoDescription=Android Assurance Extension for Adobe Mobile Marketing
mavenUploadDryRunFlag=false
Expand Down

0 comments on commit 44e07cd

Please sign in to comment.