MarketDataSelectionGraphManipulator { public DependencyGraph modifyDependencyGraph(final DependencyGraph graph, final ComputationTargetResolver.AtVersionCorrection resolver, final Map<DistinctMarketDataSelector, Set<ValueSpecification>> selectorMapping) { ArgumentChecker.notNull(graph, "graph"); ArgumentChecker.notNull(resolver, "resolver"); ArgumentChecker.notNull(selectorMapping, "selectorMapping"); final String configurationName = graph.getCalculationConfigurationName(); final MarketDataSelector combinedSelector = buildCombinedSelector(configurationName); if (!combinedSelector.hasSelectionsDefined()) { return graph; } final int roots = graph.getRootCount(); final Set<DependencyNode> newRoots = Sets.newHashSetWithExpectedSize(roots); final DefaultSelectorResolver selectorResolver = new DefaultSelectorResolver(resolver); final DependencyGraphStructureExtractor extractor = new DependencyGraphStructureExtractor(configurationName, combinedSelector, selectorResolver, selectorMapping); for (int i = 0; i < roots; i++) { final DependencyNode root = graph.getRootNode(i); newRoots.add(modifyDependencyNode(root, root.getOutputValue(0), extractor)); } final Map<ValueSpecification, Set<ValueRequirement>> terminalOutputs; if (extractor.hasTerminalValueRenames()) { terminalOutputs = new HashMap<>(graph.getTerminalOutputs()); for (Pair<ValueSpecification, ValueSpecification> rename : extractor.getTerminalValueRenames()) { final Set<ValueRequirement> terminals = terminalOutputs.remove(rename.getFirst()); if (terminals != null) { terminalOutputs.put(rename.getSecond(), terminals); } } } else { terminalOutputs = graph.getTerminalOutputs(); } return new DependencyGraphImpl(graph.getCalculationConfigurationName(), newRoots, graph.getSize() + extractor.getNodeDelta(), terminalOutputs); } MarketDataSelectionGraphManipulator(final MarketDataSelector marketDataSelector, final Map<String, Map<DistinctMarketDataSelector, FunctionParameters>> specificSelectors); DependencyGraph modifyDependencyGraph(final DependencyGraph graph, final ComputationTargetResolver.AtVersionCorrection resolver,
      final Map<DistinctMarketDataSelector, Set<ValueSpecification>> selectorMapping); boolean hasManipulationsDefined(); Serializable getCacheHintKey();  }
@Test public void testInvocationWithEmptyGraphsGivesEmptyResults() { final MarketDataSelectionGraphManipulator manipulator = createNoOpManipulator(); final Map<DistinctMarketDataSelector, Set<ValueSpecification>> result = new HashMap<>(); manipulator.modifyDependencyGraph(new TestDependencyGraphBuilder("testGraph").buildGraph(), _resolver, result); assertEquals(result.isEmpty(), true); }
@Test public void testNoOpSelectorDoesNothingToGraph() { final MarketDataSelectionGraphManipulator manipulator = createNoOpManipulator(); final DependencyGraph graph = createSimpleGraphWithMarketDataNodes(); final Set<ValueSpecification> originalOutputSpecifications = DependencyGraphImpl.getAllOutputSpecifications(graph); final Map<DistinctMarketDataSelector, Set<ValueSpecification>> result = new HashMap<>(); final DependencyGraph newGraph = manipulator.modifyDependencyGraph(graph, _resolver, result); assertEquals(result.isEmpty(), true); assertEquals(DependencyGraphImpl.getAllOutputSpecifications(newGraph), originalOutputSpecifications); }
@Test public void testYieldCurveSelectorAltersGraph() { final MarketDataSelectionGraphManipulator manipulator = new MarketDataSelectionGraphManipulator(createYieldCurveSelector(Currency.USD, "Forward3M"), createEmptyViewCalcManipulations()); final DependencyGraph graph = createSimpleGraphWithMarketDataNodes(); final Set<ValueSpecification> originalOutputSpecifications = DependencyGraphImpl.getAllOutputSpecifications(graph); final Map<DistinctMarketDataSelector, Set<ValueSpecification>> result = new HashMap<>(); final DependencyGraph newGraph = manipulator.modifyDependencyGraph(graph, _resolver, result); checkNodeHasBeenAddedToGraph(newGraph, originalOutputSpecifications, result); }
@Test public void testSpecificYieldCurveSelectorAltersNamedGraph() { final DistinctMarketDataSelector yieldCurveSelector = createYieldCurveSelector(Currency.USD, "Forward3M"); final Map<String, Map<DistinctMarketDataSelector, FunctionParameters>> specificManipulators = new HashMap<>(); specificManipulators.put("graph", createYieldCurveSelectorAndParams(Currency.USD, "Forward3M")); final MarketDataSelectionGraphManipulator manipulator = new MarketDataSelectionGraphManipulator(NoOpMarketDataSelector.getInstance(), specificManipulators); final DependencyGraph graph1 = createNamedDependencyGraph("graph"); final Set<ValueSpecification> originalOutputSpecifications1 = DependencyGraphImpl.getAllOutputSpecifications(graph1); final Map<DistinctMarketDataSelector, Set<ValueSpecification>> result1 = new HashMap<>(); final DependencyGraph newGraph1 = manipulator.modifyDependencyGraph(graph1, _resolver, result1); checkNodeHasBeenAddedToGraph(newGraph1, originalOutputSpecifications1, result1); assertEquals(result1.size(), 1); assertTrue(result1.containsKey(yieldCurveSelector)); }
@Test public void testSpecificYieldCurveSelectorDoesNotAlterDifferentNamedGraph() { final Map<String, Map<DistinctMarketDataSelector, FunctionParameters>> specificManipulators = new HashMap<>(); specificManipulators.put("graph-to-find", createYieldCurveSelectorAndParams(Currency.USD, "Forward3M")); final MarketDataSelectionGraphManipulator manipulator = new MarketDataSelectionGraphManipulator(NoOpMarketDataSelector.getInstance(), specificManipulators); final DependencyGraph graph = createNamedDependencyGraph("not-the-graph-you-are-looking-for"); final Set<ValueSpecification> originalOutputSpecifications2 = DependencyGraphImpl.getAllOutputSpecifications(graph); final Map<DistinctMarketDataSelector, Set<ValueSpecification>> result = new HashMap<>(); final DependencyGraph newGraph = manipulator.modifyDependencyGraph(graph, _resolver, result); assertTrue(result.isEmpty()); assertEquals(DependencyGraphImpl.getAllOutputSpecifications(newGraph), originalOutputSpecifications2); }
@Test public void testCompositeSelectorReturnsUnderlyingSelector() { final MarketDataSelector yieldCurveSelector = createYieldCurveSelector(Currency.USD, "Forward3M"); final MarketDataSelectionGraphManipulator manipulator = new MarketDataSelectionGraphManipulator(CompositeMarketDataSelector.of(yieldCurveSelector), createEmptyViewCalcManipulations()); final DependencyGraph graph = createSimpleGraphWithMarketDataNodes(); final Set<ValueSpecification> originalOutputSpecifications = DependencyGraphImpl.getAllOutputSpecifications(graph); final Map<DistinctMarketDataSelector, Set<ValueSpecification>> result = new HashMap<>(); final DependencyGraph newGraph = manipulator.modifyDependencyGraph(graph, _resolver, result); checkNodeHasBeenAddedToGraph(newGraph, originalOutputSpecifications, result); assertEquals(result.size(), 1); assertEquals(result.containsKey(yieldCurveSelector), true); }
@Test public void noSelectors() { Set<MarketDataSelector> noSelectors = Collections.emptySet(); MarketDataSelectionGraphManipulator manipulator = new MarketDataSelectionGraphManipulator(CompositeMarketDataSelector.of(noSelectors), createEmptyViewCalcManipulations()); DependencyGraph graph = createSimpleGraphWithMarketDataNodes(); Map<DistinctMarketDataSelector, Set<ValueSpecification>> result = new HashMap<>(); manipulator.modifyDependencyGraph(graph, _resolver, result); assertTrue(result.isEmpty()); }