@Test (dependsOnMethods = "testAddDataNode") public void testAddFlowEdge() throws Exception { Assert.assertEquals(graph.getEdges("node1").size(), 1); Assert.assertEquals(graph.getEdges("node2").size(), 1); Assert.assertEquals(graph.getEdges("node3").size(), 1); Assert.assertTrue(graph.getEdges("node1").contains(edge1)); Assert.assertTrue(graph.getEdges("node2").contains(edge2)); Assert.assertTrue(graph.getEdges("node3").contains(edge3)); Assert.assertTrue(graph.addFlowEdge(edge3c)); Assert.assertTrue(graph.getEdges("node3").contains(edge3)); Assert.assertTrue(graph.getEdges("node3").iterator().next() == edge3c); Assert.assertTrue(edge3 != edge3c); Assert.assertTrue(graph.addFlowEdge(edge3)); Field field = BaseFlowGraph.class.getDeclaredField("flowEdgeMap"); field.setAccessible(true); Map<String, FlowEdge> flowEdgeMap = (Map<String, FlowEdge>) field.get(graph); Assert.assertEquals(flowEdgeMap.get(edge1.getId()), edge1); Assert.assertEquals(flowEdgeMap.get(edge2.getId()), edge2); Assert.assertEquals(flowEdgeMap.get(edge3.getId()), edge3); }
@Override public boolean addFlowEdge(FlowEdge edge) { try { rwLock.writeLock().lock(); String srcNode = edge.getSrc(); String dstNode = edge.getDest(); if (!dataNodeMap.containsKey(srcNode) || !dataNodeMap.containsKey(dstNode)) { return false; } DataNode dataNode = getNode(srcNode); if (dataNode == null) { return false; } Set<FlowEdge> adjacentEdges = this.nodesToEdges.get(dataNode); if (!adjacentEdges.add(edge)) { adjacentEdges.remove(edge); adjacentEdges.add(edge); } this.nodesToEdges.put(dataNode, adjacentEdges); String edgeId = edge.getId(); this.flowEdgeMap.put(edgeId, edge); return true; } finally { rwLock.writeLock().unlock(); } }
BaseFlowGraph implements FlowGraph { @Override public boolean addFlowEdge(FlowEdge edge) { try { rwLock.writeLock().lock(); String srcNode = edge.getSrc(); String dstNode = edge.getDest(); if (!dataNodeMap.containsKey(srcNode) || !dataNodeMap.containsKey(dstNode)) { return false; } DataNode dataNode = getNode(srcNode); if (dataNode == null) { return false; } Set<FlowEdge> adjacentEdges = this.nodesToEdges.get(dataNode); if (!adjacentEdges.add(edge)) { adjacentEdges.remove(edge); adjacentEdges.add(edge); } this.nodesToEdges.put(dataNode, adjacentEdges); String edgeId = edge.getId(); this.flowEdgeMap.put(edgeId, edge); return true; } finally { rwLock.writeLock().unlock(); } } }
BaseFlowGraph implements FlowGraph { @Override public boolean addFlowEdge(FlowEdge edge) { try { rwLock.writeLock().lock(); String srcNode = edge.getSrc(); String dstNode = edge.getDest(); if (!dataNodeMap.containsKey(srcNode) || !dataNodeMap.containsKey(dstNode)) { return false; } DataNode dataNode = getNode(srcNode); if (dataNode == null) { return false; } Set<FlowEdge> adjacentEdges = this.nodesToEdges.get(dataNode); if (!adjacentEdges.add(edge)) { adjacentEdges.remove(edge); adjacentEdges.add(edge); } this.nodesToEdges.put(dataNode, adjacentEdges); String edgeId = edge.getId(); this.flowEdgeMap.put(edgeId, edge); return true; } finally { rwLock.writeLock().unlock(); } }  }
BaseFlowGraph implements FlowGraph { @Override public boolean addFlowEdge(FlowEdge edge) { try { rwLock.writeLock().lock(); String srcNode = edge.getSrc(); String dstNode = edge.getDest(); if (!dataNodeMap.containsKey(srcNode) || !dataNodeMap.containsKey(dstNode)) { return false; } DataNode dataNode = getNode(srcNode); if (dataNode == null) { return false; } Set<FlowEdge> adjacentEdges = this.nodesToEdges.get(dataNode); if (!adjacentEdges.add(edge)) { adjacentEdges.remove(edge); adjacentEdges.add(edge); } this.nodesToEdges.put(dataNode, adjacentEdges); String edgeId = edge.getId(); this.flowEdgeMap.put(edgeId, edge); return true; } finally { rwLock.writeLock().unlock(); } }  DataNode getNode(String nodeId); @Override boolean addDataNode(DataNode node); @Override boolean addFlowEdge(FlowEdge edge); @Override boolean deleteDataNode(String nodeId); boolean deleteDataNode(DataNode node); @Override boolean deleteFlowEdge(String edgeId); boolean deleteFlowEdge(FlowEdge edge); @Override Set<FlowEdge> getEdges(String nodeId); @Override Set<FlowEdge> getEdges(DataNode node); @Override FlowGraphPath findPath(FlowSpec flowSpec); }
BaseFlowGraph implements FlowGraph { @Override public boolean addFlowEdge(FlowEdge edge) { try { rwLock.writeLock().lock(); String srcNode = edge.getSrc(); String dstNode = edge.getDest(); if (!dataNodeMap.containsKey(srcNode) || !dataNodeMap.containsKey(dstNode)) { return false; } DataNode dataNode = getNode(srcNode); if (dataNode == null) { return false; } Set<FlowEdge> adjacentEdges = this.nodesToEdges.get(dataNode); if (!adjacentEdges.add(edge)) { adjacentEdges.remove(edge); adjacentEdges.add(edge); } this.nodesToEdges.put(dataNode, adjacentEdges); String edgeId = edge.getId(); this.flowEdgeMap.put(edgeId, edge); return true; } finally { rwLock.writeLock().unlock(); } }  DataNode getNode(String nodeId); @Override boolean addDataNode(DataNode node); @Override boolean addFlowEdge(FlowEdge edge); @Override boolean deleteDataNode(String nodeId); boolean deleteDataNode(DataNode node); @Override boolean deleteFlowEdge(String edgeId); boolean deleteFlowEdge(FlowEdge edge); @Override Set<FlowEdge> getEdges(String nodeId); @Override Set<FlowEdge> getEdges(DataNode node); @Override FlowGraphPath findPath(FlowSpec flowSpec);  }