33
33
import com .google .firebase .perf .session .gauges .GaugeManager ;
34
34
import com .google .firebase .perf .util .Clock ;
35
35
import com .google .firebase .perf .util .Timer ;
36
+ import com .google .firebase .perf .v1 .ApplicationProcessState ;
36
37
import java .lang .ref .WeakReference ;
37
38
import java .util .concurrent .ExecutionException ;
38
39
import java .util .concurrent .TimeUnit ;
@@ -82,21 +83,20 @@ public void setApplicationContext_logGaugeMetadata_afterGaugeMetadataManagerIsIn
82
83
testSessionManager .setApplicationContext (mockApplicationContext );
83
84
84
85
testSessionManager .getSyncInitFuture ().get ();
85
- inOrder .verify (mockGaugeManager ).initializeGaugeMetadataManager (any (), any () );
86
- inOrder .verify (mockGaugeManager ).logGaugeMetadata (any ());
86
+ inOrder .verify (mockGaugeManager ).initializeGaugeMetadataManager (any ());
87
+ inOrder .verify (mockGaugeManager ).logGaugeMetadata (any (), any () );
87
88
}
88
89
89
90
@ Test
90
91
public void testOnUpdateAppStateDoesNothingDuringAppStart () {
91
92
String oldSessionId = SessionManager .getInstance ().perfSession ().sessionId ();
92
- assertThat (oldSessionId ).isNotNull ();
93
93
94
94
assertThat (oldSessionId ).isNotNull ();
95
95
assertThat (oldSessionId ).isEqualTo (SessionManager .getInstance ().perfSession ().sessionId ());
96
96
97
97
AppStateMonitor .getInstance ().setIsColdStart (true );
98
98
99
- // SessionManager.getInstance().onUpdateAppState(ApplicationProcessState.FOREGROUND);
99
+ SessionManager .getInstance ().onUpdateAppState (ApplicationProcessState .FOREGROUND );
100
100
assertThat (oldSessionId ).isEqualTo (SessionManager .getInstance ().perfSession ().sessionId ());
101
101
}
102
102
@@ -107,7 +107,7 @@ public void testOnUpdateAppStateGeneratesNewSessionIdOnForegroundState() {
107
107
assertThat (oldSessionId ).isNotNull ();
108
108
assertThat (oldSessionId ).isEqualTo (SessionManager .getInstance ().perfSession ().sessionId ());
109
109
110
- // SessionManager.getInstance().onUpdateAppState(ApplicationProcessState.FOREGROUND);
110
+ SessionManager .getInstance ().onUpdateAppState (ApplicationProcessState .FOREGROUND );
111
111
assertThat (oldSessionId ).isNotEqualTo (SessionManager .getInstance ().perfSession ().sessionId ());
112
112
}
113
113
@@ -118,7 +118,7 @@ public void testOnUpdateAppStateDoesntGenerateNewSessionIdOnBackgroundState() {
118
118
assertThat (oldSessionId ).isNotNull ();
119
119
assertThat (oldSessionId ).isEqualTo (SessionManager .getInstance ().perfSession ().sessionId ());
120
120
121
- // SessionManager.getInstance().onUpdateAppState(ApplicationProcessState.BACKGROUND);
121
+ SessionManager .getInstance ().onUpdateAppState (ApplicationProcessState .BACKGROUND );
122
122
assertThat (oldSessionId ).isEqualTo (SessionManager .getInstance ().perfSession ().sessionId ());
123
123
}
124
124
@@ -132,32 +132,18 @@ public void testOnUpdateAppStateGeneratesNewSessionIdOnBackgroundStateIfPerfSess
132
132
assertThat (oldSessionId ).isNotNull ();
133
133
assertThat (oldSessionId ).isEqualTo (testSessionManager .perfSession ().sessionId ());
134
134
135
- // testSessionManager.onUpdateAppState(ApplicationProcessState.BACKGROUND);
135
+ testSessionManager .onUpdateAppState (ApplicationProcessState .BACKGROUND );
136
136
assertThat (oldSessionId ).isNotEqualTo (testSessionManager .perfSession ().sessionId ());
137
137
}
138
138
139
- @ Test
140
- public void
141
- testOnUpdateAppStateMakesGaugeManagerLogGaugeMetadataOnForegroundStateIfSessionIsVerbose () {
142
- forceVerboseSession ();
143
-
144
- SessionManager testSessionManager =
145
- new SessionManager (mockGaugeManager , mockPerfSession , mockAppStateMonitor );
146
- // testSessionManager.onUpdateAppState(ApplicationProcessState.FOREGROUND);
147
-
148
- verify (mockGaugeManager )
149
- .logGaugeMetadata (
150
- anyString (), nullable (com .google .firebase .perf .v1 .ApplicationProcessState .class ));
151
- }
152
-
153
139
@ Test
154
140
public void
155
141
testOnUpdateAppStateDoesntMakeGaugeManagerLogGaugeMetadataOnForegroundStateIfSessionIsNonVerbose () {
156
142
forceNonVerboseSession ();
157
143
158
144
SessionManager testSessionManager =
159
145
new SessionManager (mockGaugeManager , mockPerfSession , mockAppStateMonitor );
160
- // testSessionManager.onUpdateAppState(ApplicationProcessState.FOREGROUND);
146
+ testSessionManager .onUpdateAppState (ApplicationProcessState .FOREGROUND );
161
147
162
148
verify (mockGaugeManager , never ())
163
149
.logGaugeMetadata (
@@ -171,35 +157,20 @@ public void testOnUpdateAppStateGeneratesNewSessionIdOnBackgroundStateIfPerfSess
171
157
172
158
SessionManager testSessionManager =
173
159
new SessionManager (mockGaugeManager , mockPerfSession , mockAppStateMonitor );
174
- // testSessionManager.onUpdateAppState(ApplicationProcessState.BACKGROUND);
160
+ testSessionManager .onUpdateAppState (ApplicationProcessState .BACKGROUND );
175
161
176
162
verify (mockGaugeManager , never ())
177
163
.logGaugeMetadata (
178
164
anyString (), nullable (com .google .firebase .perf .v1 .ApplicationProcessState .class ));
179
165
}
180
166
181
- @ Test
182
- public void
183
- testOnUpdateAppStateMakesGaugeManagerLogGaugeMetadataOnBackgroundAppStateIfSessionIsVerboseAndTimedOut () {
184
- when (mockPerfSession .isSessionRunningTooLong ()).thenReturn (true );
185
- forceVerboseSession ();
186
-
187
- SessionManager testSessionManager =
188
- new SessionManager (mockGaugeManager , mockPerfSession , mockAppStateMonitor );
189
- // testSessionManager.onUpdateAppState(ApplicationProcessState.BACKGROUND);
190
-
191
- verify (mockGaugeManager )
192
- .logGaugeMetadata (
193
- anyString (), nullable (com .google .firebase .perf .v1 .ApplicationProcessState .class ));
194
- }
195
-
196
167
@ Test
197
168
public void testOnUpdateAppStateMakesGaugeManagerStartCollectingGaugesIfSessionIsVerbose () {
198
169
forceVerboseSession ();
199
170
200
171
SessionManager testSessionManager =
201
172
new SessionManager (mockGaugeManager , mockPerfSession , mockAppStateMonitor );
202
- // testSessionManager.onUpdateAppState(ApplicationProcessState.FOREGROUND);
173
+ testSessionManager .onUpdateAppState (ApplicationProcessState .FOREGROUND );
203
174
204
175
verify (mockGaugeManager )
205
176
.startCollectingGauges (AdditionalMatchers .not (eq (mockPerfSession )), any ());
@@ -215,7 +186,7 @@ public void testOnUpdateAppStateMakesGaugeManagerStopCollectingGaugesIfSessionIs
215
186
216
187
SessionManager testSessionManager =
217
188
new SessionManager (mockGaugeManager , mockPerfSession , mockAppStateMonitor );
218
- testSessionManager .updatePerfSession (PerfSession .createNewSession ( ));
189
+ testSessionManager .updatePerfSession (PerfSession .createWithId ( "testSessionId" ));
219
190
220
191
verify (mockGaugeManager ).stopCollectingGauges ();
221
192
}
@@ -225,37 +196,13 @@ public void testOnUpdateAppStateMakesGaugeManagerStopCollectingGaugesWhenSession
225
196
forceSessionsFeatureDisabled ();
226
197
227
198
SessionManager testSessionManager =
228
- new SessionManager (mockGaugeManager , PerfSession .createNewSession (), mockAppStateMonitor );
229
- testSessionManager .updatePerfSession (PerfSession .createNewSession ());
199
+ new SessionManager (
200
+ mockGaugeManager , PerfSession .createWithId ("testSessionId" ), mockAppStateMonitor );
201
+ testSessionManager .updatePerfSession (PerfSession .createWithId ("testSessionId2" ));
230
202
231
203
verify (mockGaugeManager ).stopCollectingGauges ();
232
204
}
233
205
234
- @ Test
235
- public void testGaugeMetadataIsFlushedOnlyWhenNewVerboseSessionIsCreated () {
236
- when (mockPerfSession .isSessionRunningTooLong ()).thenReturn (false );
237
-
238
- // Start with a non verbose session
239
- forceNonVerboseSession ();
240
- SessionManager testSessionManager =
241
- new SessionManager (mockGaugeManager , PerfSession .createNewSession (), mockAppStateMonitor );
242
-
243
- verify (mockGaugeManager , times (0 ))
244
- .logGaugeMetadata (
245
- eq ("testSessionId1" ),
246
- eq (com .google .firebase .perf .v1 .ApplicationProcessState .FOREGROUND ));
247
-
248
- // Forcing a verbose session will enable Gauge collection
249
- forceVerboseSession ();
250
- testSessionManager .updatePerfSession (PerfSession .createNewSession ());
251
- verify (mockGaugeManager , times (1 )).logGaugeMetadata (eq ("testSessionId2" ), any ());
252
-
253
- // Force a non-verbose session and verify if we are not logging metadata
254
- forceVerboseSession ();
255
- testSessionManager .updatePerfSession (PerfSession .createNewSession ());
256
- verify (mockGaugeManager , times (1 )).logGaugeMetadata (eq ("testSessionId3" ), any ());
257
- }
258
-
259
206
@ Test
260
207
public void testSessionIdDoesNotUpdateIfPerfSessionRunsTooLong () {
261
208
Timer mockTimer = mock (Timer .class );
@@ -301,7 +248,7 @@ public void testPerfSession_sessionAwareObjects_doesntNotifyIfNotRegistered() {
301
248
FakeSessionAwareObject spySessionAwareObjectOne = spy (new FakeSessionAwareObject ());
302
249
FakeSessionAwareObject spySessionAwareObjectTwo = spy (new FakeSessionAwareObject ());
303
250
304
- testSessionManager .updatePerfSession (PerfSession .createNewSession ( ));
251
+ testSessionManager .updatePerfSession (PerfSession .createWithId ( "testSessionId1" ));
305
252
306
253
verify (spySessionAwareObjectOne , never ())
307
254
.updateSession (ArgumentMatchers .nullable (PerfSession .class ));
@@ -320,8 +267,8 @@ public void testPerfSession_sessionAwareObjects_NotifiesIfRegistered() {
320
267
testSessionManager .registerForSessionUpdates (new WeakReference <>(spySessionAwareObjectOne ));
321
268
testSessionManager .registerForSessionUpdates (new WeakReference <>(spySessionAwareObjectTwo ));
322
269
323
- testSessionManager .updatePerfSession (PerfSession .createNewSession ( ));
324
- testSessionManager .updatePerfSession (PerfSession .createNewSession ( ));
270
+ testSessionManager .updatePerfSession (PerfSession .createWithId ( "testSessionId1" ));
271
+ testSessionManager .updatePerfSession (PerfSession .createWithId ( "testSessionId2" ));
325
272
326
273
verify (spySessionAwareObjectOne , times (2 ))
327
274
.updateSession (ArgumentMatchers .nullable (PerfSession .class ));
@@ -345,11 +292,11 @@ public void testPerfSession_sessionAwareObjects_DoesNotNotifyIfUnregistered() {
345
292
testSessionManager .registerForSessionUpdates (weakSpySessionAwareObjectOne );
346
293
testSessionManager .registerForSessionUpdates (weakSpySessionAwareObjectTwo );
347
294
348
- testSessionManager .updatePerfSession (PerfSession .createNewSession ( ));
295
+ testSessionManager .updatePerfSession (PerfSession .createWithId ( "testSessionId1" ));
349
296
350
297
testSessionManager .unregisterForSessionUpdates (weakSpySessionAwareObjectOne );
351
298
testSessionManager .unregisterForSessionUpdates (weakSpySessionAwareObjectTwo );
352
- testSessionManager .updatePerfSession (PerfSession .createNewSession ( ));
299
+ testSessionManager .updatePerfSession (PerfSession .createWithId ( "testSessionId2" ));
353
300
354
301
verify (spySessionAwareObjectOne , times (1 ))
355
302
.updateSession (ArgumentMatchers .nullable (PerfSession .class ));
0 commit comments