| 5827 |
amar.kumar |
1 |
/*
|
|
|
2 |
* Copyright 2005 stat4j.org
|
|
|
3 |
*
|
|
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
* you may not use this file except in compliance with the License.
|
|
|
6 |
* You may obtain a copy of the License at
|
|
|
7 |
*
|
|
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
*
|
|
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
* See the License for the specific language governing permissions and
|
|
|
14 |
* limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
package net.sourceforge.stat4j.test;
|
|
|
18 |
|
|
|
19 |
import java.net.URL;
|
|
|
20 |
|
|
|
21 |
import junit.framework.TestCase;
|
|
|
22 |
|
|
|
23 |
import net.sourceforge.stat4j.filter.MetricCollector;
|
|
|
24 |
|
|
|
25 |
import org.apache.log4j.Category;
|
|
|
26 |
import org.apache.log4j.PropertyConfigurator;
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Name: TestRate.java
|
|
|
31 |
* Date: Sep 6, 2004
|
|
|
32 |
* Description:
|
|
|
33 |
*
|
|
|
34 |
*
|
|
|
35 |
* @author Lara D'Abreo
|
|
|
36 |
*/
|
|
|
37 |
public class TestRate extends TestCase {
|
|
|
38 |
|
|
|
39 |
public Category category;
|
|
|
40 |
/**
|
|
|
41 |
*
|
|
|
42 |
*/
|
|
|
43 |
public TestRate() {
|
|
|
44 |
super();
|
|
|
45 |
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* @param arg0
|
|
|
50 |
*/
|
|
|
51 |
public TestRate(String arg0) {
|
|
|
52 |
super(arg0);
|
|
|
53 |
URL url = TestRunningCount.class.getResource("log.properties");
|
|
|
54 |
PropertyConfigurator.configure(url);
|
|
|
55 |
category = Category.getInstance("test");
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
public void testErrorRate() {
|
|
|
59 |
|
|
|
60 |
MetricCollector.getInstance().reset();
|
|
|
61 |
int count = 0;
|
|
|
62 |
long start = System.currentTimeMillis();
|
|
|
63 |
|
|
|
64 |
String log = "java.lang.Exception Problem with...";
|
|
|
65 |
|
|
|
66 |
for (int i = 0; i < 100; ++i) {
|
|
|
67 |
++count;
|
|
|
68 |
category.info(log);
|
|
|
69 |
pause();
|
|
|
70 |
} //rof
|
|
|
71 |
long end = System.currentTimeMillis();
|
|
|
72 |
long diff = end - start;
|
|
|
73 |
double noSecs = diff / 1000; // per second
|
|
|
74 |
|
|
|
75 |
System.out.println("Errors=" + count);
|
|
|
76 |
System.out.println("No secconds=" + noSecs);
|
|
|
77 |
System.out.println("rate=" + count / noSecs);
|
|
|
78 |
MetricCollector.getInstance().report(System.out);
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
public void pause() {
|
|
|
82 |
try {
|
|
|
83 |
Thread.sleep((long) (Math.random() * 100));
|
|
|
84 |
} catch (Exception e) {
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
}
|
|
|
88 |
}
|