Skip to content

Commit

Permalink
refactor: address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Feb 19, 2019
1 parent 0b8a78d commit 315a55b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
4 changes: 2 additions & 2 deletions sdk/src/androidTest/java/com/bugsnag/android/SessionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class SessionTest {

@Test
fun handledIncrementCopiesSession() {
val copy = session.incrementHandledErrCount()
val copy = session.incrementHandledAndCopy()
assertNotEquals(session, copy)
validateSessionCopied(copy)
}

@Test
fun unhandledIncrementCopiesSession() {
val copy = session.incrementUnhandledErrCount()
val copy = session.incrementUnhandledAndCopy()
assertNotEquals(session, copy)
validateSessionCopied(copy)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import static com.bugsnag.android.BugsnagTestUtils.generateClient;
import static com.bugsnag.android.BugsnagTestUtils.generateSessionStore;
import static com.bugsnag.android.BugsnagTestUtils.generateSessionTrackingApiClient;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertNotEquals;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -80,11 +78,11 @@ public void testUniqueSessionIds() throws Exception {
@Test
public void testIncrementCounts() throws Exception {
sessionTracker.startNewSession(new Date(), user, false);
sessionTracker.incrementHandledError();
sessionTracker.incrementHandledError();
sessionTracker.incrementUnhandledError();
sessionTracker.incrementUnhandledError();
sessionTracker.incrementUnhandledError();
sessionTracker.incrementHandledAndCopy();
sessionTracker.incrementHandledAndCopy();
sessionTracker.incrementUnhandledAndCopy();
sessionTracker.incrementUnhandledAndCopy();
sessionTracker.incrementUnhandledAndCopy();

Session session = sessionTracker.getCurrentSession();
assertNotNull(session);
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/main/java/com/bugsnag/android/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ void notify(@NonNull Error error,
callback.beforeNotify(report);
}

if (sessionTracker.getCurrentSession() != null) {
if (!error.getHandledState().isUnhandled() && error.getSession() != null) {
setChanged();
notifyObservers(new NativeInterface.Message(
NativeInterface.MessageType.NOTIFY_HANDLED, error.getExceptionName()));
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/main/java/com/bugsnag/android/Error.java
Original file line number Diff line number Diff line change
Expand Up @@ -457,9 +457,9 @@ private Session getSession(HandledState handledState) {
}
if (config.getAutoCaptureSessions() || !currentSession.isAutoCaptured()) {
if (handledState.isUnhandled()) {
reportedSession = sessionTracker.incrementUnhandledError();
reportedSession = sessionTracker.incrementUnhandledAndCopy();
} else {
reportedSession = sessionTracker.incrementHandledError();
reportedSession = sessionTracker.incrementHandledAndCopy();
}
}
return reportedSession;
Expand Down
4 changes: 2 additions & 2 deletions sdk/src/main/java/com/bugsnag/android/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ int getHandledCount() {
return handledCount.intValue();
}

Session incrementHandledErrCount() {
Session incrementHandledAndCopy() {
handledCount.incrementAndGet();
return copySession(this);
}

Session incrementUnhandledErrCount() {
Session incrementUnhandledAndCopy() {
unhandledCount.incrementAndGet();
return copySession(this);
}
Expand Down
20 changes: 16 additions & 4 deletions sdk/src/main/java/com/bugsnag/android/SessionTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,30 @@ Session getCurrentSession() {
return currentSession.get();
}

Session incrementUnhandledError() {
/**
* Increments the unhandled error count on the current session, then returns a deep-copy
* of the current session.
*
* @return a copy of the current session, or null if no session has been started.
*/
Session incrementUnhandledAndCopy() {
Session session = currentSession.get();
if (session != null) {
return session.incrementUnhandledErrCount();
return session.incrementUnhandledAndCopy();
}
return null;
}

Session incrementHandledError() {
/**
* Increments the handled error count on the current session, then returns a deep-copy
* of the current session.
*
* @return a copy of the current session, or null if no session has been started.
*/
Session incrementHandledAndCopy() {
Session session = currentSession.get();
if (session != null) {
return session.incrementHandledErrCount();
return session.incrementHandledAndCopy();
}
return null;
}
Expand Down

0 comments on commit 315a55b

Please sign in to comment.