RelationNotificationSeqNoTest.java revision 278
0N/A/*
2362N/A * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation.
0N/A *
2362N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0N/A * CA 95054 USA or visit www.sun.com if you need additional information or
2362N/A * have any questions.
2362N/A */
2362N/A
0N/A/*
0N/A * @test
0N/A * @bug 6701459
0N/A * @summary Test sequence numbers in RelationService notifications.
0N/A * @author Eamonn McManus
0N/A */
0N/A
0N/A/*
0N/A * Bug 6701459 is for a synchronization problem that is very unlikely to occur
0N/A * in practice and it would be very hard to test it. Instead we just check that
0N/A * the fix has not introduced any obviously-wrong behavior in the sequence
0N/A * numbers.
0N/A */
0N/A
0N/Aimport java.util.Arrays;
0N/Aimport java.util.concurrent.ArrayBlockingQueue;
0N/Aimport java.util.concurrent.BlockingQueue;
0N/Aimport javax.management.JMX;
0N/Aimport javax.management.MBeanServer;
0N/Aimport javax.management.MBeanServerFactory;
0N/Aimport javax.management.Notification;
0N/Aimport javax.management.NotificationListener;
0N/Aimport javax.management.ObjectName;
0N/Aimport javax.management.relation.RelationServiceMBean;
0N/Aimport javax.management.relation.Role;
0N/Aimport javax.management.relation.RoleInfo;
0N/Aimport javax.management.relation.RoleList;
0N/A
0N/Apublic class RelationNotificationSeqNoTest {
0N/A public static void main(String[] args) throws Exception {
0N/A MBeanServer mbs = MBeanServerFactory.newMBeanServer();
0N/A ObjectName relSvcName = new ObjectName("a:type=relationService");
0N/A RelationServiceMBean relSvc =
0N/A JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
0N/A mbs.createMBean("javax.management.relation.RelationService",
0N/A relSvcName,
0N/A new Object[] {Boolean.TRUE},
0N/A new String[] {"boolean"});
0N/A
0N/A final BlockingQueue<Notification> q =
0N/A new ArrayBlockingQueue<Notification>(100);
0N/A NotificationListener qListener = new NotificationListener() {
0N/A public void handleNotification(Notification notification,
0N/A Object handback) {
0N/A q.add(notification);
0N/A }
0N/A };
0N/A mbs.addNotificationListener(relSvcName, qListener, null, null);
0N/A
0N/A RoleInfo leftInfo =
0N/A new RoleInfo("left", "javax.management.timer.TimerMBean");
0N/A RoleInfo rightInfo =
0N/A new RoleInfo("right", "javax.management.timer.Timer");
0N/A relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
0N/A ObjectName timer1 = new ObjectName("a:type=timer,number=1");
0N/A ObjectName timer2 = new ObjectName("a:type=timer,number=2");
0N/A mbs.createMBean("javax.management.timer.Timer", timer1);
0N/A mbs.createMBean("javax.management.timer.Timer", timer2);
0N/A
0N/A Role leftRole =
0N/A new Role("left", Arrays.asList(new ObjectName[] {timer1}));
0N/A Role rightRole =
0N/A new Role("right", Arrays.asList(new ObjectName[] {timer2}));
0N/A RoleList roles =
0N/A new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));
0N/A
0N/A final int NREPEAT = 10;
0N/A
0N/A for (int i = 0; i < NREPEAT; i++) {
0N/A relSvc.createRelation("relationName", "typeName", roles);
0N/A relSvc.removeRelation("relationName");
0N/A }
0N/A
0N/A Notification firstNotif = q.remove();
0N/A long seqNo = firstNotif.getSequenceNumber();
0N/A for (int i = 0; i < NREPEAT * 2 - 1; i++) {
0N/A Notification n = q.remove();
0N/A long nSeqNo = n.getSequenceNumber();
0N/A if (nSeqNo != seqNo + 1) {
0N/A throw new Exception(
0N/A "TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
0N/A nSeqNo);
0N/A }
0N/A seqNo++;
0N/A }
0N/A System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
0N/A "with contiguous sequence numbers");
0N/A }
0N/A}
0N/A