@Test(expected = IllegalArgumentException.class) public void testDuplicatedSourceNodeNameNotAllowed() throws Exception { final Node node = new Node("myId", "opName"); node.addSource(new NodeSource("duplicated", "sourceNode1")); node.addSource(new NodeSource("duplicated", "sourceNode2")); } }
@Override public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext) { SourceList sourceList = new SourceList(); while (hierarchicalStreamReader.hasMoreChildren()) { hierarchicalStreamReader.moveDown(); String name = hierarchicalStreamReader.getNodeName(); if ("sourceProducts".equals(name)) { final String sourceNodeIdsString = hierarchicalStreamReader.getValue().trim(); if (StringUtils.isNotNullAndNotEmpty(sourceNodeIdsString)) { final String[] sourceNodeIds = StringUtils.csvToArray(sourceNodeIdsString); for (int i = 0; i < sourceNodeIds.length; i++) { String sourceNodeId = sourceNodeIds[i]; sourceList.addSource(new NodeSource(String.format("%s%d", name, i), sourceNodeId)); } } } else { String refid = hierarchicalStreamReader.getAttribute("refid"); if (refid == null) { refid = hierarchicalStreamReader.getValue().trim(); } sourceList.addSource(new NodeSource(name, refid)); } hierarchicalStreamReader.moveUp(); } return sourceList; } }
@Test public void testAddSource() throws Exception { final Node node = new Node("myId", "opName"); node.addSource(new NodeSource("nodeName", "source1")); node.addSource(new NodeSource("anotherName", "source2")); node.addSource(new NodeSource("thirdName", "source3")); assertEquals(3, node.getSources().length); assertEquals("nodeName", node.getSources()[0].getName()); assertEquals("anotherName", node.getSources()[1].getName()); assertEquals("thirdName", node.getSources()[2].getName()); }
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 } }
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()); } }
targetNode.addSource(new NodeSource("source", lastNode.getId())); targetNode.setConfiguration(configuration);
outputNode.addSource(new NodeSource("dummy", "input1")); try { new GraphContext(graph); outputNode.addSource(new NodeSource("dummy1", "input1")); outputNode.addSource(new NodeSource("dummy2", "input2")); try { new GraphContext(graph); outputNode.addSource(new NodeSource("dummy1", "input1")); outputNode.addSource(new NodeSource("dummy2", "input2")); outputNode.addSource(new NodeSource("dummy3", "input3")); try { new GraphContext(graph);
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 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 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 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 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()); }
Node node3 = new Node("N3", "N3"); node2.addSource(new NodeSource("input", "N1")); node3.addSource(new NodeSource("input", "N2"));
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")); }
Node node2 = new Node("N2", "N2"); node2.addSource(new NodeSource("input", "N1"));
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 }
@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 testTwoNodeChain() throws Exception { Graph graph1 = new Graph("myTwoNodeGraph"); Node node1 = new Node("node1", "Op1"); Node node2 = new Node("node2", "Op2"); node2.addSource(new NodeSource("key1", "node1")); graph1.addNode(node1); graph1.addNode(node2); Graph graph2 = doIO(graph1); assertEquals(graph1.getId(), graph2.getId()); Node[] nodes = graph2.getNodes(); assertNotNull(nodes); assertEquals(2, nodes.length); assertNotNull(nodes[0]); assertNotNull(nodes[1]); Node node1Copy = graph2.getNode("node1"); Node node2Copy = graph2.getNode("node2"); assertSame(nodes[0], node1Copy); assertSame(nodes[1], node2Copy); NodeSource[] sources1 = node1Copy.getSources(); assertNotNull(sources1); assertEquals(0, sources1.length); NodeSource[] sources2 = node2Copy.getSources(); assertNotNull(sources2); assertEquals(1, sources2.length); NodeSource source2 = node2Copy.getSource(0); assertSame(sources2[0], source2); assertEquals("Op1", node1Copy.getOperatorName()); assertEquals("Op2", node2Copy.getOperatorName()); assertEquals("node1", source2.getSourceNodeId()); }