コード例 #1
0
 @Test
 @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
 public void shouldSupportHDFSMethods() throws Exception {
   ////////////////
   List<String> ls = (List<String>) this.console.eval("hdfs.ls()");
   for (final String line : ls) {
     assertTrue(
         line.startsWith("-")
             || line.startsWith("r")
             || line.startsWith("w")
             || line.startsWith("x"));
     assertEquals(" ", line.substring(9, 10));
   }
   ls = (List<String>) this.console.eval("local.ls()");
   for (final String line : ls) {
     assertTrue(
         line.startsWith("-")
             || line.startsWith("r")
             || line.startsWith("w")
             || line.startsWith("x"));
     assertEquals(" ", line.substring(9, 10));
   }
   ////////////////
   this.console.eval(
       "hdfs.copyFromLocal('"
           + HadoopGraphProvider.PATHS.get("tinkerpop-classic.txt")
           + "', 'target/tinkerpop-classic.txt')");
   assertTrue((Boolean) this.console.eval("hdfs.exists('target/tinkerpop-classic.txt')"));
   ////////////////
   List<String> head =
       IteratorUtils.asList(this.console.eval("hdfs.head('target/tinkerpop-classic.txt')"));
   assertEquals(6, head.size());
   for (final String line : head) {
     assertEquals(":", line.substring(1, 2));
     assertTrue(Integer.valueOf(line.substring(0, 1)) <= 6);
   }
   head = IteratorUtils.asList(this.console.eval("hdfs.head('target/tinkerpop-classic.txt',3)"));
   assertEquals(3, head.size());
   for (final String line : head) {
     assertEquals(":", line.substring(1, 2));
     assertTrue(Integer.valueOf(line.substring(0, 1)) <= 3);
   }
   ////////////////
   this.console.eval("hdfs.rm('target/tinkerpop-classic.txt')");
   assertFalse((Boolean) this.console.eval("hdfs.exists('target/tinkerpop-classic.txt')"));
   ////////////////
   this.console.addBinding("graph", this.graph);
   this.console.addBinding("g", this.g);
   this.remote.connect(Arrays.asList("graph", "g"));
   Traversal<Vertex, String> traversal =
       (Traversal<Vertex, String>)
           this.remote.submit(
               Arrays.asList(
                   "g.V().hasLabel('person').group('m').by('age').by('name').out('knows').out('created').values('name')"));
   AbstractGremlinProcessTest.checkResults(Arrays.asList("ripple", "lop"), traversal);
   assertTrue((Boolean) this.console.eval("hdfs.exists('target/test-output/m')"));
   assertTrue(
       (Boolean)
           this.console.eval(
               "hdfs.exists('target/test-output/" + TraverserMapReduce.TRAVERSERS + "')"));
   final List<KeyValue<Integer, Collection<String>>> mList =
       IteratorUtils.asList(this.console.eval("hdfs.head('target/test-output/m',ObjectWritable)"));
   assertEquals(4, mList.size());
   mList.forEach(
       keyValue -> {
         if (keyValue.getKey().equals(29)) assertTrue(keyValue.getValue().contains("marko"));
         else if (keyValue.getKey().equals(35)) assertTrue(keyValue.getValue().contains("peter"));
         else if (keyValue.getKey().equals(32)) assertTrue(keyValue.getValue().contains("josh"));
         else if (keyValue.getKey().equals(27)) assertTrue(keyValue.getValue().contains("vadas"));
         else throw new IllegalStateException("The provided key/value is unknown: " + keyValue);
       });
   final List<KeyValue<MapReduce.NullObject, Traverser<String>>> traversersList =
       IteratorUtils.asList(
           this.console.eval(
               "hdfs.head('target/test-output/"
                   + TraverserMapReduce.TRAVERSERS
                   + "',ObjectWritable)"));
   assertEquals(2, traversersList.size());
   traversersList.forEach(
       keyValue -> {
         assertEquals(MapReduce.NullObject.instance(), keyValue.getKey());
         final String name = keyValue.getValue().get();
         assertTrue(name.equals("ripple") || name.equals("lop"));
       });
   ////////////////
 }