Coverage Report - org.apache.maven.surefire.booter.ForkTimeout
 
Classes in this File Line Coverage Branch Coverage Complexity
ForkTimeout
0%
0/7
N/A
1
ForkTimeout$SurefireTimeoutMonitor
0%
0/7
N/A
1
 
 1  
 package org.apache.maven.surefire.booter;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *     http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import org.apache.maven.surefire.providerapi.SurefireProvider;
 23  
 import org.apache.maven.surefire.report.ReporterConfiguration;
 24  
 
 25  
 import java.util.Timer;
 26  
 import java.util.TimerTask;
 27  
 
 28  
 /**
 29  
  * Handles timeout of the forked process. Basically disables reporting
 30  
  * when the timeout has expired, to avoid leaving incorrect files on disk.
 31  
  *
 32  
  * @author Kristian Rosenvold
 33  
  */
 34  
 class ForkTimeout
 35  
 {
 36  
 
 37  
     private final Timer timer;
 38  
 
 39  
 
 40  
     ForkTimeout( int timeOutInMs, ReporterConfiguration reporterConfiguration, SurefireProvider surefireProvider )
 41  0
     {
 42  0
         SurefireTimeoutMonitor timeoutTask = new SurefireTimeoutMonitor( reporterConfiguration, surefireProvider );
 43  0
         timer = new Timer( "Surefire fork timeout timer" );
 44  0
         timer.schedule( timeoutTask, timeOutInMs );
 45  0
     }
 46  
 
 47  
     public void close()
 48  
     {
 49  0
         timer.cancel();
 50  0
     }
 51  
 
 52  
     private static class SurefireTimeoutMonitor
 53  
         extends TimerTask
 54  
     {
 55  
         private final ReporterConfiguration reporterConfiguration;
 56  
         private final SurefireProvider surefireProvider;
 57  
 
 58  
 
 59  
         public SurefireTimeoutMonitor( ReporterConfiguration reporterConfiguration, SurefireProvider surefireProvider )
 60  0
         {
 61  0
             this.reporterConfiguration = reporterConfiguration;
 62  0
             this.surefireProvider = surefireProvider;
 63  0
         }
 64  
 
 65  
         public void run()
 66  
         {
 67  0
             reporterConfiguration.setTimedOut( true );
 68  0
             surefireProvider.cancel();
 69  0
         }
 70  
     }
 71  
 
 72  
 }