import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
// check that force stop tracing was requested
verify(mgr1).forceStopTracing();
}
+
+ /**
+ * Check manager stops all running tracing processes.
+ */
+ @Test
+ public void stopAll() throws Exception {
+ setupManagers();
+
+ // start processes
+ pm.startTracing(args1);
+ pm.startTracing(args2);
+
+ // setup answers on stop signals that finalize corresponding tracing context
+ Answer<Boolean> finalizeContext1 = new Answer<Boolean>() {
+ @Override
+ public Boolean answer(InvocationOnMock invocation) throws Throwable {
+ ctx1.finishContext(100500);
+ when(mgr1.isFinished()).thenReturn(true);
+ return true;
+ }
+ }, finalizeContext2 = new Answer<Boolean>() {
+ @Override
+ public Boolean answer(InvocationOnMock invocation) throws Throwable {
+ ctx2.finishContext(100500);
+ when(mgr2.isFinished()).thenReturn(true);
+ return true;
+ }
+ };
+
+ // we don't know exactly which API method will be used, therefore mock both
+ doAnswer(finalizeContext1).when(mgr1).stopTracing();
+ doAnswer(finalizeContext1).when(mgr1).stopTracing(Mockito.anyLong());
+
+ doAnswer(finalizeContext2).when(mgr2).stopTracing();
+ doAnswer(finalizeContext2).when(mgr2).stopTracing(Mockito.anyLong());
+
+ // request stop
+ DAResult result = pm.stopAll();
+
+ // check results
+ assertEquals(ErrorCode.SUCCESS.getErrorNumber(), result.getErrorNumber());
+
+ assertTrue(ctx1.isFinished());
+ assertTrue(ctx2.isFinished());
+ }
}