Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
3df8a3a8
Commit
3df8a3a8
authored
Feb 14, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
9cbf4ac2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
25 deletions
+88
-25
t/neo/storage/fs1/index.go
t/neo/storage/fs1/index.go
+39
-9
t/neo/storage/fs1/index_test.go
t/neo/storage/fs1/index_test.go
+49
-16
No files found.
t/neo/storage/fs1/index.go
View file @
3df8a3a8
...
...
@@ -147,9 +147,23 @@ out:
return
&
IndexSaveError
{
err
}
}
// XXX do we need it?
// func (fsi *fsIndex) SaveFile(topPos int64, path string) error {
// }
func
(
fsi
*
fsIndex
)
SaveFile
(
topPos
int64
,
path
string
)
(
err
error
)
{
f
,
err
:=
os
.
Create
(
path
)
if
err
!=
nil
{
return
&
IndexSaveError
{
err
}
}
defer
func
()
{
err2
:=
f
.
Close
()
if
err2
!=
nil
&&
err
==
nil
{
err
=
&
IndexSaveError
{
err2
}
}
}()
err
=
fsi
.
Save
(
topPos
,
f
)
return
}
// IndexLoadError is the error type returned by index load routines
type
IndexLoadError
struct
{
...
...
@@ -159,12 +173,13 @@ type IndexLoadError struct {
}
func
(
e
*
IndexLoadError
)
Error
()
string
{
s
:=
e
.
Filename
if
s
!=
""
{
s
+=
": "
s
:=
"index load: "
if
e
.
Filename
!=
""
{
s
+=
e
.
Filename
+
": "
}
if
e
.
Pos
!=
-
1
{
s
+=
"pickle @"
+
strconv
.
FormatInt
(
e
.
Pos
,
10
)
+
": "
}
s
+=
"index load: "
s
+=
"pickle @"
+
strconv
.
FormatInt
(
e
.
Pos
,
10
)
+
": "
s
+=
e
.
Err
.
Error
()
return
s
}
...
...
@@ -276,7 +291,22 @@ out:
return
0
,
nil
,
&
IndexLoadError
{
IOName
(
r
),
picklePos
,
err
}
}
// XXX LoadIndexFile - do we need it ?
func
LoadIndexFile
(
path
string
)
(
topPos
int64
,
fsi
*
fsIndex
,
err
error
)
{
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
0
,
nil
,
&
IndexLoadError
{
path
,
-
1
,
err
}
}
defer
func
()
{
err2
:=
f
.
Close
()
if
err2
!=
nil
&&
err
==
nil
{
err
=
&
IndexLoadError
{
path
,
-
1
,
err
}
topPos
,
fsi
=
0
,
nil
}
}()
return
LoadIndex
(
f
)
}
// CountReader is an io.Reader that count total bytes read
...
...
t/neo/storage/fs1/index_test.go
View file @
3df8a3a8
...
...
@@ -3,6 +3,8 @@
package
fs1
import
(
"io/ioutil"
"os"
"sort"
"testing"
...
...
@@ -20,6 +22,25 @@ func (p byOid) Len() int { return len(p) }
func
(
p
byOid
)
Swap
(
i
,
j
int
)
{
p
[
i
],
p
[
j
]
=
p
[
j
],
p
[
i
]
}
func
(
p
byOid
)
Less
(
i
,
j
int
)
bool
{
return
p
[
i
]
.
oid
<
p
[
j
]
.
oid
}
var
indexTest1
=
[
...
]
indexEntry
{
{
0x0000000000000000
,
111
},
{
0x0000000000000001
,
222
},
{
0x000000000000ffff
,
333
},
{
0x0000000000001234
,
444
},
{
0x0000000000010002
,
555
},
{
0x0000000000010001
,
665
},
{
0xffffffffffffffff
,
777
},
{
0xfffffffffffffff0
,
888
},
{
0x8000000000000000
,
999
},
{
0xa000000000000000
,
0x7fffffffffffffff
},
}
func
setIndex
(
fsi
*
fsIndex
,
kv
[]
indexEntry
)
{
for
_
,
entry
:=
range
kv
{
fsi
.
Set
(
entry
.
oid
,
entry
.
pos
)
}
}
func
TestIndexLookup
(
t
*
testing
.
T
)
{
// the lookup is tested in cznic.b itself
// here we only lightly exercise it
...
...
@@ -30,23 +51,10 @@ func TestIndexLookup(t *testing.T) {
}
tt
:=
[
...
]
indexEntry
{
{
0x0000000000000000
,
111
},
{
0x0000000000000001
,
222
},
{
0x000000000000ffff
,
333
},
{
0x0000000000001234
,
444
},
{
0x0000000000010002
,
555
},
{
0x0000000000010001
,
665
},
{
0xffffffffffffffff
,
777
},
{
0xfffffffffffffff0
,
888
},
{
0x8000000000000000
,
999
},
{
0xa000000000000000
,
0x7fffffffffffffff
},
}
tt
:=
indexTest1
// set
for
_
,
entry
:=
range
tt
{
fsi
.
Set
(
entry
.
oid
,
entry
.
pos
)
}
setIndex
(
fsi
,
tt
[
:
])
// get
for
_
,
entry
:=
range
tt
{
...
...
@@ -91,6 +99,31 @@ func TestIndexLookup(t *testing.T) {
}
}
//
func
TestIndexSaveLoad
(
t
*
testing
.
T
)
{
workdir
,
err
:=
ioutil
.
TempDir
(
""
,
"t-index"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
os
.
RemoveAll
(
workdir
)
topPos
:=
int64
(
786
)
fsi
:=
fsIndexNew
()
setIndex
(
fsi
,
indexTest1
[
:
])
err
=
fsi
.
SaveFile
(
topPos
,
workdir
+
"/1.fs.index"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
topPos2
,
fsi2
,
err
:=
LoadIndexFile
(
workdir
+
"/1.fs.index"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
topPos2
!=
topPos
{
t
.
Errorf
(
"index load: topPos mismatch: %v ; want %v"
,
topPos2
,
topPos
)
}
_
=
fsi2
}
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