Java Code Examples for com.tinkerpop.blueprints.Graph#addVertex()
The following examples show how to use
com.tinkerpop.blueprints.Graph#addVertex() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ElementPropertyCachingTest.java From AccumuloGraph with Apache License 2.0 | 6 votes |
@Test public void testPreloadAllProperties() { AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils.generateGraphConfig("preloadAllProperties"); cfg.setPropertyCacheTimeout(null, TIMEOUT); cfg.setPreloadAllProperties(true); Graph graph = open(cfg); AccumuloVertex v = (AccumuloVertex) graph.addVertex("V"); v.setProperty(NON_CACHED, true); v.setProperty(CACHED, true); v = (AccumuloVertex) graph.getVertex("V"); assertEquals(true, v.getPropertyInMemory(NON_CACHED)); assertEquals(true, v.getPropertyInMemory(CACHED)); graph.shutdown(); }
Example 2
Source File: ElementPropertyCachingTest.java From AccumuloGraph with Apache License 2.0 | 6 votes |
@Test public void testPreloadSomeProperties() { AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils.generateGraphConfig("preloadSomeProperties"); cfg.setPropertyCacheTimeout(null, TIMEOUT); cfg.setPreloadedProperties(new String[]{CACHED}); Graph graph = open(cfg); AccumuloVertex v = (AccumuloVertex) graph.addVertex("V"); v.setProperty(NON_CACHED, true); v.setProperty(CACHED, true); v = (AccumuloVertex) graph.getVertex("V"); assertEquals(null, v.getPropertyInMemory(NON_CACHED)); assertEquals(true, v.getPropertyInMemory(CACHED)); graph.shutdown(); }
Example 3
Source File: ElementOutputFormatTest.java From AccumuloGraph with Apache License 2.0 | 6 votes |
@Test public void testVertexOutputFormatMap() throws Exception { final String INSTANCE_NAME = "_mapreduce_instance2"; final String TEST_TABLE_1 = "_mapreduce_table_2"; if (!System.getProperty("os.name").startsWith("Windows")) { Graph g = GraphFactory.open(new AccumuloGraphConfiguration().setInstanceName(INSTANCE_NAME).setUser("root").setPassword("".getBytes()) .setGraphName(TEST_TABLE_1).setInstanceType(InstanceType.Mock).setCreate(true).getConfiguration()); for (int i = 0; i < 100; i++) { g.addVertex(i + ""); } assertEquals(0, MRTester.main(new String[] {})); assertNull(e1); assertNull(e2); assertEquals(g.getVertex("1").getProperty("NAME"), "BANANA1"); } }
Example 4
Source File: InputFormatsTest.java From AccumuloGraph with Apache License 2.0 | 6 votes |
@Test public void testVertexInputMap() throws Exception { final String INSTANCE_NAME = "_mapreduce_instance"; final String TEST_TABLE_NAME = "_mapreduce_table_vertexInputMap"; if (!System.getProperty("os.name").startsWith("Windows")) { Graph g = GraphFactory.open(new AccumuloGraphConfiguration().setInstanceName(INSTANCE_NAME) .setUser("root").setPassword("".getBytes()) .setGraphName(TEST_TABLE_NAME).setInstanceType(InstanceType.Mock) .setCreate(true).getConfiguration()); for (int i = 0; i < 100; i++) { g.addVertex(i + ""); } assertEquals(0, MRTester.main(new String[]{"root", "", TEST_TABLE_NAME, INSTANCE_NAME, "false"})); assertNull(e1); assertNull(e2); g.shutdown(); } }
Example 5
Source File: InputFormatsTest.java From AccumuloGraph with Apache License 2.0 | 6 votes |
@Test public void testEdgeInputMap() throws Exception { final String INSTANCE_NAME = "_mapreduce_instance"; final String TEST_TABLE_NAME = "_mapreduce_table_edgeInputMap"; if (!System.getProperty("os.name").startsWith("Windows")) { Graph g = GraphFactory.open(new AccumuloGraphConfiguration().setInstanceName(INSTANCE_NAME) .setUser("root").setPassword("".getBytes()) .setGraphName(TEST_TABLE_NAME).setInstanceType(InstanceType.Mock) .setAutoFlush(true).setCreate(true).getConfiguration()); for (int i = 0; i < 100; i++) { Vertex v1 = g.addVertex(i+""); Vertex v2 = g.addVertex(i+"a"); g.addEdge(null, v1, v2, "knows"); } assertEquals(0, MRTester.main(new String[]{"root", "", TEST_TABLE_NAME, INSTANCE_NAME, "true"})); assertNull(e1); assertNull(e2); g.shutdown(); } }
Example 6
Source File: ElementCacheTest.java From AccumuloGraph with Apache License 2.0 | 6 votes |
@Test public void testElementCacheSize() throws Exception { AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils .generateGraphConfig("elementCacheSize"); Graph graph = GraphFactory.open(cfg.getConfiguration()); Vertex[] verts = new Vertex[10]; for (int i = 0; i < verts.length; i++) { verts[i] = graph.addVertex(i); } Edge[] edges = new Edge[9]; for (int i = 0; i < edges.length; i++) { edges[i] = graph.addEdge(null, verts[0], verts[i+1], "edge"); } sizeTests(verts); sizeTests(edges); graph.shutdown(); }
Example 7
Source File: GraphOperations.java From bjoern with GNU General Public License v3.0 | 5 votes |
public static Vertex addNode(Graph graph, Map<String, String> properties) { Vertex newVertex = graph.addVertex(0); for (Entry<String, String> entrySet : properties.entrySet()) { newVertex.setProperty(entrySet.getKey(), entrySet.getValue()); } return newVertex; }
Example 8
Source File: AccumuloElementTest.java From AccumuloGraph with Apache License 2.0 | 5 votes |
@Test public void testNonStringIds() throws Exception { Graph graph = AccumuloGraphTestUtils.makeGraph("nonStringIds"); Object[] ids = new Object[] { 10, 20, 30L, 40L, 50.0f, 60.0f, 70.0d, 80.0d, (byte) 'a', (byte) 'b', 'c', 'd', "str1", "str2", new GenericObject("str3"), new GenericObject("str4"), }; Object[] edgeIds = new Object[] { 100, 200, 300L, 400L, 500.0f, 600.0f, 700.0d, 800.0d, (byte) 'e', (byte) 'f', 'g', 'h', "str5", "str6", new GenericObject("str7"), new GenericObject("str8"), }; for (int i = 0; i < ids.length; i++) { assertNull(graph.getVertex(ids[i])); Vertex v = graph.addVertex(ids[i]); assertNotNull(v); assertNotNull(graph.getVertex(ids[i])); } assertEquals(ids.length, count(graph.getVertices())); for (int i = 1; i < edgeIds.length; i++) { assertNull(graph.getEdge(edgeIds[i-1])); Edge e = graph.addEdge(edgeIds[i-1], graph.getVertex(ids[i-1]), graph.getVertex(ids[i]), "label"); assertNotNull(e); assertNotNull(graph.getEdge(edgeIds[i-1])); } assertEquals(edgeIds.length-1, count(graph.getEdges())); graph.shutdown(); }
Example 9
Source File: ExtendedElementTest.java From AccumuloGraph with Apache License 2.0 | 5 votes |
@Test public void testSkipExistenceChecks() throws Exception { AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils.generateGraphConfig("skipExistenceChecks"); cfg.setSkipExistenceChecks(true); Graph graph = makeGraph(cfg); String id; id = "doubleAdd"; assertNotNull(graph.addVertex(id)); assertNotNull(graph.addVertex(id)); Vertex vAdd = graph.getVertex(id); assertNotNull(vAdd); graph.removeVertex(vAdd); assertNotNull(graph.getVertex(id)); id = "doubleRemove"; Vertex vRemove = graph.addVertex(id); assertNotNull(vRemove); graph.removeVertex(vRemove); assertNotNull(graph.getVertex(id)); // MDL 24 Dec 2014: removeVertex still does checks. //graph.removeVertex(vRemove); //assertNotNull(graph.getVertex(id)); id = "notExist"; assertNotNull(graph.getVertex(id)); graph.shutdown(); }
Example 10
Source File: ElementCacheTest.java From AccumuloGraph with Apache License 2.0 | 5 votes |
@Test public void testElementCacheTimeout() throws Exception { AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils .generateGraphConfig("elementCacheTimeout"); Graph graph = GraphFactory.open(cfg.getConfiguration()); ElementCache<Element> cache = new ElementCache<Element>(10, 1000); Vertex v1 = graph.addVertex(1); Vertex v2 = graph.addVertex(2); assertNull(cache.retrieve(1)); assertNull(cache.retrieve(2)); cache.cache(v1); assertNotNull(cache.retrieve(v1.getId())); Thread.sleep(1500); assertNull(cache.retrieve(v1.getId())); Edge e = graph.addEdge(null, v1, v2, "label"); assertNull(cache.retrieve(e.getId())); cache.cache(e); assertNotNull(cache.retrieve(e.getId())); Thread.sleep(1500); assertNull(cache.retrieve(e.getId())); graph.shutdown(); }
Example 11
Source File: GraphHelper.java From org.openntf.domino with Apache License 2.0 | 5 votes |
/** * Add a vertex to the graph with specified id and provided properties. * * @param graph the graph to create a vertex in * @param id the id of the vertex to create * @param properties the properties of the vertex to add (must be String,Object,String,Object,...) * @return the vertex created in the graph with the provided properties set */ public static Vertex addVertex(final Graph graph, final Object id, final Object... properties) { if ((properties.length % 2) != 0) throw new RuntimeException("There must be an equal number of keys and values"); final Vertex vertex = graph.addVertex(id); for (int i = 0; i < properties.length; i = i + 2) { vertex.setProperty((String) properties[i], properties[i + 1]); } return vertex; }
Example 12
Source File: GraphHelper.java From org.openntf.domino with Apache License 2.0 | 5 votes |
/** * Copy the vertex/edges of one graph over to another graph. * The id of the elements in the from graph are attempted to be used in the to graph. * This method only works for graphs where the user can control the element ids. * * @param from the graph to copy from * @param to the graph to copy to */ public static void copyGraph(final Graph from, final Graph to) { for (final Vertex fromVertex : from.getVertices()) { final Vertex toVertex = to.addVertex(fromVertex.getId()); ElementHelper.copyProperties(fromVertex, toVertex); } for (final Edge fromEdge : from.getEdges()) { final Vertex outVertex = to.getVertex(fromEdge.getVertex(Direction.OUT).getId()); final Vertex inVertex = to.getVertex(fromEdge.getVertex(Direction.IN).getId()); final Edge toEdge = to.addEdge(fromEdge.getId(), outVertex, inVertex, fromEdge.getLabel()); ElementHelper.copyProperties(fromEdge, toEdge); } }
Example 13
Source File: ElementPropertyCachingTest.java From AccumuloGraph with Apache License 2.0 | 4 votes |
private static void load(Graph graph) { graph.addVertex("A"); graph.addVertex("B").setProperty(NON_CACHED, true); graph.addVertex("C").setProperty(CACHED, true); }