Skip to content

Commit ce3531a

Browse files
committed
Merge pull request #35 from gluster/fix_seek
Update global input stream position and unit test - for hbase compatibil...
2 parents 76e1501 + a3b5388 commit ce3531a

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

src/main/java/org/apache/hadoop/fs/glusterfs/GlusterFUSEInputStream.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ public long getPos() throws IOException{
8989
public synchronized int available() throws IOException{
9090
return (int) ((f.length())-getPos());
9191
}
92-
93-
public void seek(long pos) throws IOException{
94-
fuseInputStream.seek(pos);
92+
93+
public void seek(long newPos) throws IOException{
94+
fuseInputStream.seek(newPos);
9595
if(fsInputStream!=null)
96-
fsInputStream.seek(pos);
96+
fsInputStream.seek(newPos);
97+
//Important for any seek app: HBASE checks explicitly that position after seek is correct.
98+
this.pos=newPos;
9799
}
98100

99101
public boolean seekToNewSource(long pos) throws IOException{
Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,40 @@
11
package org.gluster.test;
22

33
import java.io.File;
4-
import java.io.IOException;
5-
import java.util.TreeMap;
64

7-
import org.apache.hadoop.fs.glusterfs.GlusterFSBrickClass;
5+
import junit.framework.Assert;
6+
87
import org.apache.hadoop.fs.glusterfs.GlusterFUSEInputStream;
8+
import org.apache.hadoop.fs.glusterfs.GlusterFUSEOutputStream;
9+
import org.junit.After;
10+
import org.junit.Before;
911
import org.junit.Test;
1012

1113
public class TestGlusterFuseInputStream{
14+
String infile ;
1215

16+
@Before
17+
public void create() throws Exception{
18+
//setup: no need for gluster specific path, since its just reading from local path
19+
infile=File.createTempFile("TestGlusterFuseInputStream"+System.currentTimeMillis(),"txt").getAbsolutePath();
20+
new File(infile).deleteOnExit();
21+
final GlusterFUSEOutputStream stream = new GlusterFUSEOutputStream(infile,true);
22+
stream.write("hello there, certainly, there is some data in this stream".getBytes());
23+
stream.close();
24+
}
25+
1326
@Test
14-
public void testDoubleClose() throws IOException{
15-
/**
16-
* GlusterFUSEInputStream gfi= new GlusterFUSEInputStream ( new
17-
* File(""), null, "localhost") ; gfi.close(); gfi.close();
18-
**/
19-
}
27+
public void testDoubleClose() throws Exception{
28+
//test
29+
GlusterFUSEInputStream gfi= new GlusterFUSEInputStream (new File(infile), null, "localhost") ;
30+
31+
//assert that Position is updated (necessary for hbase to function properly)
32+
gfi.seek(2);
33+
Assert.assertEquals(2,gfi.getPos());
2034

21-
@Test
22-
public void testDoubleClose2() throws IOException{
23-
/**
24-
* GlusterFUSEInputStream gfi= new GlusterFUSEInputStream ( new
25-
* File(""), null, "localhost") ; gfi.close(); gfi.close();
26-
**/
35+
gfi.close();
36+
37+
//cleanup
38+
new File(infile).delete();
2739
}
2840
}

0 commit comments

Comments
 (0)