| 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: TestSimple.java
|
|
|
30 |
* Date: Sep 6, 2004
|
|
|
31 |
* Description:
|
|
|
32 |
*
|
|
|
33 |
*
|
|
|
34 |
* @author Lara D'Abreo
|
|
|
35 |
*/
|
|
|
36 |
public class TestSimple extends TestCase {
|
|
|
37 |
public Category category;
|
|
|
38 |
|
|
|
39 |
public TestSimple(String arg0) {
|
|
|
40 |
super(arg0);
|
|
|
41 |
|
|
|
42 |
URL url = TestRunningCount.class.getResource("log.properties");
|
|
|
43 |
PropertyConfigurator.configure(url);
|
|
|
44 |
category = Category.getInstance("test");
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
public void testSimpleValueStatistic() {
|
|
|
48 |
|
|
|
49 |
MetricCollector.getInstance().reset();
|
|
|
50 |
double random = 0.0;
|
|
|
51 |
|
|
|
52 |
for (int i = 0; i < 1000; ++i) {
|
|
|
53 |
random = Math.random() * 10;
|
|
|
54 |
category.debug("Time to process post=" + random);
|
|
|
55 |
} //rof
|
|
|
56 |
|
|
|
57 |
System.out.println(">>> last reported value =" + random);
|
|
|
58 |
MetricCollector.getInstance().report(System.out);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
public void testSimpleTimeStatistic() {
|
|
|
62 |
|
|
|
63 |
MetricCollector.getInstance().reset();
|
|
|
64 |
long timestamp = 0;
|
|
|
65 |
for (int i = 0; i < 1000; ++i) {
|
|
|
66 |
|
|
|
67 |
timestamp = System.currentTimeMillis();
|
|
|
68 |
category.debug("Time to process post=1.0");
|
|
|
69 |
} //rof
|
|
|
70 |
|
|
|
71 |
System.out.println(">>> time value =" + timestamp);
|
|
|
72 |
MetricCollector.getInstance().report(System.out);
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
public void testSimpleMemoryStatistic() {
|
|
|
76 |
|
|
|
77 |
MetricCollector.getInstance().reset();
|
|
|
78 |
long mem = 0;
|
|
|
79 |
for (int i = 0; i < 1000; ++i) {
|
|
|
80 |
|
|
|
81 |
mem = Runtime.getRuntime().freeMemory();
|
|
|
82 |
category.debug("Time to process post=2.0");
|
|
|
83 |
} //rof
|
|
|
84 |
|
|
|
85 |
System.out.println(">>> free mem value =" + mem);
|
|
|
86 |
MetricCollector.getInstance().report(System.out);
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
}
|