2011-02-28 01:42:20 +00:00
|
|
|
/*
|
|
|
|
Copyright 2011 Google Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package localdisk
|
|
|
|
|
|
|
|
import (
|
2012-03-20 01:44:50 +00:00
|
|
|
. "camlistore.org/pkg/test/asserts"
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"camlistore.org/pkg/blobref"
|
2011-03-13 05:11:03 +00:00
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2011-02-28 01:42:20 +00:00
|
|
|
"os"
|
2011-03-13 05:11:03 +00:00
|
|
|
"sort"
|
2011-02-28 01:42:20 +00:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestEnumerate(t *testing.T) {
|
|
|
|
ds := NewStorage(t)
|
|
|
|
defer cleanUp(ds)
|
|
|
|
|
|
|
|
// For test simplicity foo, bar, and baz all have ascending
|
|
|
|
// sha1s and lengths.
|
|
|
|
foo := &testBlob{"foo"} // 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
|
|
|
|
bar := &testBlob{"baar"} // b23361951dde70cb3eca44c0c674181673a129dc
|
|
|
|
baz := &testBlob{"bazzz"} // e0eb17003ce1c2812ca8f19089fff44ca32b3710
|
|
|
|
foo.ExpectUploadBlob(t, ds)
|
|
|
|
bar.ExpectUploadBlob(t, ds)
|
|
|
|
baz.ExpectUploadBlob(t, ds)
|
|
|
|
|
2012-03-20 01:44:50 +00:00
|
|
|
limit := 5000
|
|
|
|
waitSeconds := time.Duration(0)
|
2011-05-10 23:13:37 +00:00
|
|
|
ch := make(chan blobref.SizedBlobRef)
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
errCh := make(chan error)
|
2011-02-28 01:42:20 +00:00
|
|
|
go func() {
|
2011-05-09 16:11:18 +00:00
|
|
|
errCh <- ds.EnumerateBlobs(ch, "", limit, waitSeconds)
|
2011-02-28 01:42:20 +00:00
|
|
|
}()
|
|
|
|
|
2011-05-10 23:13:37 +00:00
|
|
|
var (
|
|
|
|
sb blobref.SizedBlobRef
|
|
|
|
ok bool
|
|
|
|
)
|
|
|
|
sb, ok = <-ch
|
|
|
|
Assert(t, ok, "got 1st blob")
|
2011-02-28 01:42:20 +00:00
|
|
|
ExpectInt(t, 3, int(sb.Size), "1st blob size")
|
2011-05-10 23:13:37 +00:00
|
|
|
sb, ok = <-ch
|
|
|
|
Assert(t, ok, "got 2nd blob")
|
2011-02-28 01:42:20 +00:00
|
|
|
ExpectInt(t, 4, int(sb.Size), "2nd blob size")
|
2011-05-10 23:13:37 +00:00
|
|
|
sb, ok = <-ch
|
|
|
|
Assert(t, ok, "got 3rd blob")
|
2011-02-28 01:42:20 +00:00
|
|
|
ExpectInt(t, 5, int(sb.Size), "3rd blob size")
|
2011-05-10 23:13:37 +00:00
|
|
|
sb, ok = <-ch
|
|
|
|
Assert(t, !ok, "got channel close")
|
2011-02-28 01:42:20 +00:00
|
|
|
ExpectNil(t, <-errCh, "EnumerateBlobs return value")
|
|
|
|
|
|
|
|
// Now again, but skipping foo's blob
|
2011-05-10 23:13:37 +00:00
|
|
|
ch = make(chan blobref.SizedBlobRef)
|
2011-02-28 01:42:20 +00:00
|
|
|
go func() {
|
2011-05-09 16:11:18 +00:00
|
|
|
errCh <- ds.EnumerateBlobs(ch,
|
2011-02-28 01:42:20 +00:00
|
|
|
foo.BlobRef().String(),
|
|
|
|
limit, waitSeconds)
|
|
|
|
}()
|
2011-05-10 23:13:37 +00:00
|
|
|
sb, ok = <-ch
|
2011-07-02 16:09:50 +00:00
|
|
|
Assert(t, ok, "got 1st blob, skipping foo")
|
|
|
|
ExpectInt(t, 4, int(sb.Size), "blob size")
|
|
|
|
sb, ok = <-ch
|
|
|
|
Assert(t, ok, "got 2nd blob, skipping foo")
|
|
|
|
ExpectInt(t, 5, int(sb.Size), "blob size")
|
|
|
|
sb, ok = <-ch
|
|
|
|
Assert(t, !ok, "got final nil")
|
|
|
|
ExpectNil(t, <-errCh, "EnumerateBlobs return value")
|
2011-02-28 01:42:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestEnumerateEmpty(t *testing.T) {
|
|
|
|
ds := NewStorage(t)
|
|
|
|
defer cleanUp(ds)
|
|
|
|
|
2012-03-20 01:44:50 +00:00
|
|
|
limit := 5000
|
|
|
|
wait := time.Duration(0)
|
2011-05-10 23:13:37 +00:00
|
|
|
ch := make(chan blobref.SizedBlobRef)
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
errCh := make(chan error)
|
2011-02-28 01:42:20 +00:00
|
|
|
go func() {
|
2012-03-20 01:44:50 +00:00
|
|
|
errCh <- ds.EnumerateBlobs(ch, "", limit, wait)
|
2011-02-28 01:42:20 +00:00
|
|
|
}()
|
|
|
|
|
2011-05-10 23:13:37 +00:00
|
|
|
_, ok := <-ch
|
|
|
|
Expect(t, !ok, "no first blob")
|
2011-02-28 01:42:20 +00:00
|
|
|
ExpectNil(t, <-errCh, "EnumerateBlobs return value")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEnumerateEmptyLongPoll(t *testing.T) {
|
|
|
|
ds := NewStorage(t)
|
|
|
|
defer cleanUp(ds)
|
|
|
|
|
2012-03-20 01:44:50 +00:00
|
|
|
limit := 5000
|
|
|
|
wait := 1 * time.Second
|
2011-05-10 23:13:37 +00:00
|
|
|
ch := make(chan blobref.SizedBlobRef)
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
errCh := make(chan error)
|
2011-02-28 01:42:20 +00:00
|
|
|
go func() {
|
2012-03-20 01:44:50 +00:00
|
|
|
errCh <- ds.EnumerateBlobs(ch, "", limit, wait)
|
2011-02-28 01:42:20 +00:00
|
|
|
}()
|
|
|
|
|
2011-07-02 16:09:50 +00:00
|
|
|
foo := &testBlob{"foo"} // 0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33
|
2011-02-28 01:42:20 +00:00
|
|
|
go func() {
|
2011-07-02 16:09:50 +00:00
|
|
|
time.Sleep(100e6) // 100 ms
|
2011-02-28 01:42:20 +00:00
|
|
|
foo.ExpectUploadBlob(t, ds)
|
|
|
|
}()
|
|
|
|
|
2011-05-10 23:13:37 +00:00
|
|
|
sb, ok := <-ch
|
2011-07-02 16:09:50 +00:00
|
|
|
Assert(t, ok, "got a blob")
|
|
|
|
ExpectInt(t, 3, int(sb.Size), "blob size")
|
2011-02-28 01:42:20 +00:00
|
|
|
ExpectString(t, "sha1-0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33", sb.BlobRef.String(), "got the right blob")
|
|
|
|
|
2011-05-10 23:13:37 +00:00
|
|
|
sb, ok = <-ch
|
|
|
|
Expect(t, !ok, "only one blob returned")
|
2011-02-28 01:42:20 +00:00
|
|
|
ExpectNil(t, <-errCh, "EnumerateBlobs return value")
|
|
|
|
}
|
|
|
|
|
2011-05-10 23:13:37 +00:00
|
|
|
type SortedSizedBlobs []blobref.SizedBlobRef
|
2011-03-13 05:11:03 +00:00
|
|
|
|
|
|
|
func (sb SortedSizedBlobs) Len() int {
|
|
|
|
return len(sb)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sb SortedSizedBlobs) Less(i, j int) bool {
|
|
|
|
return sb[i].BlobRef.String() < sb[j].BlobRef.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sb SortedSizedBlobs) Swap(i, j int) {
|
|
|
|
panic("not needed")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestEnumerateIsSorted(t *testing.T) {
|
|
|
|
ds := NewStorage(t)
|
|
|
|
defer cleanUp(ds)
|
|
|
|
|
|
|
|
const blobsToMake = 250
|
|
|
|
t.Logf("Uploading test blobs...")
|
|
|
|
for i := 0; i < blobsToMake; i++ {
|
|
|
|
blob := &testBlob{fmt.Sprintf("blob-%d", i)}
|
|
|
|
blob.ExpectUploadBlob(t, ds)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make some fake blobs in other partitions to confuse the
|
|
|
|
// enumerate code.
|
|
|
|
fakeDir := ds.root + "/partition/queue-indexer/sha1/1f0/710"
|
|
|
|
ExpectNil(t, os.MkdirAll(fakeDir, 0755), "creating fakeDir")
|
2011-07-02 16:09:50 +00:00
|
|
|
ExpectNil(t, ioutil.WriteFile(fakeDir+"/sha1-1f07105465650aa243cfc1b1bbb1c68ea95c6812.dat",
|
2011-03-13 05:11:03 +00:00
|
|
|
[]byte("fake file"), 0644), "writing fake blob")
|
|
|
|
|
2011-07-02 16:09:50 +00:00
|
|
|
var tests = []struct {
|
|
|
|
limit int
|
|
|
|
after string
|
|
|
|
}{
|
|
|
|
{200, ""},
|
|
|
|
{blobsToMake, ""},
|
|
|
|
{200, "sha1-2"},
|
|
|
|
{200, "sha1-3"},
|
|
|
|
{200, "sha1-4"},
|
|
|
|
{200, "sha1-5"},
|
|
|
|
{200, "sha1-e"},
|
|
|
|
{200, "sha1-f"},
|
|
|
|
{200, "sha1-ff"},
|
2011-03-13 05:11:03 +00:00
|
|
|
}
|
|
|
|
for _, test := range tests {
|
2012-03-20 01:44:50 +00:00
|
|
|
limit := test.limit
|
2011-05-10 23:13:37 +00:00
|
|
|
ch := make(chan blobref.SizedBlobRef)
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
errCh := make(chan error)
|
2011-03-13 05:11:03 +00:00
|
|
|
go func() {
|
2011-05-09 16:11:18 +00:00
|
|
|
errCh <- ds.EnumerateBlobs(ch, test.after, limit, 0)
|
2011-03-13 05:11:03 +00:00
|
|
|
}()
|
2011-05-10 23:13:37 +00:00
|
|
|
var got = make([]blobref.SizedBlobRef, 0, blobsToMake)
|
|
|
|
for sb := range ch {
|
2011-03-13 05:11:03 +00:00
|
|
|
got = append(got, sb)
|
|
|
|
}
|
|
|
|
if !sort.IsSorted(SortedSizedBlobs(got)) {
|
|
|
|
t.Errorf("expected sorted; offset=%q, limit=%d", test.after, limit)
|
|
|
|
}
|
|
|
|
}
|
2011-07-02 16:09:50 +00:00
|
|
|
}
|