Skip to content

Commit f68f8b9

Browse files
committed
Update global input stream position and unit test - for hbase compatibility
1 parent 6d4b387 commit f68f8b9

File tree

2 files changed

+31
-19
lines changed

2 files changed

+31
-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: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
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.Before;
910
import org.junit.Test;
1011

1112
public class TestGlusterFuseInputStream{
13+
final String infile = "/mnt/glusterfs/testGFIStream";
1214

15+
@Before
16+
public void create() throws Exception{
17+
//setup
18+
final GlusterFUSEOutputStream stream = new GlusterFUSEOutputStream(infile,true);
19+
stream.write("hello there, certainly, there is some data in this stream".getBytes());
20+
stream.close();
21+
22+
}
23+
1324
@Test
14-
public void testDoubleClose() throws IOException{
15-
/**
16-
* GlusterFUSEInputStream gfi= new GlusterFUSEInputStream ( new
17-
* File(""), null, "localhost") ; gfi.close(); gfi.close();
18-
**/
19-
}
25+
public void testDoubleClose() throws Exception{
26+
//test
27+
GlusterFUSEInputStream gfi= new GlusterFUSEInputStream (new File(infile), null, "localhost") ;
28+
29+
//assert that Position is updated (necessary for hbase to function properly)
30+
gfi.seek(2);
31+
Assert.assertEquals(2,gfi.getPos());
2032

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

0 commit comments

Comments
 (0)