Java 类javax.management.relation.RoleInfo 实例源码

项目:freeVM    文件:StructureTest.java   
public Result testNotWritable() throws Exception {

        MBeanServer server = MBeanServerFactory.createMBeanServer();

        ObjectName unitName = new ObjectName("a:b=c");
        server.registerMBean(new Unit(), unitName);

        RelationService rService = new RelationService(true);
        server.registerMBean(rService, new ObjectName("a:b=d"));

        /* Role is not readable */
        RoleInfo[] rInfo = { new RoleInfo("role", classPath, true, false) };
        rService.createRelationType("relationType", rInfo);

        RoleList unitRoles = new RoleList();
        unitRoles.add(new Role("role", Collections.singletonList(unitName)));

        try {
            rService.createRelation("relation", "relationType", unitRoles);
            return passed();
        } catch (Throwable t) {
            return failed(t.toString());
        }
    }
项目:freeVM    文件:StructureTest.java   
public Result testNotRegisteredException() throws Exception {

        /* Initialisation without registering */
        MBeanServer server = MBeanServerFactory.createMBeanServer();

        ObjectName unitName = new ObjectName("a:b=c");
        server.registerMBean(new Unit(), unitName);

        RelationService rService = new RelationService(true);
        RoleInfo[] rInfo = { new RoleInfo("role", classPath) };
        rService.createRelationType("relationType", rInfo);

        RoleList unitRoles = new RoleList();
        unitRoles.add(new Role("role", Collections.singletonList(unitName)));

        /* catch RelationServiceNotRegisteredException */
        try {
            rService.createRelation("relation", "relationType", unitRoles);
            return failed("");
        } catch (RelationServiceNotRegisteredException e) {
            return passed();
        } catch (Throwable t) {
            return failed(t.toString());
        }
    }
项目:freeVM    文件:StructureTest.java   
public Result testNullRelationName() throws Exception {

        MBeanServer server = MBeanServerFactory.createMBeanServer();

        ObjectName unitName = new ObjectName("a:b=c");
        server.registerMBean(new Unit(), unitName);

        RelationService rService = new RelationService(true);
        server.registerMBean(rService, new ObjectName("a:b=d"));

        RoleInfo[] rInfo = { new RoleInfo("role", classPath) };
        rService.createRelationType("relationType", rInfo);

        RoleList unitRoles = new RoleList();
        unitRoles.add(new Role("role", Collections.singletonList(unitName)));

        /* set null relation name */
        try {
            rService.createRelation(null, "relationType", unitRoles);
            return failed("");
        } catch (IllegalArgumentException e) {
            return passed();
        } catch (Throwable t) {
            return failed(t.toString());
        }
    }
项目:freeVM    文件:StructureTest.java   
public Result testNumberOfMBeanLessThanNeed() throws Exception {

        MBeanServer server = MBeanServerFactory.createMBeanServer();

        ObjectName unitName = new ObjectName("a:b=c");
        server.registerMBean(new Unit(), unitName);

        RelationService rService = new RelationService(true);
        server.registerMBean(rService, new ObjectName("a:b=d"));

        RoleInfo[] rInfo = { new RoleInfo("role", classPath) };
        rService.createRelationType("relationType", rInfo);

        RoleList unitRoles = new RoleList();
        /* The Number of MBeans is less than default (1) */
        unitRoles.add(new Role("role", new ArrayList()));
        try {
            rService.createRelation("relation", "relationType", unitRoles);
            return failed("");
        } catch (InvalidRoleValueException e) {
            return passed();
        } catch (Throwable t) {
            return failed(t.toString());
        }
    }
项目:freeVM    文件:StructureTest.java   
public Result testMBeanNotRegistered() throws Exception {

        MBeanServer server = MBeanServerFactory.createMBeanServer();

        ObjectName unitName = new ObjectName("a:b=c");

        RelationService rService = new RelationService(true);
        server.registerMBean(rService, new ObjectName("a:b=d"));

        RoleInfo[] rInfo = { new RoleInfo("role", classPath) };
        rService.createRelationType("relationType", rInfo);

        RoleList unitRoles = new RoleList();

        /* Referenced MBean hasn't registered */
        unitRoles.add(new Role("role", Collections.singletonList(unitName)));

        try {
            rService.createRelation("relation", "relationType", unitRoles);
            return failed("");
        } catch (InvalidRoleValueException e) {
            return passed();
        } catch (Throwable t) {
            return failed(t.toString());
        }
    }
项目:freeVM    文件:StructureTest.java   
public Result testNotReadable() throws Exception {

        MBeanServer server = MBeanServerFactory.createMBeanServer();

        ObjectName unitName = new ObjectName("a:b=c");
        server.registerMBean(new Unit(), unitName);

        RelationService rService = new RelationService(true);
        server.registerMBean(rService, new ObjectName("a:b=d"));

        /* Role is not readable */
        RoleInfo[] rInfo = { new RoleInfo("role", classPath, false, true) };
        rService.createRelationType("relationType", rInfo);

        RoleList unitRoles = new RoleList();
        unitRoles.add(new Role("role", Collections.singletonList(unitName)));

        try {
            rService.createRelation("relation", "relationType", unitRoles);
            return passed();
        } catch (Throwable t) {
            return failed(t.toString());
        }
    }
项目:freeVM    文件:RoleTest.java   
/**
 * This test verifies that minimum role value also can be infinite
 */

public Result testRoleInfoInfinity() throws Exception {

    try {
        new RoleInfo("usualRole", classPath, true, true,
                RoleInfo.ROLE_CARDINALITY_INFINITY, 4, "Unit role");
        new RoleInfo("usualRole", classPath, true, true,
                RoleInfo.ROLE_CARDINALITY_INFINITY,
                RoleInfo.ROLE_CARDINALITY_INFINITY, "Unit role");
        new RoleInfo("usualRole", classPath, true, true, 0,
                RoleInfo.ROLE_CARDINALITY_INFINITY, "Unit role");
    } catch (Exception e) {
        return failed(e.toString());
    }

    return passed();
}
项目:cacheonix-core    文件:SimplePersonalLibrary.java   
public SimplePersonalLibrary(String relationTypeName)
{
   super(relationTypeName);

   try
   {
      RoleInfo ownerRoleInfo = new RoleInfo("owner",
                                            // the name of the MBean class of which all members must be an instance.
                                            "mx4j.examples.services.relation.SimpleOwner",
                                            true, //read
                                            true, //write
                                            1, // only one owner
                                            1,
                                            "Owner");
      addRoleInfo(ownerRoleInfo);

      RoleInfo booksRoleInfo = new RoleInfo("books",
                                            "mx4j.examples.services.relation.SimpleBooks",
                                            true,
                                            true,
                                            1, // feeling nasty can only own max 4 books and no fewer than 1
                                            4,
                                            "Books");
      addRoleInfo(booksRoleInfo);
   }
   catch (Exception ex)
   {
      throw new RuntimeException(ex.getMessage());
   }
}
项目:freeVM    文件:StructureTest.java   
/**
 * This test verifies that MBeans don't have to be registered before
 * creation of role.
 */

public Result testMBeansDoNotHaveTo() throws Exception {

    MBeanServer mBeanServer = MBeanServerFactory.createMBeanServer();

    // Register Relation Service
    RelationService relationService = new RelationService(true);
    ObjectName relationServiceName = new ObjectName(
            "mBeanServer:type=RelationService,name=rs");
    mBeanServer.registerMBean(relationService, relationServiceName);

    // Create Role Information Array
    RoleInfo[] roleInfo = new RoleInfo[1];
    roleInfo[0] = new RoleInfo("unitRole", classPath, true, true, 1, 2,
            "Unit role");

    // Creating an Internal Relation Type
    relationService.createRelationType("internalRelationType", roleInfo);

    ObjectName unit1Name = new ObjectName(
            "mBeanServer:type=Unit,name=Unit1");

    // Create RoleLists for single unit and double unit relations
    ArrayList unitList = new ArrayList();
    unitList.add(unit1Name);
    Role unitRole = new Role("unitRole", unitList);

    return !unitRole.getRoleValue().contains(unit1Name) ? failed("")
            : passed();
}
项目:freeVM    文件:StructureTest.java   
public Result testRoleNotFound() throws Exception {

        MBeanServer server = MBeanServerFactory.createMBeanServer();

        ObjectName unitName = new ObjectName("a:b=c");
        server.registerMBean(new Unit(), unitName);

        RelationService rService = new RelationService(true);
        server.registerMBean(rService, new ObjectName("a:b=d"));

        RoleInfo[] rInfo = { new RoleInfo("role", classPath) };
        rService.createRelationType("relationType", rInfo);

        RoleList unitRoles = new RoleList();
        /* role name differs from role info contains */
        unitRoles.add(new Role("another role", Collections
                .singletonList(unitName)));

        /* catch RoleNotFoundException */
        try {
            rService.createRelation("relation", "relationType", unitRoles);
            return failed("");
        } catch (RoleNotFoundException e) {
            return passed();
        } catch (Throwable t) {
            return failed(t.toString());
        }
    }
项目:freeVM    文件:StructureTest.java   
public Result testIdAlreadyUsed() throws Exception {

        MBeanServer server = MBeanServerFactory.createMBeanServer();

        ObjectName unitName = new ObjectName("a:b=c");
        server.registerMBean(new Unit(), unitName);

        RelationService rService = new RelationService(true);
        server.registerMBean(rService, new ObjectName("a:b=d"));

        RoleInfo[] rInfo = { new RoleInfo("role", classPath) };
        rService.createRelationType("relationType", rInfo);

        RoleList unitRoles = new RoleList();
        unitRoles.add(new Role("role", Collections.singletonList(unitName)));

        rService.createRelation("relation", "relationType", unitRoles);

        /* now try to create another relation with the same name */
        /* create another relation type for clearance */
        rService.createRelationType("another relationType", rInfo);

        try {
            rService.createRelation("relation", "another relationType",
                    unitRoles);
            return failed("");
        } catch (InvalidRelationIdException e) {
            return passed();
        } catch (Throwable t) {
            return failed(t.toString());
        }
    }
项目:freeVM    文件:StructureTest.java   
public Result testTheSameRoleName() throws Exception {

        MBeanServer server = MBeanServerFactory.createMBeanServer();

        ObjectName unitName = new ObjectName("a:b=c");
        ObjectName unitName2 = new ObjectName("a:b=c2");
        server.registerMBean(new Unit(), unitName);
        server.registerMBean(new Unit(), unitName2);

        RelationService rService = new RelationService(true);
        server.registerMBean(rService, new ObjectName("a:b=d"));

        RoleInfo[] rInfo = { new RoleInfo("role", classPath) };
        rService.createRelationType("relationType", rInfo);

        RoleList unitRoles = new RoleList();

        /* Add 2 roles with the same name */
        unitRoles.add(new Role("role", Collections.singletonList(unitName)));
        unitRoles.add(new Role("role", Collections.singletonList(unitName2)));

        try {
            rService.createRelation("relation", "relationType", unitRoles);
            return failed("");
        } catch (InvalidRoleValueException e) {
            return passed();
        } catch (Throwable t) {
            return failed(t.toString());
        }
    }
项目:freeVM    文件:StructureTest.java   
public Result testNumberOfMBeanMoreThanNeed() throws Exception {

        MBeanServer server = MBeanServerFactory.createMBeanServer();

        ObjectName unitName = new ObjectName("a:b=c");
        ObjectName unitName2 = new ObjectName("a:b=c2");
        server.registerMBean(new Unit(), unitName);
        server.registerMBean(new Unit(), unitName2);

        RelationService rService = new RelationService(true);
        server.registerMBean(rService, new ObjectName("a:b=d"));

        RoleInfo[] rInfo = { new RoleInfo("role", classPath) };
        rService.createRelationType("relationType", rInfo);

        RoleList unitRoles = new RoleList();
        /* The Number of MBeans is more than default (1) */
        ArrayList units = new ArrayList();
        units.add(unitName);
        units.add(unitName2);

        unitRoles.add(new Role("role", units));

        try {
            rService.createRelation("relation", "relationType", unitRoles);
            return failed("");
        } catch (InvalidRoleValueException e) {
            return passed();
        } catch (Throwable t) {
            return failed(t.toString());
        }
    }
项目:freeVM    文件:StructureTest.java   
public Result testDifferentTypeMBean() throws Exception {

        MBeanServer server = MBeanServerFactory.createMBeanServer();

        ObjectName unitName = new ObjectName("a:b=c");
        /* MBean class is NotUnit */
        server.registerMBean(new NotUnit(), unitName);

        RelationService rService = new RelationService(true);
        server.registerMBean(rService, new ObjectName("a:b=d"));

        RoleInfo[] rInfo = { new RoleInfo("role", classPath) };
        rService.createRelationType("relationType", rInfo);

        RoleList unitRoles = new RoleList();

        /* Referenced MBean hasn't registered */
        unitRoles.add(new Role("role", Collections.singletonList(unitName)));

        try {
            rService.createRelation("relation", "relationType", unitRoles);
            return failed("");
        } catch (InvalidRoleValueException e) {
            return passed();
        } catch (Throwable t) {
            return failed(t.toString());
        }
    }
项目:freeVM    文件:StructureTest.java   
public Result testExistenceAfterException() throws Exception {

        MBeanServer server = MBeanServerFactory.createMBeanServer();

        ObjectName unitName = new ObjectName("a:b=c");
        server.registerMBean(new Unit(), unitName);

        RelationService rService = new RelationService(true);
        server.registerMBean(rService, new ObjectName("a:b=d"));

        RoleInfo[] rInfo = { new RoleInfo("role", classPath),
                new RoleInfo("another role", classPath) };
        rService.createRelationType("relationType", rInfo);

        RoleList unitRoles = new RoleList();
        /*
         * "anotherRole is incorrect - the number of MBeans is less than
         * default"
         */
        unitRoles.add(new Role("role", Collections.singletonList(unitName)));
        unitRoles.add(new Role("another role", new ArrayList()));

        try {
            rService.createRelation("relation", "relationType", unitRoles);
            System.out.println("existenceAfterExceptions test failed");
        } catch (InvalidRoleValueException e) {
            /* this exception should be caught */
        } catch (Throwable t) {
            System.out.println("existenceAfterExceptions test failed: "
                    + t.toString());
        }

        /* now verify is relation exists */
        if (!rService.getAllRelationIds().contains("relation")) {
            return passed();
        }
        return failed("");
    }
项目:freeVM    文件:StructureTest.java   
public Result testPurgeRemains() throws Exception {

        MBeanServer server = MBeanServerFactory.createMBeanServer();

        ObjectName[] unitNames = { new ObjectName("a:b=c"),
                new ObjectName("a:b=c2") };

        server.registerMBean(new Unit(), unitNames[0]);
        server.registerMBean(new Unit(), unitNames[1]);

        RelationService rService = new RelationService(true);
        server.registerMBean(rService, new ObjectName("a:b=d"));

        /* This role remains after unregister one of unit */
        RoleInfo[] rInfo = { new RoleInfo("role", classPath, true, true, 1, 2,
                "role") };
        rService.createRelationType("relationType", rInfo);

        RoleList unitRoles = new RoleList();
        Role role = new Role("role", Arrays.asList(unitNames));
        unitRoles.add(role);

        rService.createRelation("relation", "relationType", unitRoles);

        /* now remove one of MBeans */
        server.unregisterMBean(unitNames[0]);

        /* verify relation is exist */
        if (!rService.getAllRelationIds().contains("relation")) {
            return failed("");
        }
        return passed();
    }
项目:freeVM    文件:StructureTest.java   
public Result testPurgeRemoves() throws Exception {

        MBeanServer server = MBeanServerFactory.createMBeanServer();

        ObjectName[] unitNames = { new ObjectName("a:b=c"),
                new ObjectName("a:b=c2") };

        server.registerMBean(new Unit(), unitNames[0]);
        server.registerMBean(new Unit(), unitNames[1]);

        RelationService rService = new RelationService(true);
        server.registerMBean(rService, new ObjectName("a:b=d"));

        /* This role remains after unregister one of unit */
        RoleInfo[] rInfo = { new RoleInfo("role", classPath, true, true, 2, 2,
                "role") };
        rService.createRelationType("relationType", rInfo);

        RoleList unitRoles = new RoleList();
        Role role = new Role("role", Arrays.asList(unitNames));
        unitRoles.add(role);

        rService.createRelation("relation", "relationType", unitRoles);

        /* now remove one of MBeans */
        server.unregisterMBean(unitNames[0]);

        /* verify relation is exist */
        if (rService.getAllRelationIds().contains("relation")) {
            return failed("");
        }
        return passed();
    }
项目:freeVM    文件:RoleTest.java   
/**
 * This test verifies that rolelist can be null in relation creation
 */
public Result testRoleListCanBeNull() throws Exception {

    // Create MBean Server
    MBeanServer mBeanServer = MBeanServerFactory.createMBeanServer();

    // Register Relation Service
    RelationService relationService = new RelationService(true);
    ObjectName relationServiceName = new ObjectName(
            "mBeanServer:type=RelationService,name=rs");
    mBeanServer.registerMBean(relationService, relationServiceName);

    UnitMBean unit1 = new Unit();
    ObjectName unitName = new ObjectName("mBeanServer:type=Unit,name=Unit1");
    mBeanServer.registerMBean(unit1, unitName);

    RoleInfo[] roleInfo = new RoleInfo[1];
    roleInfo[0] = new RoleInfo("Role", classPath, true, true, 1, 1,
            "The Role can contain any number of MBeans");

    relationService.createRelationType("internalRelationType", roleInfo);

    try {
        relationService.createRelation("relationId",
                "internalRelationType", null);
    } catch (Exception e) {
        return failed("Role list can be null: " + e.toString());
    }

    return passed();
}
项目:freeVM    文件:RoleTest.java   
/**
 * Step by step for verification that then MBean is unregistered Role
 * becomes incorrect
 * <ul>
 * <li>a. Create relation
 * <li>b. Unregister referenced MBean
 * <li>c. Verify that relation becomes incorrect
 * </ul>
 * 
 */
public Result testInfluenceMBeanUnregToRole() throws Exception {

    MBeanServer mBeanServer = MBeanServerFactory.createMBeanServer();

    RelationService relationService = new RelationService(true);
    ObjectName relationServiceName = new ObjectName(
            "mBeanServer:type=RelationService,name=rs");
    mBeanServer.registerMBean(relationService, relationServiceName);

    UnitMBean unit1 = new Unit();
    ObjectName unitName = new ObjectName("mBeanServer:type=Unit,name=Unit1");
    mBeanServer.registerMBean(unit1, unitName);

    RoleInfo[] roleInfo = new RoleInfo[1];
    roleInfo[0] = new RoleInfo("usualRole", classPath);

    relationService.createRelationType("internalRelationType", roleInfo);

    ArrayList unitList = new ArrayList();
    unitList.add(unitName);

    Role usualRole = new Role("usualRole", unitList);

    mBeanServer.unregisterMBean(unitName);

    if (relationService.checkRoleWriting(usualRole, "internalRelationType",
            Boolean.TRUE).byteValue() != 7) {
        return failed("unregisterMBean influence to Role incorrect");
    }
    return passed();
}
项目:freeVM    文件:RoleTest.java   
/**
 * This test verifies getAllRelationTypeNames method
 */
public Result testGetAllRelationTypeNames() throws Exception {

    MBeanServer mBeanServer = MBeanServerFactory.createMBeanServer();

    RelationService relationService = new RelationService(true);
    ObjectName relationServiceName = new ObjectName(
            "mBeanServer:type=RelationService,name=rs");
    mBeanServer.registerMBean(relationService, relationServiceName);

    RoleInfo[] roleInfo = { new RoleInfo("JustRole", classPath) };

    relationService.createRelationType("RelationType0", roleInfo);
    relationService.addRelationType(new RelationTypeSupport(
            "RelationType1", roleInfo));
    relationService.addRelationType(new ERelationType("RelationType2",
            roleInfo));
    try {
        relationService.addRelationType(new ERelationType("RelationType3"));
    } catch (Exception e) {
        /* Correct state */
    }

    for (int i = 0; i < 3; i++) {
        if (!relationService.getAllRelationTypeNames().contains(
                "RelationType" + i)) {
            return failed("getAllRelationTypeNames missed data");
        }
    }
    if (relationService.getAllRelationTypeNames().contains(
            "RelationType" + 3)) {
        return failed("Incorrect Relation Type Added");
    }
    return passed();

}
项目:jdk8u-jdk    文件:RelationNotificationSeqNoTest.java   
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName relSvcName = new ObjectName("a:type=relationService");
    RelationServiceMBean relSvc =
            JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
    mbs.createMBean("javax.management.relation.RelationService",
                    relSvcName,
                    new Object[] {Boolean.TRUE},
                    new String[] {"boolean"});

    final BlockingQueue<Notification> q =
            new ArrayBlockingQueue<Notification>(100);
    NotificationListener qListener = new NotificationListener() {
        public void handleNotification(Notification notification,
                                       Object handback) {
            q.add(notification);
        }
    };
    mbs.addNotificationListener(relSvcName, qListener, null, null);

    RoleInfo leftInfo =
        new RoleInfo("left", "javax.management.timer.TimerMBean");
    RoleInfo rightInfo =
        new RoleInfo("right", "javax.management.timer.Timer");
    relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
    ObjectName timer1 = new ObjectName("a:type=timer,number=1");
    ObjectName timer2 = new ObjectName("a:type=timer,number=2");
    mbs.createMBean("javax.management.timer.Timer", timer1);
    mbs.createMBean("javax.management.timer.Timer", timer2);

    Role leftRole =
        new Role("left", Arrays.asList(new ObjectName[] {timer1}));
    Role rightRole =
        new Role("right", Arrays.asList(new ObjectName[] {timer2}));
    RoleList roles =
        new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));

    final int NREPEAT = 10;

    for (int i = 0; i < NREPEAT; i++) {
        relSvc.createRelation("relationName", "typeName", roles);
        relSvc.removeRelation("relationName");
    }

    Notification firstNotif = q.remove();
    long seqNo = firstNotif.getSequenceNumber();
    for (int i = 0; i < NREPEAT * 2 - 1; i++) {
        Notification n = q.remove();
        long nSeqNo = n.getSequenceNumber();
        if (nSeqNo != seqNo + 1) {
            throw new Exception(
                    "TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
                    nSeqNo);
        }
        seqNo++;
    }
    System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
            "with contiguous sequence numbers");
}
项目:openjdk-jdk10    文件:RelationNotificationSeqNoTest.java   
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName relSvcName = new ObjectName("a:type=relationService");
    RelationServiceMBean relSvc =
            JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
    mbs.createMBean("javax.management.relation.RelationService",
                    relSvcName,
                    new Object[] {Boolean.TRUE},
                    new String[] {"boolean"});

    final BlockingQueue<Notification> q =
            new ArrayBlockingQueue<Notification>(100);
    NotificationListener qListener = new NotificationListener() {
        public void handleNotification(Notification notification,
                                       Object handback) {
            q.add(notification);
        }
    };
    mbs.addNotificationListener(relSvcName, qListener, null, null);

    RoleInfo leftInfo =
        new RoleInfo("left", "javax.management.timer.TimerMBean");
    RoleInfo rightInfo =
        new RoleInfo("right", "javax.management.timer.Timer");
    relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
    ObjectName timer1 = new ObjectName("a:type=timer,number=1");
    ObjectName timer2 = new ObjectName("a:type=timer,number=2");
    mbs.createMBean("javax.management.timer.Timer", timer1);
    mbs.createMBean("javax.management.timer.Timer", timer2);

    Role leftRole =
        new Role("left", Arrays.asList(new ObjectName[] {timer1}));
    Role rightRole =
        new Role("right", Arrays.asList(new ObjectName[] {timer2}));
    RoleList roles =
        new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));

    final int NREPEAT = 10;

    for (int i = 0; i < NREPEAT; i++) {
        relSvc.createRelation("relationName", "typeName", roles);
        relSvc.removeRelation("relationName");
    }

    Notification firstNotif = q.remove();
    long seqNo = firstNotif.getSequenceNumber();
    for (int i = 0; i < NREPEAT * 2 - 1; i++) {
        Notification n = q.remove();
        long nSeqNo = n.getSequenceNumber();
        if (nSeqNo != seqNo + 1) {
            throw new Exception(
                    "TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
                    nSeqNo);
        }
        seqNo++;
    }
    System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
            "with contiguous sequence numbers");
}
项目:openjdk9    文件:RelationNotificationSeqNoTest.java   
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName relSvcName = new ObjectName("a:type=relationService");
    RelationServiceMBean relSvc =
            JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
    mbs.createMBean("javax.management.relation.RelationService",
                    relSvcName,
                    new Object[] {Boolean.TRUE},
                    new String[] {"boolean"});

    final BlockingQueue<Notification> q =
            new ArrayBlockingQueue<Notification>(100);
    NotificationListener qListener = new NotificationListener() {
        public void handleNotification(Notification notification,
                                       Object handback) {
            q.add(notification);
        }
    };
    mbs.addNotificationListener(relSvcName, qListener, null, null);

    RoleInfo leftInfo =
        new RoleInfo("left", "javax.management.timer.TimerMBean");
    RoleInfo rightInfo =
        new RoleInfo("right", "javax.management.timer.Timer");
    relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
    ObjectName timer1 = new ObjectName("a:type=timer,number=1");
    ObjectName timer2 = new ObjectName("a:type=timer,number=2");
    mbs.createMBean("javax.management.timer.Timer", timer1);
    mbs.createMBean("javax.management.timer.Timer", timer2);

    Role leftRole =
        new Role("left", Arrays.asList(new ObjectName[] {timer1}));
    Role rightRole =
        new Role("right", Arrays.asList(new ObjectName[] {timer2}));
    RoleList roles =
        new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));

    final int NREPEAT = 10;

    for (int i = 0; i < NREPEAT; i++) {
        relSvc.createRelation("relationName", "typeName", roles);
        relSvc.removeRelation("relationName");
    }

    Notification firstNotif = q.remove();
    long seqNo = firstNotif.getSequenceNumber();
    for (int i = 0; i < NREPEAT * 2 - 1; i++) {
        Notification n = q.remove();
        long nSeqNo = n.getSequenceNumber();
        if (nSeqNo != seqNo + 1) {
            throw new Exception(
                    "TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
                    nSeqNo);
        }
        seqNo++;
    }
    System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
            "with contiguous sequence numbers");
}
项目:jdk8u_jdk    文件:RelationNotificationSeqNoTest.java   
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName relSvcName = new ObjectName("a:type=relationService");
    RelationServiceMBean relSvc =
            JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
    mbs.createMBean("javax.management.relation.RelationService",
                    relSvcName,
                    new Object[] {Boolean.TRUE},
                    new String[] {"boolean"});

    final BlockingQueue<Notification> q =
            new ArrayBlockingQueue<Notification>(100);
    NotificationListener qListener = new NotificationListener() {
        public void handleNotification(Notification notification,
                                       Object handback) {
            q.add(notification);
        }
    };
    mbs.addNotificationListener(relSvcName, qListener, null, null);

    RoleInfo leftInfo =
        new RoleInfo("left", "javax.management.timer.TimerMBean");
    RoleInfo rightInfo =
        new RoleInfo("right", "javax.management.timer.Timer");
    relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
    ObjectName timer1 = new ObjectName("a:type=timer,number=1");
    ObjectName timer2 = new ObjectName("a:type=timer,number=2");
    mbs.createMBean("javax.management.timer.Timer", timer1);
    mbs.createMBean("javax.management.timer.Timer", timer2);

    Role leftRole =
        new Role("left", Arrays.asList(new ObjectName[] {timer1}));
    Role rightRole =
        new Role("right", Arrays.asList(new ObjectName[] {timer2}));
    RoleList roles =
        new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));

    final int NREPEAT = 10;

    for (int i = 0; i < NREPEAT; i++) {
        relSvc.createRelation("relationName", "typeName", roles);
        relSvc.removeRelation("relationName");
    }

    Notification firstNotif = q.remove();
    long seqNo = firstNotif.getSequenceNumber();
    for (int i = 0; i < NREPEAT * 2 - 1; i++) {
        Notification n = q.remove();
        long nSeqNo = n.getSequenceNumber();
        if (nSeqNo != seqNo + 1) {
            throw new Exception(
                    "TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
                    nSeqNo);
        }
        seqNo++;
    }
    System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
            "with contiguous sequence numbers");
}
项目:lookaside_java-1.8.0-openjdk    文件:RelationNotificationSeqNoTest.java   
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName relSvcName = new ObjectName("a:type=relationService");
    RelationServiceMBean relSvc =
            JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
    mbs.createMBean("javax.management.relation.RelationService",
                    relSvcName,
                    new Object[] {Boolean.TRUE},
                    new String[] {"boolean"});

    final BlockingQueue<Notification> q =
            new ArrayBlockingQueue<Notification>(100);
    NotificationListener qListener = new NotificationListener() {
        public void handleNotification(Notification notification,
                                       Object handback) {
            q.add(notification);
        }
    };
    mbs.addNotificationListener(relSvcName, qListener, null, null);

    RoleInfo leftInfo =
        new RoleInfo("left", "javax.management.timer.TimerMBean");
    RoleInfo rightInfo =
        new RoleInfo("right", "javax.management.timer.Timer");
    relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
    ObjectName timer1 = new ObjectName("a:type=timer,number=1");
    ObjectName timer2 = new ObjectName("a:type=timer,number=2");
    mbs.createMBean("javax.management.timer.Timer", timer1);
    mbs.createMBean("javax.management.timer.Timer", timer2);

    Role leftRole =
        new Role("left", Arrays.asList(new ObjectName[] {timer1}));
    Role rightRole =
        new Role("right", Arrays.asList(new ObjectName[] {timer2}));
    RoleList roles =
        new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));

    final int NREPEAT = 10;

    for (int i = 0; i < NREPEAT; i++) {
        relSvc.createRelation("relationName", "typeName", roles);
        relSvc.removeRelation("relationName");
    }

    Notification firstNotif = q.remove();
    long seqNo = firstNotif.getSequenceNumber();
    for (int i = 0; i < NREPEAT * 2 - 1; i++) {
        Notification n = q.remove();
        long nSeqNo = n.getSequenceNumber();
        if (nSeqNo != seqNo + 1) {
            throw new Exception(
                    "TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
                    nSeqNo);
        }
        seqNo++;
    }
    System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
            "with contiguous sequence numbers");
}
项目:infobip-open-jdk-8    文件:RelationNotificationSeqNoTest.java   
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName relSvcName = new ObjectName("a:type=relationService");
    RelationServiceMBean relSvc =
            JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
    mbs.createMBean("javax.management.relation.RelationService",
                    relSvcName,
                    new Object[] {Boolean.TRUE},
                    new String[] {"boolean"});

    final BlockingQueue<Notification> q =
            new ArrayBlockingQueue<Notification>(100);
    NotificationListener qListener = new NotificationListener() {
        public void handleNotification(Notification notification,
                                       Object handback) {
            q.add(notification);
        }
    };
    mbs.addNotificationListener(relSvcName, qListener, null, null);

    RoleInfo leftInfo =
        new RoleInfo("left", "javax.management.timer.TimerMBean");
    RoleInfo rightInfo =
        new RoleInfo("right", "javax.management.timer.Timer");
    relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
    ObjectName timer1 = new ObjectName("a:type=timer,number=1");
    ObjectName timer2 = new ObjectName("a:type=timer,number=2");
    mbs.createMBean("javax.management.timer.Timer", timer1);
    mbs.createMBean("javax.management.timer.Timer", timer2);

    Role leftRole =
        new Role("left", Arrays.asList(new ObjectName[] {timer1}));
    Role rightRole =
        new Role("right", Arrays.asList(new ObjectName[] {timer2}));
    RoleList roles =
        new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));

    final int NREPEAT = 10;

    for (int i = 0; i < NREPEAT; i++) {
        relSvc.createRelation("relationName", "typeName", roles);
        relSvc.removeRelation("relationName");
    }

    Notification firstNotif = q.remove();
    long seqNo = firstNotif.getSequenceNumber();
    for (int i = 0; i < NREPEAT * 2 - 1; i++) {
        Notification n = q.remove();
        long nSeqNo = n.getSequenceNumber();
        if (nSeqNo != seqNo + 1) {
            throw new Exception(
                    "TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
                    nSeqNo);
        }
        seqNo++;
    }
    System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
            "with contiguous sequence numbers");
}
项目:jdk8u-dev-jdk    文件:RelationNotificationSeqNoTest.java   
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName relSvcName = new ObjectName("a:type=relationService");
    RelationServiceMBean relSvc =
            JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
    mbs.createMBean("javax.management.relation.RelationService",
                    relSvcName,
                    new Object[] {Boolean.TRUE},
                    new String[] {"boolean"});

    final BlockingQueue<Notification> q =
            new ArrayBlockingQueue<Notification>(100);
    NotificationListener qListener = new NotificationListener() {
        public void handleNotification(Notification notification,
                                       Object handback) {
            q.add(notification);
        }
    };
    mbs.addNotificationListener(relSvcName, qListener, null, null);

    RoleInfo leftInfo =
        new RoleInfo("left", "javax.management.timer.TimerMBean");
    RoleInfo rightInfo =
        new RoleInfo("right", "javax.management.timer.Timer");
    relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
    ObjectName timer1 = new ObjectName("a:type=timer,number=1");
    ObjectName timer2 = new ObjectName("a:type=timer,number=2");
    mbs.createMBean("javax.management.timer.Timer", timer1);
    mbs.createMBean("javax.management.timer.Timer", timer2);

    Role leftRole =
        new Role("left", Arrays.asList(new ObjectName[] {timer1}));
    Role rightRole =
        new Role("right", Arrays.asList(new ObjectName[] {timer2}));
    RoleList roles =
        new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));

    final int NREPEAT = 10;

    for (int i = 0; i < NREPEAT; i++) {
        relSvc.createRelation("relationName", "typeName", roles);
        relSvc.removeRelation("relationName");
    }

    Notification firstNotif = q.remove();
    long seqNo = firstNotif.getSequenceNumber();
    for (int i = 0; i < NREPEAT * 2 - 1; i++) {
        Notification n = q.remove();
        long nSeqNo = n.getSequenceNumber();
        if (nSeqNo != seqNo + 1) {
            throw new Exception(
                    "TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
                    nSeqNo);
        }
        seqNo++;
    }
    System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
            "with contiguous sequence numbers");
}
项目:jdk7-jdk    文件:RelationNotificationSeqNoTest.java   
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName relSvcName = new ObjectName("a:type=relationService");
    RelationServiceMBean relSvc =
            JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
    mbs.createMBean("javax.management.relation.RelationService",
                    relSvcName,
                    new Object[] {Boolean.TRUE},
                    new String[] {"boolean"});

    final BlockingQueue<Notification> q =
            new ArrayBlockingQueue<Notification>(100);
    NotificationListener qListener = new NotificationListener() {
        public void handleNotification(Notification notification,
                                       Object handback) {
            q.add(notification);
        }
    };
    mbs.addNotificationListener(relSvcName, qListener, null, null);

    RoleInfo leftInfo =
        new RoleInfo("left", "javax.management.timer.TimerMBean");
    RoleInfo rightInfo =
        new RoleInfo("right", "javax.management.timer.Timer");
    relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
    ObjectName timer1 = new ObjectName("a:type=timer,number=1");
    ObjectName timer2 = new ObjectName("a:type=timer,number=2");
    mbs.createMBean("javax.management.timer.Timer", timer1);
    mbs.createMBean("javax.management.timer.Timer", timer2);

    Role leftRole =
        new Role("left", Arrays.asList(new ObjectName[] {timer1}));
    Role rightRole =
        new Role("right", Arrays.asList(new ObjectName[] {timer2}));
    RoleList roles =
        new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));

    final int NREPEAT = 10;

    for (int i = 0; i < NREPEAT; i++) {
        relSvc.createRelation("relationName", "typeName", roles);
        relSvc.removeRelation("relationName");
    }

    Notification firstNotif = q.remove();
    long seqNo = firstNotif.getSequenceNumber();
    for (int i = 0; i < NREPEAT * 2 - 1; i++) {
        Notification n = q.remove();
        long nSeqNo = n.getSequenceNumber();
        if (nSeqNo != seqNo + 1) {
            throw new Exception(
                    "TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
                    nSeqNo);
        }
        seqNo++;
    }
    System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
            "with contiguous sequence numbers");
}
项目:openjdk-source-code-learn    文件:RelationNotificationSeqNoTest.java   
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName relSvcName = new ObjectName("a:type=relationService");
    RelationServiceMBean relSvc =
            JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
    mbs.createMBean("javax.management.relation.RelationService",
                    relSvcName,
                    new Object[] {Boolean.TRUE},
                    new String[] {"boolean"});

    final BlockingQueue<Notification> q =
            new ArrayBlockingQueue<Notification>(100);
    NotificationListener qListener = new NotificationListener() {
        public void handleNotification(Notification notification,
                                       Object handback) {
            q.add(notification);
        }
    };
    mbs.addNotificationListener(relSvcName, qListener, null, null);

    RoleInfo leftInfo =
        new RoleInfo("left", "javax.management.timer.TimerMBean");
    RoleInfo rightInfo =
        new RoleInfo("right", "javax.management.timer.Timer");
    relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
    ObjectName timer1 = new ObjectName("a:type=timer,number=1");
    ObjectName timer2 = new ObjectName("a:type=timer,number=2");
    mbs.createMBean("javax.management.timer.Timer", timer1);
    mbs.createMBean("javax.management.timer.Timer", timer2);

    Role leftRole =
        new Role("left", Arrays.asList(new ObjectName[] {timer1}));
    Role rightRole =
        new Role("right", Arrays.asList(new ObjectName[] {timer2}));
    RoleList roles =
        new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));

    final int NREPEAT = 10;

    for (int i = 0; i < NREPEAT; i++) {
        relSvc.createRelation("relationName", "typeName", roles);
        relSvc.removeRelation("relationName");
    }

    Notification firstNotif = q.remove();
    long seqNo = firstNotif.getSequenceNumber();
    for (int i = 0; i < NREPEAT * 2 - 1; i++) {
        Notification n = q.remove();
        long nSeqNo = n.getSequenceNumber();
        if (nSeqNo != seqNo + 1) {
            throw new Exception(
                    "TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
                    nSeqNo);
        }
        seqNo++;
    }
    System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
            "with contiguous sequence numbers");
}
项目:OLD-OpenJDK8    文件:RelationNotificationSeqNoTest.java   
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName relSvcName = new ObjectName("a:type=relationService");
    RelationServiceMBean relSvc =
            JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
    mbs.createMBean("javax.management.relation.RelationService",
                    relSvcName,
                    new Object[] {Boolean.TRUE},
                    new String[] {"boolean"});

    final BlockingQueue<Notification> q =
            new ArrayBlockingQueue<Notification>(100);
    NotificationListener qListener = new NotificationListener() {
        public void handleNotification(Notification notification,
                                       Object handback) {
            q.add(notification);
        }
    };
    mbs.addNotificationListener(relSvcName, qListener, null, null);

    RoleInfo leftInfo =
        new RoleInfo("left", "javax.management.timer.TimerMBean");
    RoleInfo rightInfo =
        new RoleInfo("right", "javax.management.timer.Timer");
    relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
    ObjectName timer1 = new ObjectName("a:type=timer,number=1");
    ObjectName timer2 = new ObjectName("a:type=timer,number=2");
    mbs.createMBean("javax.management.timer.Timer", timer1);
    mbs.createMBean("javax.management.timer.Timer", timer2);

    Role leftRole =
        new Role("left", Arrays.asList(new ObjectName[] {timer1}));
    Role rightRole =
        new Role("right", Arrays.asList(new ObjectName[] {timer2}));
    RoleList roles =
        new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));

    final int NREPEAT = 10;

    for (int i = 0; i < NREPEAT; i++) {
        relSvc.createRelation("relationName", "typeName", roles);
        relSvc.removeRelation("relationName");
    }

    Notification firstNotif = q.remove();
    long seqNo = firstNotif.getSequenceNumber();
    for (int i = 0; i < NREPEAT * 2 - 1; i++) {
        Notification n = q.remove();
        long nSeqNo = n.getSequenceNumber();
        if (nSeqNo != seqNo + 1) {
            throw new Exception(
                    "TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
                    nSeqNo);
        }
        seqNo++;
    }
    System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
            "with contiguous sequence numbers");
}
项目:JAVA_UNIT    文件:RelationNotificationSeqNoTest.java   
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName relSvcName = new ObjectName("a:type=relationService");
    RelationServiceMBean relSvc =
            JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
    mbs.createMBean("javax.management.relation.RelationService",
                    relSvcName,
                    new Object[] {Boolean.TRUE},
                    new String[] {"boolean"});

    final BlockingQueue<Notification> q =
            new ArrayBlockingQueue<Notification>(100);
    NotificationListener qListener = new NotificationListener() {
        public void handleNotification(Notification notification,
                                       Object handback) {
            q.add(notification);
        }
    };
    mbs.addNotificationListener(relSvcName, qListener, null, null);

    RoleInfo leftInfo =
        new RoleInfo("left", "javax.management.timer.TimerMBean");
    RoleInfo rightInfo =
        new RoleInfo("right", "javax.management.timer.Timer");
    relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
    ObjectName timer1 = new ObjectName("a:type=timer,number=1");
    ObjectName timer2 = new ObjectName("a:type=timer,number=2");
    mbs.createMBean("javax.management.timer.Timer", timer1);
    mbs.createMBean("javax.management.timer.Timer", timer2);

    Role leftRole =
        new Role("left", Arrays.asList(new ObjectName[] {timer1}));
    Role rightRole =
        new Role("right", Arrays.asList(new ObjectName[] {timer2}));
    RoleList roles =
        new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));

    final int NREPEAT = 10;

    for (int i = 0; i < NREPEAT; i++) {
        relSvc.createRelation("relationName", "typeName", roles);
        relSvc.removeRelation("relationName");
    }

    Notification firstNotif = q.remove();
    long seqNo = firstNotif.getSequenceNumber();
    for (int i = 0; i < NREPEAT * 2 - 1; i++) {
        Notification n = q.remove();
        long nSeqNo = n.getSequenceNumber();
        if (nSeqNo != seqNo + 1) {
            throw new Exception(
                    "TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
                    nSeqNo);
        }
        seqNo++;
    }
    System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
            "with contiguous sequence numbers");
}
项目:openjdk-jdk7u-jdk    文件:RelationNotificationSeqNoTest.java   
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName relSvcName = new ObjectName("a:type=relationService");
    RelationServiceMBean relSvc =
            JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
    mbs.createMBean("javax.management.relation.RelationService",
                    relSvcName,
                    new Object[] {Boolean.TRUE},
                    new String[] {"boolean"});

    final BlockingQueue<Notification> q =
            new ArrayBlockingQueue<Notification>(100);
    NotificationListener qListener = new NotificationListener() {
        public void handleNotification(Notification notification,
                                       Object handback) {
            q.add(notification);
        }
    };
    mbs.addNotificationListener(relSvcName, qListener, null, null);

    RoleInfo leftInfo =
        new RoleInfo("left", "javax.management.timer.TimerMBean");
    RoleInfo rightInfo =
        new RoleInfo("right", "javax.management.timer.Timer");
    relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
    ObjectName timer1 = new ObjectName("a:type=timer,number=1");
    ObjectName timer2 = new ObjectName("a:type=timer,number=2");
    mbs.createMBean("javax.management.timer.Timer", timer1);
    mbs.createMBean("javax.management.timer.Timer", timer2);

    Role leftRole =
        new Role("left", Arrays.asList(new ObjectName[] {timer1}));
    Role rightRole =
        new Role("right", Arrays.asList(new ObjectName[] {timer2}));
    RoleList roles =
        new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));

    final int NREPEAT = 10;

    for (int i = 0; i < NREPEAT; i++) {
        relSvc.createRelation("relationName", "typeName", roles);
        relSvc.removeRelation("relationName");
    }

    Notification firstNotif = q.remove();
    long seqNo = firstNotif.getSequenceNumber();
    for (int i = 0; i < NREPEAT * 2 - 1; i++) {
        Notification n = q.remove();
        long nSeqNo = n.getSequenceNumber();
        if (nSeqNo != seqNo + 1) {
            throw new Exception(
                    "TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
                    nSeqNo);
        }
        seqNo++;
    }
    System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
            "with contiguous sequence numbers");
}
项目:freeVM    文件:StructureTest.java   
/**
 * This testcase verifies MBeanToUnregister field in notifications.
 */

public Result testRemovalNotification() throws Exception {

    incorrectNotificationFlag = false;

    MBeanServer mBeanServer = MBeanServerFactory.createMBeanServer();

    RelationService relationService = new RelationService(true);
    ObjectName relationServiceName = new ObjectName(
            "mBeanServer:type=RelationService,name=rs");
    mBeanServer.registerMBean(relationService, relationServiceName);

    NotificationFilterSupport filter = new NotificationFilterSupport();
    filter.enableType("jmx.relation");
    relationService.addNotificationListener(this, filter, null);
    checkNotifications = true;

    RoleInfo[] roleInfo = new RoleInfo[1];
    roleInfo[0] = new RoleInfo("unitRole", classPath, true, true, 1, 2,
            "Unit role");

    // Creating an Internal Relation Type
    relationService.createRelationType("internalRelationType", roleInfo);

    UnitMBean unit = new Unit();
    ObjectName unitName = new ObjectName("mBeanServer:type=Unit,name=Unit");
    mBeanServer.registerMBean(unit, unitName);

    ArrayList unitList = new ArrayList();
    unitList.add(unitName);

    Role unitRole = new Role("unitRole", unitList);
    RoleList unitRoles = new RoleList();
    unitRoles.add(unitRole);

    // Now Create relations between unit MBeans

    // Notification Data
    relationNotification = new RelationNotificationForCompare(
            "jmx.relation.creation.basic", relationService, 1, 10,
            "Creation of relation internalRelation", "internalRelation",
            "internalRelationType", null, null);

    relationService.createRelation("internalRelation",
            "internalRelationType", unitRoles);

    // Notification Data
    relationNotification = new RelationNotificationForCompare(
            "jmx.relation.removal.basic", relationService, 2, 10,
            "Removal of relation internalRelation", "internalRelation",
            "internalRelationType", null, new ArrayList());

    relationService.removeRelation("internalRelation");

    if (incorrectNotificationFlag) {
        return failed("IncorrectNotifications (see log for more information)");
    }
    return passed();
}
项目:freeVM    文件:StructureTest.java   
/**
 * Step by step for verification that relation is removed as soon as its
 * relation type is removed.
 * <ul>
 * <li>a. Create relation
 * <li>b. Remove relation type
 * <li>c. Check that relation isn't present in relation service
 * </ul>
 */
public Result testRemoveRelationType() throws Exception {

    MBeanServer mBeanServer = MBeanServerFactory.createMBeanServer();

    RelationService relationService = new RelationService(true);
    ObjectName relationServiceName = new ObjectName(
            "mBeanServer:type=RelationService,name=rs");
    mBeanServer.registerMBean(relationService, relationServiceName);

    RoleInfo[] roleInfo = new RoleInfo[1];
    roleInfo[0] = new RoleInfo("unitRole", classPath, true, true, 1, 2,
            "Unit role");

    /* Creating an Internal Relation Type */
    relationService.createRelationType("internalRelationType", roleInfo);

    /* 2 MBean objects to be associate */
    UnitMBean unit1 = new Unit();
    ObjectName unit1Name = new ObjectName(
            "mBeanServer:type=Unit,name=Unit1");
    mBeanServer.registerMBean(unit1, unit1Name);

    /* Create Role */
    ArrayList unitList = new ArrayList();
    unitList.add(unit1Name);

    Role unitRole = new Role("unitRole", unitList);
    RoleList unitRoles = new RoleList();
    unitRoles.add(unitRole);

    /* Now Create relations between unit MBeans */
    relationService.createRelation("internalRelation",
            "internalRelationType", unitRoles);

    ERelation externalRelation = new ERelation("externalRelation",
            relationServiceName, mBeanServer, "internalRelationType",
            unitRoles);
    mBeanServer.registerMBean(externalRelation, externalRelation
            .getRelationON());

    /* Relations created. Now Remove Relation type */
    relationService.removeRelationType("internalRelationType");

    /* Check relations are removed */
    if (relationService.hasRelation("internalRelation").booleanValue()
            && relationService.hasRelation("externalRelation")
                    .booleanValue()) {
        return failed("Relation type had been removed, but relation is not");
    }

    return passed();
}
项目:freeVM    文件:StructureTest.java   
/**
 * Test creates 2 relation types with equals names and RoleInfos, but
 * referred to different relation services. Test checks that when first
 * relation type creates relation, second relation type is not affected
 */
public Result testTheSameRelationType() throws Exception {

    MBeanServer mBeanServer = MBeanServerFactory.createMBeanServer();

    RelationService firstRelationService = new RelationService(true);
    RelationService secondRelationService = new RelationService(true);

    ObjectName firstRelationServiceName = new ObjectName(
            "mBeanServer:type=RelationService,name=first");
    ObjectName secondRelationServiceName = new ObjectName(
            "mBeanServer:type=RelationService,name=second");

    mBeanServer.registerMBean(firstRelationService,
            firstRelationServiceName);
    mBeanServer.registerMBean(secondRelationService,
            secondRelationServiceName);

    RoleInfo roleInfo = new RoleInfo("usualRole", classPath, true, true, 1,
            1, "usual role");

    ERelationType eRelationType = new ERelationType("relationType",
            roleInfo);

    firstRelationService.addRelationType(eRelationType);
    secondRelationService.addRelationType(eRelationType);

    UnitMBean unit1 = new Unit();

    ObjectName unit1Name = new ObjectName(
            "mBeanServer:type=Unit,name=Unit1");
    mBeanServer.registerMBean(unit1, unit1Name);

    ArrayList unitList = new ArrayList();
    unitList.add(unit1Name);

    Role singleUnitRole = new Role("usualRole", unitList);

    RoleList singleunitRoles = new RoleList();
    singleunitRoles.add(singleUnitRole);

    firstRelationService.createRelation("relation", "relationType",
            singleunitRoles);

    if (secondRelationService.hasRelation("relation").booleanValue()) {
        return failed("RelationType Mismatch");
    }
    return passed();
}
项目:freeVM    文件:StructureTest.java   
/**
 * In this test External relation unregistered MBeans by itself. After this
 * verified relation service consistency.
 */

public Result testSelfUnregistration() throws Exception {

    MBeanServer mBeanServer = MBeanServerFactory.createMBeanServer();

    RelationService relationService = new RelationService(true);
    ObjectName relationServiceName = new ObjectName(
            "mBeanServer:type=RelationService,name=rs");
    mBeanServer.registerMBean(relationService, relationServiceName);

    RoleInfo[] roleInfo = new RoleInfo[1];
    roleInfo[0] = new RoleInfo("unitRole", classPath, true, true, 1, 2,
            "Unit role");

    // Creating an Internal Relation Type
    relationService.createRelationType("internalRelationType", roleInfo);

    // Registering 2 MBean objects
    UnitMBean unit1 = new Unit();
    ObjectName unit1Name = new ObjectName(
            "mBeanServer:type=Unit,name=Unit1");
    mBeanServer.registerMBean(unit1, unit1Name);

    ArrayList unitList = new ArrayList();

    unitList.add(unit1Name);
    Role unitRole = new Role("unitRole", unitList);
    RoleList unitRoles = new RoleList();
    unitRoles.add(unitRole);

    ERelation externalRelation = new ERelation("externalRelation",
            relationServiceName, mBeanServer, "internalRelationType",
            unitRoles);
    mBeanServer.registerMBean(externalRelation, externalRelation
            .getRelationON());
    relationService.addRelation(externalRelation.getRelationON());

    externalRelation.unregisterMBean(unit1Name);

    if (relationService.hasRelation("externalRelation").booleanValue()) {
        return failed("Consistency Failed");
    }
    return passed();
}
项目:freeVM    文件:StructureTest.java   
/**
 * This test verifies findReferencingRelations method
 */

public Result testRelationIdMap() throws Exception {

    MBeanServer mBeanServer = MBeanServerFactory.createMBeanServer();

    // Register Relation Service
    RelationService relationService = new RelationService(true);
    ObjectName relationServiceName = new ObjectName(
            "mBeanServer:type=RelationService,name=rs");
    mBeanServer.registerMBean(relationService, relationServiceName);

    // Create Role Information Array
    RoleInfo[] roleInfo = new RoleInfo[1];
    roleInfo[0] = new RoleInfo("unitRole", classPath, true, true, 1, 2,
            "Unit role");

    // Creating an Internal Relation Type
    relationService.createRelationType("internalRelationType", roleInfo);

    // Registering 2 MBean objects
    UnitMBean unit1 = new Unit();

    ObjectName unit2Name = new ObjectName(
            "mBeanServer:type=Unit,name=Unit2");
    mBeanServer.registerMBean(unit1, unit2Name);

    ObjectName unit1Name = new ObjectName(
            "mBeanServer:type=Unit,name=Unit1");
    mBeanServer.registerMBean(unit1, unit1Name);

    // Create RoleLists for single unit and double unit relations
    ArrayList unitList = new ArrayList();

    unitList.add(unit1Name);
    Role singleUnitRole = new Role("unitRole", unitList);

    unitList.add(unit2Name);
    Role doubleUnitRole = new Role("unitRole", unitList);

    RoleList singleunitRoles = new RoleList();
    singleunitRoles.add(singleUnitRole);

    RoleList doubleunitRoles = new RoleList();
    doubleunitRoles.add(doubleUnitRole);

    // Create 2 Internal Relations
    relationService.createRelation("internalRelationSingle",
            "internalRelationType", singleunitRoles);
    relationService.createRelation("internalRelationDouble",
            "internalRelationType", doubleunitRoles);
    ERelation externalRelation = new ERelation("externalRelation",
            relationServiceName, mBeanServer, "internalRelationType",
            doubleunitRoles);
    mBeanServer.registerMBean(externalRelation, externalRelation
            .getRelationON());
    relationService.addRelation(externalRelation.getRelationON());

    if ((!relationService.findReferencingRelations(unit2Name,
            "internalRelationType", "unitRole").containsKey(
            "internalRelationDouble"))
            || (!relationService.findReferencingRelations(unit1Name,
                    "internalRelationType", "unitRole").containsKey(
                    "internalRelationDouble"))
            || (!relationService.findReferencingRelations(unit1Name,
                    "internalRelationType", "unitRole").containsKey(
                    "internalRelationSingle"))
            || (!relationService.findReferencingRelations(unit1Name,
                    "internalRelationType", "unitRole").containsKey(
                    "externalRelation"))
            || (!relationService.findReferencingRelations(unit2Name,
                    "internalRelationType", "unitRole").containsKey(
                    "externalRelation"))) {
        log.info(relationService.findReferencingRelations(unit1Name,
                "internalRelationType", "unitRole").toString());
        return failed("findReferencingRelations method is incorrect");
    }
    return passed();
}
项目:freeVM    文件:RoleTest.java   
/**
 * This test verifies getRoles method
 */

public Result testGetRoles() throws Exception {

    MBeanServer mBeanServer = MBeanServerFactory.createMBeanServer();

    RelationService relationService = new RelationService(true);
    ObjectName relationServiceName = new ObjectName(
            "mBeanServer:type=RelationService,name=rs");
    mBeanServer.registerMBean(relationService, relationServiceName);

    UnitMBean unit1 = new Unit();
    ObjectName unit1Name = new ObjectName(
            "mBeanServer:type=Unit,name=Unit1");
    mBeanServer.registerMBean(unit1, unit1Name);

    RoleInfo[] roleInfo = new RoleInfo[1];
    roleInfo[0] = new RoleInfo("unitRole", classPath, true, true, 0, 2,
            "usual role");

    relationService.createRelationType("RelationType", roleInfo);

    ArrayList unitList = new ArrayList();
    unitList.add(unit1Name);

    Role unitRole = new Role("unitRole", unitList);
    RoleList unitRoles = new RoleList();
    unitRoles.add(unitRole);

    String[] roleNameArray = { "unitRole" };

    ERelation externalRelation = new ERelation("externalRelation",
            relationServiceName, mBeanServer, "RelationType", unitRoles);
    mBeanServer.registerMBean(externalRelation, externalRelation
            .getRelationON());
    relationService.addRelation(externalRelation.getRelationON());

    try {
        relationService.getRoles("externalRelation", roleNameArray);
    } catch (Exception e) {
        return failed(e.toString());
    }
    return passed();
}
项目:openjdk-icedtea7    文件:RelationNotificationSeqNoTest.java   
public static void main(String[] args) throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName relSvcName = new ObjectName("a:type=relationService");
    RelationServiceMBean relSvc =
            JMX.newMBeanProxy(mbs, relSvcName, RelationServiceMBean.class);
    mbs.createMBean("javax.management.relation.RelationService",
                    relSvcName,
                    new Object[] {Boolean.TRUE},
                    new String[] {"boolean"});

    final BlockingQueue<Notification> q =
            new ArrayBlockingQueue<Notification>(100);
    NotificationListener qListener = new NotificationListener() {
        public void handleNotification(Notification notification,
                                       Object handback) {
            q.add(notification);
        }
    };
    mbs.addNotificationListener(relSvcName, qListener, null, null);

    RoleInfo leftInfo =
        new RoleInfo("left", "javax.management.timer.TimerMBean");
    RoleInfo rightInfo =
        new RoleInfo("right", "javax.management.timer.Timer");
    relSvc.createRelationType("typeName", new RoleInfo[] {leftInfo, rightInfo});
    ObjectName timer1 = new ObjectName("a:type=timer,number=1");
    ObjectName timer2 = new ObjectName("a:type=timer,number=2");
    mbs.createMBean("javax.management.timer.Timer", timer1);
    mbs.createMBean("javax.management.timer.Timer", timer2);

    Role leftRole =
        new Role("left", Arrays.asList(new ObjectName[] {timer1}));
    Role rightRole =
        new Role("right", Arrays.asList(new ObjectName[] {timer2}));
    RoleList roles =
        new RoleList(Arrays.asList(new Role[] {leftRole, rightRole}));

    final int NREPEAT = 10;

    for (int i = 0; i < NREPEAT; i++) {
        relSvc.createRelation("relationName", "typeName", roles);
        relSvc.removeRelation("relationName");
    }

    Notification firstNotif = q.remove();
    long seqNo = firstNotif.getSequenceNumber();
    for (int i = 0; i < NREPEAT * 2 - 1; i++) {
        Notification n = q.remove();
        long nSeqNo = n.getSequenceNumber();
        if (nSeqNo != seqNo + 1) {
            throw new Exception(
                    "TEST FAILED: expected seqNo " + (seqNo + 1) + "; got " +
                    nSeqNo);
        }
        seqNo++;
    }
    System.out.println("TEST PASSED: got " + (NREPEAT * 2) + " notifications " +
            "with contiguous sequence numbers");
}
项目:freeVM    文件:ERelationType.java   
public ERelationType(String name, RoleInfo[] roleInfo)
        throws InvalidRelationTypeException, IllegalArgumentException {

    super(name);
    for (int i = 0; i < roleInfo.length; i++) {
        addRoleInfo(roleInfo[i]);

    }

}