diff --git a/sdk/appcenter/src/main/java/com/microsoft/appcenter/channel/DefaultChannel.java b/sdk/appcenter/src/main/java/com/microsoft/appcenter/channel/DefaultChannel.java index fe98c6ff84..f832b2dbd7 100644 --- a/sdk/appcenter/src/main/java/com/microsoft/appcenter/channel/DefaultChannel.java +++ b/sdk/appcenter/src/main/java/com/microsoft/appcenter/channel/DefaultChannel.java @@ -518,7 +518,7 @@ public void onCallSucceeded(String payload) { @Override public void run() { - handleSendingSuccess(groupState, currentState, batchId); + handleSendingSuccess(groupState, batchId); } }); } @@ -529,7 +529,7 @@ public void onCallFailed(final Exception e) { @Override public void run() { - handleSendingFailure(groupState, currentState, batchId, e); + handleSendingFailure(groupState, batchId, e); } }); } @@ -555,15 +555,13 @@ private void checkPendingLogsAfterPost(@NonNull final GroupState groupState, int /** * The actual implementation to react to sending a batch to the server successfully. * - * @param groupState The group state. - * @param currentState The current state. - * @param batchId The batch ID. + * @param groupState The group state. + * @param batchId The batch ID. */ - private synchronized void handleSendingSuccess(@NonNull final GroupState groupState, int currentState, @NonNull final String batchId) { - if (checkStateDidNotChange(groupState, currentState)) { - String groupName = groupState.mName; - mPersistence.deleteLogs(groupName, batchId); - List removedLogsForBatchId = groupState.mSendingBatches.remove(batchId); + private synchronized void handleSendingSuccess(@NonNull GroupState groupState, @NonNull String batchId) { + List removedLogsForBatchId = groupState.mSendingBatches.remove(batchId); + if (removedLogsForBatchId != null) { + mPersistence.deleteLogs(groupState.mName, batchId); GroupListener groupListener = groupState.mListener; if (groupListener != null) { for (Log log : removedLogsForBatchId) { @@ -579,16 +577,15 @@ private synchronized void handleSendingSuccess(@NonNull final GroupState groupSt * Will disable the sender in case of a recoverable error. * Will delete batch of data in case of a non-recoverable error. * - * @param groupState the group state - * @param currentState the current state - * @param batchId the batch ID - * @param e the exception + * @param groupState the group state + * @param batchId the batch ID + * @param e the exception */ - private synchronized void handleSendingFailure(@NonNull final GroupState groupState, int currentState, @NonNull final String batchId, @NonNull final Exception e) { - if (checkStateDidNotChange(groupState, currentState)) { - String groupName = groupState.mName; + private synchronized void handleSendingFailure(@NonNull GroupState groupState, @NonNull String batchId, @NonNull Exception e) { + String groupName = groupState.mName; + List removedLogsForBatchId = groupState.mSendingBatches.remove(batchId); + if (removedLogsForBatchId != null) { AppCenterLog.error(LOG_TAG, "Sending logs groupName=" + groupName + " id=" + batchId + " failed", e); - List removedLogsForBatchId = groupState.mSendingBatches.remove(batchId); boolean recoverableError = HttpUtils.isRecoverableError(e); if (recoverableError) { groupState.mPendingLogCount += removedLogsForBatchId.size(); diff --git a/sdk/appcenter/src/test/java/com/microsoft/appcenter/channel/DefaultChannelRaceConditionTest.java b/sdk/appcenter/src/test/java/com/microsoft/appcenter/channel/DefaultChannelRaceConditionTest.java index 117333b2fc..ef8a5e5f1a 100644 --- a/sdk/appcenter/src/test/java/com/microsoft/appcenter/channel/DefaultChannelRaceConditionTest.java +++ b/sdk/appcenter/src/test/java/com/microsoft/appcenter/channel/DefaultChannelRaceConditionTest.java @@ -131,6 +131,7 @@ public boolean matches(Object argument) { return argument instanceof CancellationException; } })); + verify(mockPersistence, never()).deleteLogs(anyString(), anyString()); } @Test