Skip to content

Commit

Permalink
Simplify state change detection and fix null check at same time
Browse files Browse the repository at this point in the history
In ingestion callbacks used by channel.
  • Loading branch information
guperrot committed Oct 30, 2018
1 parent 55e2d86 commit 908b4bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ public void onCallSucceeded(String payload) {

@Override
public void run() {
handleSendingSuccess(groupState, currentState, batchId);
handleSendingSuccess(groupState, batchId);
}
});
}
Expand All @@ -529,7 +529,7 @@ public void onCallFailed(final Exception e) {

@Override
public void run() {
handleSendingFailure(groupState, currentState, batchId, e);
handleSendingFailure(groupState, batchId, e);
}
});
}
Expand All @@ -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<Log> removedLogsForBatchId = groupState.mSendingBatches.remove(batchId);
private synchronized void handleSendingSuccess(@NonNull GroupState groupState, @NonNull String batchId) {
List<Log> removedLogsForBatchId = groupState.mSendingBatches.remove(batchId);
if (removedLogsForBatchId != null) {
mPersistence.deleteLogs(groupState.mName, batchId);
GroupListener groupListener = groupState.mListener;
if (groupListener != null) {
for (Log log : removedLogsForBatchId) {
Expand All @@ -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<Log> removedLogsForBatchId = groupState.mSendingBatches.remove(batchId);
if (removedLogsForBatchId != null) {
AppCenterLog.error(LOG_TAG, "Sending logs groupName=" + groupName + " id=" + batchId + " failed", e);
List<Log> removedLogsForBatchId = groupState.mSendingBatches.remove(batchId);
boolean recoverableError = HttpUtils.isRecoverableError(e);
if (recoverableError) {
groupState.mPendingLogCount += removedLogsForBatchId.size();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public boolean matches(Object argument) {
return argument instanceof CancellationException;
}
}));
verify(mockPersistence, never()).deleteLogs(anyString(), anyString());
}

@Test
Expand Down

0 comments on commit 908b4bb

Please sign in to comment.