KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > execution > JmxEtlManagerITest


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
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 scriptella.execution;
17
18 import scriptella.AbstractTestCase;
19 import scriptella.interactive.ProgressIndicator;
20
21 import javax.management.MBeanServer JavaDoc;
22 import javax.management.MalformedObjectNameException JavaDoc;
23 import javax.management.ObjectName JavaDoc;
24 import java.lang.management.ManagementFactory JavaDoc;
25 import java.util.Date JavaDoc;
26 import java.util.Set JavaDoc;
27
28
29 /**
30  * Integration test for {@link JmxEtlManager}.
31  *
32  * @author Fyodor Kupolov
33  * @version 1.0
34  */

35 public class JmxEtlManagerITest extends AbstractTestCase {
36     public void test() throws EtlExecutorException, MalformedObjectNameException JavaDoc {
37         final EtlExecutor e = newEtlExecutor();
38         e.setJmxEnabled(true);
39
40         final ObjectName JavaDoc name = JmxEtlManager.toObjectName(e.getConfiguration().getDocumentUrl().toString(), 0);
41         final MBeanServer JavaDoc srv = ManagementFactory.getPlatformMBeanServer();
42         final long started = System.currentTimeMillis();
43         e.execute(new ProgressIndicator() {
44             public void showProgress(final double progress, final String JavaDoc message) {
45                 if (progress==1) { //oncomplete
46
//MBean is still present
47
final Set JavaDoc set = srv.queryMBeans(name, null);
48                     assertEquals(1, set.size());
49
50                     try {
51                         final Number JavaDoc n = (Number JavaDoc) srv.getAttribute(name, "ExecutedStatementsCount");
52                         assertEquals(2, n.intValue());
53                     } catch (Exception JavaDoc e) {
54                         fail(e.getMessage());
55                     }
56                     try {
57                         final Date JavaDoc d = (Date JavaDoc) srv.getAttribute(name, "StartDate");
58                         assertTrue(d.getTime()>=started && d.getTime()<=System.currentTimeMillis());
59                     } catch (Exception JavaDoc e) {
60                         fail(e.getMessage());
61                     }
62                     try {
63                         final Number JavaDoc n = (Number JavaDoc) srv.getAttribute(name, "Throughput");
64                         assertTrue(n.doubleValue()>0);
65                     } catch (Exception JavaDoc e) {
66                         fail(e.getMessage());
67                     }
68
69
70
71                 }
72             }
73         });
74         //Mbean should be unregistered
75
assertFalse(srv.isRegistered(name));
76
77     }
78
79
80
81 }
82
Popular Tags