mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-04 11:30:14 -05:00
Remove futureFromValue. Another step toward removing Future.
This commit is contained in:
+1
-1
@@ -72,7 +72,7 @@ func NewBlob(r io.Reader, cs chunks.ChunkStore) (Blob, error) {
|
||||
}
|
||||
|
||||
co := compoundObject{offsets, blobs, &ref.Ref{}, cs}
|
||||
co = splitCompoundObject(co, compoundObjectToBlobFuture)
|
||||
co = splitCompoundObject(co, cs)
|
||||
return compoundBlob{co}, nil
|
||||
}
|
||||
|
||||
|
||||
+10
-151
@@ -20,7 +20,7 @@ func getTestCompoundBlob(datas ...string) compoundBlob {
|
||||
ms := chunks.NewMemoryStore()
|
||||
for i, s := range datas {
|
||||
b, _ := NewBlob(bytes.NewBufferString(s), ms)
|
||||
blobs[i] = futureFromValue(b)
|
||||
blobs[i] = futureFromRef(WriteValue(b, ms))
|
||||
length += uint64(len(s))
|
||||
offsets[i] = length
|
||||
}
|
||||
@@ -64,7 +64,6 @@ func TestCompoundBlobReader(t *testing.T) {
|
||||
t.Skip("Skipping test in short mode.")
|
||||
}
|
||||
assert := assert.New(t)
|
||||
cs := chunks.NewMemoryStore()
|
||||
|
||||
cb := getTestCompoundBlob("hello", "world")
|
||||
bs, err := ioutil.ReadAll(cb.Reader())
|
||||
@@ -78,9 +77,8 @@ func TestCompoundBlobReader(t *testing.T) {
|
||||
bs2, err := ioutil.ReadAll(r)
|
||||
assert.Equal(bs2, bs)
|
||||
|
||||
ref := WriteValue(cb, cs)
|
||||
|
||||
cb2 := ReadValue(ref, cs)
|
||||
ref := WriteValue(cb, cb.cs.(chunks.ChunkStore))
|
||||
cb2 := ReadValue(ref, cb.cs)
|
||||
bs3, err := ioutil.ReadAll(cb2.(Blob).Reader())
|
||||
assert.NoError(err)
|
||||
assert.Equal("helloworld", string(bs3))
|
||||
@@ -96,144 +94,6 @@ func (b testBlob) Reader() io.ReadSeeker {
|
||||
return b.blobLeaf.Reader()
|
||||
}
|
||||
|
||||
func TestCompoundBlobReaderLazy(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
readCount1 := 0
|
||||
b1 := newBlobLeaf([]byte("hi"))
|
||||
tb1 := &testBlob{b1, &readCount1}
|
||||
|
||||
readCount2 := 0
|
||||
b2 := newBlobLeaf([]byte("bye"))
|
||||
tb2 := &testBlob{b2, &readCount2}
|
||||
|
||||
cb := newCompoundBlob([]uint64{2, 5}, []Future{futureFromValue(tb1), futureFromValue(tb2)}, nil)
|
||||
|
||||
r := cb.Reader()
|
||||
assert.Equal(0, readCount1)
|
||||
assert.Equal(0, readCount2)
|
||||
|
||||
p := []byte{0}
|
||||
n, err := r.Read(p)
|
||||
assert.NoError(err)
|
||||
assert.Equal(1, n)
|
||||
assert.Equal(1, readCount1)
|
||||
assert.Equal(0, readCount2)
|
||||
|
||||
n, err = r.Read(p)
|
||||
assert.NoError(err)
|
||||
assert.Equal(1, n)
|
||||
assert.Equal(1, readCount1)
|
||||
assert.Equal(0, readCount2)
|
||||
|
||||
n, err = r.Read(p)
|
||||
assert.NoError(err)
|
||||
assert.Equal(1, n)
|
||||
assert.Equal(1, readCount1)
|
||||
assert.Equal(1, readCount2)
|
||||
|
||||
n, err = r.Read(p)
|
||||
assert.NoError(err)
|
||||
assert.Equal(1, n)
|
||||
assert.Equal(1, readCount1)
|
||||
assert.Equal(1, readCount2)
|
||||
}
|
||||
|
||||
func TestCompoundBlobReaderLazySeek(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
readCount1 := 0
|
||||
b1 := newBlobLeaf([]byte("hi"))
|
||||
tb1 := &testBlob{b1, &readCount1}
|
||||
|
||||
readCount2 := 0
|
||||
b2 := newBlobLeaf([]byte("bye"))
|
||||
tb2 := &testBlob{b2, &readCount2}
|
||||
|
||||
cb := newCompoundBlob([]uint64{2, 5}, []Future{futureFromValue(tb1), futureFromValue(tb2)}, nil)
|
||||
|
||||
r := cb.Reader()
|
||||
|
||||
_, err := r.Seek(0, 4)
|
||||
assert.Error(err)
|
||||
|
||||
_, err = r.Seek(-1, 0)
|
||||
assert.Error(err)
|
||||
|
||||
p := []byte{0}
|
||||
|
||||
n, err := r.Seek(3, 0)
|
||||
assert.NoError(err)
|
||||
assert.Equal(int64(3), n)
|
||||
assert.Equal(0, readCount1)
|
||||
assert.Equal(1, readCount2)
|
||||
|
||||
n2, err := r.Read(p)
|
||||
assert.NoError(err)
|
||||
assert.Equal(1, n2)
|
||||
assert.Equal(0, readCount1)
|
||||
assert.Equal(1, readCount2)
|
||||
assert.Equal("y", string(p))
|
||||
|
||||
n, err = r.Seek(-1, 1)
|
||||
assert.NoError(err)
|
||||
assert.Equal(int64(3), n)
|
||||
assert.Equal(0, readCount1)
|
||||
assert.Equal(1, readCount2)
|
||||
|
||||
n2, err = r.Read(p)
|
||||
assert.NoError(err)
|
||||
assert.Equal(1, n2)
|
||||
assert.Equal(0, readCount1)
|
||||
assert.Equal(1, readCount2)
|
||||
assert.Equal("y", string(p))
|
||||
|
||||
n, err = r.Seek(-5, 2)
|
||||
assert.NoError(err)
|
||||
assert.Equal(int64(0), n)
|
||||
assert.Equal(1, readCount1)
|
||||
assert.Equal(1, readCount2)
|
||||
|
||||
n2, err = r.Read(p)
|
||||
assert.NoError(err)
|
||||
assert.Equal(1, n2)
|
||||
assert.Equal(1, readCount1)
|
||||
assert.Equal(1, readCount2)
|
||||
assert.Equal("h", string(p))
|
||||
|
||||
n, err = r.Seek(100, 0)
|
||||
assert.NoError(err)
|
||||
assert.Equal(int64(100), n)
|
||||
assert.Equal(1, readCount1)
|
||||
assert.Equal(1, readCount2)
|
||||
|
||||
n2, err = r.Read(p)
|
||||
assert.Equal(io.EOF, err)
|
||||
assert.Equal(0, n2)
|
||||
assert.Equal(1, readCount1)
|
||||
assert.Equal(1, readCount2)
|
||||
|
||||
n, err = r.Seek(-99, 1)
|
||||
assert.NoError(err)
|
||||
assert.Equal(int64(1), n)
|
||||
assert.Equal(2, readCount1)
|
||||
assert.Equal(1, readCount2)
|
||||
|
||||
n2, err = r.Read(p)
|
||||
assert.NoError(err)
|
||||
assert.Equal(1, n2)
|
||||
assert.Equal(2, readCount1)
|
||||
assert.Equal(1, readCount2)
|
||||
assert.Equal("i", string(p))
|
||||
|
||||
n2, err = r.Read(p)
|
||||
assert.NoError(err)
|
||||
assert.Equal(1, n2)
|
||||
assert.Equal(2, readCount1)
|
||||
assert.Equal(2, readCount2)
|
||||
assert.Equal("b", string(p))
|
||||
}
|
||||
|
||||
func TestCompoundBlobLen(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
cb := getTestCompoundBlob("hello", "world")
|
||||
@@ -248,13 +108,12 @@ func TestCompoundBlobChunks(t *testing.T) {
|
||||
cs := chunks.NewMemoryStore()
|
||||
|
||||
cb := getTestCompoundBlob("hello", "world")
|
||||
assert.Equal(0, len(cb.Chunks()))
|
||||
assert.Equal(2, len(cb.Chunks()))
|
||||
|
||||
bl1 := newBlobLeaf([]byte("hello"))
|
||||
blr1 := bl1.Ref()
|
||||
bl2 := newBlobLeaf([]byte("world"))
|
||||
cb = newCompoundBlob([]uint64{5, 10}, []Future{futureFromRef(blr1), futureFromValue(bl2)}, cs)
|
||||
assert.Equal(1, len(cb.Chunks()))
|
||||
cb = newCompoundBlob([]uint64{5, 10}, []Future{futureFromRef(WriteValue(bl1, cs)), futureFromRef(WriteValue(bl2, cs))}, cs)
|
||||
assert.Equal(2, len(cb.Chunks()))
|
||||
}
|
||||
|
||||
func TestCompoundBlobSameChunksWithPrefix(t *testing.T) {
|
||||
@@ -284,8 +143,8 @@ func TestCompoundBlobSameChunksWithPrefix(t *testing.T) {
|
||||
assert.NotEqual(cb1.futures[0].Ref(), cb2.futures[0].Ref())
|
||||
assert.Equal(cb1.futures[1].Ref(), cb2.futures[1].Ref())
|
||||
|
||||
futures1 := cb1.futures[0].Deref(nil).(compoundBlob).futures
|
||||
futures2 := cb2.futures[0].Deref(nil).(compoundBlob).futures
|
||||
futures1 := cb1.futures[0].Deref(cb1.cs).(compoundBlob).futures
|
||||
futures2 := cb2.futures[0].Deref(cb2.cs).(compoundBlob).futures
|
||||
assert.NotEqual(futures1[0].Ref(), futures2[0].Ref())
|
||||
assert.Equal(futures1[1].Ref(), futures2[1].Ref())
|
||||
}
|
||||
@@ -317,8 +176,8 @@ func TestCompoundBlobSameChunksWithSuffix(t *testing.T) {
|
||||
assert.Equal(cb1.futures[0].Ref(), cb2.futures[0].Ref())
|
||||
assert.NotEqual(cb1.futures[1].Ref(), cb2.futures[1].Ref())
|
||||
|
||||
futures1 := cb1.futures[1].Deref(nil).(compoundBlob).futures
|
||||
futures2 := cb2.futures[1].Deref(nil).(compoundBlob).futures
|
||||
futures1 := cb1.futures[1].Deref(cb1.cs).(compoundBlob).futures
|
||||
futures2 := cb2.futures[1].Deref(cb2.cs).(compoundBlob).futures
|
||||
assert.Equal(futures1[0].Ref(), futures2[0].Ref())
|
||||
assert.Equal(futures1[len(futures1)-2].Ref(), futures2[len(futures2)-2].Ref())
|
||||
assert.NotEqual(futures1[len(futures1)-1].Ref(), futures2[len(futures2)-1].Ref())
|
||||
|
||||
@@ -34,16 +34,18 @@ func (co compoundObject) Chunks() (chunks []ref.Ref) {
|
||||
|
||||
type compoundObjectToFuture func(co compoundObject) Future
|
||||
|
||||
func compoundObjectToBlobFuture(co compoundObject) Future {
|
||||
return futureFromValue(compoundBlob{co})
|
||||
}
|
||||
|
||||
// splitCompoundObject chunks a compound list/blob into smaller compound
|
||||
// lists/blobs. If no split was made the same compoundObject is returned.
|
||||
func splitCompoundObject(co compoundObject, toFuture compoundObjectToFuture) compoundObject {
|
||||
func splitCompoundObject(co compoundObject, cs chunks.ChunkSink) compoundObject {
|
||||
offsets := []uint64{}
|
||||
futures := []Future{}
|
||||
|
||||
toFuture := func(co compoundObject) Future {
|
||||
cb := compoundBlob{co}
|
||||
r := WriteValue(cb, cs)
|
||||
return futureFromRef(r)
|
||||
}
|
||||
|
||||
startIndex := uint64(0)
|
||||
h := buzhash.NewBuzHash(objectWindowSize)
|
||||
|
||||
@@ -85,7 +87,7 @@ func splitCompoundObject(co compoundObject, toFuture compoundObjectToFuture) com
|
||||
}
|
||||
|
||||
// Split again.
|
||||
return splitCompoundObject(compoundObject{offsets, futures, &ref.Ref{}, co.cs}, toFuture)
|
||||
return splitCompoundObject(compoundObject{offsets, futures, &ref.Ref{}, co.cs}, cs)
|
||||
}
|
||||
|
||||
func makeSubObject(co compoundObject, startIndex, endIndex uint64, toFuture compoundObjectToFuture) Future {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
|
||||
"github.com/attic-labs/noms/chunks"
|
||||
)
|
||||
|
||||
func TestValueEquals(t *testing.T) {
|
||||
@@ -59,9 +60,10 @@ func TestValueEquals(t *testing.T) {
|
||||
return v
|
||||
},
|
||||
func() Value {
|
||||
b1, _ := NewMemoryBlob(bytes.NewBufferString("hi"))
|
||||
b2, _ := NewMemoryBlob(bytes.NewBufferString("bye"))
|
||||
return newCompoundBlob([]uint64{2, 5}, []Future{futureFromValue(b1), futureFromValue(b2)}, nil)
|
||||
ms := chunks.NewMemoryStore()
|
||||
b1, _ := NewBlob(bytes.NewBufferString("hi"), ms)
|
||||
b2, _ := NewBlob(bytes.NewBufferString("bye"), ms)
|
||||
return newCompoundBlob([]uint64{2, 5}, []Future{futureFromRef(WriteValue(b1, ms)), futureFromRef(WriteValue(b2, ms))}, ms)
|
||||
},
|
||||
func() Value { return NewList() },
|
||||
func() Value { return NewList(NewString("foo")) },
|
||||
|
||||
@@ -39,10 +39,6 @@ func futureEqualsValue(f Future, v Value) bool {
|
||||
}
|
||||
}
|
||||
|
||||
func futureFromValue(v Value) Future {
|
||||
return resolvedFuture{v}
|
||||
}
|
||||
|
||||
type targetRef interface {
|
||||
TargetRef() ref.Ref
|
||||
}
|
||||
|
||||
@@ -5,17 +5,8 @@ import (
|
||||
|
||||
"github.com/attic-labs/noms/Godeps/_workspace/src/github.com/stretchr/testify/assert"
|
||||
"github.com/attic-labs/noms/chunks"
|
||||
"github.com/attic-labs/noms/ref"
|
||||
)
|
||||
|
||||
func TestResolvedFuture(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
v := Int32(42)
|
||||
f := futureFromValue(v)
|
||||
v2 := f.Deref(nil)
|
||||
assert.True(v.Equals(v2))
|
||||
}
|
||||
|
||||
func TestUnresolvedFuture(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
@@ -32,34 +23,3 @@ func TestUnresolvedFuture(t *testing.T) {
|
||||
assert.Equal(1, cs.Reads)
|
||||
assert.True(v2.Equals(v3))
|
||||
}
|
||||
|
||||
func TestEqualsFastPath(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
cs := chunks.NewMemoryStore()
|
||||
|
||||
v := Int32(1)
|
||||
r := WriteValue(v, cs)
|
||||
|
||||
fv := futureFromValue(v)
|
||||
fr := futureFromRef(r)
|
||||
|
||||
count := 0
|
||||
getRefOverride = func(val Value) ref.Ref {
|
||||
count += 1
|
||||
return getRefNoOverride(val)
|
||||
}
|
||||
defer func() { getRefOverride = nil }()
|
||||
|
||||
assert.True(futuresEqual(fv, fr))
|
||||
assert.True(futuresEqual(fr, fv))
|
||||
assert.Equal(2, count)
|
||||
|
||||
fr.Deref(cs)
|
||||
|
||||
count = 0
|
||||
assert.True(futuresEqual(fv, fv))
|
||||
assert.True(futuresEqual(fv, fr))
|
||||
assert.True(futuresEqual(fr, fv))
|
||||
|
||||
assert.Equal(0, count)
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ func TestEnsureRef(t *testing.T) {
|
||||
}()
|
||||
|
||||
bl := newBlobLeaf([]byte("hi"))
|
||||
cb := newCompoundBlob([]uint64{2}, []Future{futureFromValue(bl)}, cs)
|
||||
cb := newCompoundBlob([]uint64{2}, []Future{futureFromRef(WriteValue(bl, cs))}, cs)
|
||||
|
||||
values := []Value{
|
||||
newBlobLeaf([]byte{}),
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/attic-labs/noms/chunks"
|
||||
"github.com/attic-labs/noms/ref"
|
||||
)
|
||||
|
||||
type resolvedFuture struct {
|
||||
val Value
|
||||
}
|
||||
|
||||
func (rf resolvedFuture) Ref() ref.Ref {
|
||||
return rf.val.Ref()
|
||||
}
|
||||
|
||||
func (rf resolvedFuture) Val() Value {
|
||||
return rf.val
|
||||
}
|
||||
|
||||
func (rf resolvedFuture) Deref(cs chunks.ChunkSource) Value {
|
||||
return rf.val
|
||||
}
|
||||
|
||||
func (rf resolvedFuture) Release() {
|
||||
}
|
||||
Reference in New Issue
Block a user