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
c4dae76e
Commit
c4dae76e
authored
Jul 05, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
e4ff923f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
150 additions
and
13 deletions
+150
-13
go/internal/xtesting/xtesting.go
go/internal/xtesting/xtesting.go
+122
-1
go/zodb/storage.go
go/zodb/storage.go
+21
-11
go/zodb/storage/fs1/filestorage_test.go
go/zodb/storage/fs1/filestorage_test.go
+7
-1
No files found.
go/internal/xtesting/xtesting.go
View file @
c4dae76e
// Copyright (C) 2017-20
19
Nexedi SA and Contributors.
// Copyright (C) 2017-20
20
Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
...
...
@@ -22,9 +22,12 @@ package xtesting
import
(
"bytes"
"context"
"fmt"
"net/url"
"os"
"os/exec"
"reflect"
"sync"
"testing"
...
...
@@ -128,3 +131,121 @@ func ZPyCommitRaw(zurl string, at zodb.Tid, objv ...ZRawObject) (_ zodb.Tid, err
return
tid
,
nil
}
// XXX + ZPyCommitSrv ?
// ---- storage driver tests ----
// TestDrvWatch verifies that storage driver watcher can observe commits done from outside.
func
TestDrvWatch
(
t
*
testing
.
T
,
zurl
string
,
drvOpen
zodb
.
DriverOpener
)
{
t
.
Helper
()
X
:=
func
(
err
error
)
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
NeedPy
(
t
,
"zodbtools"
)
u
,
err
:=
url
.
Parse
(
zurl
);
X
(
err
)
// xcommit commits new transaction into zurl with raw data specified by objv.
xcommit
:=
func
(
at
zodb
.
Tid
,
objv
...
ZRawObject
)
zodb
.
Tid
{
t
.
Helper
()
tid
,
err
:=
ZPyCommitRaw
(
zurl
,
at
,
objv
...
);
X
(
err
)
return
tid
}
// force database creation & open zurl at go side
at
:=
xcommit
(
0
,
ZRawObject
{
0
,
b
(
"data0"
)})
ctx
:=
context
.
Background
()
watchq
:=
make
(
chan
zodb
.
Event
)
zdrv
,
at0
,
err
:=
drvOpen
(
ctx
,
u
,
&
zodb
.
DriverOptions
{
ReadOnly
:
true
,
Watchq
:
watchq
})
if
at0
!=
at
{
t
.
Fatalf
(
"opened @ %s ; want %s"
,
at0
,
at
)
}
checkHead
:=
func
(
headOk
zodb
.
Tid
)
{
t
.
Helper
()
head
,
err
:=
zdrv
.
Sync
(
ctx
);
X
(
err
)
if
head
!=
headOk
{
t
.
Fatalf
(
"check head: got %s; want %s"
,
head
,
headOk
)
}
}
checkHead
(
at
)
checkLoad
:=
func
(
at
zodb
.
Tid
,
oid
zodb
.
Oid
,
dataOk
string
,
serialOk
zodb
.
Tid
)
{
t
.
Helper
()
xid
:=
zodb
.
Xid
{
at
,
oid
}
buf
,
serial
,
err
:=
zdrv
.
Load
(
ctx
,
xid
);
X
(
err
)
data
:=
string
(
buf
.
XData
())
if
!
(
data
==
dataOk
&&
serial
==
serialOk
)
{
t
.
Fatalf
(
"check load %s:
\n
have: %q %s
\n
want: %q %s"
,
xid
,
data
,
serial
,
dataOk
,
serialOk
)
}
}
// commit -> check watcher observes what we committed.
//
// XXX python `import pkg_resources` takes ~ 300ms.
// https://github.com/pypa/setuptools/issues/510
//
// Since pkg_resources are used everywhere (e.g. in zodburi to find all
// uri resolvers) this import slowness becomes the major part of time to
// run py `zodb commit`.
//
// if one day it is either fixed, or worked around, we could ↑ 10 to 100.
for
i
:=
zodb
.
Oid
(
1
);
i
<=
10
;
i
++
{
data0
:=
fmt
.
Sprintf
(
"data0.%d"
,
i
)
datai
:=
fmt
.
Sprintf
(
"data%d"
,
i
)
at
=
xcommit
(
at
,
ZRawObject
{
0
,
b
(
data0
)},
ZRawObject
{
i
,
b
(
datai
)})
// TODO also test for watcher errors
event
:=
<-
watchq
var
δ
*
zodb
.
EventCommit
switch
event
:=
event
.
(
type
)
{
default
:
panic
(
fmt
.
Sprintf
(
"unexpected event: %T"
,
event
))
case
*
zodb
.
EventError
:
t
.
Fatal
(
event
.
Err
)
case
*
zodb
.
EventCommit
:
δ
=
event
}
if
objvWant
:=
[]
zodb
.
Oid
{
0
,
i
};
!
(
δ
.
Tid
==
at
&&
reflect
.
DeepEqual
(
δ
.
Changev
,
objvWant
))
{
t
.
Fatalf
(
"watch:
\n
have: %s %s
\n
want: %s %s"
,
δ
.
Tid
,
δ
.
Changev
,
at
,
objvWant
)
}
checkHead
(
at
)
// make sure we can load what was committed.
checkLoad
(
at
,
0
,
data0
,
at
)
checkLoad
(
at
,
i
,
datai
,
at
)
}
err
=
zdrv
.
Close
();
X
(
err
)
e
,
ok
:=
<-
watchq
if
ok
{
t
.
Fatalf
(
"watch after close -> %v; want closed"
,
e
)
}
}
// b is syntatic sugar for byte literals.
//
// e.g.
//
// b("hello")
func
b
(
data
string
)
[]
byte
{
return
[]
byte
(
data
)
}
go/zodb/storage.go
View file @
c4dae76e
...
...
@@ -73,14 +73,8 @@ func RegisterDriver(scheme string, opener DriverOpener) {
driverRegistry
[
scheme
]
=
opener
}
// Open opens ZODB storage by URL.
//
// Only URL schemes registered to zodb package are handled.
// Users should import in storage packages they use or zodb/wks package to
// get support for well-known storages.
//
// Storage authors should register their storages with RegisterStorage.
func
Open
(
ctx
context
.
Context
,
zurl
string
,
opt
*
OpenOptions
)
(
IStorage
,
error
)
{
// XXX
func
openDriver
(
ctx
context
.
Context
,
zurl
string
,
opt
*
DriverOptions
)
(
_
IStorageDriver
,
at0
Tid
,
_
error
)
{
// no scheme -> file://
if
!
strings
.
Contains
(
zurl
,
"://"
)
{
zurl
=
"file://"
+
zurl
...
...
@@ -88,7 +82,7 @@ func Open(ctx context.Context, zurl string, opt *OpenOptions) (IStorage, error)
u
,
err
:=
url
.
Parse
(
zurl
)
if
err
!=
nil
{
return
nil
,
err
return
nil
,
InvalidTid
,
err
}
// XXX commonly handle some options from url -> opt?
...
...
@@ -97,16 +91,32 @@ func Open(ctx context.Context, zurl string, opt *OpenOptions) (IStorage, error)
opener
,
ok
:=
driverRegistry
[
u
.
Scheme
]
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"zodb: URL scheme
\"
%s://
\"
not supported"
,
u
.
Scheme
)
return
nil
,
InvalidTid
,
fmt
.
Errorf
(
"zodb: URL scheme
\"
%s://
\"
not supported"
,
u
.
Scheme
)
}
storDriver
,
at0
,
err
:=
opener
(
ctx
,
u
,
opt
)
if
err
!=
nil
{
return
nil
,
InvalidTid
,
err
}
return
storDriver
,
at0
,
nil
}
// Open opens ZODB storage by URL.
//
// Only URL schemes registered to zodb package are handled.
// Users should import in storage packages they use or zodb/wks package to
// get support for well-known storages.
//
// Storage authors should register their storages with RegisterStorage.
func
Open
(
ctx
context
.
Context
,
zurl
string
,
opt
*
OpenOptions
)
(
IStorage
,
error
)
{
drvWatchq
:=
make
(
chan
Event
)
drvOpt
:=
&
DriverOptions
{
ReadOnly
:
opt
.
ReadOnly
,
Watchq
:
drvWatchq
,
}
storDriver
,
at0
,
err
:=
open
er
(
ctx
,
u
,
drvOpt
)
storDriver
,
at0
,
err
:=
open
Driver
(
ctx
,
zurl
,
drvOpt
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
go/zodb/storage/fs1/filestorage_test.go
View file @
c4dae76e
// Copyright (C) 2017-20
19
Nexedi SA and Contributors.
// Copyright (C) 2017-20
20
Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
...
...
@@ -350,6 +350,7 @@ func BenchmarkIterate(b *testing.B) {
b
.
StopTimer
()
}
/*
// b is syntatic sugar for byte literals.
//
// e.g.
...
...
@@ -358,9 +359,13 @@ func BenchmarkIterate(b *testing.B) {
func b(data string) []byte {
return []byte(data)
}
*/
// TestWatch verifies that watcher can observe commits done from outside.
func
TestWatch
(
t
*
testing
.
T
)
{
workdir
:=
xworkdir
(
t
)
xtesting
.
TestDrvWatch
(
t
,
workdir
+
"/t.fs"
,
openByURL
)
/*
X := exc.Raiseif
xtesting.NeedPy(t, "zodbtools")
...
...
@@ -454,6 +459,7 @@ func TestWatch(t *testing.T) {
if ok {
t.Fatalf("watch after close -> %v; want closed", e)
}
*/
}
// TestOpenRecovery verifies how Open handles data file with not-finished voted
...
...
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