@Test
  public void testRolesInDistributedVMs() {
    // connect all four vms...
    final String[] vmRoles = new String[] {"VM_A", "BAR", "Foo,BAR", "Bip,BAM"};
    final Object[][] roleCounts = new Object[][] {{"VM_A", 1}, {"BAR", 2},
        {"Foo", 1}, {"Bip", 1}, {"BAM", 1}};

    for (int i = 0; i < vmRoles.length; i++) {
      final int vm = i;
      Host.getHost(0).getVM(vm).invoke(new SerializableRunnable("create system") {
        @Override
        public void run() {
          disconnectFromDS();
          Properties config = new Properties();
          config.setProperty(ROLES, vmRoles[vm]);
          config.setProperty(LOG_LEVEL, "fine");
          distributionProperties = config;
          getSystem();
        }
      });
    }

    // validate roles from each vm...
    for (int i = 0; i < vmRoles.length; i++) {
      final int vm = i;
      Host.getHost(0).getVM(vm).invoke(new SerializableRunnable("verify roles") {
        @Override
        public void run() {
          InternalDistributedSystem sys = getSystem();
          DistributionManager dm = sys.getDistributionManager();

          Set allRoles = dm.getAllRoles();
          assertEquals(
              "allRoles is " + allRoles.size() + " but roleCounts should be " + roleCounts.length,
              roleCounts.length, allRoles.size());

          for (final Object allRole : allRoles) {
            // match role with string in roleCounts
            Role role = (Role) allRole;
            for (final Object[] roleCount : roleCounts) {
              if (role.getName().equals(roleCount[0])) {
                // parse count
                int count = (Integer) roleCount[1];
                // assert count
                assertEquals("count for role " + role + " is wrong", count, dm.getRoleCount(role));
                assertEquals("isRolePresent for role " + role + " should be true", true,
                    dm.isRolePresent(role));
              }
            }
          }
        }
      });
    }
    System.out.println("testRolesInDistributedVMs completed");
  }
Tests usage of Roles in four distributed vms.
geode-core/src/distributedTest/java/org/apache/geode/distributed/RoleDUnitTest.java