Skip to content

Commit 6ef3aa9

Browse files
committed
address comments
1 parent 2f347a1 commit 6ef3aa9

File tree

4 files changed

+33
-55
lines changed

4 files changed

+33
-55
lines changed

firebase-crashlytics/src/androidTest/java/com/google/firebase/crashlytics/internal/common/CrashlyticsCoreTest.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public void whenAvailable(
7070

7171
private CrashlyticsCore crashlyticsCore;
7272
private BreadcrumbSource mockBreadcrumbSource;
73+
private static final CrashlyticsWorker commonWorker =
74+
new CrashlyticsWorker(TestOnlyExecutors.background());
75+
private static final CrashlyticsWorker diskWriteWorker =
76+
new CrashlyticsWorker(TestOnlyExecutors.background());
7377

7478
@Override
7579
protected void setUp() throws Exception {
@@ -93,7 +97,7 @@ public void testCustomAttributes() throws Exception {
9397

9498
final String id = "id012345";
9599
crashlyticsCore.setUserId(id);
96-
crashlyticsCore.commonWorker.await();
100+
commonWorker.await();
97101
assertEquals(id, metadata.getUserId());
98102

99103
final StringBuffer idBuffer = new StringBuffer(id);
@@ -104,13 +108,13 @@ public void testCustomAttributes() throws Exception {
104108
final String superLongId = longId + "more chars";
105109

106110
crashlyticsCore.setUserId(superLongId);
107-
crashlyticsCore.commonWorker.await();
111+
commonWorker.await();
108112
assertEquals(longId, metadata.getUserId());
109113

110114
final String key1 = "key1";
111115
final String value1 = "value1";
112116
crashlyticsCore.setCustomKey(key1, value1);
113-
crashlyticsCore.commonWorker.await();
117+
commonWorker.await();
114118
assertEquals(value1, metadata.getCustomKeys().get(key1));
115119

116120
// Adding an existing key with the same value should return false
@@ -124,7 +128,7 @@ public void testCustomAttributes() throws Exception {
124128

125129
// test truncation of custom keys and attributes
126130
crashlyticsCore.setCustomKey(superLongId, superLongValue);
127-
crashlyticsCore.commonWorker.await();
131+
commonWorker.await();
128132
assertNull(metadata.getCustomKeys().get(superLongId));
129133
assertEquals(longValue, metadata.getCustomKeys().get(longId));
130134

@@ -133,28 +137,28 @@ public void testCustomAttributes() throws Exception {
133137
final String key = "key" + i;
134138
final String value = "value" + i;
135139
crashlyticsCore.setCustomKey(key, value);
136-
crashlyticsCore.commonWorker.await();
140+
commonWorker.await();
137141
assertEquals(value, metadata.getCustomKeys().get(key));
138142
}
139143
// should be full now, extra key, value pairs will be dropped.
140144
final String key = "new key";
141145
crashlyticsCore.setCustomKey(key, "some value");
142-
crashlyticsCore.commonWorker.await();
146+
commonWorker.await();
143147
assertFalse(metadata.getCustomKeys().containsKey(key));
144148

145149
// should be able to update existing keys
146150
crashlyticsCore.setCustomKey(key1, longValue);
147-
crashlyticsCore.commonWorker.await();
151+
commonWorker.await();
148152
assertEquals(longValue, metadata.getCustomKeys().get(key1));
149153

150154
// when we set a key to null, it should still exist with an empty value
151155
crashlyticsCore.setCustomKey(key1, null);
152-
crashlyticsCore.commonWorker.await();
156+
commonWorker.await();
153157
assertEquals("", metadata.getCustomKeys().get(key1));
154158

155159
// keys and values are trimmed.
156160
crashlyticsCore.setCustomKey(" " + key1 + " ", " " + longValue + " ");
157-
crashlyticsCore.commonWorker.await();
161+
commonWorker.await();
158162
assertTrue(metadata.getCustomKeys().containsKey(key1));
159163
assertEquals(longValue, metadata.getCustomKeys().get(key1));
160164
}
@@ -205,7 +209,7 @@ public void testBulkCustomKeys() throws Exception {
205209
keysAndValues.put(intKey, String.valueOf(intValue));
206210

207211
crashlyticsCore.setCustomKeys(keysAndValues);
208-
crashlyticsCore.commonWorker.await();
212+
commonWorker.await();
209213

210214
assertEquals(stringValue, metadata.getCustomKeys().get(stringKey));
211215
assertEquals(trimmedValue, metadata.getCustomKeys().get(trimmedKey));
@@ -226,7 +230,7 @@ public void testBulkCustomKeys() throws Exception {
226230
addlKeysAndValues.put(key, value);
227231
}
228232
crashlyticsCore.setCustomKeys(addlKeysAndValues);
229-
crashlyticsCore.commonWorker.await();
233+
commonWorker.await();
230234

231235
// Ensure all keys have been set
232236
assertEquals(UserMetadata.MAX_ATTRIBUTES, metadata.getCustomKeys().size(), DELTA);
@@ -244,7 +248,7 @@ public void testBulkCustomKeys() throws Exception {
244248
extraKeysAndValues.put(key, value);
245249
}
246250
crashlyticsCore.setCustomKeys(extraKeysAndValues);
247-
crashlyticsCore.commonWorker.await();
251+
commonWorker.await();
248252

249253
// Make sure the extra keys were not added
250254
for (int i = UserMetadata.MAX_ATTRIBUTES; i < UserMetadata.MAX_ATTRIBUTES + 10; ++i) {
@@ -270,7 +274,7 @@ public void testBulkCustomKeys() throws Exception {
270274
updatedKeysAndValues.put(intKey, String.valueOf(updatedIntValue));
271275

272276
crashlyticsCore.setCustomKeys(updatedKeysAndValues);
273-
crashlyticsCore.commonWorker.await();
277+
commonWorker.await();
274278

275279
assertEquals(updatedStringValue, metadata.getCustomKeys().get(stringKey));
276280
assertFalse(Boolean.parseBoolean(metadata.getCustomKeys().get(booleanKey)));
@@ -443,8 +447,8 @@ CrashlyticsCore build(Context context) {
443447
new FileStore(context),
444448
mock(CrashlyticsAppQualitySessionsSubscriber.class),
445449
mock(RemoteConfigDeferredProxy.class),
446-
new CrashlyticsWorker(TestOnlyExecutors.background()),
447-
new CrashlyticsWorker(TestOnlyExecutors.background()));
450+
commonWorker,
451+
diskWriteWorker);
448452
return crashlyticsCore;
449453
}
450454
}

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsCore.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ public class CrashlyticsCore {
9696

9797
private final RemoteConfigDeferredProxy remoteConfigDeferredProxy;
9898

99-
@VisibleForTesting final CrashlyticsWorker commonWorker;
100-
@VisibleForTesting final CrashlyticsWorker diskWriteWorker;
99+
private final CrashlyticsWorker commonWorker;
100+
private final CrashlyticsWorker diskWriteWorker;
101101

102102
// region Constructors
103103

@@ -338,7 +338,11 @@ public void logException(@NonNull Throwable throwable) {
338338
*/
339339
public void log(final String msg) {
340340
final long timestamp = System.currentTimeMillis() - startTime;
341-
diskWriteWorker.submit(() -> controller.writeToLog(timestamp, msg));
341+
// queuing up on common worker to maintain the order
342+
commonWorker.submit(
343+
() -> {
344+
diskWriteWorker.submit(() -> controller.writeToLog(timestamp, msg));
345+
});
342346
}
343347

344348
public void setUserId(String identifier) {

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/CrashlyticsLifecycleEvents.java

Lines changed: 0 additions & 28 deletions
This file was deleted.

firebase-crashlytics/src/main/java/com/google/firebase/crashlytics/internal/common/SessionReportingCoordinator.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@
4848
import java.util.concurrent.Executor;
4949

5050
/**
51-
* This class handles Crashlytics lifecycle events and coordinates session data capture and
51+
* This class coordinates Crashlytics session data capture and
5252
* persistence, as well as sending of reports to Firebase Crashlytics.
5353
*/
54-
public class SessionReportingCoordinator implements CrashlyticsLifecycleEvents {
54+
public class SessionReportingCoordinator {
5555

5656
private static final String EVENT_TYPE_CRASH = "crash";
5757
private static final String EVENT_TYPE_LOGGED = "error";
@@ -95,7 +95,7 @@ public static SessionReportingCoordinator create(
9595
private final UserMetadata reportMetadata;
9696
private final IdManager idManager;
9797

98-
final CrashlyticsWorker diskWriteWorker;
98+
private final CrashlyticsWorker diskWriteWorker;
9999

100100
SessionReportingCoordinator(
101101
CrashlyticsReportDataCapture dataCapture,
@@ -114,7 +114,6 @@ public static SessionReportingCoordinator create(
114114
this.diskWriteWorker = diskWriteWorker;
115115
}
116116

117-
@Override
118117
public void onBeginSession(@NonNull String sessionId, long timestampSeconds) {
119118
final CrashlyticsReport capturedReport =
120119
dataCapture.captureReportData(sessionId, timestampSeconds);
@@ -323,7 +322,7 @@ private void persistEvent(
323322
@NonNull String sessionId,
324323
@NonNull String eventType,
325324
long timestamp,
326-
boolean includeAllThreads) {
325+
boolean isFatal) {
327326

328327
final boolean isHighPriority = eventType.equals(EVENT_TYPE_CRASH);
329328

@@ -335,12 +334,11 @@ private void persistEvent(
335334
timestamp,
336335
EVENT_THREAD_IMPORTANCE,
337336
MAX_CHAINED_EXCEPTION_DEPTH,
338-
includeAllThreads);
337+
isFatal);
339338
CrashlyticsReport.Session.Event finallizedEvent = addMetaDataToEvent(capturedEvent);
340339

341-
// Non-fatal case, non-fatal does not include all threads
342-
// We move to diskWriteWorker for persistence
343-
if (!includeAllThreads) {
340+
// Non-fatal, persistence write task we move to diskWriteWorker
341+
if (!isFatal) {
344342
diskWriteWorker.submit(
345343
() -> {
346344
reportPersistence.persistEvent(finallizedEvent, sessionId, isHighPriority);

0 commit comments

Comments
 (0)