User: juhalindfors
Date: 02/03/19 13:04:36
Modified: src/main/test/implementation/modelmbean ModelMBeanSUITE.java
XMBeanTEST.java
Added: src/main/test/implementation/modelmbean
AttributeCacheTEST.java
Log:
Revision Changes Path
1.2 +1 -0 jmx/src/main/test/implementation/modelmbean/ModelMBeanSUITE.java
Index: ModelMBeanSUITE.java
===================================================================
RCS file:
/cvsroot/jboss/jmx/src/main/test/implementation/modelmbean/ModelMBeanSUITE.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ModelMBeanSUITE.java 21 Feb 2002 06:47:23 -0000 1.1
+++ ModelMBeanSUITE.java 19 Mar 2002 21:04:36 -0000 1.2
@@ -22,6 +22,7 @@
TestSuite suite = new TestSuite("JBossMX Model MBean Tests");
suite.addTest(new TestSuite(XMBeanTEST.class));
+ suite.addTest(new TestSuite(AttributeCacheTEST.class));
return suite;
}
1.5 +18 -28 jmx/src/main/test/implementation/modelmbean/XMBeanTEST.java
Index: XMBeanTEST.java
===================================================================
RCS file:
/cvsroot/jboss/jmx/src/main/test/implementation/modelmbean/XMBeanTEST.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XMBeanTEST.java 8 Mar 2002 16:09:54 -0000 1.4
+++ XMBeanTEST.java 19 Mar 2002 21:04:36 -0000 1.5
@@ -29,7 +29,7 @@
* XMBean class and the MBean creation (this is the doc ;)
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
- * @version $Revision: 1.4 $
+ * @version $Revision: 1.5 $
*/
public class XMBeanTEST extends TestCase
{
@@ -40,33 +40,21 @@
public void testCreateXMBean() throws Exception
{
-// try
-// {
- MBeanServer server = MBeanServerFactory.createMBeanServer();
- XMBean mmb = new XMBean(new User(),
"file:./src/main/test/implementation/modelmbean/support/xml/UserManagementInterface.xml");
-
- ObjectName name = new ObjectName(":test=test");
-
- server.registerMBean(mmb, name);
- assertTrue(server.isRegistered(name));
-
- server.setAttribute(name, new Attribute("Name", "Juha"));
- assertTrue(server.getAttribute(name, "Name").equals("Juha"));
-
- server.setAttribute(name, new Attribute("Address", "StrawBerry Street"));
- assertTrue(server.getAttribute(name, "Address").equals("StrawBerry
Street"));
-
- assertTrue(server.invoke(name, "printInfo", null, null) instanceof String);
-// }
-// catch (AssertionFailedError e)
-// {
-// throw e;
-// }
-// catch (Throwable t)
-// {
-// t.printStackTrace();
-// fail("Unexpected error: " + t.toString());
-// }
+ MBeanServer server = MBeanServerFactory.createMBeanServer();
+ XMBean mmb = new XMBean(new User(),
"file:./src/main/test/implementation/modelmbean/support/xml/UserManagementInterface.xml");
+
+ ObjectName name = new ObjectName(":test=test");
+
+ server.registerMBean(mmb, name);
+ assertTrue(server.isRegistered(name));
+
+ server.setAttribute(name, new Attribute("Name", "Juha"));
+ assertTrue(server.getAttribute(name, "Name").equals("Juha"));
+
+ server.setAttribute(name, new Attribute("Address", "StrawBerry Street"));
+ assertTrue(server.getAttribute(name, "Address").equals("StrawBerry Street"));
+
+ assertTrue(server.invoke(name, "printInfo", null, null) instanceof String);
}
public void testCreateWithJBossXMBean10DTD() throws Exception
@@ -82,6 +70,7 @@
server.setAttribute(new ObjectName(":test=test"), new Attribute("Name",
"Juha"));
assertTrue(server.getAttribute(new ObjectName(":test=test"),
"Name").equals("Juha"));
+
}
public void testCreateWithStandardInterface() throws Exception
@@ -101,5 +90,6 @@
Boolean b = (Boolean)server.invoke(name, "doOperation", new Object[] { "" },
new String[] { "java.lang.String" });
assertTrue(b.booleanValue() == true);
}
+
}
1.1
jmx/src/main/test/implementation/modelmbean/AttributeCacheTEST.java
Index: AttributeCacheTEST.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package test.implementation.modelmbean;
import java.net.URL;
import junit.framework.TestCase;
import junit.framework.AssertionFailedError;
import javax.management.Attribute;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import javax.management.ObjectName;
import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.AttributeChangeNotification;
import org.jboss.mx.modelmbean.XMBean;
import org.jboss.mx.modelmbean.XMBeanConstants;
import test.implementation.modelmbean.support.Test;
/**
* Tests attribute caching and operation mapping for XMBean.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
* @version $Revision: 1.1 $
*/
public class AttributeCacheTEST extends TestCase
{
public AttributeCacheTEST(String s)
{
super(s);
}
/**
* Tests that attribute values are not cached if nothing is declared in xml.
*
* This test uses the xmbean.dtd
*/
public void testImplicitDisabledAttributeCaching() throws Exception
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
Test resource = new Test();
XMBean mmb = new XMBean(resource,
"file:./src/main/test/implementation/modelmbean/support/xml/TrivialManagementInterface.xml");
ObjectName name = new ObjectName(":test=test");
server.registerMBean(mmb, name);
for (int i = 0; i < 10; ++i)
{
server.setAttribute(name, new Attribute("Something", "foo"));
server.getAttribute(name, "Something");
}
assertTrue(resource.getFooCount() == 10);
assertTrue(resource.getBarCount() == 10);
}
/**
* Tests that attribute values are not cached if currencyTimeLimit = 0
*
* This test uses the xmbean.dtd
*/
public void testExplicitDisabledAttributeCaching() throws Exception
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
Test resource = new Test();
XMBean mmb = new XMBean(resource,
"file:./src/main/test/implementation/modelmbean/support/xml/TrivialManagementInterface2.xml");
ObjectName name = new ObjectName(":test=test");
server.registerMBean(mmb, name);
for (int i = 0; i < 8; ++i)
{
server.setAttribute(name, new Attribute("Something", "foo"));
server.getAttribute(name, "Something");
}
assertTrue(resource.getFooCount() == 8);
assertTrue(resource.getBarCount() == 8);
}
/**
* Tests attribute that is never stale (currencyTimeLimit = -1)
*
* This test uses the xmbean.dtd
*/
public void testNeverStaleAttributeCaching() throws Exception
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
Test resource = new Test();
XMBean mmb = new XMBean(resource,
"file:./src/main/test/implementation/modelmbean/support/xml/TrivialManagementInterface3.xml");
ObjectName name = new ObjectName(":test=test");
server.registerMBean(mmb, name);
for (int i = 0; i < 11; ++i)
{
server.setAttribute(name, new Attribute("Something", "foo"));
server.getAttribute(name, "Something");
}
assertTrue(resource.getFooCount() == 11);
assertTrue(resource.getBarCount() == 0);
}
/**
* Tests attribute that caches the value for 10 secs.
*
* This test uses the xmbean.dtd
*/
public void testCachedAttribute() throws Exception
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
Test resource = new Test();
XMBean mmb = new XMBean(resource,
"file:./src/main/test/implementation/modelmbean/support/xml/TrivialManagementInterface4.xml");
ObjectName name = new ObjectName(":test=test");
server.registerMBean(mmb, name);
for (int i = 0; i < 7; ++i)
{
server.setAttribute(name, new Attribute("Something", "foo"));
server.getAttribute(name, "Something");
}
assertTrue(resource.getFooCount() == 7);
assertTrue(resource.getBarCount() == 0);
}
/**
* Tests attribute that caches the value for 1 secs.
*
* This test uses the xmbean.dtd
*/
public void testCachedAttribute2() throws Exception
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
Test resource = new Test();
XMBean mmb = new XMBean(resource,
"file:./src/main/test/implementation/modelmbean/support/xml/TrivialManagementInterface5.xml");
ObjectName name = new ObjectName(":test=test");
server.registerMBean(mmb, name);
server.getAttribute(name, "Something");
assertTrue(resource.getBarCount() == 1);
server.setAttribute(name, new Attribute("Something", "yksi"));
assertTrue(resource.getFooCount() == 1);
String str = (String)server.getAttribute(name, "Something");
assertTrue(resource.getBarCount() == 1);
assertTrue(str.equals("yksi"));
try { Thread.sleep(1100); } catch (Throwable t) {}
server.getAttribute(name, "Something");
assertTrue(resource.getBarCount() == 2);
server.setAttribute(name, new Attribute("Something", "kaksi"));
assertTrue(resource.getFooCount() == 2);
try { Thread.sleep(1100); } catch (Throwable t) {}
str = (String)server.getAttribute(name, "Something");
assertTrue(resource.getBarCount() == 3);
assertTrue(str.equals("kaksi"));
str = (String)server.getAttribute(name, "Something");
assertTrue(resource.getBarCount() == 3);
assertTrue(str.equals("kaksi"));
}
/**
* Tests attribute change notifications
*/
public void testAttributeChangeNotifications() throws Exception
{
MBeanServer server = MBeanServerFactory.createMBeanServer();
Test resource = new Test();
XMBean mmb = new XMBean(resource,
"file:./src/main/test/implementation/modelmbean/support/xml/TrivialManagementInterface5.xml");
ObjectName name = new ObjectName(":test=test");
server.registerMBean(mmb, name);
class MyNotificationListener implements NotificationListener
{
int notifCount = 0;
public void handleNotification(Notification notification, Object handback)
{
AttributeChangeNotification notif =
(AttributeChangeNotification)notification;
assertTrue(notif.getNewValue().equals("mit�vaan"));
notifCount++;
}
}
MyNotificationListener listener = new MyNotificationListener();
server.addNotificationListener(name, listener, null, null);
for (int i = 0; i < 10; ++i)
server.setAttribute(name, new Attribute("Something", "mit�vaan"));
assertTrue(listener.notifCount == 10);
}
}
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development