示例#1
0
func TestDataStoreDeleteConcurrent(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewMemoryStore()
	ds := NewDataStore(cs)
	datasetID := "ds1"

	datasets := ds.Datasets()
	assert.Zero(datasets.Len())

	// |a|
	a := types.NewString("a")
	aCommit := NewCommit().SetValue(a)
	ds, err := ds.Commit(datasetID, aCommit)
	assert.NoError(err)

	// |a| <- |b|
	b := types.NewString("b")
	bCommit := NewCommit().SetValue(b).SetParents(NewSetOfRefOfCommit().Insert(NewRefOfCommit(aCommit.Ref())))
	ds2, err := ds.Commit(datasetID, bCommit)
	assert.NoError(err)
	assert.True(ds.Head(datasetID).Value().Equals(a))
	assert.True(ds2.Head(datasetID).Value().Equals(b))

	ds, err = ds.Delete(datasetID)
	assert.NoError(err)
	h, present := ds.MaybeHead(datasetID)
	assert.False(present, "Dataset %s should not be present, but head is %v", datasetID, h.Value())
	h, present = ds2.MaybeHead(datasetID)
	assert.True(present, "Dataset %s should be present", datasetID)

	// Get a fresh datastore, and verify that no datastores are present
	newDs := NewDataStore(cs)
	datasets = newDs.Datasets()
	assert.Equal(uint64(0), datasets.Len())
}
示例#2
0
func TestDataStoreDelete(t *testing.T) {
	assert := assert.New(t)
	cs := chunks.NewMemoryStore()
	ds := NewDataStore(cs)
	datasetID1, datasetID2 := "ds1", "ds2"

	datasets := ds.Datasets()
	assert.Zero(datasets.Len())

	// |a|
	a := types.NewString("a")
	ds, err := ds.Commit(datasetID1, NewCommit().SetValue(a))
	assert.NoError(err)
	assert.True(ds.Head(datasetID1).Value().Equals(a))

	// ds1; |a|, ds2: |b|
	b := types.NewString("b")
	ds, err = ds.Commit(datasetID2, NewCommit().SetValue(b))
	assert.NoError(err)
	assert.True(ds.Head(datasetID2).Value().Equals(b))

	ds, err = ds.Delete(datasetID1)
	assert.NoError(err)
	assert.True(ds.Head(datasetID2).Value().Equals(b))
	h, present := ds.MaybeHead(datasetID1)
	assert.False(present, "Dataset %s should not be present, but head is %v", datasetID1, h.Value())

	// Get a fresh datastore, and verify that only ds1 is present
	newDs := NewDataStore(cs)
	datasets = newDs.Datasets()
	assert.Equal(uint64(1), datasets.Len())
	_, present = ds.MaybeHead(datasetID2)
	assert.True(present, "Dataset %s should be present", datasetID2)
}
示例#3
0
文件: util_test.go 项目: arv/noms-old
func (suite *LibTestSuite) TestCompositeTypes() {
	// [false true]
	suite.EqualValues(
		types.NewList().Append(types.Bool(false)).Append(types.Bool(true)),
		NomsValueFromDecodedJSON([]interface{}{false, true}))

	// [[false true]]
	suite.EqualValues(
		types.NewList().Append(
			types.NewList().Append(types.Bool(false)).Append(types.Bool(true))),
		NomsValueFromDecodedJSON([]interface{}{[]interface{}{false, true}}))

	// {"string": "string",
	//  "list": [false true],
	//  "map": {"nested": "string"}
	// }
	m := MapOfStringToValueDef{
		"string": types.NewString("string"),
		"list":   types.NewList().Append(types.Bool(false)).Append(types.Bool(true)),
		"map":    MapOfStringToValueDef{"nested": types.NewString("string")}.New(),
	}.New()
	o := NomsValueFromDecodedJSON(map[string]interface{}{
		"string": "string",
		"list":   []interface{}{false, true},
		"map":    map[string]interface{}{"nested": "string"},
	})

	suite.True(m.Equals(o))
}
示例#4
0
func TestTwoClientsWithEmptyDataset(t *testing.T) {
	assert := assert.New(t)
	id1 := "testdataset"
	cs := chunks.NewMemoryStore()

	dsx := newDS(id1, cs)
	dsy := newDS(id1, cs)

	// dsx: || -> |a|
	a := types.NewString("a")
	dsx, err := dsx.Commit(a)
	assert.NoError(err)
	assert.True(dsx.Head().Value().Equals(a))

	// dsy: || -> |b|
	_, ok := dsy.MaybeHead()
	assert.False(ok)
	b := types.NewString("b")
	dsy, err = dsy.Commit(b)
	assert.Error(err)
	// Commit failed, but ds1 now has latest head, so we should be able to just try again.
	// dsy: |a| -> |b|
	dsy, err = dsy.Commit(b)
	assert.NoError(err)
	assert.True(dsy.Head().Value().Equals(b))
}
示例#5
0
文件: read_test.go 项目: arv/noms-old
func TestRead(t *testing.T) {
	assert := assert.New(t)
	ds := datas.NewDataStore(chunks.NewMemoryStore())

	dataString := `a,1,true
b,2,false
`
	r := NewCSVReader(bytes.NewBufferString(dataString), ',')

	headers := []string{"A", "B", "C"}
	kinds := KindSlice{types.StringKind, types.Int8Kind, types.BoolKind}
	l, typeRef, typeDef := Read(r, "test", headers, kinds, ds)

	assert.Equal(uint64(2), l.Len())

	assert.True(typeRef.IsUnresolved())

	desc, ok := typeDef.Desc.(types.StructDesc)
	assert.True(ok)
	assert.Len(desc.Fields, 3)
	assert.Equal("A", desc.Fields[0].Name)
	assert.Equal("B", desc.Fields[1].Name)
	assert.Equal("C", desc.Fields[2].Name)

	assert.True(l.Get(0).(types.Struct).Get("A").Equals(types.NewString("a")))
	assert.True(l.Get(1).(types.Struct).Get("A").Equals(types.NewString("b")))

	assert.True(l.Get(0).(types.Struct).Get("B").Equals(types.Int8(1)))
	assert.True(l.Get(1).(types.Struct).Get("B").Equals(types.Int8(2)))

	assert.True(l.Get(0).(types.Struct).Get("C").Equals(types.Bool(true)))
	assert.True(l.Get(1).(types.Struct).Get("C").Equals(types.Bool(false)))
}
示例#6
0
func readerForUser(v types.Value) []types.Value {
	values := []types.Value{}
	s := v.(User)
	values = append(values, types.NewString(s._Id))
	values = append(values, types.NewString(s._Name))
	values = append(values, s._Photos)
	return values
}
示例#7
0
func (s Song) ChildValues() (ret []types.Value) {
	ret = append(ret, types.NewString(s._Title))
	ret = append(ret, types.NewString(s._Artist))
	ret = append(ret, types.NewString(s._Album))
	ret = append(ret, types.NewString(s._Year))
	ret = append(ret, s._Mp3)
	return
}
示例#8
0
func readerForAlbum(v types.Value) []types.Value {
	values := []types.Value{}
	s := v.(Album)
	values = append(values, types.NewString(s._Id))
	values = append(values, types.NewString(s._Title))
	values = append(values, s._Photos)
	return values
}
示例#9
0
func readerForSong(v types.Value) []types.Value {
	values := []types.Value{}
	s := v.(Song)
	values = append(values, types.NewString(s._Title))
	values = append(values, types.NewString(s._Artist))
	values = append(values, types.NewString(s._Album))
	values = append(values, types.NewString(s._Year))
	values = append(values, s._Mp3)
	return values
}
示例#10
0
func (s RemotePhoto) ChildValues() (ret []types.Value) {
	ret = append(ret, types.NewString(s._Id))
	ret = append(ret, types.NewString(s._Title))
	ret = append(ret, s._Date)
	ret = append(ret, s._Geoposition)
	ret = append(ret, s._Sizes)
	ret = append(ret, s._Tags)
	ret = append(ret, s._Faces)
	return
}
示例#11
0
func readerForRemotePhoto(v types.Value) []types.Value {
	values := []types.Value{}
	s := v.(RemotePhoto)
	values = append(values, types.NewString(s._Id))
	values = append(values, types.NewString(s._Title))
	values = append(values, s._Date)
	values = append(values, s._Geoposition)
	values = append(values, s._Sizes)
	values = append(values, s._Tags)
	values = append(values, s._Faces)
	return values
}
示例#12
0
func (def MapOfStringToRefOfCompanyDef) New() MapOfStringToRefOfCompany {
	kv := make([]types.Value, 0, len(def)*2)
	for k, v := range def {
		kv = append(kv, types.NewString(k), NewRefOfCompany(v))
	}
	return MapOfStringToRefOfCompany{types.NewTypedMap(__typeForMapOfStringToRefOfCompany, kv...), &ref.Ref{}}
}
示例#13
0
文件: ref.noms.go 项目: arv/noms-old
func (l ListOfString) fromElemSlice(p []string) []types.Value {
	r := make([]types.Value, len(p))
	for i, v := range p {
		r[i] = types.NewString(v)
	}
	return r
}
示例#14
0
文件: ref.noms.go 项目: arv/noms-old
func (def ListOfStringDef) New() ListOfString {
	l := make([]types.Value, len(def))
	for i, d := range def {
		l[i] = types.NewString(d)
	}
	return ListOfString{types.NewTypedList(__typeForListOfString, l...), &ref.Ref{}}
}
示例#15
0
func (s *testSuite) TestCSVImporterWithPipe() {
	oldDelimiter := delimiter
	newDelimiter := "|"
	delimiter = &newDelimiter
	defer func() { delimiter = oldDelimiter }()

	input, err := ioutil.TempFile(s.TempDir, "")
	d.Chk.NoError(err)
	defer input.Close()
	defer os.Remove(input.Name())

	_, err = input.WriteString("a|b\n1|2\n")
	d.Chk.NoError(err)

	storeName := "store"
	setName := "csv"
	out := s.Run(main, []string{"-store", storeName, "-column-types", "String,Uint8", "-ds", setName, input.Name()})
	s.Equal("", out)

	cs := chunks.NewLevelDBStore(s.LdbDir, storeName, 1, false)
	ds := dataset.NewDataset(datas.NewDataStore(cs), setName)
	defer ds.Store().Close()
	defer os.RemoveAll(s.LdbDir)

	l := ds.Head().Value().(types.List)
	s.Equal(uint64(1), l.Len())
	v := l.Get(0)
	st := v.(types.Struct)
	s.Equal(types.NewString("1"), st.Get("a"))
	s.Equal(types.Uint8(2), st.Get("b"))
}
示例#16
0
文件: map.noms.go 项目: arv/noms-old
func (def MapOfStringToValueDef) New() MapOfStringToValue {
	kv := make([]types.Value, 0, len(def)*2)
	for k, v := range def {
		kv = append(kv, types.NewString(k), v)
	}
	return MapOfStringToValue{types.NewTypedMap(__typeForMapOfStringToValue, kv...), &ref.Ref{}}
}
示例#17
0
文件: walk_test.go 项目: arv/noms-old
func (suite *WalkTestSuite) SetupTest() {
	suite.vs = types.NewTestValueStore()
	suite.shouldSeeItem = types.NewString("zzz")
	suite.shouldSee = types.NewList(suite.shouldSeeItem)
	suite.deadValue = types.Uint64(0xDEADBEEF)
	suite.mustSkip = types.NewList(suite.deadValue)
}
示例#18
0
文件: map_test.go 项目: arv/noms-old
func TestValueMapDef(t *testing.T) {
	assert := assert.New(t)

	def := gen.MapOfStringToValueDef{"s": types.NewString("s"), "i": types.Int32(42)}
	m := def.New()

	assert.Equal(uint64(2), m.Len())
	assert.True(types.NewString("s").Equals(m.Get("s")))
	assert.True(types.Int32(42).Equals(m.Get("i")))

	def2 := m.Def()
	assert.Equal(def, def2)

	m2 := gen.NewMapOfStringToValue().Set("s", types.NewString("s")).Set("i", types.Int32(42))
	assert.True(m.Equals(m2))
}
示例#19
0
func NewKey() Key {
	return Key{
		__unionIndex: 0,
		__unionValue: types.NewString(""),
		ref:          &ref.Ref{},
	}
}
示例#20
0
func (def MapOfSizeToStringDef) New() MapOfSizeToString {
	kv := make([]types.Value, 0, len(def)*2)
	for k, v := range def {
		kv = append(kv, k.New(), types.NewString(v))
	}
	return MapOfSizeToString{types.NewTypedMap(__typeForMapOfSizeToString, kv...), &ref.Ref{}}
}
示例#21
0
文件: map.noms.go 项目: arv/noms-old
func (m MapOfStringToValue) MaybeGet(p string) (types.Value, bool) {
	v, ok := m.m.MaybeGet(types.NewString(p))
	if !ok {
		return types.Bool(false), false
	}
	return v, ok
}
示例#22
0
func (m MapOfStringToRefOfCompany) MaybeGet(p string) (RefOfCompany, bool) {
	v, ok := m.m.MaybeGet(types.NewString(p))
	if !ok {
		return NewRefOfCompany(ref.Ref{}), false
	}
	return v.(RefOfCompany), ok
}
示例#23
0
func (m MapOfStringToRefOfListOfPitch) MaybeGet(p string) (RefOfListOfPitch, bool) {
	v, ok := m.m.MaybeGet(types.NewString(p))
	if !ok {
		return NewRefOfListOfPitch(ref.Ref{}), false
	}
	return v.(RefOfListOfPitch), ok
}
示例#24
0
func (s StructWithList) ChildValues() (ret []types.Value) {
	ret = append(ret, s._l)
	ret = append(ret, types.Bool(s._b))
	ret = append(ret, types.NewString(s._s))
	ret = append(ret, types.Int64(s._i))
	return
}
示例#25
0
func readerForS(v types.Value) []types.Value {
	values := []types.Value{}
	s := v.(S)
	values = append(values, types.NewString(s._s))
	values = append(values, types.Bool(s._b))
	return values
}
示例#26
0
func TestExplicitBranchUsingDatasets(t *testing.T) {
	assert := assert.New(t)
	id1 := "testdataset"
	id2 := "othertestdataset"
	cs := chunks.NewMemoryStore()

	ds1 := newDS(id1, cs)

	// ds1: |a|
	a := types.NewString("a")
	ds1, err := ds1.Commit(a)
	assert.NoError(err)
	assert.True(ds1.Head().Value().Equals(a))

	// ds1: |a|
	//        \ds2
	ds2 := newDS(id2, cs)
	ds2, err = ds2.Commit(ds1.Head().Value())
	assert.NoError(err)
	assert.True(ds2.Head().Value().Equals(a))

	// ds1: |a| <- |b|
	b := types.NewString("b")
	ds1, err = ds1.Commit(b)
	assert.NoError(err)
	assert.True(ds1.Head().Value().Equals(b))

	// ds1: |a|    <- |b|
	//        \ds2 <- |c|
	c := types.NewString("c")
	ds2, err = ds2.Commit(c)
	assert.NoError(err)
	assert.True(ds2.Head().Value().Equals(c))

	// ds1: |a|    <- |b| <--|d|
	//        \ds2 <- |c| <--/
	mergeParents := datas.NewSetOfRefOfCommit().Insert(datas.NewRefOfCommit(ds1.Head().Ref())).Insert(datas.NewRefOfCommit(ds2.Head().Ref()))
	d := types.NewString("d")
	ds2, err = ds2.CommitWithParents(d, mergeParents)
	assert.NoError(err)
	assert.True(ds2.Head().Value().Equals(d))

	ds1, err = ds1.CommitWithParents(d, mergeParents)
	assert.NoError(err)
	assert.True(ds1.Head().Value().Equals(d))
}
示例#27
0
func (s Face) ChildValues() (ret []types.Value) {
	ret = append(ret, types.Float32(s._Top))
	ret = append(ret, types.Float32(s._Left))
	ret = append(ret, types.Float32(s._Width))
	ret = append(ret, types.Float32(s._Height))
	ret = append(ret, types.NewString(s._PersonName))
	return
}
示例#28
0
func readerForImport(v types.Value) []types.Value {
	values := []types.Value{}
	s := v.(Import)
	values = append(values, types.NewString(s._FileSHA1))
	values = append(values, s._Date)
	values = append(values, s._Companies)
	return values
}
示例#29
0
func (s OptionalStruct) ChildValues() (ret []types.Value) {
	if s.__optionals {
		ret = append(ret, types.NewString(s._s))
	}
	if s.__optionalb {
		ret = append(ret, types.Bool(s._b))
	}
	return
}
示例#30
0
func readerForStructWithList(v types.Value) []types.Value {
	values := []types.Value{}
	s := v.(StructWithList)
	values = append(values, s._l)
	values = append(values, types.Bool(s._b))
	values = append(values, types.NewString(s._s))
	values = append(values, types.Int64(s._i))
	return values
}