Github user mateiz commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1658#discussion_r18611451
  
    --- Diff: core/src/test/java/org/apache/spark/JavaAPISuite.java ---
    @@ -836,6 +839,84 @@ public void sequenceFile() {
         Assert.assertEquals(pairs, readRDD.collect());
       }
     
    +    @Test
    +    public void binaryFiles() throws Exception {
    +        // Reusing the wholeText files example
    +        byte[] content1 = "spark is easy to use.\n".getBytes("utf-8");
    +
    +
    +        String tempDirName = tempDir.getAbsolutePath();
    +        File file1 = new File(tempDirName + "/part-00000");
    +
    +        FileOutputStream fos1 = new FileOutputStream(file1);
    +
    +        FileChannel channel1 = fos1.getChannel();
    +        ByteBuffer bbuf = java.nio.ByteBuffer.wrap(content1);
    +        channel1.write(bbuf);
    +        channel1.close();
    +        JavaPairRDD<String, PortableDataStream> readRDD = 
sc.binaryFiles(tempDirName,3);
    +        List<Tuple2<String, PortableDataStream>> result = 
readRDD.collect();
    +        for (Tuple2<String, PortableDataStream> res : result) {
    +            Assert.assertArrayEquals(content1, res._2().toArray());
    +        }
    +    }
    +
    +    @Test
    +    public void binaryFilesCaching() throws Exception {
    +        // Reusing the wholeText files example
    +        byte[] content1 = "spark is easy to use.\n".getBytes("utf-8");
    +
    +
    +        String tempDirName = tempDir.getAbsolutePath();
    +        File file1 = new File(tempDirName + "/part-00000");
    +
    +        FileOutputStream fos1 = new FileOutputStream(file1);
    +
    +        FileChannel channel1 = fos1.getChannel();
    +        ByteBuffer bbuf = java.nio.ByteBuffer.wrap(content1);
    +        channel1.write(bbuf);
    +        channel1.close();
    +
    +        JavaPairRDD<String, PortableDataStream> readRDD = 
sc.binaryFiles(tempDirName,3).cache();
    +        readRDD.foreach(new 
VoidFunction<Tuple2<String,PortableDataStream>>() {
    +            @Override
    +            public void call(Tuple2<String, PortableDataStream> 
stringPortableDataStreamTuple2) throws Exception {
    +                stringPortableDataStreamTuple2._2().toArray(); // force 
the file to read
    +            }
    +        });
    +
    +        List<Tuple2<String, PortableDataStream>> result = 
readRDD.collect();
    +        for (Tuple2<String, PortableDataStream> res : result) {
    +            Assert.assertArrayEquals(content1, res._2().toArray());
    +        }
    +    }
    +
    +    @Test
    +    public void binaryRecords() throws Exception {
    +        // Reusing the wholeText files example
    +        byte[] content1 = "spark isn't always easy to 
use.\n".getBytes("utf-8");
    +        int numOfCopies = 10;
    +        String tempDirName = tempDir.getAbsolutePath();
    +        File file1 = new File(tempDirName + "/part-00000");
    +
    +        FileOutputStream fos1 = new FileOutputStream(file1);
    +
    +        FileChannel channel1 = fos1.getChannel();
    +
    +        for (int i=0;i<numOfCopies;i++) {
    +            ByteBuffer bbuf = java.nio.ByteBuffer.wrap(content1);
    +            channel1.write(bbuf);
    +        }
    +        channel1.close();
    +
    +        JavaRDD<byte[]> readRDD = 
sc.binaryRecords(tempDirName,content1.length);
    --- End diff --
    
    Add spaces after commas (affects several places in here)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to