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
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
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
Show 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:
...
@@ -147,9 +147,23 @@ out:
return
&
IndexSaveError
{
err
}
return
&
IndexSaveError
{
err
}
}
}
// XXX do we need it?
func
(
fsi
*
fsIndex
)
SaveFile
(
topPos
int64
,
path
string
)
(
err
error
)
{
// func (fsi *fsIndex) SaveFile(topPos int64, path string) 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
// IndexLoadError is the error type returned by index load routines
type
IndexLoadError
struct
{
type
IndexLoadError
struct
{
...
@@ -159,12 +173,13 @@ type IndexLoadError struct {
...
@@ -159,12 +173,13 @@ type IndexLoadError struct {
}
}
func
(
e
*
IndexLoadError
)
Error
()
string
{
func
(
e
*
IndexLoadError
)
Error
()
string
{
s
:=
e
.
Filename
s
:=
"index load: "
if
s
!=
""
{
if
e
.
Filename
!=
""
{
s
+=
": "
s
+=
e
.
Filename
+
": "
}
}
s
+=
"index load: "
if
e
.
Pos
!=
-
1
{
s
+=
"pickle @"
+
strconv
.
FormatInt
(
e
.
Pos
,
10
)
+
": "
s
+=
"pickle @"
+
strconv
.
FormatInt
(
e
.
Pos
,
10
)
+
": "
}
s
+=
e
.
Err
.
Error
()
s
+=
e
.
Err
.
Error
()
return
s
return
s
}
}
...
@@ -276,7 +291,22 @@ out:
...
@@ -276,7 +291,22 @@ out:
return
0
,
nil
,
&
IndexLoadError
{
IOName
(
r
),
picklePos
,
err
}
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
// CountReader is an io.Reader that count total bytes read
...
...
t/neo/storage/fs1/index_test.go
View file @
3df8a3a8
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
package
fs1
package
fs1
import
(
import
(
"io/ioutil"
"os"
"sort"
"sort"
"testing"
"testing"
...
@@ -20,17 +22,7 @@ func (p byOid) Len() int { return len(p) }
...
@@ -20,17 +22,7 @@ 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
)
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
}
func
(
p
byOid
)
Less
(
i
,
j
int
)
bool
{
return
p
[
i
]
.
oid
<
p
[
j
]
.
oid
}
func
TestIndexLookup
(
t
*
testing
.
T
)
{
var
indexTest1
=
[
...
]
indexEntry
{
// the lookup is tested in cznic.b itself
// here we only lightly exercise it
fsi
:=
fsIndexNew
()
if
fsi
.
Len
()
!=
0
{
t
.
Errorf
(
"index created non empty"
)
}
tt
:=
[
...
]
indexEntry
{
{
0x0000000000000000
,
111
},
{
0x0000000000000000
,
111
},
{
0x0000000000000001
,
222
},
{
0x0000000000000001
,
222
},
{
0x000000000000ffff
,
333
},
{
0x000000000000ffff
,
333
},
...
@@ -41,12 +33,28 @@ func TestIndexLookup(t *testing.T) {
...
@@ -41,12 +33,28 @@ func TestIndexLookup(t *testing.T) {
{
0xfffffffffffffff0
,
888
},
{
0xfffffffffffffff0
,
888
},
{
0x8000000000000000
,
999
},
{
0x8000000000000000
,
999
},
{
0xa000000000000000
,
0x7fffffffffffffff
},
{
0xa000000000000000
,
0x7fffffffffffffff
},
}
}
// set
func
setIndex
(
fsi
*
fsIndex
,
kv
[]
indexEntry
)
{
for
_
,
entry
:=
range
tt
{
for
_
,
entry
:=
range
kv
{
fsi
.
Set
(
entry
.
oid
,
entry
.
pos
)
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
fsi
:=
fsIndexNew
()
if
fsi
.
Len
()
!=
0
{
t
.
Errorf
(
"index created non empty"
)
}
tt
:=
indexTest1
// set
setIndex
(
fsi
,
tt
[
:
])
// get
// get
for
_
,
entry
:=
range
tt
{
for
_
,
entry
:=
range
tt
{
...
@@ -91,6 +99,31 @@ func TestIndexLookup(t *testing.T) {
...
@@ -91,6 +99,31 @@ func TestIndexLookup(t *testing.T) {
}
}
}
}
//
func
TestIndexSaveLoad
(
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