| 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: TestUserCount.java
|
|
|
30 |
* Date: Sep 4, 2004
|
|
|
31 |
* Description:
|
|
|
32 |
*
|
|
|
33 |
*
|
|
|
34 |
* @author Lara D'Abreo
|
|
|
35 |
*/
|
|
|
36 |
public class TestRunningCount extends TestCase {
|
|
|
37 |
|
|
|
38 |
public Category category;
|
|
|
39 |
|
|
|
40 |
public TestRunningCount() {
|
|
|
41 |
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
public TestRunningCount(String arg0) {
|
|
|
45 |
super(arg0);
|
|
|
46 |
|
|
|
47 |
URL url = TestRunningCount.class.getResource("log.properties");
|
|
|
48 |
PropertyConfigurator.configure(url);
|
|
|
49 |
category = Category.getInstance("test");
|
|
|
50 |
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
public void testUserCount() {
|
|
|
54 |
MetricCollector.getInstance().reset();
|
|
|
55 |
int count = 0;
|
|
|
56 |
int max = 0;
|
|
|
57 |
|
|
|
58 |
String login = "Test user login.";
|
|
|
59 |
String logout = "Test user logout.";
|
|
|
60 |
|
|
|
61 |
for (int i = 0; i < 1000; ++i) {
|
|
|
62 |
double d = Math.random() * 1000;
|
|
|
63 |
if (d < 500) {
|
|
|
64 |
++count;
|
|
|
65 |
category.info(login);
|
|
|
66 |
|
|
|
67 |
} else {
|
|
|
68 |
--count;
|
|
|
69 |
category.info(logout);
|
|
|
70 |
}
|
|
|
71 |
if (count > max) {
|
|
|
72 |
max = count;
|
|
|
73 |
}
|
|
|
74 |
pause();
|
|
|
75 |
} //rof
|
|
|
76 |
System.out.println(">>> Number of users=" + count);
|
|
|
77 |
System.out.println(">>> Max number of users=" + max);
|
|
|
78 |
MetricCollector.getInstance().report(System.out);
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
public void testMaxUserCount() {
|
|
|
82 |
MetricCollector.getInstance().reset();
|
|
|
83 |
int count = 0;
|
|
|
84 |
int max = 0;
|
|
|
85 |
|
|
|
86 |
String login = "Test user login.";
|
|
|
87 |
String logout = "Test user logout.";
|
|
|
88 |
|
|
|
89 |
for (int i = 0; i < 1000; ++i) {
|
|
|
90 |
double d = Math.random() * 1000;
|
|
|
91 |
if (d < 500) {
|
|
|
92 |
++count;
|
|
|
93 |
category.info(login);
|
|
|
94 |
|
|
|
95 |
} else {
|
|
|
96 |
--count;
|
|
|
97 |
category.info(logout);
|
|
|
98 |
}
|
|
|
99 |
if (count > max) {
|
|
|
100 |
max = count;
|
|
|
101 |
}
|
|
|
102 |
pause();
|
|
|
103 |
} //rof
|
|
|
104 |
System.out.println(">>> Number of users=" + count);
|
|
|
105 |
System.out.println(">>> Max number of users=" + max);
|
|
|
106 |
MetricCollector.getInstance().report(System.out);
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
public void pause() {
|
|
|
110 |
try {
|
|
|
111 |
Thread.sleep((long)(Math.random() * 10));
|
|
|
112 |
}catch (Exception e){}
|
|
|
113 |
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
}
|