3333import com .google .firebase .perf .session .gauges .GaugeManager ;
3434import com .google .firebase .perf .util .Clock ;
3535import com .google .firebase .perf .util .Timer ;
36+ import com .google .firebase .perf .v1 .ApplicationProcessState ;
3637import java .lang .ref .WeakReference ;
3738import java .util .concurrent .ExecutionException ;
3839import java .util .concurrent .TimeUnit ;
@@ -82,21 +83,20 @@ public void setApplicationContext_logGaugeMetadata_afterGaugeMetadataManagerIsIn
8283 testSessionManager .setApplicationContext (mockApplicationContext );
8384
8485 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 () );
8788 }
8889
8990 @ Test
9091 public void testOnUpdateAppStateDoesNothingDuringAppStart () {
9192 String oldSessionId = SessionManager .getInstance ().perfSession ().sessionId ();
92- assertThat (oldSessionId ).isNotNull ();
9393
9494 assertThat (oldSessionId ).isNotNull ();
9595 assertThat (oldSessionId ).isEqualTo (SessionManager .getInstance ().perfSession ().sessionId ());
9696
9797 AppStateMonitor .getInstance ().setIsColdStart (true );
9898
99- // SessionManager.getInstance().onUpdateAppState(ApplicationProcessState.FOREGROUND);
99+ SessionManager .getInstance ().onUpdateAppState (ApplicationProcessState .FOREGROUND );
100100 assertThat (oldSessionId ).isEqualTo (SessionManager .getInstance ().perfSession ().sessionId ());
101101 }
102102
@@ -107,7 +107,7 @@ public void testOnUpdateAppStateGeneratesNewSessionIdOnForegroundState() {
107107 assertThat (oldSessionId ).isNotNull ();
108108 assertThat (oldSessionId ).isEqualTo (SessionManager .getInstance ().perfSession ().sessionId ());
109109
110- // SessionManager.getInstance().onUpdateAppState(ApplicationProcessState.FOREGROUND);
110+ SessionManager .getInstance ().onUpdateAppState (ApplicationProcessState .FOREGROUND );
111111 assertThat (oldSessionId ).isNotEqualTo (SessionManager .getInstance ().perfSession ().sessionId ());
112112 }
113113
@@ -118,7 +118,7 @@ public void testOnUpdateAppStateDoesntGenerateNewSessionIdOnBackgroundState() {
118118 assertThat (oldSessionId ).isNotNull ();
119119 assertThat (oldSessionId ).isEqualTo (SessionManager .getInstance ().perfSession ().sessionId ());
120120
121- // SessionManager.getInstance().onUpdateAppState(ApplicationProcessState.BACKGROUND);
121+ SessionManager .getInstance ().onUpdateAppState (ApplicationProcessState .BACKGROUND );
122122 assertThat (oldSessionId ).isEqualTo (SessionManager .getInstance ().perfSession ().sessionId ());
123123 }
124124
@@ -132,32 +132,18 @@ public void testOnUpdateAppStateGeneratesNewSessionIdOnBackgroundStateIfPerfSess
132132 assertThat (oldSessionId ).isNotNull ();
133133 assertThat (oldSessionId ).isEqualTo (testSessionManager .perfSession ().sessionId ());
134134
135- // testSessionManager.onUpdateAppState(ApplicationProcessState.BACKGROUND);
135+ testSessionManager .onUpdateAppState (ApplicationProcessState .BACKGROUND );
136136 assertThat (oldSessionId ).isNotEqualTo (testSessionManager .perfSession ().sessionId ());
137137 }
138138
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-
153139 @ Test
154140 public void
155141 testOnUpdateAppStateDoesntMakeGaugeManagerLogGaugeMetadataOnForegroundStateIfSessionIsNonVerbose () {
156142 forceNonVerboseSession ();
157143
158144 SessionManager testSessionManager =
159145 new SessionManager (mockGaugeManager , mockPerfSession , mockAppStateMonitor );
160- // testSessionManager.onUpdateAppState(ApplicationProcessState.FOREGROUND);
146+ testSessionManager .onUpdateAppState (ApplicationProcessState .FOREGROUND );
161147
162148 verify (mockGaugeManager , never ())
163149 .logGaugeMetadata (
@@ -171,35 +157,20 @@ public void testOnUpdateAppStateGeneratesNewSessionIdOnBackgroundStateIfPerfSess
171157
172158 SessionManager testSessionManager =
173159 new SessionManager (mockGaugeManager , mockPerfSession , mockAppStateMonitor );
174- // testSessionManager.onUpdateAppState(ApplicationProcessState.BACKGROUND);
160+ testSessionManager .onUpdateAppState (ApplicationProcessState .BACKGROUND );
175161
176162 verify (mockGaugeManager , never ())
177163 .logGaugeMetadata (
178164 anyString (), nullable (com .google .firebase .perf .v1 .ApplicationProcessState .class ));
179165 }
180166
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-
196167 @ Test
197168 public void testOnUpdateAppStateMakesGaugeManagerStartCollectingGaugesIfSessionIsVerbose () {
198169 forceVerboseSession ();
199170
200171 SessionManager testSessionManager =
201172 new SessionManager (mockGaugeManager , mockPerfSession , mockAppStateMonitor );
202- // testSessionManager.onUpdateAppState(ApplicationProcessState.FOREGROUND);
173+ testSessionManager .onUpdateAppState (ApplicationProcessState .FOREGROUND );
203174
204175 verify (mockGaugeManager )
205176 .startCollectingGauges (AdditionalMatchers .not (eq (mockPerfSession )), any ());
@@ -215,7 +186,7 @@ public void testOnUpdateAppStateMakesGaugeManagerStopCollectingGaugesIfSessionIs
215186
216187 SessionManager testSessionManager =
217188 new SessionManager (mockGaugeManager , mockPerfSession , mockAppStateMonitor );
218- testSessionManager .updatePerfSession (PerfSession .createNewSession ( ));
189+ testSessionManager .updatePerfSession (PerfSession .createWithId ( "testSessionId" ));
219190
220191 verify (mockGaugeManager ).stopCollectingGauges ();
221192 }
@@ -225,37 +196,13 @@ public void testOnUpdateAppStateMakesGaugeManagerStopCollectingGaugesWhenSession
225196 forceSessionsFeatureDisabled ();
226197
227198 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" ));
230202
231203 verify (mockGaugeManager ).stopCollectingGauges ();
232204 }
233205
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-
259206 @ Test
260207 public void testSessionIdDoesNotUpdateIfPerfSessionRunsTooLong () {
261208 Timer mockTimer = mock (Timer .class );
@@ -301,7 +248,7 @@ public void testPerfSession_sessionAwareObjects_doesntNotifyIfNotRegistered() {
301248 FakeSessionAwareObject spySessionAwareObjectOne = spy (new FakeSessionAwareObject ());
302249 FakeSessionAwareObject spySessionAwareObjectTwo = spy (new FakeSessionAwareObject ());
303250
304- testSessionManager .updatePerfSession (PerfSession .createNewSession ( ));
251+ testSessionManager .updatePerfSession (PerfSession .createWithId ( "testSessionId1" ));
305252
306253 verify (spySessionAwareObjectOne , never ())
307254 .updateSession (ArgumentMatchers .nullable (PerfSession .class ));
@@ -320,8 +267,8 @@ public void testPerfSession_sessionAwareObjects_NotifiesIfRegistered() {
320267 testSessionManager .registerForSessionUpdates (new WeakReference <>(spySessionAwareObjectOne ));
321268 testSessionManager .registerForSessionUpdates (new WeakReference <>(spySessionAwareObjectTwo ));
322269
323- testSessionManager .updatePerfSession (PerfSession .createNewSession ( ));
324- testSessionManager .updatePerfSession (PerfSession .createNewSession ( ));
270+ testSessionManager .updatePerfSession (PerfSession .createWithId ( "testSessionId1" ));
271+ testSessionManager .updatePerfSession (PerfSession .createWithId ( "testSessionId2" ));
325272
326273 verify (spySessionAwareObjectOne , times (2 ))
327274 .updateSession (ArgumentMatchers .nullable (PerfSession .class ));
@@ -345,11 +292,11 @@ public void testPerfSession_sessionAwareObjects_DoesNotNotifyIfUnregistered() {
345292 testSessionManager .registerForSessionUpdates (weakSpySessionAwareObjectOne );
346293 testSessionManager .registerForSessionUpdates (weakSpySessionAwareObjectTwo );
347294
348- testSessionManager .updatePerfSession (PerfSession .createNewSession ( ));
295+ testSessionManager .updatePerfSession (PerfSession .createWithId ( "testSessionId1" ));
349296
350297 testSessionManager .unregisterForSessionUpdates (weakSpySessionAwareObjectOne );
351298 testSessionManager .unregisterForSessionUpdates (weakSpySessionAwareObjectTwo );
352- testSessionManager .updatePerfSession (PerfSession .createNewSession ( ));
299+ testSessionManager .updatePerfSession (PerfSession .createWithId ( "testSessionId2" ));
353300
354301 verify (spySessionAwareObjectOne , times (1 ))
355302 .updateSession (ArgumentMatchers .nullable (PerfSession .class ));
0 commit comments