|
|
@ -2,14 +2,16 @@ package dataswamp
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"caj-larsson/bog/dataswamp/namespace"
|
|
|
|
"caj-larsson/bog/dataswamp/swampfile"
|
|
|
|
"caj-larsson/bog/dataswamp/swampfile"
|
|
|
|
|
|
|
|
m_namespace "caj-larsson/bog/infrastructure/memory/namespace"
|
|
|
|
|
|
|
|
m_swampfile "caj-larsson/bog/infrastructure/memory/swampfile"
|
|
|
|
|
|
|
|
"caj-larsson/bog/infrastructure/system_time"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"github.com/matryer/is"
|
|
|
|
"github.com/matryer/is"
|
|
|
|
"github.com/spf13/afero"
|
|
|
|
"github.com/spf13/afero"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
// "caj-larsson/bog/dataswamp/namespace"
|
|
|
|
|
|
|
|
m_namespace "caj-larsson/bog/infrastructure/memory/namespace"
|
|
|
|
|
|
|
|
m_swampfile "caj-larsson/bog/infrastructure/memory/swampfile"
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type TestLogger struct{}
|
|
|
|
type TestLogger struct{}
|
|
|
@ -22,15 +24,25 @@ var file_ref1 = swampfile.FileReference{"/path1", "ns1"}
|
|
|
|
var file_ref2 = swampfile.FileReference{"/path1", "ns2"}
|
|
|
|
var file_ref2 = swampfile.FileReference{"/path1", "ns2"}
|
|
|
|
var file_ref3 = swampfile.FileReference{"/path2", "ns1"}
|
|
|
|
var file_ref3 = swampfile.FileReference{"/path2", "ns1"}
|
|
|
|
|
|
|
|
|
|
|
|
func NewTestSwampFileService() SwampFileService {
|
|
|
|
func NewTestDataSwampService() DataSwampService {
|
|
|
|
file_repo := m_swampfile.NewRepository()
|
|
|
|
file_repo := m_swampfile.NewRepository()
|
|
|
|
ns_repo := m_namespace.NewRepository()
|
|
|
|
ns_repo := m_namespace.NewRepository()
|
|
|
|
return NewSwampFileService(ns_repo, file_repo, 1024, time.Hour, TestLogger{})
|
|
|
|
|
|
|
|
|
|
|
|
logger := TestLogger{}
|
|
|
|
|
|
|
|
ns_svc := namespace.NewNamespaceService(
|
|
|
|
|
|
|
|
ns_repo,
|
|
|
|
|
|
|
|
logger,
|
|
|
|
|
|
|
|
system_time.Clock{},
|
|
|
|
|
|
|
|
time.Hour,
|
|
|
|
|
|
|
|
1024,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return *NewDataSwampService(*ns_svc, file_repo, logger)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestFileDontExist(t *testing.T) {
|
|
|
|
func TestFileDontExist(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
is := is.New(t)
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
s := NewTestDataSwampService()
|
|
|
|
outfile, err := s.OpenOutFile(file_ref1)
|
|
|
|
outfile, err := s.OpenOutFile(file_ref1)
|
|
|
|
|
|
|
|
|
|
|
|
is.True(err == swampfile.ErrNotExists)
|
|
|
|
is.True(err == swampfile.ErrNotExists)
|
|
|
@ -39,7 +51,7 @@ func TestFileDontExist(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestFileIsStored(t *testing.T) {
|
|
|
|
func TestFileIsStored(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
is := is.New(t)
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
s := NewTestDataSwampService()
|
|
|
|
|
|
|
|
|
|
|
|
fakefile := bytes.NewBufferString("My bog data")
|
|
|
|
fakefile := bytes.NewBufferString("My bog data")
|
|
|
|
|
|
|
|
|
|
|
@ -60,7 +72,7 @@ func TestFileIsStored(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestFileIsReadBack(t *testing.T) {
|
|
|
|
func TestFileIsReadBack(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
is := is.New(t)
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
s := NewTestDataSwampService()
|
|
|
|
|
|
|
|
|
|
|
|
infile := bytes.NewBufferString("My bog data")
|
|
|
|
infile := bytes.NewBufferString("My bog data")
|
|
|
|
|
|
|
|
|
|
|
@ -76,7 +88,7 @@ func TestFileIsReadBack(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestNSIsolation(t *testing.T) {
|
|
|
|
func TestNSIsolation(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
is := is.New(t)
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
s := NewTestDataSwampService()
|
|
|
|
|
|
|
|
|
|
|
|
ns1_file := bytes.NewBufferString("My bog data ns1")
|
|
|
|
ns1_file := bytes.NewBufferString("My bog data ns1")
|
|
|
|
ns2_file := bytes.NewBufferString("My bog data ns2")
|
|
|
|
ns2_file := bytes.NewBufferString("My bog data ns2")
|
|
|
@ -94,7 +106,7 @@ func TestNSIsolation(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestPathStrictMode(t *testing.T) {
|
|
|
|
func TestPathStrictMode(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
is := is.New(t)
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
s := NewTestDataSwampService()
|
|
|
|
|
|
|
|
|
|
|
|
ns_file := bytes.NewBufferString("My bog data ns1")
|
|
|
|
ns_file := bytes.NewBufferString("My bog data ns1")
|
|
|
|
|
|
|
|
|
|
|
@ -114,7 +126,7 @@ func TestPathStrictMode(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestQuotaWithContenSizeLieOver(t *testing.T) {
|
|
|
|
func TestQuotaWithContenSizeLieOver(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
is := is.New(t)
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
s := NewTestDataSwampService()
|
|
|
|
|
|
|
|
|
|
|
|
largefakefile := bytes.NewBufferString("")
|
|
|
|
largefakefile := bytes.NewBufferString("")
|
|
|
|
|
|
|
|
|
|
|
@ -129,7 +141,7 @@ func TestQuotaWithContenSizeLieOver(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
func TestQuotaWithContenSizeLieUnder(t *testing.T) {
|
|
|
|
func TestQuotaWithContenSizeLieUnder(t *testing.T) {
|
|
|
|
is := is.New(t)
|
|
|
|
is := is.New(t)
|
|
|
|
s := NewTestSwampFileService()
|
|
|
|
s := NewTestDataSwampService()
|
|
|
|
|
|
|
|
|
|
|
|
largefakefile := bytes.NewBufferString("small")
|
|
|
|
largefakefile := bytes.NewBufferString("small")
|
|
|
|
|
|
|
|
|
|
|
@ -144,22 +156,32 @@ func TestCleanUpExpired(t *testing.T) {
|
|
|
|
fs := afero.NewMemMapFs()
|
|
|
|
fs := afero.NewMemMapFs()
|
|
|
|
file_repo := m_swampfile.Repository{fs}
|
|
|
|
file_repo := m_swampfile.Repository{fs}
|
|
|
|
ns_repo := m_namespace.NewRepository()
|
|
|
|
ns_repo := m_namespace.NewRepository()
|
|
|
|
s := NewSwampFileService(ns_repo, file_repo, 1024, time.Hour, TestLogger{})
|
|
|
|
logger := TestLogger{}
|
|
|
|
|
|
|
|
ns_svc := namespace.NewNamespaceService(
|
|
|
|
|
|
|
|
ns_repo,
|
|
|
|
|
|
|
|
logger,
|
|
|
|
|
|
|
|
system_time.Clock{},
|
|
|
|
|
|
|
|
time.Hour,
|
|
|
|
|
|
|
|
1024,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
fakefile := bytes.NewBufferString("My bog data")
|
|
|
|
s := NewDataSwampService(*ns_svc, file_repo, logger)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fakefile := bytes.NewBufferString("My bog")
|
|
|
|
err := s.SaveFile(file_ref1, fakefile, int64(fakefile.Len()))
|
|
|
|
err := s.SaveFile(file_ref1, fakefile, int64(fakefile.Len()))
|
|
|
|
is.NoErr(err)
|
|
|
|
is.NoErr(err)
|
|
|
|
|
|
|
|
|
|
|
|
fakefile = bytes.NewBufferString("My bog data")
|
|
|
|
fakefile = bytes.NewBufferString("My bog")
|
|
|
|
err = s.SaveFile(file_ref3, fakefile, int64(fakefile.Len()))
|
|
|
|
err = s.SaveFile(file_ref3, fakefile, int64(fakefile.Len()))
|
|
|
|
is.NoErr(err)
|
|
|
|
is.NoErr(err)
|
|
|
|
|
|
|
|
|
|
|
|
err = fs.Chtimes("1/path1", time.Now(), time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC))
|
|
|
|
err = fs.Chtimes("1/path1", time.Now(), time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC))
|
|
|
|
is.NoErr(err)
|
|
|
|
|
|
|
|
is.NoErr(s.CleanUpExpiredFiles())
|
|
|
|
is.NoErr(s.CleanUpExpiredFiles())
|
|
|
|
|
|
|
|
|
|
|
|
ns, err := ns_repo.GetByName("ns1")
|
|
|
|
ns, err := ns_repo.GetByName("ns1")
|
|
|
|
|
|
|
|
fmt.Printf("file final usage %v\n", ns.FileQuota)
|
|
|
|
is.NoErr(err)
|
|
|
|
is.NoErr(err)
|
|
|
|
|
|
|
|
fmt.Printf("file\n")
|
|
|
|
is.Equal(ns.FileQuota.CurrentUsage, int64(len("My bog data")))
|
|
|
|
is.Equal(ns.FileQuota.CurrentUsage, int64(len("My bog")))
|
|
|
|
}
|
|
|
|
}
|
|
|
|