CommandLineDriverSettingsModule extends AbstractModule { @VisibleForTesting static FrameworkInfo buildFrameworkInfo( String executorUser, Optional<String> principal, Amount<Long, Time> failoverTimeout, boolean revocable, Optional<String> role) { FrameworkInfo.Builder infoBuilder = FrameworkInfo.newBuilder() .setUser(executorUser) .setName(TWITTER_FRAMEWORK_NAME) .setCheckpoint(true) .setFailoverTimeout(failoverTimeout.as(Time.SECONDS)); if (principal.isPresent()) { infoBuilder.setPrincipal(principal.get()); } if (revocable) { infoBuilder.addCapabilities(Capability.newBuilder().setType(REVOCABLE_RESOURCES)); } if (role.isPresent()) { infoBuilder.setRole(role.get()); } return infoBuilder.build(); }    }
@Test public void testFrameworkInfoNoRevocable() { Protos.FrameworkInfo info = CommandLineDriverSettingsModule.buildFrameworkInfo( "user", Optional.absent(), Amount.of(1L, Time.MINUTES), false, Optional.absent()); assertEquals("", info.getPrincipal()); assertEquals(0, info.getCapabilitiesCount()); assertFalse(info.hasRole()); }
@Test public void testFrameworkInfoRevocable() { Protos.FrameworkInfo info = CommandLineDriverSettingsModule.buildFrameworkInfo( "user", Optional.absent(), Amount.of(1L, Time.MINUTES), true, Optional.absent()); assertEquals("", info.getPrincipal()); assertEquals(1, info.getCapabilitiesCount()); assertEquals(REVOCABLE_RESOURCES, info.getCapabilities(0).getType()); assertFalse(info.hasRole()); }
@Test public void testFrameworkInfoNoRevocableWithAnnouncedPrincipal() { Protos.FrameworkInfo info = CommandLineDriverSettingsModule.buildFrameworkInfo( "user", Optional.of("auroraprincipal"), Amount.of(1L, Time.MINUTES), false, Optional.absent()); assertEquals("auroraprincipal", info.getPrincipal()); assertEquals(0, info.getCapabilitiesCount()); assertFalse(info.hasRole()); }
@Test public void testFrameworkInfoRevocableWithAnnouncedPrincipalAndRole() { Protos.FrameworkInfo info = CommandLineDriverSettingsModule.buildFrameworkInfo( "user", Optional.of("auroraprincipal"), Amount.of(1L, Time.MINUTES), true, Optional.of(TEST_ROLE)); assertEquals("auroraprincipal", info.getPrincipal()); assertEquals(1, info.getCapabilitiesCount()); assertEquals(REVOCABLE_RESOURCES, info.getCapabilities(0).getType()); assertTrue(info.hasRole()); assertEquals(TEST_ROLE, info.getRole()); }