public void testRemoveNamespace() {
    SailGraph graph = new MemoryStoreSailGraph();
    GremlinScriptContext context = new GremlinScriptContext();
    context
        .getBindings(ScriptContext.ENGINE_SCOPE)
        .put(Tokens.GRAPH_VARIABLE, new Atom<Graph>(graph));

    Function<Object> function = new RemoveNamespaceFunction();
    assertNotNull(graph.getNamespaces().get("rdf"));
    this.stopWatch();
    Atom<Object> atom = function.compute(createUnaryArgs(graph, "rdf"), context);
    printPerformance(
        function.getFunctionName() + " function", 1, "namespace removed", this.stopWatch());
    assertNull(atom.getValue());
    assertNull(graph.getNamespaces().get("rdf"));

    assertNotNull(graph.getNamespaces().get("rdfs"));
    this.stopWatch();
    atom = function.compute(createUnaryArgs("rdfs"), context);
    printPerformance(
        function.getFunctionName() + " function", 1, "namespace removed", this.stopWatch());
    assertTrue(atom.isNull());
    assertNull(graph.getNamespaces().get("rdfs"));

    graph.shutdown();
  }
예제 #2
0
  public Object invokeFunction(String name, Object... args)
      throws NoSuchMethodException, ScriptException {
    GremlinScriptContext ctx = (GremlinScriptContext) this.getContext();
    int colonIndex = name.indexOf(":");
    Function function;
    try {
      function =
          ctx.getFunctionLibrary()
              .getFunction(name.substring(0, colonIndex), name.substring(colonIndex + 1));
    } catch (RuntimeException e) {
      throw new NoSuchMethodException();
    }

    List<Operation> arguments = new ArrayList<Operation>();
    for (Object arg : args) {
      arguments.add(new UnaryOperation(new Atom(arg)));
    }
    try {
      Atom ret = function.compute(arguments, ctx);
      if (ret.isNull()) return null;
      else return ret.getValue();
    } catch (Exception e) {
      throw new ScriptException(e.getMessage());
    }
  }
예제 #3
0
  public void testSet() {
    GremlinScriptContext context = new GremlinScriptContext();
    Function<Set> function = new SetFunction();
    this.stopWatch();
    Atom<Set> atom = function.compute(new ArrayList<Operation>(), context);
    printPerformance(function.getFunctionName() + " function", 0, "arguments", this.stopWatch());
    assertEquals(count(atom.getValue()), 0);

    this.stopWatch();
    atom = function.compute(createUnaryArgs(1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4), context);
    printPerformance(function.getFunctionName() + " function", 0, "arguments", this.stopWatch());
    assertEquals(count(atom.getValue()), 4);
    assertTrue(atom.getValue().contains(1));
    assertTrue(atom.getValue().contains(2));
    assertTrue(atom.getValue().contains(3));
    assertTrue(atom.getValue().contains(4));
  }