@@ -20,7 +20,7 @@ func TestSimple(t *testing.T) {
20
20
//create a file, make sure that use and group information is correct
21
21
testFile := filepath .Join (mountPoint , "somefile" )
22
22
loginfo (fmt .Sprintf ("New file: %s" , testFile ), nil )
23
- createFile (t , testFile )
23
+ createFile (t , testFile , "some data" )
24
24
fi , _ := os .Stat (testFile )
25
25
fstat := fi .Sys ().(* syscall.Stat_t )
26
26
grupInfo , _ := user .LookupGroupId (fmt .Sprintf ("%d" , fstat .Gid ))
@@ -30,6 +30,48 @@ func TestSimple(t *testing.T) {
30
30
})
31
31
}
32
32
33
+ // testing multiple read write clients perfile
34
+ func TestMultipleRWCllients (t * testing.T ) {
35
+
36
+ withMount (t , "/" , func (mountPoint string , hdfsAccessor HdfsAccessor ) {
37
+ //create a file, make sure that use and group information is correct
38
+ // mountPoint = "/tmp"
39
+ testFile1 := filepath .Join (mountPoint , "somefile" )
40
+ testFile2 := filepath .Join (mountPoint , "somefile.bak" )
41
+ loginfo (fmt .Sprintf ("New file: %s" , testFile1 ), nil )
42
+ createFile (t , testFile1 , "initial data\n adsf\n " )
43
+
44
+ c1 , _ := os .OpenFile (testFile1 , os .O_RDWR , 0600 )
45
+ c2 , _ := os .OpenFile (testFile1 , os .O_RDWR , 0600 )
46
+ c3 , _ := os .OpenFile (testFile1 , os .O_RDWR , 0600 )
47
+
48
+ c1 .WriteString ("First client\n " )
49
+ c1 .Close ()
50
+
51
+ os .Rename (testFile1 , testFile2 )
52
+
53
+ c2 .WriteString ("Second client\n Second client\n " )
54
+ c3 .WriteString ("Third client\n Third client\n Third Client\n " )
55
+ c2 .Close ()
56
+ c3 .Close ()
57
+
58
+ c5 , err := os .Open (testFile2 )
59
+
60
+ if err != nil {
61
+ t .Error ("The file should have opened successfully" )
62
+ } else {
63
+ loginfo ("File opened successfully" , nil )
64
+ buffer := make ([]byte , 1024 )
65
+ c5 .Read (buffer )
66
+ //fmt.Printf("%s", buffer)
67
+ }
68
+ c5 .Close ()
69
+
70
+ os .Remove (testFile1 )
71
+ os .Remove (testFile2 )
72
+ })
73
+ }
74
+
33
75
func TestMountSubDir (t * testing.T ) {
34
76
//mount and create some files and dirs
35
77
dirs := 5
@@ -41,7 +83,7 @@ func TestMountSubDir(t *testing.T) {
41
83
mkdir (t , dir )
42
84
for j := 0 ; j < filesPdir ; j ++ {
43
85
f := filepath .Join (dir , "file" + strconv .Itoa (j ))
44
- createFile (t , f )
86
+ createFile (t , f , "initial data" )
45
87
}
46
88
}
47
89
@@ -57,8 +99,7 @@ func TestMountSubDir(t *testing.T) {
57
99
if len (content ) != filesPdir {
58
100
t .Errorf ("Failed. Expected == %d, Got %d " , filesPdir , len (content ))
59
101
for _ , ent := range content {
60
- loginfo (fmt .Sprintf ("%s" , ent .Name ()), nil )
61
-
102
+ loginfo (fmt .Sprintf ("file/dir %s" , ent .Name ()), nil )
62
103
}
63
104
}
64
105
})
@@ -78,8 +119,6 @@ func TestMountSubDir(t *testing.T) {
78
119
}
79
120
80
121
func withMount (t testing.TB , srcDir string , fn func (mntPath string , hdfsAccessor HdfsAccessor )) {
81
- initLogger ("error" , false , "" )
82
-
83
122
hdfsAccessor , err := NewHdfsAccessor ("localhost:8020" , WallClock {}, TLSConfig {TLS : false })
84
123
if err != nil {
85
124
logfatal (fmt .Sprintf ("Error/NewHdfsAccessor: %v " , err ), nil )
@@ -115,13 +154,13 @@ func mkdir(t testing.TB, dir string) {
115
154
116
155
}
117
156
118
- func createFile (t testing.TB , filePath string ) {
157
+ func createFile (t testing.TB , filePath string , data string ) {
119
158
t .Helper ()
120
159
out , err := os .Create (filePath )
121
160
if err != nil {
122
161
t .Errorf ("Faile to create test file %s. Error: %v" , filePath , err )
123
162
}
124
- out .WriteString ("This is some test string" )
163
+ out .WriteString (data )
125
164
out .Close ()
126
165
}
127
166
0 commit comments