Esempio n. 1
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())) })
}
Esempio n. 2
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())) })
}
Esempio n. 3
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())) })
}
Esempio n. 4
0
File: main.go Progetto: arv/noms-old
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	flag.Usage = func() {
		fmt.Printf("Usage: %s -ldb=/path/to/db -input-ref=sha1-xyz -output-ds=quadtree\n\n", os.Args[0])
		flag.PrintDefaults()
	}

	flag.Parse()
	start := time.Now()

	datastore, ok := datasFlags.CreateDataStore()
	if !ok || *inputRefStr == "" || *outputDs == "" {
		flag.Usage()
		return
	}
	defer datastore.Close()
	dataset := dataset.NewDataset(datastore, *outputDs)

	var inputRef ref.Ref
	err := d.Try(func() {
		inputRef = ref.Parse(*inputRefStr)
	})
	if err != nil {
		log.Fatalf("Invalid inputRef: %v", *inputRefStr)
	}

	gr := common.GeorectangleDef{
		TopLeft:     common.GeopositionDef{Latitude: 37.83, Longitude: -122.52},
		BottomRight: common.GeopositionDef{Latitude: 37.70, Longitude: -122.36},
	}
	qtRoot := common.QuadTreeDef{
		Nodes:          common.ListOfNodeDef{},
		Tiles:          common.MapOfStringToQuadTreeDef{},
		Depth:          0,
		NumDescendents: 0,
		Path:           "",
		Georectangle:   gr,
	}
	if !*quietFlag {
		fmt.Printf("quadTreeRoot: %+v\n", qtRoot.Georectangle)
	}

	nChan := make(chan *common.NodeDef, 1024)
	nodesConverted := uint32(0)

	type hasGeoposition interface {
		Geoposition() common.Geoposition
	}

	go func() {
		ds := dataset.Store()
		walk.SomeP(ds.ReadValue(inputRef), ds, func(v types.Value) (stop bool) {
			var g common.Geoposition

			switch v := v.(type) {
			case hasGeoposition:
				g = v.Geoposition()
			case types.Struct:
				if mg, ok := v.MaybeGet("geo"); ok {
					if mg, ok := mg.(common.Geoposition); ok {
						g = mg
						break
					}
				}
			default:
				return
			}

			// TODO: This check is mega bummer. We really only want to consider RefOfStruct, but it's complicated to filter the case of an inline struct out.
			if !ds.Has(v.Ref()) {
				return
			}

			stop = true

			nodeDef := &common.NodeDef{Geoposition: g.Def(), Reference: v.Ref()}
			nChan <- nodeDef
			nConverted := atomic.AddUint32(&nodesConverted, 1)
			if !*quietFlag && nConverted%1e5 == 0 {
				fmt.Printf("Nodes Converted: %d, elapsed time: %.2f secs\n", nodesConverted, SecsSince(start))
			}
			return
		}, 64)
		close(nChan)
	}()

	nodesAppended := uint32(0)
	for nodeDef := range nChan {
		qtRoot.Append(nodeDef)
		nodesAppended++
		if !*quietFlag && nodesAppended%1e5 == 0 {
			fmt.Printf("Nodes Appended: %d, elapsed time: %.2f secs\n", nodesAppended, SecsSince(start))
			qtRoot.Analyze()
		}
	}

	if !*quietFlag {
		fmt.Printf("Nodes Appended: %d, elapsed time: %.2f secs\n", nodesAppended, SecsSince(start))
		qtRoot.Analyze()
		fmt.Printf("Calling SaveToNoms(), elapsed time: %.2f secs\n", SecsSince(start))
	}

	nomsQtRoot := qtRoot.SaveToNoms(dataset.Store(), start, *quietFlag)
	if !*quietFlag {
		fmt.Printf("Calling Commit(), elapsed time: %.2f secs\n", SecsSince(start))
	}
	_, err = dataset.Commit(types.NewRef(nomsQtRoot.Ref()))
	d.Exp.NoError(err)
	if !*quietFlag {
		fmt.Printf("Commit completed, elapsed time: %.2f secs\n", time.Now().Sub(start).Seconds())
	}
	fmt.Println("QuadTree ref:", nomsQtRoot.Ref())
}