View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.util;
15  
16  
17  import java.io.BufferedReader;
18  import java.io.FileReader;
19  import java.io.IOException;
20  import java.util.regex.Matcher;
21  import java.util.regex.Pattern;
22  
23  public class ResilienceUtil {
24  
25      static public int countLines(String logfile, String regexp)
26              throws NumberFormatException, IOException {
27          FileReader fr = new FileReader(logfile);
28          BufferedReader br = new BufferedReader(fr);
29          Pattern p = Pattern.compile(regexp);
30          String line;
31  
32          int totalLines = 0;
33          int oldNum = -1;
34          int gaps = 0;
35          while ((line = br.readLine()) != null) {
36              Matcher m = p.matcher(line);
37              if (m.matches()) {
38                  totalLines++;
39                  String g = m.group(1);
40                  int num = Integer.parseInt(g);
41                  if (oldNum != -1 && num != oldNum + 1) {
42                      gaps++;
43                  }
44                  oldNum = num;
45              }
46          }
47          fr.close();
48          br.close();
49  
50          return totalLines;
51          
52  //        int lowerLimit = (int) (totalSteps * successRatioLowerBound);
53  //        assertTrue("totalLines=" + totalLines + " less than " + lowerLimit, totalLines > lowerLimit);
54  //
55  //        // we want at least one gap indicating recuperation
56  //        assertTrue("gaps=" + gaps + " less than 1", gaps >= 1);
57  
58      }
59  }