Exemplo n.º 1
0
func TestIncrementalLoadList(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewTestStore()
	vs := newValueStore(cs)

	expected := NewList(testVals...)
	ref := vs.WriteValue(expected).TargetRef()

	actualVar := vs.ReadValue(ref)
	actual := actualVar.(List)

	expectedCount := cs.Reads
	assert.Equal(1, expectedCount)
	// There will be one read per chunk.
	chunkReads := make([]int, expected.Len())
	for i := uint64(0); i < expected.Len(); i++ {
		v := actual.Get(i)
		assert.True(expected.Get(i).Equals(v))

		expectedCount += isEncodedOutOfLine(v)
		assert.Equal(expectedCount+chunkReads[i], cs.Reads)

		// Do it again to make sure multiple derefs don't do multiple loads.
		v = actual.Get(i)
		assert.Equal(expectedCount+chunkReads[i], cs.Reads)
	}
}
Exemplo n.º 2
0
func TestWriteRefToNonexistentValue(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewTestStore()
	ds := NewDataStore(cs)

	assert.Panics(func() { ds.WriteValue(types.NewRef(types.Bool(true).Ref())) })
}
Exemplo n.º 3
0
func SkipTestIncrementalAddRef(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewTestStore()
	vs := newValueStore(cs)

	expectedItem := Uint32(42)
	ref := vs.WriteValue(expectedItem).TargetRef()

	expected := NewList(NewRef(ref))
	ref = vs.WriteValue(expected).TargetRef()
	actualVar := vs.ReadValue(ref)

	assert.Equal(1, cs.Reads)
	assert.True(expected.Equals(actualVar))

	actual := actualVar.(List)
	actualItem := actual.Get(0)
	assert.Equal(2, cs.Reads)
	assert.True(expectedItem.Equals(actualItem))

	// do it again to make sure caching works.
	actualItem = actual.Get(0)
	assert.Equal(2, cs.Reads)
	assert.True(expectedItem.Equals(actualItem))
}
Exemplo n.º 4
0
func TestHasCachingChunkStore(t *testing.T) {
	assert := assert.New(t)
	ts := chunks.NewTestStore()
	ccs := newHasCachingChunkStore(ts)
	input := "abc"

	c := chunks.NewChunk([]byte(input))
	c1 := ccs.Get(c.Ref())
	assert.True(c1.IsEmpty())

	assert.False(ccs.Has(c.Ref()))
	assert.Equal(ts.Hases, 0)

	ccs.Put(c)
	assert.True(ccs.Has(c.Ref()))
	assert.Equal(ts.Hases, 0)

	c1 = ccs.Get(c.Ref())
	assert.False(c1.IsEmpty())

	assert.True(ccs.Has(c.Ref()))
	assert.Equal(ts.Hases, 0)

	c = chunks.NewChunk([]byte("stuff"))
	assert.False(ccs.Has(c.Ref()))
	assert.Equal(ts.Hases, 1)
}
Exemplo n.º 5
0
func TestWriteValueTypeRef(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewTestStore()
	ds := NewDataStore(cs)

	b := types.Bool(true)
	assert.NotEqual(ref.Ref{}, ds.WriteValue(b))

	assert.NotPanics(func() { ds.WriteValue(types.NewRef(b.Ref())) })
}
Exemplo n.º 6
0
func TestReadWriteCache(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewTestStore()
	ds := NewDataStore(cs)

	var v types.Value = types.Bool(true)
	assert.NotEqual(ref.Ref{}, ds.WriteValue(v))
	assert.Equal(1, cs.Writes)
	r := ds.WriteValue(v).TargetRef()
	assert.Equal(1, cs.Writes)

	v = ds.ReadValue(r)
	assert.True(v.Equals(types.Bool(true)))
}
Exemplo n.º 7
0
func TestReadValueTypeRefPanics_BUG1121(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewTestStore()
	ds := NewDataStore(cs)

	b := types.NewEmptyBlob()
	assert.NotEqual(ref.Ref{}, ds.WriteValue(b))

	datasetID := "ds1"
	aCommit := NewCommit().SetValue(types.NewRef(b.Ref()))
	ds2, err := ds.Commit(datasetID, aCommit)
	assert.NoError(err)

	_, ok := ds2.MaybeHead(datasetID)
	assert.True(ok)
	// Fix BUG 1121 and then uncomment this line and delete the one after
	// assert.NotPanics(func() { ds2.WriteValue(types.NewRefOfBlob(b.Ref())) })
	assert.Panics(func() { ds2.WriteValue(types.NewRefOfBlob(b.Ref())) })
}
Exemplo n.º 8
0
func SkipTestIncrementalLoadSet(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewTestStore()
	vs := newValueStore(cs)

	expected := NewSet(testVals...)
	ref := vs.WriteValue(expected).TargetRef()

	actualVar := vs.ReadValue(ref)
	actual := actualVar.(Set)

	expectedCount := cs.Reads
	assert.Equal(1, expectedCount)
	actual.Iter(func(v Value) (stop bool) {
		expectedCount += isEncodedOutOfLine(v)
		assert.Equal(expectedCount, cs.Reads)
		return
	})
}
Exemplo n.º 9
0
func TestTolerateUngettableRefs(t *testing.T) {
	assert := assert.New(t)
	ds := NewDataStore(chunks.NewTestStore())
	v := ds.ReadValue(ref.Ref{})
	assert.Nil(v)
}
Exemplo n.º 10
0
func createTestDataset(name string) Dataset {
	return NewDataset(datas.NewDataStore(chunks.NewTestStore()), name)
}