Commit ac4dd680 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 35c7ae8b
...@@ -59,6 +59,7 @@ def main(): ...@@ -59,6 +59,7 @@ def main():
emit("// Code generated by %s; DO NOT EDIT." % __file__) emit("// Code generated by %s; DO NOT EDIT." % __file__)
emit("package main\n") emit("package main\n")
emit("const blksize = %s" % blksize)
emit("const z0_oid = %s" % u64(z0._p_oid)) emit("const z0_oid = %s" % u64(z0._p_oid))
emit("const z1_oid = %s" % u64(z1._p_oid)) emit("const z1_oid = %s" % u64(z1._p_oid))
emit("const zf_oid = %s" % u64(zf._p_oid)) emit("const zf_oid = %s" % u64(zf._p_oid))
......
...@@ -22,10 +22,11 @@ package main ...@@ -22,10 +22,11 @@ package main
import ( import (
//"context" "context"
"fmt" "fmt"
"reflect" "reflect"
"lab.nexedi.com/kirr/go123/mem"
"lab.nexedi.com/kirr/neo/go/zodb" "lab.nexedi.com/kirr/neo/go/zodb"
"lab.nexedi.com/kirr/neo/go/zodb/btree" "lab.nexedi.com/kirr/neo/go/zodb/btree"
pickle "github.com/kisielk/og-rek" pickle "github.com/kisielk/og-rek"
...@@ -59,6 +60,18 @@ func (zb *zBlk0State) PySetState(pystate interface{}) error { ...@@ -59,6 +60,18 @@ func (zb *zBlk0State) PySetState(pystate interface{}) error {
return nil return nil
} }
func (zb *ZBlk0) LoadBlkData(ctx context.Context) ([]byte, error) {
// XXX err ctx
err := zb.PActivate(ctx)
if err != nil {
return nil, err
}
defer zb.PDeactivate()
return mem.Bytes(zb.blkdata), nil
}
// ---- ZBlk1 --- // ---- ZBlk1 ---
// ZData mimics ZData from python. // ZData mimics ZData from python.
...@@ -107,6 +120,12 @@ func (zb *zBlk1State) PySetState(pystate interface{}) error { ...@@ -107,6 +120,12 @@ func (zb *zBlk1State) PySetState(pystate interface{}) error {
return nil return nil
} }
func (zb *ZBlk1) LoadBlkData(ctx context.Context) ([]byte, error) {
// XXX empty .chunktab -> ø
panic("TODO")
}
// ---------------------------------------- // ----------------------------------------
......
...@@ -23,16 +23,20 @@ package main ...@@ -23,16 +23,20 @@ package main
import ( import (
"context" "context"
"encoding/binary"
"testing" "testing"
"lab.nexedi.com/kirr/go123/exc" "lab.nexedi.com/kirr/go123/exc"
"lab.nexedi.com/kirr/neo/go/transaction" "lab.nexedi.com/kirr/neo/go/transaction"
"lab.nexedi.com/kirr/neo/go/zodb" "lab.nexedi.com/kirr/neo/go/zodb"
_ "lab.nexedi.com/kirr/neo/go/zodb/wks" _ "lab.nexedi.com/kirr/neo/go/zodb/wks"
"github.com/stretchr/testify/require"
) )
func TestZBlk(t *testing.T) { func TestZBlk(t *testing.T) {
X := exc.Raiseif X := exc.Raiseif
assert := require.New(t)
ctx := context.Background() ctx := context.Background()
stor, err := zodb.OpenStorage(ctx, "testdata/zblk.fs", &zodb.OpenOptions{ReadOnly: true}); X(err) stor, err := zodb.OpenStorage(ctx, "testdata/zblk.fs", &zodb.OpenOptions{ReadOnly: true}); X(err)
db := zodb.NewDB(stor) db := zodb.NewDB(stor)
...@@ -63,7 +67,39 @@ func TestZBlk(t *testing.T) { ...@@ -63,7 +67,39 @@ func TestZBlk(t *testing.T) {
t.Fatalf("zf: want ZBigFile; got %T", xzf) t.Fatalf("zf: want ZBigFile; got %T", xzf)
} }
xactivate := func(obj zodb.IPersistent) {
err := obj.PActivate(ctx)
if err != nil {
t.Fatal(err)
}
}
// data that must be stored in ZBlk*
data := make([]byte, blksize)
for i := uint32(0); i < blksize / 4; i++ {
binary.BigEndian.PutUint32(data[i*4:], i)
}
z0Data, err := z0.LoadBlkData(ctx); X(err)
assert.Equal(z0Data, data, "ZBlk0 data wrong")
z1Data, err := z1.LoadBlkData(ctx); X(err)
assert.Equal(z1Data, data, "ZBlk0 data wrong")
// XXX // XXX
_, _, _ = z0, z1, zf _, _, _ = z0, z1, zf
_ = xactivate
/*
xactivate(zf)
if zf.blksize != blksize {
t.Fatalf("zf: blksize=%d; want %d", zf.blksize, blksize)
}
// XXX zf.blktab.Get(0) -> z0
// XXX zf.blktab.Get(1) -> z1
*/
} }
// Code generated by ./testdata/zblk_test_gen.py; DO NOT EDIT. // Code generated by ./testdata/zblk_test_gen.py; DO NOT EDIT.
package main package main
const blksize = 2097152
const z0_oid = 2 const z0_oid = 2
const z1_oid = 3 const z1_oid = 3
const zf_oid = 1 const zf_oid = 1
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment