public void testEmptyChain() { Graph graph = new Graph("test-graph"); try { new GraphContext(graph); fail("GraphException expected due to empty graph"); } catch (GraphException e) { // ok } }
/** * Executes the graph using a new default {@link GraphContext}. * * @param graph the {@link Graph} * @param pm a progress monitor. Can be used to signal progress. * * @throws GraphException if any error occurs during execution * @see GraphProcessor#executeGraph(GraphContext, com.bc.ceres.core.ProgressMonitor) */ public void executeGraph(Graph graph, ProgressMonitor pm) throws GraphException { GraphContext graphContext; try { pm.beginTask("Executing processing graph", 100); graphContext = new GraphContext(graph); executeGraph(graphContext, SubProgressMonitor.create(pm, 90)); graphContext.dispose(); } finally { pm.done(); } }
private NodeContext getTargetNodeContext(Graph graph) throws GraphException { GraphContext graphContext = new GraphContext(graph, this); NodeContext targetNodeContext = null; Header header = graph.getHeader(); if (header != null) { HeaderTarget headerTarget = header.getTarget(); Node targetNode = graph.getNode(headerTarget.getNodeId()); for (Node node : graph.getNodes()) { if (node == targetNode) { targetNodeContext = graphContext.getNodeContext(node); break; } } } return targetNodeContext; }
public void testSpiCreation() throws GraphException { Graph graph = new Graph("chain1"); Node node1 = new Node("node1", "Op1"); graph.addNode(node1); GraphContext graphContext = new GraphContext(graph); NodeContext nodeContext = graphContext.getNodeContext(node1); assertEquals("Op1", graph.getNode("node1").getOperatorName()); assertEquals("org.esa.beam.framework.gpf.TestOps$Op1", nodeContext.getOperator().getClass().getName()); }
public void testOptionalAndWrongProductIsNotGiven() throws GraphException { Graph graph = new Graph("graph"); Node wrongBandsNode = new Node("WrongBands", wrongBandsOpSpi.getOperatorAlias()); Node consumerNode = new Node("OptionalConsumer", optionalConsumerOpSpi.getOperatorAlias()); graph.addNode(wrongBandsNode); graph.addNode(consumerNode); new GraphContext(graph); }
public void testTargetProductCreation() throws GraphException { Graph graph = new Graph("chain1"); Node node1 = new Node("node1", "Op1"); graph.addNode(node1); GraphContext graphContext = new GraphContext(graph); Product[] outputProducts = graphContext.getOutputProducts(); assertNotNull(outputProducts); assertEquals(1, outputProducts.length); assertNotNull(outputProducts[0]); }
public void testNotInitialzedInputResultsInException() { Graph graph = new Graph("graph"); Node goodNode = new Node("Good", goodOpSpi.getOperatorAlias()); Node consumerNode = new Node("Consumer", consumerOpSpi.getOperatorAlias()); graph.addNode(goodNode); graph.addNode(consumerNode); try { new GraphContext(graph); fail("GraphException expected, because input1 is not initialized"); } catch (GraphException ge) { } }
public void testAnySourcesOp() { final String opName = "AnySourcesOp"; Graph graph; Node outputNode; graph = createTestGraph(opName); try { new GraphContext(graph); fail("GraphException expected, at least one source expected"); } catch (GraphException ge) { } graph = createTestGraph(opName); outputNode = graph.getNode("output"); outputNode.addSource(new NodeSource("dummy1", "input1")); outputNode.addSource(new NodeSource("dummy2", "input2")); outputNode.addSource(new NodeSource("dummy3", "input3")); try { new GraphContext(graph); } catch (GraphException ge) { fail("GraphException not expected, any number of sources allowed. Error: " + ge.getMessage()); } }
public void testOptSourcesOp() { final String opName = "OptSourcesOp"; Graph graph; Node outputNode; graph = createTestGraph(opName); try { new GraphContext(graph); } catch (GraphException ge) { fail("GraphException not expected, sources not checked. Error: " + ge.getMessage()); } graph = createTestGraph(opName); outputNode = graph.getNode("output"); outputNode.addSource(new NodeSource("dummy1", "input1")); outputNode.addSource(new NodeSource("dummy2", "input2")); outputNode.addSource(new NodeSource("dummy3", "input3")); try { new GraphContext(graph); } catch (GraphException ge) { fail("GraphException not expected, sources not checked. Error: " + ge.getMessage()); } }
public void testTargetProductIsSetByAnnotation() throws GraphException { Graph graph = new Graph("graph"); Node node = new Node("OutputNotSet", notInitTargetProductOpSPI.getOperatorAlias()); graph.addNode(node); GraphContext graphContext = new GraphContext(graph); NodeContext nodeContext = graphContext.getNodeContext(node); NotInitOutputOperator notInitOutputOperator = (NotInitOutputOperator) nodeContext.getOperator(); assertNotNull("Output of operator is null", notInitOutputOperator.output); assertSame(nodeContext.getTargetProduct(), notInitOutputOperator.output); }
public void testOptionalAndWrongProductIsGiven() { Graph graph = new Graph("graph"); Node wrongBandsNode = new Node("WrongBands", wrongBandsOpSpi.getOperatorAlias()); Node consumerNode = new Node("OptionalConsumer", optionalConsumerOpSpi.getOperatorAlias()); consumerNode.addSource(new NodeSource("input1", "WrongBands")); graph.addNode(wrongBandsNode); graph.addNode(consumerNode); try { new GraphContext(graph); fail("GraphException expected, caused by missing bands, even if optional"); } catch (GraphException ge) { } }
public void testForWrongType() { Graph graph = new Graph("graph"); Node wrongTypeNode = new Node("WrongType", wrongTypeOpSpi.getOperatorAlias()); Node consumerNode = new Node("Consumer", consumerOpSpi.getOperatorAlias()); consumerNode.addSource(new NodeSource("input1", "WrongType")); graph.addNode(wrongTypeNode); graph.addNode(consumerNode); try { new GraphContext(graph); fail("GraphException expected caused by wrong type of source product"); } catch (GraphException ge) { } }
public void testForWrongBands() { Graph graph = new Graph("graph"); Node wrongBandsNode = new Node("WrongBands", wrongBandsOpSpi.getOperatorAlias()); Node consumerNode = new Node("Consumer", consumerOpSpi.getOperatorAlias()); consumerNode.addSource(new NodeSource("input1", "WrongBands")); graph.addNode(wrongBandsNode); graph.addNode(consumerNode); try { new GraphContext(graph); fail("GraphException expected, caused by missing bands"); } catch (GraphException ge) { } }
public void testSourceProductWithAlias() throws GraphException { Graph graph = new Graph("graph"); Node goodNode = new Node("Good", goodOpSpi.getOperatorAlias()); Node consumerNode = new Node("AliasConsumer", aliasConsumerOpSpi.getOperatorAlias()); consumerNode.addSource(new NodeSource("alias", "Good")); graph.addNode(goodNode); graph.addNode(consumerNode); GraphContext graphContext = new GraphContext(graph); NodeContext consumerNodeContext = graphContext.getNodeContext(consumerNode); assertSame(((ConsumerWithAliasSourceOperator) consumerNodeContext.getOperator()).input1, consumerNodeContext.getSourceProduct("alias")); }
public void testMissingSpi() { Graph graph = new Graph("graph"); Node node1 = new Node("node1", "Opa"); Node node2 = new Node("node2", "Op2"); Node node3 = new Node("node3", "Op3"); node2.addSource(new NodeSource("input", "node1")); node3.addSource(new NodeSource("input1", "node1")); node3.addSource(new NodeSource("input2", "node2")); try { graph.addNode(node1); graph.addNode(node3); new GraphContext(graph); fail("GraphException expected."); } catch (GraphException e) { // expected } }
public void testMissingNode() { Graph graph = new Graph("graph"); Node node1 = new Node("node1", "Op1"); Node node2 = new Node("node2", "Op2"); Node node3 = new Node("node3", "Op3"); node2.addSource(new NodeSource("input", "node1")); node3.addSource(new NodeSource("input1", "node1")); node3.addSource(new NodeSource("input2", "node2")); try { graph.addNode(node1); graph.addNode(node3); new GraphContext(graph); fail("GraphException expected."); } catch (GraphException e) { // expected } }
@SuppressWarnings("null") public void testTwoOpsExecutionOrder() throws Exception { GraphProcessor processor = new GraphProcessor(); Graph graph = new Graph("chain1"); Node node1 = new Node("node1", "Op1"); Node node2 = new Node("node2", "Op2"); node2.addSource(new NodeSource("input", "node1")); graph.addNode(node1); graph.addNode(node2); GraphContext graphContext = new GraphContext(graph); Product chainOut = processor.executeGraph(graphContext, ProgressMonitor.NULL)[0]; assertNotNull(chainOut); assertEquals("Op2Name", chainOut.getName()); assertEquals("Op1;Op2;", TestOps.getCalls()); TestOps.clearCalls(); }
public void testThreeOpsExecutionOrder() throws Exception { VerbousTileCache.setVerbous(false); Graph graph = new Graph("graph"); Node node1 = new Node("node1", "Op1"); Node node2 = new Node("node2", "Op2"); Node node3 = new Node("node3", "Op3"); node2.addSource(new NodeSource("input", "node1")); node3.addSource(new NodeSource("input1", "node1")); node3.addSource(new NodeSource("input2", "node2")); graph.addNode(node1); graph.addNode(node2); graph.addNode(node3); GraphProcessor processor = new GraphProcessor(); GraphContext graphContext = new GraphContext(graph); Product chainOut = graphContext.getOutputProducts()[0]; assertNotNull(chainOut); assertEquals("Op3Name", chainOut.getName()); processor.executeGraph(graphContext, ProgressMonitor.NULL); // - Op3 requires the two bands of Op2 // - Op2 computes all bands // --> Op2 should only be called once assertEquals("Op1;Op2;Op3;", TestOps.getCalls()); TestOps.clearCalls(); VerbousTileCache.setVerbous(false); }
public void testSourceToNodeResolving() throws GraphException { Graph graph = new Graph("chain1"); Node node1 = new Node("node1", "org.esa.beam.framework.gpf.TestOps$Op1$Spi"); Node node2 = new Node("node2", "org.esa.beam.framework.gpf.TestOps$Op2$Spi"); node2.addSource(new NodeSource("input", "node1")); Node node3 = new Node("node3", "org.esa.beam.framework.gpf.TestOps$Op3$Spi"); node3.addSource(new NodeSource("input1", "node1")); node3.addSource(new NodeSource("input2", "node2")); graph.addNode(node1); graph.addNode(node2); graph.addNode(node3); GraphContext graphContext = new GraphContext(graph); assertEquals(node2.getSource(0).getSourceNode(), node1); assertEquals(node3.getSource(0).getSourceNode(), node1); assertEquals(node3.getSource(1).getSourceNode(), node2); assertFalse(graphContext.getNodeContext(node1).isOutput()); assertFalse(graphContext.getNodeContext(node2).isOutput()); assertTrue(graphContext.getNodeContext(node3).isOutput()); }
public void testAnnotationsProcessed() throws Exception { Graph graph = new Graph("graph"); Node node1 = new Node("node1", "Op1"); Node node2 = new Node("node2", "Op2"); Node node3 = new Node("node3", "Op3"); node2.addSource(new NodeSource("input", "node1")); node3.addSource(new NodeSource("input1", "node1")); node3.addSource(new NodeSource("input2", "node2")); graph.addNode(node1); graph.addNode(node2); graph.addNode(node3); GraphContext graphContext = new GraphContext(graph); NodeContext nodeContext2 = graphContext.getNodeContext(node2); NodeContext nodeContext3 = graphContext.getNodeContext(node3); TestOps.Op2 op2 = ((TestOps.Op2) nodeContext2.getOperator()); TestOps.Op3 op3 = ((TestOps.Op3) nodeContext3.getOperator()); assertNotNull(op2.input); assertSame(nodeContext2.getSourceProduct("input"), op2.input); assertNotNull(op3.input1); assertNotNull(op3.input2); assertSame(nodeContext3.getSourceProduct("input1"), op3.input1); assertSame(nodeContext3.getSourceProduct("input2"), op3.input2); assertNotNull(op3.inputs); assertEquals(0, op3.inputs.length); assertEquals(false, op3.ignoreSign); // has NO default value assertEquals("NN", op3.interpolMethod); // has default value assertEquals(1.5, op3.factor); // has default value }