Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-ds-flatfs
Commits
23052ff7
Commit
23052ff7
authored
Jul 07, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better batch testing stuff
parent
9ff7509b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
31 deletions
+15
-31
flatfs.go
flatfs.go
+2
-2
flatfs_test.go
flatfs_test.go
+13
-29
No files found.
flatfs.go
View file @
23052ff7
...
...
@@ -330,12 +330,12 @@ type flatfsBatch struct {
ds
*
Datastore
}
func
(
fs
*
Datastore
)
Batch
()
datastore
.
Batch
{
func
(
fs
*
Datastore
)
Batch
()
(
datastore
.
Batch
,
error
)
{
return
&
flatfsBatch
{
puts
:
make
(
map
[
datastore
.
Key
]
interface
{}),
deletes
:
make
(
map
[
datastore
.
Key
]
struct
{}),
ds
:
fs
,
}
}
,
nil
}
func
(
bt
*
flatfsBatch
)
Put
(
key
datastore
.
Key
,
val
interface
{})
error
{
...
...
flatfs_test.go
View file @
23052ff7
package
flatfs_test
import
(
"bytes"
"encoding/base32"
"io/ioutil"
"os"
...
...
@@ -12,6 +11,7 @@ import (
"github.com/jbenet/go-datastore"
"github.com/jbenet/go-datastore/flatfs"
"github.com/jbenet/go-datastore/query"
dstest
"github.com/jbenet/go-datastore/test"
rand
"github.com/jbenet/go-datastore/Godeps/_workspace/src/github.com/dustin/randbo"
)
...
...
@@ -330,38 +330,19 @@ func TestBatchPut(t *testing.T) {
t
.
Fatalf
(
"New fail: %v
\n
"
,
err
)
}
batch
:=
fs
.
Batch
()
r
:=
rand
.
New
()
var
blocks
[][]
byte
var
keys
[]
datastore
.
Key
for
i
:=
0
;
i
<
20
;
i
++
{
blk
:=
make
([]
byte
,
256
*
1024
)
r
.
Read
(
blk
)
blocks
=
append
(
blocks
,
blk
)
dstest
.
RunBatchTest
(
t
,
fs
)
}
key
:=
datastore
.
NewKey
(
base32
.
StdEncoding
.
EncodeToString
(
blk
[
:
8
]))
keys
=
append
(
keys
,
key
)
func
TestBatchDelete
(
t
*
testing
.
T
)
{
temp
,
cleanup
:=
tempdir
(
t
)
defer
cleanup
()
err
:=
batch
.
Put
(
key
,
blk
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
err
=
batch
.
Commit
()
fs
,
err
:=
flatfs
.
New
(
temp
,
2
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
f
(
"New fail: %v
\n
"
,
err
)
}
for
i
,
k
:=
range
keys
{
blk
,
err
:=
fs
.
Get
(
k
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
bytes
.
Equal
(
blk
.
([]
byte
),
blocks
[
i
])
{
t
.
Fatal
(
"blocks not correct!"
)
}
}
dstest
.
RunBatchDeleteTest
(
t
,
fs
)
}
func
BenchmarkConsecutivePut
(
b
*
testing
.
B
)
{
...
...
@@ -417,7 +398,10 @@ func BenchmarkBatchedPut(b *testing.B) {
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
{
batch
:=
fs
.
Batch
()
batch
,
err
:=
fs
.
Batch
()
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
for
n
:=
i
;
i
-
n
<
512
&&
i
<
b
.
N
;
i
++
{
err
:=
batch
.
Put
(
keys
[
i
],
blocks
[
i
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment