@@ -70,6 +70,10 @@ public void whenAvailable(
70
70
71
71
private CrashlyticsCore crashlyticsCore ;
72
72
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 ());
73
77
74
78
@ Override
75
79
protected void setUp () throws Exception {
@@ -93,7 +97,7 @@ public void testCustomAttributes() throws Exception {
93
97
94
98
final String id = "id012345" ;
95
99
crashlyticsCore .setUserId (id );
96
- crashlyticsCore . commonWorker .await ();
100
+ commonWorker .await ();
97
101
assertEquals (id , metadata .getUserId ());
98
102
99
103
final StringBuffer idBuffer = new StringBuffer (id );
@@ -104,13 +108,13 @@ public void testCustomAttributes() throws Exception {
104
108
final String superLongId = longId + "more chars" ;
105
109
106
110
crashlyticsCore .setUserId (superLongId );
107
- crashlyticsCore . commonWorker .await ();
111
+ commonWorker .await ();
108
112
assertEquals (longId , metadata .getUserId ());
109
113
110
114
final String key1 = "key1" ;
111
115
final String value1 = "value1" ;
112
116
crashlyticsCore .setCustomKey (key1 , value1 );
113
- crashlyticsCore . commonWorker .await ();
117
+ commonWorker .await ();
114
118
assertEquals (value1 , metadata .getCustomKeys ().get (key1 ));
115
119
116
120
// Adding an existing key with the same value should return false
@@ -124,7 +128,7 @@ public void testCustomAttributes() throws Exception {
124
128
125
129
// test truncation of custom keys and attributes
126
130
crashlyticsCore .setCustomKey (superLongId , superLongValue );
127
- crashlyticsCore . commonWorker .await ();
131
+ commonWorker .await ();
128
132
assertNull (metadata .getCustomKeys ().get (superLongId ));
129
133
assertEquals (longValue , metadata .getCustomKeys ().get (longId ));
130
134
@@ -133,28 +137,28 @@ public void testCustomAttributes() throws Exception {
133
137
final String key = "key" + i ;
134
138
final String value = "value" + i ;
135
139
crashlyticsCore .setCustomKey (key , value );
136
- crashlyticsCore . commonWorker .await ();
140
+ commonWorker .await ();
137
141
assertEquals (value , metadata .getCustomKeys ().get (key ));
138
142
}
139
143
// should be full now, extra key, value pairs will be dropped.
140
144
final String key = "new key" ;
141
145
crashlyticsCore .setCustomKey (key , "some value" );
142
- crashlyticsCore . commonWorker .await ();
146
+ commonWorker .await ();
143
147
assertFalse (metadata .getCustomKeys ().containsKey (key ));
144
148
145
149
// should be able to update existing keys
146
150
crashlyticsCore .setCustomKey (key1 , longValue );
147
- crashlyticsCore . commonWorker .await ();
151
+ commonWorker .await ();
148
152
assertEquals (longValue , metadata .getCustomKeys ().get (key1 ));
149
153
150
154
// when we set a key to null, it should still exist with an empty value
151
155
crashlyticsCore .setCustomKey (key1 , null );
152
- crashlyticsCore . commonWorker .await ();
156
+ commonWorker .await ();
153
157
assertEquals ("" , metadata .getCustomKeys ().get (key1 ));
154
158
155
159
// keys and values are trimmed.
156
160
crashlyticsCore .setCustomKey (" " + key1 + " " , " " + longValue + " " );
157
- crashlyticsCore . commonWorker .await ();
161
+ commonWorker .await ();
158
162
assertTrue (metadata .getCustomKeys ().containsKey (key1 ));
159
163
assertEquals (longValue , metadata .getCustomKeys ().get (key1 ));
160
164
}
@@ -205,7 +209,7 @@ public void testBulkCustomKeys() throws Exception {
205
209
keysAndValues .put (intKey , String .valueOf (intValue ));
206
210
207
211
crashlyticsCore .setCustomKeys (keysAndValues );
208
- crashlyticsCore . commonWorker .await ();
212
+ commonWorker .await ();
209
213
210
214
assertEquals (stringValue , metadata .getCustomKeys ().get (stringKey ));
211
215
assertEquals (trimmedValue , metadata .getCustomKeys ().get (trimmedKey ));
@@ -226,7 +230,7 @@ public void testBulkCustomKeys() throws Exception {
226
230
addlKeysAndValues .put (key , value );
227
231
}
228
232
crashlyticsCore .setCustomKeys (addlKeysAndValues );
229
- crashlyticsCore . commonWorker .await ();
233
+ commonWorker .await ();
230
234
231
235
// Ensure all keys have been set
232
236
assertEquals (UserMetadata .MAX_ATTRIBUTES , metadata .getCustomKeys ().size (), DELTA );
@@ -244,7 +248,7 @@ public void testBulkCustomKeys() throws Exception {
244
248
extraKeysAndValues .put (key , value );
245
249
}
246
250
crashlyticsCore .setCustomKeys (extraKeysAndValues );
247
- crashlyticsCore . commonWorker .await ();
251
+ commonWorker .await ();
248
252
249
253
// Make sure the extra keys were not added
250
254
for (int i = UserMetadata .MAX_ATTRIBUTES ; i < UserMetadata .MAX_ATTRIBUTES + 10 ; ++i ) {
@@ -270,7 +274,7 @@ public void testBulkCustomKeys() throws Exception {
270
274
updatedKeysAndValues .put (intKey , String .valueOf (updatedIntValue ));
271
275
272
276
crashlyticsCore .setCustomKeys (updatedKeysAndValues );
273
- crashlyticsCore . commonWorker .await ();
277
+ commonWorker .await ();
274
278
275
279
assertEquals (updatedStringValue , metadata .getCustomKeys ().get (stringKey ));
276
280
assertFalse (Boolean .parseBoolean (metadata .getCustomKeys ().get (booleanKey )));
@@ -443,8 +447,8 @@ CrashlyticsCore build(Context context) {
443
447
new FileStore (context ),
444
448
mock (CrashlyticsAppQualitySessionsSubscriber .class ),
445
449
mock (RemoteConfigDeferredProxy .class ),
446
- new CrashlyticsWorker ( TestOnlyExecutors . background ()) ,
447
- new CrashlyticsWorker ( TestOnlyExecutors . background ()) );
450
+ commonWorker ,
451
+ diskWriteWorker );
448
452
return crashlyticsCore ;
449
453
}
450
454
}
0 commit comments