def test_singletons(self): g = Graph().traversal() bytecode = g.withStrategies(ReadOnlyStrategy()).bytecode assert 1 == len(bytecode.source_instructions) assert 2 == len(bytecode.source_instructions[0]) assert "withStrategies" == bytecode.source_instructions[0][0] assert ReadOnlyStrategy() == bytecode.source_instructions[0][1] assert "ReadOnlyStrategy" == str(bytecode.source_instructions[0][1]) assert hash(ReadOnlyStrategy()) == hash( bytecode.source_instructions[0][1]) assert 0 == len(g.traversal_strategies.traversal_strategies ) # these strategies are proxies ## g = g.withStrategies(ReadOnlyStrategy(), IncidentToAdjacentStrategy()) bytecode = g.bytecode assert 1 == len(bytecode.source_instructions) assert 3 == len(bytecode.source_instructions[0]) assert "withStrategies" == bytecode.source_instructions[0][0] assert ReadOnlyStrategy() == bytecode.source_instructions[0][1] assert IncidentToAdjacentStrategy( ) == bytecode.source_instructions[0][2] ## bytecode = g.V().bytecode assert 1 == len(bytecode.source_instructions) assert 3 == len(bytecode.source_instructions[0]) assert "withStrategies" == bytecode.source_instructions[0][0] assert ReadOnlyStrategy() == bytecode.source_instructions[0][1] assert IncidentToAdjacentStrategy( ) == bytecode.source_instructions[0][2] assert 1 == len(bytecode.step_instructions) assert "V" == bytecode.step_instructions[0][0] ## bytecode = g.withoutStrategies(ReadOnlyStrategy()).V().bytecode assert 2 == len(bytecode.source_instructions) assert 3 == len(bytecode.source_instructions[0]) assert 2 == len(bytecode.source_instructions[1]) assert "withStrategies" == bytecode.source_instructions[0][0] assert ReadOnlyStrategy() == bytecode.source_instructions[0][1] assert IncidentToAdjacentStrategy( ) == bytecode.source_instructions[0][2] assert "withoutStrategies" == bytecode.source_instructions[1][0] assert ReadOnlyStrategy() == bytecode.source_instructions[1][1] assert 1 == len(bytecode.step_instructions) assert "V" == bytecode.step_instructions[0][0] ## bytecode = g.withoutStrategies(ReadOnlyStrategy(), LazyBarrierStrategy()).V().bytecode assert 2 == len(bytecode.source_instructions) assert 3 == len(bytecode.source_instructions[0]) assert 3 == len(bytecode.source_instructions[1]) assert "withStrategies" == bytecode.source_instructions[0][0] assert ReadOnlyStrategy() == bytecode.source_instructions[0][1] assert IncidentToAdjacentStrategy( ) == bytecode.source_instructions[0][2] assert "withoutStrategies" == bytecode.source_instructions[1][0] assert ReadOnlyStrategy() == bytecode.source_instructions[1][1] assert LazyBarrierStrategy() == bytecode.source_instructions[1][2] assert 1 == len(bytecode.step_instructions) assert "V" == bytecode.step_instructions[0][0]
def test_strategies(self): statics.load_statics(globals()) connection = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g') # g = Graph().traversal().withRemote(connection). \ withStrategies(TraversalStrategy("SubgraphStrategy", {"vertices": __.hasLabel("person"), "edges": __.hasLabel("created")})) assert 4 == g.V().count().next() assert 0 == g.E().count().next() assert 1 == g.V().label().dedup().count().next() assert "person" == g.V().label().dedup().next() # g = Graph().traversal().withRemote(connection). \ withStrategies(SubgraphStrategy(vertices=__.hasLabel("person"), edges=__.hasLabel("created"))) assert 4 == g.V().count().next() assert 0 == g.E().count().next() assert 1 == g.V().label().dedup().count().next() assert "person" == g.V().label().dedup().next() # g = g.withoutStrategies(SubgraphStrategy). \ withComputer(workers=4, vertices=__.has("name", "marko"), edges=__.limit(0)) assert 1 == g.V().count().next() assert 0 == g.E().count().next() assert "person" == g.V().label().next() assert "marko" == g.V().name.next() # g = Graph().traversal().withRemote(connection).withComputer() assert 6 == g.V().count().next() assert 6 == g.E().count().next() connection.close()
def test_strategies(self): statics.load_statics(globals()) connection = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g') # g = Graph().traversal().withRemote(connection). \ withStrategies(TraversalStrategy("SubgraphStrategy", {"vertices": __.hasLabel("person"), "edges": __.hasLabel("created")})) assert 4 == g.V().count().next() assert 0 == g.E().count().next() assert 1 == g.V().label().dedup().count().next() assert "person" == g.V().label().dedup().next() # g = Graph().traversal().withRemote(connection). \ withStrategies(SubgraphStrategy(vertices=__.hasLabel("person"), edges=__.hasLabel("created"))) assert 4 == g.V().count().next() assert 0 == g.E().count().next() assert 1 == g.V().label().dedup().count().next() assert "person" == g.V().label().dedup().next() # g = g.withoutStrategies(SubgraphStrategy). \ withComputer(workers=4, vertices=__.has("name", "marko"), edges=__.limit(0)) assert 1 == g.V().count().next() assert 0 == g.E().count().next() assert "person" == g.V().label().next() assert "marko" == g.V().name.next() # g = Graph().traversal().withRemote(connection).withComputer() assert 6 == g.V().count().next() assert 6 == g.E().count().next() connection.close()
def test_strategies(self, remote_connection): statics.load_statics(globals()) # g = Graph().traversal().withRemote(remote_connection). \ withStrategies(TraversalStrategy("SubgraphStrategy", {"vertices": __.hasLabel("person"), "edges": __.hasLabel("created")})) assert 4 == g.V().count().next() assert 0 == g.E().count().next() assert 1 == g.V().label().dedup().count().next() assert "person" == g.V().label().dedup().next() # g = Graph().traversal().withRemote(remote_connection). \ withStrategies(SubgraphStrategy(vertices=__.hasLabel("person"), edges=__.hasLabel("created"))) assert 4 == g.V().count().next() assert 0 == g.E().count().next() assert 1 == g.V().label().dedup().count().next() assert "person" == g.V().label().dedup().next() # g = g.withoutStrategies(SubgraphStrategy). \ withComputer(vertices=__.has("name", "marko"), edges=__.limit(0)) assert 1 == g.V().count().next() assert 0 == g.E().count().next() assert "person" == g.V().label().next() assert "marko" == g.V().name.next() # g = Graph().traversal().withRemote(remote_connection).withComputer() assert 6 == g.V().count().next() assert 6 == g.E().count().next()