29
29
import static org .junit .Assert .assertFalse ;
30
30
import static org .junit .Assert .assertTrue ;
31
31
32
- import java .io .File ;
33
32
import java .io .IOException ;
34
- import java .net .InetAddress ;
35
33
36
- import org .apache .hadoop .conf .Configuration ;
37
34
import org .apache .hadoop .fs .FSDataInputStream ;
38
35
import org .apache .hadoop .fs .FSDataOutputStream ;
39
36
import org .apache .hadoop .fs .FileStatus ;
52
49
*
53
50
*/
54
51
public class TestGluster {
55
-
56
- protected static File tempDirectory ;
57
- protected static String glusterVolume =System .getProperty ("gluster-volume" );
58
- protected static String glusterHost =System .getProperty ("gluster-host" );
59
- protected static GlusterFileSystem gfs ;
60
- private static File temp ;
61
- private static File mount ;
62
-
63
- @ AfterClass
64
- public static void after () throws IOException {
65
- gfs .close ();
66
- FileUtils .delete (tempDirectory );
67
- }
68
-
52
+
53
+ static GlusterFileSystem gfs ;
54
+
69
55
@ BeforeClass
70
- public static void before () throws Exception {
71
- /*
72
- * the user can over ride the default gluster volume used for test with
73
- * ENV var
74
- */
75
- glusterVolume =System .getProperty ("GLUSTER_VOLUME" );
76
- if (glusterVolume ==null ||glusterVolume .equals ("" )){
77
- System .out .println ("WARNING: HOST NOT DEFINED IN ENVIRONMENT! See README" );
78
- glusterVolume ="HadoopVol" ;
79
- }
80
-
81
- glusterHost =System .getProperty ("GLUSTER_HOST" );
82
- if (glusterHost ==null ||glusterHost .equals ("" )){
83
- System .out .println ("WARNING: HOST NOT DEFINED IN ENVIRONMENT! See README" );
84
- InetAddress addr =InetAddress .getLocalHost ();
85
- glusterHost =addr .getHostName ();
86
- }
87
-
88
- System .out .println ("Testing against host=" +glusterHost );
89
- System .out .println ("Testing against volume=" +glusterVolume );
90
-
56
+ public static void setup () throws Exception {
91
57
/**
92
- * Create a temporary directory for the mount point .
58
+ * Automount = true .
93
59
*/
94
- tempDirectory =new File (System .getProperty ("java.io.tmpdir" ), "gluster-test-mount-point" );
95
- tempDirectory .mkdirs ();
96
- tempDirectory .delete ();
97
- tempDirectory .mkdir ();
98
-
99
- if (glusterVolume ==null ){
100
- glusterVolume ="hadoop-gluster" ;
101
- }
102
-
103
- gfs =new GlusterFileSystem ();
104
-
105
- /* retrieve the local machines hostname */
106
- if (glusterHost ==null ||"" .compareTo (glusterHost )==0 ){
107
- InetAddress addr =null ;
108
-
109
- addr =InetAddress .getLocalHost ();
110
-
111
- glusterHost =addr .getHostName ();
112
- }
113
-
114
- System .out .println ("Confirmed that configuration properties from gluster were found , now creating dirs" );
115
-
116
- gfs =new GlusterFileSystem ();
117
- temp =new File (tempDirectory , "hadoop-temp" );
118
- mount =new File (tempDirectory , "mount" );
119
-
120
- /**
121
- * We mount to "mount" which is /tmp
122
- */
123
- temp .mkdir ();
124
- mount .mkdir ();
125
-
126
- System .out .println ("Now initializing GlusterFS ! - We will mount to " +mount .getAbsolutePath ());
127
-
128
- Configuration conf =new Configuration ();
129
- conf .set ("fs.glusterfs.volname" , glusterVolume );
130
- conf .set ("fs.glusterfs.mount" , mount .getAbsolutePath ());
131
- conf .set ("fs.glusterfs.server" , glusterHost );
132
- conf .set ("fs.default.name" , "glusterfs://" +glusterHost +":9000" );
133
- System .out .println ("server " +conf .get ("fs.glusterfs.server" ));
134
- gfs .initialize (temp .toURI (), conf );
60
+ gfs = GFSUtil .create (true );
61
+ }
62
+
63
+ @ AfterClass
64
+ public static void after () throws IOException {
65
+ gfs .close ();
66
+ FileUtils .delete (GFSUtil .getTempDirectory ());
135
67
}
136
68
137
69
@ org .junit .Test
@@ -409,8 +341,7 @@ public void testFileIO() throws Exception{
409
341
410
342
// BZ908899
411
343
@ Test
412
- public void test0aPermissions () throws Exception {
413
- System .out .println ("working dir : " +gfs .getWorkingDirectory ());
344
+ public void testPermissionsChanging () throws Exception {
414
345
Path theFile =new Path ("/mnt/glusterfs/changePerms/a" );
415
346
416
347
gfs .create (theFile );
@@ -436,7 +367,6 @@ public void test0aPermissions() throws Exception{
436
367
437
368
}
438
369
439
-
440
370
@ Test
441
371
public void testCreateNR () throws Exception {
442
372
Path nonrec = new Path ("nonrec" );
@@ -447,4 +377,4 @@ public void testCreateNR() throws Exception{
447
377
Assert .assertTrue (this .gfs .exists (new Path ("nonrec" )));
448
378
this .gfs .delete (nonrec );
449
379
}
450
- }
380
+ }
0 commit comments