func TestHeaderSize(t *testing.T) { SetupCluster() log.Info("Testing TestHeaderSize...") header, err := tc.nodes[2].Fss.Header(fs.NewPath("/header/should/not/exists"), nil) if err != nil { t.Errorf("1) Header returned an an error for: %s\n", err) } if header.Size > 0 { t.Errorf("2) Header Size shouldn't higher than 0: %d", header.Size) } byts := []byte("salut!") buf := bytes.NewBuffer(byts) tc.nodes[3].Fss.Write(fs.NewPath("/header/tests/io/size"), int64(len(byts)), "", buf, nil) header, err = tc.nodes[1].Fss.Header(fs.NewPath("/header/tests/io/size"), nil) if err != nil { t.Errorf("3) Header returned an an error for: %s\n", err) } if header.Size != 6 { t.Errorf("4) Header Exists should be equal to 6: %s", header.Size) } byts = []byte("ca") buf = bytes.NewBuffer(byts) tc.nodes[3].Fss.Write(fs.NewPath("/header/tests/io/size"), int64(len(byts)), "", buf, nil) header, err = tc.nodes[1].Fss.Header(fs.NewPath("/header/tests/io/size"), nil) if err != nil { t.Errorf("5) Header returned an an error for: %s\n", err) } if header.Size != 2 { t.Errorf("6) Header Exists should be equal to 2: %s", header.Size) } }
func TestHeaderMimeType(t *testing.T) { SetupCluster() log.Info("Testing TestHeaderMimeType...") byts := []byte("salut!") buf := bytes.NewBuffer(byts) tc.nodes[3].Fss.Write(fs.NewPath("/header/tests/mimetype"), int64(len(byts)), "text/html", buf, nil) header, err := tc.nodes[1].Fss.Header(fs.NewPath("/header/tests/mimetype"), nil) if err != nil { t.Errorf("1) Header returned an an error for: %s\n", err) } if header.MimeType != "text/html" { t.Errorf("2) Header type should be equal to text/html: %s", header.MimeType) } byts = []byte("salut!") buf = bytes.NewBuffer(byts) tc.nodes[3].Fss.Write(fs.NewPath("/header/tests/mimetype"), int64(len(byts)), "text/css", buf, nil) header, err = tc.nodes[1].Fss.Header(fs.NewPath("/header/tests/mimetype"), nil) if err != nil { t.Errorf("3) Header returned an an error for: %s\n", err) } if header.MimeType != "text/css" { t.Errorf("4) Header type should be equal to text/css: %s", header.MimeType) } }
func TestExists(t *testing.T) { SetupCluster() log.Info("Testing TestExists...") exists, err := tc.nodes[1].Fss.Exists(fs.NewPath("/should/not/exists"), nil) if err != nil { t.Errorf("1) Exists returned an an error for: %s\n", err) } if exists == true { t.Errorf("2) Exists returned bad value: %s", exists) } exists, err = tc.nodes[2].Fss.Exists(fs.NewPath("/should/not/exists"), nil) if err != nil { t.Errorf("3) Exists returned an an error for: %s\n", err) } if exists == true { t.Errorf("4) Exists returned bad value: %s", exists) } byts := []byte("salut!") buf := bytes.NewBuffer(byts) tc.nodes[0].Fss.Write(fs.NewPath("/tests/io/exists"), int64(len(byts)), "", buf, nil) exists, err = tc.nodes[2].Fss.Exists(fs.NewPath("/tests/io/exists"), nil) if err != nil { t.Errorf("5) Exists returned an an error for: %s\n", err) } if exists == false { t.Errorf("6) Exists returned bad value: %s", exists) } }
func TestBaseName(t *testing.T) { path := fs.NewPath("/home") if path.BaseName() != "home" { t.Errorf("1) BaseName should be 'home' but received '%s'\n", path.BaseName()) } path = fs.NewPath("/home/..") if path.BaseName() != "" { t.Errorf("2) BaseName should be '' but received '%s'\n", path.BaseName()) } path = fs.NewPath("/") if path.BaseName() != "" { t.Errorf("3) BaseName should be '' but received '%s'\n", path.BaseName()) } path = fs.NewPath("/..") if path.BaseName() != "" { t.Errorf("4) BaseName should be '' but received '%s'\n", path.BaseName()) } path = fs.NewPath("/home/test/..") if path.BaseName() != "home" { t.Errorf("5) BaseName should be 'home' but received '%s'\n", path.BaseName()) } }
func TestHeaderExists(t *testing.T) { SetupCluster() log.Info("Testing TestHeaderExists...") //t.Errorf("%s", tc.nodes[1].Cluster.Resolve("/header/should/not/exists").Get(0)) header, err := tc.nodes[4].Fss.Header(fs.NewPath("/header/should/not/exists"), nil) if err != nil { t.Errorf("1) Header returned an an error for: %s\n", err) } if header.Exists { t.Errorf("2) Header Exists shouldn't be true: %s\n", header.Exists) } header, err = tc.nodes[2].Fss.Header(fs.NewPath("/header/should/not/exists"), nil) if err != nil { t.Errorf("3) Header returned an an error for: %s\n", err) } if header.Exists { t.Errorf("4) Header Exists shouldn't be true: %s", header.Exists) } byts := []byte("salut!") buf := bytes.NewBuffer(byts) tc.nodes[3].Fss.Write(fs.NewPath("/header/tests/io/exists"), int64(len(byts)), "", buf, nil) header, err = tc.nodes[1].Fss.Header(fs.NewPath("/header/tests/io/exists"), nil) if err != nil { t.Errorf("5) Header returned an an error for: %s\n", err) } if !header.Exists { t.Errorf("6) Header Exists shouldn't be false: %s", header.Exists) } }
func TestChildAddReplication(t *testing.T) { SetupCluster() log.Info("Testing TestChildAddReplication...") _, other := GetProcessForPath("/tests/replication/write/childadd") resolv := tc.nodes[0].Cluster.Rings.GetGlobalRing().Resolve("/tests/replication/write") _, otherparent := GetProcessForPath("/tests/replication/write") buf := buffer.NewFromString("write1") err := other.Fss.Write(fs.NewPath("/tests/replication/write/childadd"), buf.Size, "application/mytest", buf, nil) if err != nil { t.Errorf("1) Got an error while write: %s", err) } // check if its not on another node context := tc.nodes[0].Fss.NewContext() context.ForceLocal = true children, err := otherparent.Fss.Children(fs.NewPath("/tests/replication/write"), context) if err == nil && len(children) != 0 { t.Errorf("2) Children should not exists on another node") } // check on first secondary secondaryid := resolv.GetOnline(1).Id context = tc.nodes[secondaryid].Fss.NewContext() context.ForceLocal = true children, err = tc.nodes[secondaryid].Fss.Children(fs.NewPath("/tests/replication/write"), context) if err != nil { t.Errorf("3) Got an error while exists: %s", err) } found := false for _, child := range children { if child.Name == "childadd" { found = true } } if !found { t.Errorf("4) Couldn't find child 'childadd'") } // check on second secondary secondaryid = resolv.GetOnline(1).Id context = tc.nodes[secondaryid].Fss.NewContext() context.ForceLocal = true children, err = tc.nodes[secondaryid].Fss.Children(fs.NewPath("/tests/replication/write"), context) if err != nil { t.Errorf("5) Got an error while exists: %s", err) } found = false for _, child := range children { if child.Name == "childadd" { found = true } } if !found { t.Errorf("6) Couldn't find child 'childadd'") } }
func TestWriteReadReplication(t *testing.T) { SetupCluster() log.Info("Testing TestWriteReadReplication...") _, other := GetProcessForPath("/tests/replication/write/read") resolv := tc.nodes[0].Cluster.Rings.GetGlobalRing().Resolve("/tests/replication/write/read") buf := buffer.NewFromString("write1") err := other.Fss.Write(fs.NewPath("/tests/replication/write/read"), buf.Size, "application/mytest", buf, nil) if err != nil { t.Errorf("1) Got an error while write: %s", err) } // test force local on exists context := tc.nodes[0].Fss.NewContext() context.ForceLocal = true bufwriter := bytes.NewBuffer(make([]byte, 0)) buffer := io.Writer(bufwriter) n, err := other.Fss.Read(fs.NewPath("/tests/replication/write/read"), 0, -1, 0, buffer, context) if err != fs.ErrorFileNotFound { t.Errorf("2) File shouldn't exists on another node: %s", err) } // force local replication on each secondary tc.nodes[resolv.GetOnline(1).Id].Fss.Flush() tc.nodes[resolv.GetOnline(2).Id].Fss.Flush() // check on first secondary secondaryid := resolv.GetOnline(1).Id context = tc.nodes[secondaryid].Fss.NewContext() context.ForceLocal = true bufwriter = bytes.NewBuffer(make([]byte, 0)) buffer = io.Writer(bufwriter) n, err = tc.nodes[secondaryid].Fss.Read(fs.NewPath("/tests/replication/write/read"), 0, -1, 0, buffer, context) if err != nil { t.Errorf("3) Got an error from read: %s", err) } if n != buf.Size || bytes.Compare(bufwriter.Bytes(), buf.Bytes()) != 0 { t.Errorf("4) Didn't read what was written: %s!=%s", buf.Bytes(), bufwriter) } // check on second secondary secondaryid = resolv.GetOnline(2).Id context = tc.nodes[secondaryid].Fss.NewContext() context.ForceLocal = true bufwriter = bytes.NewBuffer(make([]byte, 0)) buffer = io.Writer(bufwriter) n, err = tc.nodes[secondaryid].Fss.Read(fs.NewPath("/tests/replication/write/read"), 0, -1, 0, buffer, context) if err != nil { t.Errorf("3) Got an error from read: %s", err) } if n != buf.Size || bytes.Compare(bufwriter.Bytes(), buf.Bytes()) != 0 { t.Errorf("4) Didn't read what was written: %s!=%s", buf.Bytes(), bufwriter) } }
func TestFsChildAddWriteNeedNetworkTimeout(t *testing.T) { SetupCluster() log.Info("Testing TestFsChildAddWriteNeedNetworkTimeout...") resp2, other2 := GetProcessForPath("/tests/timeout2/write") resp1, other1 := GetProcessForPath("/tests/timeout2") initadr := resp2.Cluster.Nodes.Get(resp1.Cluster.MyNode.Id).Address resp2.Cluster.Nodes.Get(resp1.Cluster.MyNode.Id).Address = net.ParseIP("224.0.0.2") // Create the child, it should never get added to the parent buf := buffer.NewFromString("write1") err := other2.Fss.Write(fs.NewPath("/tests/timeout2/write"), buf.Size, "", buf, nil) if err != nil && err != comm.ErrorTimeout { t.Error("1) Received an error: %s", err) } time.Sleep(900000000) children, _ := other1.Fss.Children(fs.NewPath("/tests/timeout2"), nil) found := false for _, child := range children { if child.Name == "write" { found = true } } if found { t.Error("2) Child should not have been added") } // Test one timeout + 1 retry, no error buf = buffer.NewFromString("write1") go func() { time.Sleep(1500 * 1000 * 1000) // set the address back resp2.Cluster.Nodes.Get(resp1.Cluster.MyNode.Id).Address = initadr }() err = other2.Fss.Write(fs.NewPath("/tests/timeout2/write3"), buf.Size, "", buf, nil) if err != nil { t.Error("3) Received an error: %s", err) } children, err = other1.Fss.Children(fs.NewPath("/tests/timeout2"), nil) found = false for _, child := range children { if child.Name == "write3" { found = true } } if !found { t.Error("4) Child should have been added") } }
func TestChildPath(t *testing.T) { path := fs.NewPath("/home") child := path.ChildPath("test") if child.String() != "/home/test" { t.Errorf("1) Wrong child path: %s %s\n", child, path.Parts) } path = fs.NewPath("/") child = path.ChildPath("home") if child.String() != "/home" { t.Errorf("2) Wrong child path: %s %s\n", child, path.Parts) } }
func TestFsDeleteNetworkTimeout(t *testing.T) { SetupCluster() log.Info("Testing TestFsDeleteNetworkTimeout...") resp, other := GetProcessForPath("/tests/timeouts/delete1") buf := buffer.NewFromString("write1") other.Fss.Write(fs.NewPath("/tests/timeouts/delete1"), buf.Size, "", buf, nil) initadr := other.Cluster.Nodes.Get(resp.Cluster.MyNode.Id).Address other.Cluster.Nodes.Get(resp.Cluster.MyNode.Id).Address = net.ParseIP("224.0.0.2") // Test full timeout and return of an error timeoutTest(1500*4, func() { buf = buffer.NewFromString("write1") err := other.Fss.Delete(fs.NewPath("/tests/timeouts/delete1"), false, nil) if err != comm.ErrorTimeout { t.Error("1) Didn't receive timeout error: %s", err) } }, func(returned bool) { if !returned { t.Error("2) Write network timeout is endlessly sleeping") } }) resp, other = GetProcessForPath("/tests/timeouts/delete2") buf = buffer.NewFromString("write1") other.Fss.Write(fs.NewPath("/tests/timeouts/delete2"), buf.Size, "", buf, nil) // Test one timeout + 1 retry, no error timeoutTest(1500*4, func() { // wait 50ms and change addr of the remote node go func() { time.Sleep(500000000) other.Cluster.Nodes.Get(resp.Cluster.MyNode.Id).Address = initadr }() buf = buffer.NewFromString("write1") err := other.Fss.Write(fs.NewPath("/tests/timeouts/delete2"), buf.Size, "", buf, nil) if err == comm.ErrorTimeout { t.Error("3) Received timeout error: %s", err) } }, func(returned bool) { if !returned { t.Error("4) Write network timeout is endlessly sleeping") } }) }
func TestIsRoot(t *testing.T) { path := fs.NewPath("/home") if path.IsRoot() { t.Errorf("1) /home should not considered root\n") } path = fs.NewPath("/") if !path.IsRoot() { t.Errorf("2) / should be considered root: '%s'\n", path.Parts[0]) } path = fs.NewPath("/test/..") if !path.IsRoot() { t.Errorf("3) /test/.. should be considered root\n") } }
func TestReadWrite(t *testing.T) { SetupCluster() log.Info("Testing TestReadWrite...") // Read write test path := fs.NewPath("/tests/io/write1") byts := []byte("write1") buf := bytes.NewBuffer(byts) err := tc.nodes[0].Fss.Write(path, int64(len(byts)), "", buf, nil) if err != nil { t.Errorf("1) Write returned an an error for: %s\n", err) } // Check if read data is the same as written bufwriter := bytes.NewBuffer(make([]byte, 0)) buffer := io.Writer(bufwriter) n, err := tc.nodes[2].Fss.Read(path, 0, -1, 0, buffer, nil) if n != int64(len(byts)) || bytes.Compare(bufwriter.Bytes(), byts) != 0 { t.Errorf("2) Didn't read written data correctly: %s!=%s\n", byts, bufwriter) } // Get from another node bufwriter = bytes.NewBuffer(make([]byte, 0)) buffer = io.Writer(bufwriter) n, err = tc.nodes[6].Fss.Read(path, 0, -1, 0, buffer, nil) if n != int64(len(byts)) || bytes.Compare(bufwriter.Bytes(), byts) != 0 { t.Errorf("3) Didn't read written data correctly: %s!=%s\n", byts, bufwriter) } // Rewrite on a file with new data path = fs.NewPath("/tests/io/write1") byts = []byte("this is new data blabla") buf = bytes.NewBuffer(byts) err = tc.nodes[4].Fss.Write(path, int64(len(byts)), "", buf, nil) if err != nil { t.Errorf("4) Write returned an an error for: %s\n", err) } // Check written data bufwriter = bytes.NewBuffer(make([]byte, 0)) buffer = io.Writer(bufwriter) n, err = tc.nodes[9].Fss.Read(path, 0, -1, 0, buffer, nil) if n != int64(len(byts)) || bytes.Compare(bufwriter.Bytes(), byts) != 0 { t.Errorf("5) Didn't read written data correctly: %s!=%s\n", byts, bufwriter) } }
func TestWriteExistsReplication(t *testing.T) { SetupCluster() log.Info("Testing TestWriteExistsReplication...") _, other := GetProcessForPath("/tests/replication/write/exists") resolv := tc.nodes[0].Cluster.Rings.GetGlobalRing().Resolve("/tests/replication/write/exists") buf := buffer.NewFromString("write1") err := other.Fss.Write(fs.NewPath("/tests/replication/write/exists"), buf.Size, "application/mytest", buf, nil) if err != nil { t.Errorf("1) Got an error while write: %s", err) } // test force local on exists context := tc.nodes[0].Fss.NewContext() context.ForceLocal = true exists, err := other.Fss.Exists(fs.NewPath("/tests/replication/write/exists"), context) if err != nil { t.Errorf("2) Got an error while exists: %s", err) } if exists { t.Errorf("3) Shouldn't exists on another node when forced local") } // check on first secondary secondaryid := resolv.GetOnline(1).Id context = tc.nodes[secondaryid].Fss.NewContext() context.ForceLocal = true exists, err = tc.nodes[secondaryid].Fss.Exists(fs.NewPath("/tests/replication/write/exists"), context) if err != nil { t.Errorf("4) Got an error while exists: %s", err) } if !exists { t.Errorf("5) Received exists = false, should be true") } // check on second secondary secondaryid = resolv.GetOnline(2).Id exists, err = tc.nodes[secondaryid].Fss.Exists(fs.NewPath("/tests/replication/write/exists"), context) if err != nil { t.Errorf("6) Got an error while exists: %s", err) } if !exists { t.Errorf("7) Received exists = false, should be true") } }
func TestWriteHeaderReplication(t *testing.T) { SetupCluster() log.Info("Testing TestWriteHeaderReplication...") resp, other := GetProcessForPath("/tests/replication/write/header") resolv := tc.nodes[0].Cluster.Rings.GetGlobalRing().Resolve("/tests/replication/write/header") buf := buffer.NewFromString("write1") err := other.Fss.Write(fs.NewPath("/tests/replication/write/header"), buf.Size, "application/mytest", buf, nil) if err != nil { t.Error("1) Got an error while write: %s", err) } // check header on master header, err := resp.Fss.Header(fs.NewPath("/tests/replication/write/header"), nil) version := header.Version // check on first secondary secondaryid := resolv.GetOnline(1).Id header, err = tc.nodes[secondaryid].Fss.Header(fs.NewPath("/tests/replication/write/header"), nil) if header.Version != version { t.Errorf("2) Version on secondary node wasn't the same as on master: %d != %d", version, header.Version) } if header.MimeType != "application/mytest" { t.Errorf("3) Mimetype on secondary node wasn't the same as on master: %s != %s", "application/mytest", header.MimeType) } if header.Size != buf.Size { t.Errorf("4) Size on secondary node wasn't the same as on master: %d != %d", 6, header.Size) } // check on second secondary secondaryid = resolv.GetOnline(2).Id header, err = tc.nodes[secondaryid].Fss.Header(fs.NewPath("/tests/replication/write/header"), nil) if header.Version != version { t.Errorf("5) Version on secondary node wasn't the same as on master: %d != %d", version, header.Version) } if header.MimeType != "application/mytest" { t.Errorf("6) Mimetype on secondary node wasn't the same as on master: %s != %s", "application/mytest", header.MimeType) } if header.Size != buf.Size { t.Errorf("7) Size on secondary node wasn't the same as on master: %d != %d", 6, header.Size) } }
func TestFsReadNetworkTimeout(t *testing.T) { SetupCluster() log.Info("Testing TestFsReadNetworkTimeout...") bufwriter := bytes.NewBuffer(make([]byte, 0)) buffer := io.Writer(bufwriter) resp, other := GetProcessForPath("/") initadr := other.Cluster.Nodes.Get(resp.Cluster.MyNode.Id).Address other.Cluster.Nodes.Get(resp.Cluster.MyNode.Id).Address = net.ParseIP("224.0.0.2") // Test full timeout and return of an error timeoutTest(1500*4, func() { _, err := other.Fss.Read(fs.NewPath("/"), 0, -1, 0, buffer, nil) if err != comm.ErrorTimeout { t.Error("1) Didn't receive timeout error: %s", err) } }, func(returned bool) { if !returned { t.Error("2) Read network timeout is endlessly sleeping") } }) // Test one timeout + 1 retry, no error timeoutTest(1500*4, func() { // wait 50ms and change addr of the remote node go func() { time.Sleep(500000000) other.Cluster.Nodes.Get(resp.Cluster.MyNode.Id).Address = initadr }() _, err := other.Fss.Read(fs.NewPath("/"), 0, -1, 0, buffer, nil) if err == comm.ErrorTimeout { t.Error("3) Received timeout error: %s", err) } }, func(returned bool) { if !returned { t.Error("4) Read network timeout is endlessly sleeping") } }) }
func BenchmarkExists(b *testing.B) { b.StopTimer() SetupCluster() path := fs.NewPath("/tests/io/benchwrite") b.StartTimer() for i := 0; i < b.N; i++ { tc.nodes[7].Fss.Exists(path, nil) } }
/* * Benchmarks */ func BenchmarkWrite(b *testing.B) { b.StopTimer() SetupCluster() path := fs.NewPath("/tests/io/benchwrite") b.StartTimer() for i := 0; i < b.N; i++ { buf := bytes.NewBuffer([]byte("azsdrfjqlmndufir")) tc.nodes[6].Fss.Write(path, 16, "", buf, nil) } }
func TestDeleteNonRecursiveMultipleLevel(t *testing.T) { SetupCluster() log.Info("Testing TestDeleteNonRecursiveMultipleLevel...") byts := []byte("data") buf := bytes.NewBuffer(byts) tc.nodes[0].Fss.Write(fs.NewPath("/tests/delete/nonrecml/level1/level2/level3"), int64(len(byts)), "", buf, nil) time.Sleep(10000000) err := tc.nodes[0].Fss.Delete(fs.NewPath("/tests/delete/nonrecml/level1"), false, nil) if err != fs.ErrorNotEmpty { t.Errorf("1) Should get an error if trying to delete a multiple level file") } exists, _ := tc.nodes[2].Fss.Exists(fs.NewPath("/tests/delete/nonrecml/level1/level2/level3"), nil) if !exists { t.Errorf("2) Should not be deleted since it was a multilevel with non recursive\n") } }
func BenchmarkRead(b *testing.B) { b.StopTimer() SetupCluster() path := fs.NewPath("/tests/io/benchwrite") b.StartTimer() for i := 0; i < b.N; i++ { bufwriter := bytes.NewBuffer(make([]byte, 0)) buffer := io.Writer(bufwriter) tc.nodes[7].Fss.Read(path, 0, -1, 0, buffer, nil) } }
func TestFsChildRemoveDeleteNetworkTimeout(t *testing.T) { SetupCluster() log.Info("Testing TestFsChildRemoveDeleteNetworkTimeout...") resp3, other3 := GetProcessForPath("/test/timeout/delete1", "/test/timeout") resp2, other2 := GetProcessForPath("/test/timeout/delete2", "/test/timeout", "/test/timeout/delete2") resp1, other1 := GetProcessForPath("/test/timeout") buf := buffer.NewFromString("write1") resp3.Fss.Write(fs.NewPath("/test/timeout/delete1"), buf.Size, "", buf, nil) buf = buffer.NewFromString("write1") resp3.Fss.Write(fs.NewPath("/test/timeout/delete2"), buf.Size, "", buf, nil) initadr := resp2.Cluster.Nodes.Get(resp1.Cluster.MyNode.Id).Address resp2.Cluster.Nodes.Get(resp1.Cluster.MyNode.Id).Address = net.ParseIP("224.0.0.2") resp3.Cluster.Nodes.Get(resp1.Cluster.MyNode.Id).Address = net.ParseIP("224.0.0.2") time.Sleep(900000000) // Delete child, it should never get delete from the parent err := other2.Fss.Delete(fs.NewPath("/test/timeout/delete1"), false, nil) if err != nil { t.Error("1) Received an error: %s", err) } time.Sleep(900000000) children, _ := other1.Fss.Children(fs.NewPath("/test/timeout"), nil) found := false for _, child := range children { if child.Name == "delete1" { found = true } } if !found { t.Error("2) Child should not have been deleted") } // Test timeout of the first and write of a new one err = other3.Fss.Delete(fs.NewPath("/test/timeout/delete2"), false, nil) if err != nil { t.Error("3) Received an error: %s", err) } // Set back the address resp2.Cluster.Nodes.Get(resp1.Cluster.MyNode.Id).Address = initadr resp3.Cluster.Nodes.Get(resp1.Cluster.MyNode.Id).Address = initadr time.Sleep(6000000000) children, _ = other1.Fss.Children(fs.NewPath("/test/timeout"), nil) found1, found2 := false, false for _, child := range children { if child.Name == "delete2" { found2 = true } else if child.Name == "delete1" { found1 = true } } if found1 || found2 { t.Error("4) At least one of the children is still there", found1, found2) } }
func TestUnicode(t *testing.T) { SetupCluster() log.Info("Testing TestUnicode...") // Read write test path := fs.NewPath("/tests/io/writeunicode") byts := []byte("Some é unicode à data 世界") buf := bytes.NewBuffer(byts) err := tc.nodes[0].Fss.Write(path, int64(len(byts)), "", buf, nil) if err != nil { t.Errorf("1) Write returned an an error for: %s\n", err) } // Check if read data is the same as written bufwriter := bytes.NewBuffer(make([]byte, 0)) n, err := tc.nodes[2].Fss.Read(path, 0, -1, 0, io.Writer(bufwriter), nil) if n != int64(len(byts)) || bytes.Compare(bufwriter.Bytes(), byts) != 0 { t.Errorf("2) Didn't read written data correctly: %s!=%s\n", byts, bufwriter) } // Test unicode path path = fs.NewPath("/école èàaû/世界.txt") wrtnData := buffer.NewFromString("some data") err = tc.nodes[0].Fss.Write(path, wrtnData.Size, "", wrtnData, nil) if err != nil { t.Errorf("3) Error while writing: %s\n", err) } // Reading written data rdData := buffer.NewWithSize(0, false) n, err = tc.nodes[1].Fss.Read(path, 0, -1, 0, rdData, nil) if n != wrtnData.Size || bytes.Compare(rdData.Bytes(), wrtnData.Bytes()) != 0 { t.Errorf("4) Didn't read what had ben written: %s!=%s", rdData.Bytes(), wrtnData.Bytes()) } }
func TestReadNotExists(t *testing.T) { SetupCluster() log.Info("Testing TestReadNotExists...") path := fs.NewPath("/should/not/exists") bufwriter := bytes.NewBuffer(make([]byte, 0)) buffer := io.Writer(bufwriter) // Local _, err := tc.nodes[1].Fss.Read(path, 0, -1, 0, buffer, nil) if err != fs.ErrorFileNotFound { t.Errorf("1) Read didn't return that the file don't exists: %s\n", err) } // Remote _, err = tc.nodes[5].Fss.Read(path, 0, -1, 0, buffer, nil) if err != fs.ErrorFileNotFound { t.Errorf("2) Read didn't return that the file don't exists: %s\n", err) } }
func TestDeleteParentHierarchie(t *testing.T) { SetupCluster() log.Info("Testing TestDeleteParentHierarchie...") path := fs.NewPath("/tests/delete/hierarchie/child1") byts := []byte("child1") buf := bytes.NewBuffer(byts) tc.nodes[2].Fss.Write(path, int64(len(byts)), "", buf, nil) time.Sleep(100000000) tc.nodes[5].Fss.Delete(path, false, nil) time.Sleep(100000000) children, _ := tc.nodes[6].Fss.Children(path.ParentPath(), nil) for _, child := range children { if child.Name == "child1" { t.Errorf("1) File hasn't been removed from parent children") } } }
func TestDeleteNonRecursive(t *testing.T) { SetupCluster() log.Info("Testing TestDeleteNonRecursive...") path := fs.NewPath("/tests/delete/nonrec/level1") byts := []byte("data") buf := bytes.NewBuffer(byts) tc.nodes[0].Fss.Write(path, int64(len(byts)), "", buf, nil) time.Sleep(50000000) exists, _ := tc.nodes[2].Fss.Exists(path, nil) if !exists { t.Errorf("1) Created file should exists\n") } tc.nodes[0].Fss.Delete(path, false, nil) exists, _ = tc.nodes[2].Fss.Exists(path, nil) if exists { t.Errorf("2) Deleted file shouldn't exists\n") } }
func BenchmarkParsing(b *testing.B) { for i := 0; i < b.N; i++ { fs.NewPath("/home/test/toto/../toto/tata/./") } }
func TestParsing(t *testing.T) { path := fs.NewPath("/") parent := path.ParentPath() if path.String() != "/" { t.Errorf("1) Expected path of / != %s\n", path) } if parent.String() != "/" { t.Errorf("2) Expected parent of / is / != %s\n", parent) } path = fs.NewPath("/home") parent = path.ParentPath() if path.String() != "/home" { t.Errorf("3) Expected path of /home != %s\n", path) } if parent.String() != "/" { t.Errorf("4) Expected parent of /home is / != %s\n", parent) } path = fs.NewPath("/home/test") parent = path.ParentPath() if path.String() != "/home/test" { t.Errorf("5) Expected path of /home/test != %s\n", path) } if parent.String() != "/home" { t.Errorf("6) Expected parent of /home/test is /home != %s\n", parent) } path = fs.NewPath("/home/test/") parent = path.ParentPath() if path.String() != "/home/test" { t.Errorf("7) Expected path of /home/test != %s\n", path) } if parent.String() != "/home" { t.Errorf("8) Expected parent of /home/test is /home != %s\n", parent) } path = fs.NewPath("/home/test/..") parent = path.ParentPath() if path.String() != "/home" { t.Errorf("9) Expected path of /home != %s\n", path) } if parent.String() != "/" { t.Errorf("10) Expected parent of /home is / != %s\n", parent) } path = fs.NewPath("/home/..") parent = path.ParentPath() if path.String() != "/" { t.Errorf("11) Expected path of / != %s\n", path) } if parent.String() != "/" { t.Errorf("12) Expected parent of / is / != %s\n", parent) } path = fs.NewPath("/..") parent = path.ParentPath() if path.String() != "/" { t.Errorf("13) Expected path of / != %s\n", path) } if parent.String() != "/" { t.Errorf("14) Expected parent of / is / != %s\n", parent) } path = fs.NewPath("/.") parent = path.ParentPath() if path.String() != "/" { t.Errorf("15) Expected path of / != %s\n", path) } if parent.String() != "/" { t.Errorf("16) Expected parent of /. is / != %s\n", parent) } path = fs.NewPath("/home/.") parent = path.ParentPath() if path.String() != "/home" { t.Errorf("17) Expected path of /home != %s\n", path) } if parent.String() != "/" { t.Errorf("18) Expected parent of /home is / != %s\n", parent) } path = fs.NewPath("/home/./test") parent = path.ParentPath() if path.String() != "/home/test" { t.Errorf("19) Expected path of /home/test != %s\n", path) } if parent.String() != "/home" { t.Errorf("20) Expected parent of /home/test is /home != %s\n", parent) } path = fs.NewPath("/home/./test/..") parent = path.ParentPath() if path.String() != "/home" { t.Errorf("21) Expected path of /home != %s\n", path) } if parent.String() != "/" { t.Errorf("22) Expected parent of /home/./test/.. is / != %s\n", parent) } path = fs.NewPath("/home/./test/../test/tata/../toto/./") parent = path.ParentPath() if path.String() != "/home/test/toto" { t.Errorf("23) Expected path of /home/test/toto != %s\n", path) } if parent.String() != "/home/test" { t.Errorf("24) Expected parent of /home/test/toto is /home/test != %s\n", parent) } }
func TestDeleteReplication(t *testing.T) { SetupCluster() log.Info("Testing TestDeleteReplication...") resp, other := GetProcessForPath("/tests/replication/write/childdelete") resolv := tc.nodes[0].Cluster.Rings.GetGlobalRing().Resolve("/tests/replication/write/childdelete") respparent, _ := GetProcessForPath("/tests/replication/write") resolvparent := tc.nodes[0].Cluster.Rings.GetGlobalRing().Resolve("/tests/replication/write") buf := buffer.NewFromString("write1") err := other.Fss.Write(fs.NewPath("/tests/replication/write/childdelete"), buf.Size, "application/mytest", buf, nil) if err != nil { t.Errorf("1) Got an error while write: %s", err) } // check if its not on another node err = other.Fss.Delete(fs.NewPath("/tests/replication/write/childdelete"), true, nil) if err != nil { t.Errorf("2) Got an error while deleting: %s", err) } // check on master context := tc.nodes[0].Fss.NewContext() context.ForceLocal = true exists, err := resp.Fss.Exists(fs.NewPath("/tests/replication/write/childdelete"), context) if err != nil { t.Errorf("3) Got an error while exists: %s", err) } if exists { t.Errorf("4) Shouldn't exists on master") } // check on first secondary secondaryid := resolv.GetOnline(1).Id context = tc.nodes[secondaryid].Fss.NewContext() context.ForceLocal = true exists, err = tc.nodes[secondaryid].Fss.Exists(fs.NewPath("/tests/replication/write/childdelete"), context) if err != nil { t.Errorf("5) Got an error while exists: %s", err) } if exists { t.Errorf("6) Shouldn't exists on master") } // check on second secondary secondaryid = resolv.GetOnline(2).Id context = tc.nodes[secondaryid].Fss.NewContext() context.ForceLocal = true exists, err = tc.nodes[secondaryid].Fss.Exists(fs.NewPath("/tests/replication/write/childdelete"), context) if err != nil { t.Errorf("7) Got an error while exists: %s", err) } if exists { t.Errorf("8) Shouldn't exists on master") } time.Sleep(500000000) // check master parent secondaryid = resolvparent.GetOnline(2).Id context = tc.nodes[secondaryid].Fss.NewContext() context.ForceLocal = true children, err := respparent.Fss.Children(fs.NewPath("/tests/replication/write"), context) if err != nil { t.Errorf("9) Got an error while exists: %s", err) } found := false for _, child := range children { if child.Name == "childdelete" { found = true } } if found { t.Errorf("10) Child 'childdelete' should exists on master anymore") } // check first secondary secondaryid = resolvparent.GetOnline(1).Id context = tc.nodes[secondaryid].Fss.NewContext() context.ForceLocal = true children, err = tc.nodes[secondaryid].Fss.Children(fs.NewPath("/tests/replication/write"), context) if err != nil { t.Errorf("11) Got an error while exists: %s", err) } found = false for _, child := range children { if child.Name == "childdelete" { found = true } } if found { t.Errorf("12) Child 'childdelete' should exists on secondary anymore") } // check second secondary secondaryid = resolvparent.GetOnline(2).Id context = tc.nodes[secondaryid].Fss.NewContext() context.ForceLocal = true children, err = tc.nodes[secondaryid].Fss.Children(fs.NewPath("/tests/replication/write"), context) if err != nil { t.Errorf("13) Got an error while exists: %s", err) } found = false for _, child := range children { if child.Name == "childdelete" { found = true } } if found { t.Errorf("14) Child 'childdelete' should exists on secondary anymore") } }
func TestDeleteRecursive(t *testing.T) { SetupCluster() log.Info("Testing TestDeleteRecursive...") path := fs.NewPath("/tests/delete/rec/level1-a/level2-a") byts := []byte("data") buf := bytes.NewBuffer(byts) tc.nodes[8].Fss.Write(path, int64(len(byts)), "", buf, nil) path = fs.NewPath("/tests/delete/rec/level1-a/level2-b") byts = []byte("data") buf = bytes.NewBuffer(byts) tc.nodes[0].Fss.Write(path, int64(len(byts)), "", buf, nil) path = fs.NewPath("/tests/delete/rec/level1-b/level2-a") byts = []byte("data") buf = bytes.NewBuffer(byts) tc.nodes[1].Fss.Write(path, int64(len(byts)), "", buf, nil) path = fs.NewPath("/tests/delete/rec/level1-b/level2-b") byts = []byte("data") buf = bytes.NewBuffer(byts) tc.nodes[4].Fss.Write(path, int64(len(byts)), "", buf, nil) path = fs.NewPath("/tests/delete/rec/level1-c/level2-a") byts = []byte("data") buf = bytes.NewBuffer(byts) tc.nodes[2].Fss.Write(path, int64(len(byts)), "", buf, nil) path = fs.NewPath("/tests/delete/rec/level1-c/level2-b") byts = []byte("data") buf = bytes.NewBuffer(byts) tc.nodes[6].Fss.Write(path, int64(len(byts)), "", buf, nil) time.Sleep(10000000) // 1 level with recursive on tc.nodes[5].Fss.Delete(fs.NewPath("/tests/delete/rec/level1-a/level2-a"), true, nil) exists, _ := tc.nodes[1].Fss.Exists(fs.NewPath("/tests/delete/rec/level1-a/level2-a"), nil) if exists { t.Errorf("1) Deleted file shouldn't exists\n") } // 2 level with recursive on tc.nodes[3].Fss.Delete(fs.NewPath("/tests/delete/rec/level1-a"), true, nil) exists, _ = tc.nodes[4].Fss.Exists(fs.NewPath("/tests/delete/rec/level1-a"), nil) if exists { t.Errorf("2) Deleted file shouldn't exists\n") } exists, _ = tc.nodes[5].Fss.Exists(fs.NewPath("/tests/delete/rec/level1-a/level2-b"), nil) if exists { t.Errorf("3) Deleted file shouldn't exists\n") } // 3 level with recursive on tc.nodes[3].Fss.Delete(fs.NewPath("/tests/delete/rec"), true, nil) exists, _ = tc.nodes[4].Fss.Exists(fs.NewPath("/tests/delete/rec"), nil) if exists { t.Errorf("4) Deleted file shouldn't exists\n") } exists, _ = tc.nodes[5].Fss.Exists(fs.NewPath("/tests/delete/rec/level1-c"), nil) if exists { t.Errorf("5) Deleted file shouldn't exists\n") } exists, _ = tc.nodes[5].Fss.Exists(fs.NewPath("/tests/delete/rec/level1-c/level2-a"), nil) if exists { t.Errorf("6) Deleted file shouldn't exists\n") } exists, _ = tc.nodes[5].Fss.Exists(fs.NewPath("/tests/delete/rec/level1-c/level2-b"), nil) if exists { t.Errorf("6) Deleted file shouldn't exists\n") } }
func TestChildrenList(t *testing.T) { SetupCluster() log.Info("Testing TestChildrenList...") // Read write test byts := []byte("child1 data of size 22") buf := bytes.NewBuffer(byts) tc.nodes[0].Fss.Write(fs.NewPath("/tests/hierarchie/childrenlist/child1"), int64(len(byts)), "application/json", buf, nil) byts = []byte("child2") buf = bytes.NewBuffer(byts) tc.nodes[1].Fss.Write(fs.NewPath("/tests/hierarchie/childrenlist/child2"), int64(len(byts)), "text/html", buf, nil) byts = []byte("child3") buf = bytes.NewBuffer(byts) tc.nodes[3].Fss.Write(fs.NewPath("/tests/hierarchie/childrenlist/child3"), int64(len(byts)), "text/css", buf, nil) byts = []byte("otherchildrenlist") buf = bytes.NewBuffer(byts) tc.nodes[3].Fss.Write(fs.NewPath("/tests/hierarchie/otherchildrenlist"), int64(len(byts)), "", buf, nil) // Check third level children, err := tc.nodes[5].Fss.Children(fs.NewPath("/tests/hierarchie/childrenlist"), nil) if err != nil { t.Errorf("1) Children returned an an error for: %s\n", err) } if len(children) != 3 { t.Errorf("2) Children didn't return 3 children: %d\n", len(children)) } one, two, three := false, false, false for _, child := range children { switch child.Name { case "child1": if child.MimeType != "application/json" { t.Errorf("3) child1 should have a type application/json: %s\n", child.MimeType) } if child.Size != 22 { t.Errorf("4) child1 should have a size of 22: %d\n", child.Size) } one = true case "child2": two = true if child.MimeType != "text/html" { t.Errorf("5) child2 should have a type text/html: %s\n", child.MimeType) } if child.Size != 6 { t.Errorf("6) child2 should have a size of 6: %d\n", child.Size) } case "child3": three = true default: t.Errorf("7) Received invalid child: %s\n", child) } } if !one || !two || !three { t.Errorf("8) One or more children missing. Received: %s\n", children) } // Check second level children, err = tc.nodes[8].Fss.Children(fs.NewPath("/tests/hierarchie"), nil) if err != nil { t.Errorf("9) Children returned an an error for: %s\n", err) } if len(children) != 2 { t.Errorf("10) Children didn't return 3 children: %d\n", len(children)) } one, two, three = false, false, false for _, child := range children { switch child.Name { case "childrenlist": one = true case "otherchildrenlist": two = true default: t.Errorf("11) Received invalid child: %s\n", child) } } if !one || !two { t.Errorf("12) One or more children missing. Received: %s\n", children) } // Check first level children, err = tc.nodes[4].Fss.Children(fs.NewPath("/tests"), nil) if err != nil { t.Errorf("13) Children returned an an error for: %s\n", err) } if len(children) < 1 { t.Errorf("14) Children didn't return at least 1: %d\n", len(children)) } one = false for _, child := range children { if child.Name == "hierarchie" { one = true } } if !one { t.Errorf("15) Didn't receive 'hierarchie' child. Received: %s\n", children) } }