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
d385911c
Commit
d385911c
authored
Dec 16, 2016
by
Kevin Atkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test to make sure suffix sharding prevents prefix clustering.
Closes #8
parent
4965aa42
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
0 deletions
+45
-0
flatfs_test.go
flatfs_test.go
+45
-0
No files found.
flatfs_test.go
View file @
d385911c
...
@@ -3,6 +3,7 @@ package flatfs_test
...
@@ -3,6 +3,7 @@ package flatfs_test
import
(
import
(
"encoding/base32"
"encoding/base32"
"io/ioutil"
"io/ioutil"
"math"
"os"
"os"
"path/filepath"
"path/filepath"
"runtime"
"runtime"
...
@@ -400,6 +401,50 @@ func testBatchDelete(dirFunc mkShardFunc, t *testing.T) {
...
@@ -400,6 +401,50 @@ func testBatchDelete(dirFunc mkShardFunc, t *testing.T) {
func
TestBatchDelete
(
t
*
testing
.
T
)
{
tryAllShardFuncs
(
t
,
testBatchDelete
)
}
func
TestBatchDelete
(
t
*
testing
.
T
)
{
tryAllShardFuncs
(
t
,
testBatchDelete
)
}
func
TestNoCluster
(
t
*
testing
.
T
)
{
tempdir
,
cleanup
:=
tempdir
(
t
)
defer
cleanup
()
fs
,
err
:=
flatfs
.
New
(
tempdir
,
flatfs
.
NextToLast
(
1
),
false
)
if
err
!=
nil
{
t
.
Fatalf
(
"New fail: %v
\n
"
,
err
)
}
r
:=
rand
.
New
()
N
:=
1024
// should be divisible by 32 so the math works out
for
i
:=
0
;
i
<
N
;
i
++
{
blk
:=
make
([]
byte
,
1000
)
r
.
Read
(
blk
)
key
:=
"CIQ"
+
base32
.
StdEncoding
.
EncodeToString
(
blk
[
:
10
])
err
:=
fs
.
Put
(
datastore
.
NewKey
(
key
),
blk
)
if
err
!=
nil
{
t
.
Fatalf
(
"Put fail: %v
\n
"
,
err
)
}
}
dirs
,
err
:=
ioutil
.
ReadDir
(
tempdir
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadDir fail: %v
\n
"
,
err
)
}
if
len
(
dirs
)
!=
32
{
t
.
Fatalf
(
"Expected 32 directories in %s"
,
tempdir
)
}
idealFilesPerDir
:=
float64
(
N
)
/
32.0
tolerance
:=
math
.
Floor
(
idealFilesPerDir
*
0.50
)
for
_
,
dir
:=
range
dirs
{
files
,
err
:=
ioutil
.
ReadDir
(
filepath
.
Join
(
tempdir
,
dir
.
Name
()))
if
err
!=
nil
{
t
.
Fatalf
(
"ReadDir fail: %v
\n
"
,
err
)
}
num
:=
float64
(
len
(
files
))
if
math
.
Abs
(
num
-
idealFilesPerDir
)
>
tolerance
{
t
.
Fatalf
(
"Dir %s has %.0f files, expected between %.f and %.f files"
,
filepath
.
Join
(
tempdir
,
dir
.
Name
()),
num
,
idealFilesPerDir
-
tolerance
,
idealFilesPerDir
+
tolerance
)
}
}
}
func
BenchmarkConsecutivePut
(
b
*
testing
.
B
)
{
func
BenchmarkConsecutivePut
(
b
*
testing
.
B
)
{
r
:=
rand
.
New
()
r
:=
rand
.
New
()
var
blocks
[][]
byte
var
blocks
[][]
byte
...
...
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