public Optional<SupervisorSpec> getSupervisorSpec(String id) { Pair<Supervisor, SupervisorSpec> supervisor = supervisors.get(id); return supervisor == null ? Optional.absent() : Optional.fromNullable(supervisor.rhs); }
@Test public void testSpecGet() { SupervisorSpec spec = new TestSupervisorSpec("my-id", null, null); EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.of(supervisorManager)).times(2); EasyMock.expect(supervisorManager.getSupervisorSpec("my-id")).andReturn(Optional.of(spec)); EasyMock.expect(supervisorManager.getSupervisorSpec("my-id-2")).andReturn(Optional.absent()); replayAll(); Response response = supervisorResource.specGet("my-id"); Assert.assertEquals(200, response.getStatus()); Assert.assertEquals(spec, response.getEntity()); response = supervisorResource.specGet("my-id-2"); Assert.assertEquals(404, response.getStatus()); verifyAll(); resetAll(); EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.absent()); replayAll(); response = supervisorResource.specGet("my-id"); verifyAll(); Assert.assertEquals(503, response.getStatus()); }
private Optional<OrConditionSegment> buildCondition(final ParserRuleContext node, final Map<ParserRuleContext, Integer> placeholderIndexes) { Optional<ParserRuleContext> exprNode = ExtractorUtils.findFirstChildNode(node, RuleName.EXPR); return exprNode.isPresent() ? predicateSegmentExtractor.extractCondition(placeholderIndexes, exprNode.get()) : Optional.<OrConditionSegment>absent(); } }
private void fillAggregationDistinctSelectItemSegment(final AggregationDistinctSelectItemSegment selectItemSegment, final SelectStatement selectStatement) { selectStatement.getItems().add( new AggregationDistinctSelectItem(selectItemSegment.getType(), selectItemSegment.getInnerExpression(), selectItemSegment.getAlias(), selectItemSegment.getDistinctExpression())); Optional<String> derivedAlias = Optional.absent(); if (DerivedAlias.isDerivedAlias(selectItemSegment.getAlias().get())) { derivedAlias = Optional.of(selectItemSegment.getAlias().get()); } selectStatement.getSQLTokens().add(new AggregationDistinctToken(selectItemSegment.getStartIndex(), selectItemSegment.getStopIndex(), selectItemSegment.getDistinctExpression(), derivedAlias)); }
@VisibleForTesting AccessControlAction(Config actionConfig, FileSystem fs, Config jobConfig) { super(actionConfig, fs, jobConfig); this.permission = actionConfig.hasPath(MODE_KEY) ? Optional.of(new FsPermission(actionConfig.getString(MODE_KEY))) : Optional .<FsPermission> absent(); this.owner = Optional.fromNullable(ConfigUtils.getString(actionConfig, OWNER_KEY, null)); this.group = Optional.fromNullable(ConfigUtils.getString(actionConfig, GROUP_KEY, null)); this.selectionPolicy = createSelectionPolicy(actionConfig, jobConfig); }
@Test public void remove_processed_files() { when(movedFilesRepository.getOriginalFile(any(Component.class))).thenReturn(Optional.absent()); underTest.afterComponent(component); verify(movedFilesRepository).getOriginalFile(component); verify(componentsWithUnprocessedIssues).remove(UUID); verifyNoMoreInteractions(componentsWithUnprocessedIssues); }
@Override public Optional<Long> sizeIfKnown() { Optional<Long> optionalUnslicedSize = ByteSource.this.sizeIfKnown(); if (optionalUnslicedSize.isPresent()) { long unslicedSize = optionalUnslicedSize.get(); long off = Math.min(offset, unslicedSize); return Optional.of(Math.min(length, unslicedSize - off)); } return Optional.absent(); }
@Test public void testTerminate() { EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.of(supervisorManager)).times(2); EasyMock.expect(supervisorManager.stopAndRemoveSupervisor("my-id")).andReturn(true); EasyMock.expect(supervisorManager.stopAndRemoveSupervisor("my-id-2")).andReturn(false); replayAll(); Response response = supervisorResource.terminate("my-id"); Assert.assertEquals(200, response.getStatus()); Assert.assertEquals(ImmutableMap.of("id", "my-id"), response.getEntity()); response = supervisorResource.terminate("my-id-2"); Assert.assertEquals(404, response.getStatus()); verifyAll(); resetAll(); EasyMock.expect(taskMaster.getSupervisorManager()).andReturn(Optional.absent()); replayAll(); response = supervisorResource.terminate("my-id"); verifyAll(); Assert.assertEquals(503, response.getStatus()); }
@Test public void testGetSupervisorStatus() { SupervisorReport<Void> report = new SupervisorReport<>("id1", DateTimes.nowUtc(), null); Map<String, SupervisorSpec> existingSpecs = ImmutableMap.of( "id1", new TestSupervisorSpec("id1", supervisor1) ); EasyMock.expect(metadataSupervisorManager.getLatest()).andReturn(existingSpecs); supervisor1.start(); EasyMock.expect(supervisor1.getStatus()).andReturn(report); replayAll(); manager.start(); Assert.assertEquals(Optional.absent(), manager.getSupervisorStatus("non-existent-id")); Assert.assertEquals(report, manager.getSupervisorStatus("id1").get()); verifyAll(); }
FluentIterable(Iterable<E> iterable) { checkNotNull(iterable); this.iterableDelegate = Optional.fromNullable(this != iterable ? iterable : null); }
@Override protected Optional<ParserRuleContext> extractTable(final FromWhereSegment fromWhereSegment, final ParserRuleContext ancestorNode, final Map<ParserRuleContext, Integer> placeholderIndexes) { Optional<ParserRuleContext> tableReferenceNode = ExtractorUtils.findFirstChildNode(ancestorNode, RuleName.TABLE_REFERENCE); if (!tableReferenceNode.isPresent()) { return Optional.absent(); } this.extractTableReference(fromWhereSegment, tableReferenceNode.get(), placeholderIndexes); extractSetColumns(ancestorNode, (UpdateSetWhereSegment) fromWhereSegment, placeholderIndexes); return ExtractorUtils.findFirstChildNodeNoneRecursive(ancestorNode, RuleName.WHERE_CLAUSE); }