Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
package net.sourceforge.stat4j.test;
17
 
18
import java.net.URL;
19
 
20
import junit.framework.TestCase;
21
 
22
import net.sourceforge.stat4j.filter.MetricCollector;
23
 
24
import org.apache.log4j.Category;
25
import org.apache.log4j.PropertyConfigurator;
26
 
27
 
28
/**
29
 * Name:		TestDelta.java
30
 * Date:		Sep 6, 2004
31
 * Description:
32
 * 
33
 * 
34
 * @author Lara D'Abreo
35
 */
36
public class TestDelta extends TestCase {
37
	public Category category;
38
 
39
	/**
40
	 * @param arg0
41
	 */
42
	public TestDelta(String arg0) {
43
		super(arg0);
44
		URL url = TestRunningCount.class.getResource("log.properties");
45
		PropertyConfigurator.configure(url);
46
		category = Category.getInstance("test");
47
	}
48
 
49
	public void testFooMetrics() {
50
		MetricCollector.getInstance().reset();
51
 
52
		String begin = "BEGIN foo() ...";
53
		String end = "END foo()...";
54
 
55
		long max = 0;
56
		long total = 0;
57
 
58
 
59
		for (int i = 0; i < 100; ++i) {
60
			long wait = (long)(Math.random() * 100);
61
 
62
			category.info(begin);
63
			pause(wait);
64
			category.info(end);
65
 
66
			if (wait > max) {
67
				max = wait;
68
			}
69
			total = total + wait;
70
		} //rof
71
 
72
		System.out.println(">>> Max Duration of foo()=" + max);
73
		System.out.println(">>> Avg Duration of foo()=" + total/100);
74
		MetricCollector.getInstance().report(System.out);
75
	}
76
 
77
	public void pause() {
78
		try {
79
			Thread.sleep((long) (Math.random() * 10));
80
		} catch (Exception e) {
81
		}
82
 
83
	}
84
 
85
	public void pause(long wait) {
86
		try {
87
			Thread.sleep(wait);
88
		} catch (Exception e) {
89
		}
90
 
91
	}
92
}