コード例 #1
0
ファイル: index.noms.go プロジェクト: arv/noms-old
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
	p := types.NewPackage([]types.Type{
		types.MakeEnumType("QuarterEnum", "Q1", "Q2", "Q3", "Q4"),
		types.MakeStructType("Quarter",
			[]types.Field{
				types.Field{"Year", types.MakePrimitiveType(types.Int32Kind), false},
				types.Field{"Quarter", types.MakeType(ref.Ref{}, 0), false},
			},
			types.Choices{},
		),
		types.MakeStructType("Key",
			[]types.Field{},
			types.Choices{
				types.Field{"Category", types.MakePrimitiveType(types.StringKind), false},
				types.Field{"Quarter", types.MakeType(ref.Ref{}, 1), false},
				types.Field{"Region", types.MakePrimitiveType(types.StringKind), false},
				types.Field{"RoundType", types.MakeType(ref.Ref{}, 3), false},
				types.Field{"Year", types.MakePrimitiveType(types.Int32Kind), false},
			},
		),
		types.MakeEnumType("RoundTypeEnum", "Seed", "SeriesA", "SeriesB", "SeriesC", "SeriesD", "SeriesE", "SeriesF", "SeriesG", "SeriesH", "UnknownRoundType"),
	}, []ref.Ref{
		ref.Parse("sha1-6c64b08a509e25f9814dbf036489267c957a6fd8"),
		ref.Parse("sha1-91ae65b19b4817fc15d4e2c5c7472c68b4950b77"),
	})
	__mainPackageInFile_index_CachedRef = types.RegisterPackage(&p)
}
コード例 #2
0
func (suite *ChunkStoreTestSuite) TestChunkStoreRoot() {
	oldRoot := suite.Store.Root()
	suite.True(oldRoot.IsEmpty())

	bogusRoot := ref.Parse("sha1-81c870618113ba29b6f2b396ea3a69c6f1d626c5") // sha1("Bogus, Dude")
	newRoot := ref.Parse("sha1-907d14fb3af2b0d4f18c2d46abe8aedce17367bd")   // sha1("Hello, World")

	// Try to update root with bogus oldRoot
	result := suite.Store.UpdateRoot(newRoot, bogusRoot)
	suite.False(result)

	// Now do a valid root update
	result = suite.Store.UpdateRoot(newRoot, oldRoot)
	suite.True(result)
}
コード例 #3
0
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
	p := types.NewPackage([]types.Type{
		types.MakeEnumType("LocalE", "LocalE1", "Ignored"),
		types.MakeStructType("ImportUser",
			[]types.Field{
				types.Field{"importedStruct", types.MakeType(ref.Parse("sha1-eda4273cba9d5d4a1bccf41bcaec64743863cde0"), 0), false},
				types.Field{"enum", types.MakeType(ref.Ref{}, 0), false},
			},
			types.Choices{},
		),
	}, []ref.Ref{
		ref.Parse("sha1-eda4273cba9d5d4a1bccf41bcaec64743863cde0"),
	})
	__genPackageInFile_struct_with_imports_CachedRef = types.RegisterPackage(&p)
}
コード例 #4
0
ファイル: sha1_6c64b08.go プロジェクト: arv/noms-old
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
	p := types.NewPackage([]types.Type{
		types.MakeStructType("Import",
			[]types.Field{
				types.Field{"FileSHA1", types.MakePrimitiveType(types.StringKind), false},
				types.Field{"Date", types.MakeType(ref.Parse("sha1-0b4ac7cb0583d7fecd71a1584a3f846e5d8b08eb"), 0), false},
				types.Field{"Companies", types.MakeCompoundType(types.RefKind, types.MakeCompoundType(types.MapKind, types.MakePrimitiveType(types.StringKind), types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-91ae65b19b4817fc15d4e2c5c7472c68b4950b77"), 0)))), false},
			},
			types.Choices{},
		),
	}, []ref.Ref{
		ref.Parse("sha1-0b4ac7cb0583d7fecd71a1584a3f846e5d8b08eb"),
		ref.Parse("sha1-91ae65b19b4817fc15d4e2c5c7472c68b4950b77"),
	})
	__mainPackageInFile_sha1_6c64b08_CachedRef = types.RegisterPackage(&p)
}
コード例 #5
0
ファイル: handlers.go プロジェクト: arv/noms-old
func HandleGetHasRefs(w http.ResponseWriter, req *http.Request, ps URLParams, ds DataStore) {
	err := d.Try(func() {
		d.Exp.Equal("POST", req.Method)

		req.ParseForm()
		refStrs := req.PostForm["ref"]
		d.Exp.True(len(refStrs) > 0)

		refs := make([]ref.Ref, len(refStrs))
		for idx, refStr := range refStrs {
			refs[idx] = ref.Parse(refStr)
		}

		w.Header().Add("Content-Type", "text/plain")
		writer := w.(io.Writer)
		if strings.Contains(req.Header.Get("Accept-Encoding"), "gzip") {
			w.Header().Add("Content-Encoding", "gzip")
			gw := gzip.NewWriter(w)
			defer gw.Close()
			writer = gw
		}

		sz := chunks.NewSerializer(writer)
		for _, r := range refs {
			has := ds.transitionalChunkStore().Has(r)
			fmt.Fprintf(writer, "%s %t\n", r, has)
		}
		sz.Close()
	})

	if err != nil {
		http.Error(w, fmt.Sprintf("Error: %v", err), http.StatusBadRequest)
		return
	}
}
コード例 #6
0
ファイル: type_test.go プロジェクト: arv/noms-old
func TestTypes(t *testing.T) {
	assert := assert.New(t)
	vs := NewTestValueStore()

	boolType := MakePrimitiveType(BoolKind)
	uint8Type := MakePrimitiveType(Uint8Kind)
	stringType := MakePrimitiveType(StringKind)
	mapType := MakeCompoundType(MapKind, stringType, uint8Type)
	setType := MakeCompoundType(SetKind, stringType)
	mahType := MakeStructType("MahStruct", []Field{
		Field{"Field1", stringType, false},
		Field{"Field2", boolType, true},
	}, Choices{})
	otherType := MakeStructType("MahOtherStruct", []Field{}, Choices{
		Field{"StructField", mahType, false},
		Field{"StringField", stringType, false},
	})
	pkgRef := ref.Parse("sha1-0123456789abcdef0123456789abcdef01234567")
	trType := MakeType(pkgRef, 42)

	mRef := vs.WriteValue(mapType).TargetRef()
	setRef := vs.WriteValue(setType).TargetRef()
	otherRef := vs.WriteValue(otherType).TargetRef()
	mahRef := vs.WriteValue(mahType).TargetRef()
	trRef := vs.WriteValue(trType).TargetRef()

	assert.True(otherType.Equals(vs.ReadValue(otherRef)))
	assert.True(mapType.Equals(vs.ReadValue(mRef)))
	assert.True(setType.Equals(vs.ReadValue(setRef)))
	assert.True(mahType.Equals(vs.ReadValue(mahRef)))
	assert.True(trType.Equals(vs.ReadValue(trRef)))
}
コード例 #7
0
ファイル: leveldb_store.go プロジェクト: arv/noms-old
func (l *internalLevelDBStore) rootByKey(key []byte) ref.Ref {
	val, err := l.db.Get(key, nil)
	if err == errors.ErrNotFound {
		return ref.Ref{}
	}
	d.Chk.NoError(err)

	return ref.Parse(string(val))
}
コード例 #8
0
func TestWriteCompoundBlob(t *testing.T) {
	assert := assert.New(t)

	r1 := ref.Parse("sha1-0000000000000000000000000000000000000001")
	r2 := ref.Parse("sha1-0000000000000000000000000000000000000002")
	r3 := ref.Parse("sha1-0000000000000000000000000000000000000003")

	v := newCompoundBlob([]metaTuple{
		newMetaTuple(Uint64(20), nil, newRef(r1, MakeRefType(typeForBlob))),
		newMetaTuple(Uint64(40), nil, newRef(r2, MakeRefType(typeForBlob))),
		newMetaTuple(Uint64(60), nil, newRef(r3, MakeRefType(typeForBlob))),
	}, NewTestValueStore())
	w := newJsonArrayWriter(NewTestValueStore())
	w.writeTopLevelValue(v)

	// the order of the elements is based on the ref of the value.
	assert.EqualValues([]interface{}{BlobKind, true, []interface{}{r1.String(), "20", r2.String(), "40", r3.String(), "60"}}, w.toArray())
}
コード例 #9
0
ファイル: http_store.go プロジェクト: arv/noms-old
func (h *HTTPStore) Root() ref.Ref {
	// GET http://<host>/root. Response will be ref of root.
	res := h.requestRoot("GET", ref.Ref{}, ref.Ref{})
	defer closeResponse(res)

	d.Chk.Equal(http.StatusOK, res.StatusCode, "Unexpected response: %s", http.StatusText(res.StatusCode))
	data, err := ioutil.ReadAll(res.Body)
	d.Chk.NoError(err)
	return ref.Parse(string(data))
}
コード例 #10
0
func TestWriteRef(t *testing.T) {
	assert := assert.New(t)

	typ := MakeCompoundType(RefKind, MakePrimitiveType(Uint32Kind))
	r := ref.Parse("sha1-0123456789abcdef0123456789abcdef01234567")
	v := NewRef(r)

	w := newJsonArrayWriter(NewTestValueStore())
	w.writeTopLevelValue(testRef{Value: v, t: typ})
	assert.EqualValues([]interface{}{RefKind, Uint32Kind, r.String()}, w.toArray())
}
コード例 #11
0
ファイル: sha1_eda4273.go プロジェクト: arv/noms-old
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
	p := types.NewPackage([]types.Type{
		types.MakeStructType("D",
			[]types.Field{
				types.Field{"structField", types.MakeType(ref.Parse("sha1-1c216c6f1d6989e4ede5f78b7689214948dabeef"), 0), false},
				types.Field{"enumField", types.MakeType(ref.Parse("sha1-1c216c6f1d6989e4ede5f78b7689214948dabeef"), 1), false},
			},
			types.Choices{},
		),
		types.MakeStructType("DUser",
			[]types.Field{
				types.Field{"Dfield", types.MakeType(ref.Ref{}, 0), false},
			},
			types.Choices{},
		),
	}, []ref.Ref{
		ref.Parse("sha1-1c216c6f1d6989e4ede5f78b7689214948dabeef"),
	})
	__genPackageInFile_sha1_eda4273_CachedRef = types.RegisterPackage(&p)
}
コード例 #12
0
func TestWritePackage2(t *testing.T) {
	assert := assert.New(t)

	setTref := MakeCompoundType(SetKind, MakePrimitiveType(Uint32Kind))
	r := ref.Parse("sha1-0123456789abcdef0123456789abcdef01234567")
	v := Package{[]Type{setTref}, []ref.Ref{r}, &ref.Ref{}}

	w := newJsonArrayWriter(NewTestValueStore())
	w.writeTopLevelValue(v)
	assert.EqualValues([]interface{}{PackageKind, []interface{}{SetKind, []interface{}{Uint32Kind}}, []interface{}{r.String()}}, w.toArray())
}
コード例 #13
0
func TestReadValueRef(t *testing.T) {
	assert := assert.New(t)
	cs := NewTestValueStore()

	r := ref.Parse("sha1-a9993e364706816aba3e25717850c26c9cd0d89d")
	a := parseJson(`[%d, %d, %d, "%s"]`, ValueKind, RefKind, Uint32Kind, r.String())
	reader := newJsonArrayReader(a, cs)
	v := reader.readTopLevelValue()
	tr := MakeCompoundType(RefKind, MakePrimitiveType(Uint32Kind))
	assert.True(refFromType(r, tr).Equals(v))
}
コード例 #14
0
func TestReadPackage2(t *testing.T) {
	cs := NewTestValueStore()

	rr := ref.Parse("sha1-a9993e364706816aba3e25717850c26c9cd0d89d")
	setTref := MakeCompoundType(SetKind, MakePrimitiveType(Uint32Kind))
	pkg := NewPackage([]Type{setTref}, []ref.Ref{rr})

	a := []interface{}{float64(PackageKind), []interface{}{float64(SetKind), []interface{}{float64(Uint32Kind)}}, []interface{}{rr.String()}}
	r := newJsonArrayReader(a, cs)
	v := r.readTopLevelValue().(Package)
	assert.True(t, pkg.Equals(v))
}
コード例 #15
0
func TestReadCompoundBlob(t *testing.T) {
	assert := assert.New(t)
	cs := NewTestValueStore()

	r1 := ref.Parse("sha1-0000000000000000000000000000000000000001")
	r2 := ref.Parse("sha1-0000000000000000000000000000000000000002")
	r3 := ref.Parse("sha1-0000000000000000000000000000000000000003")
	a := parseJson(`[%d, true, ["%s", "20", "%s", "40", "%s", "60"]]`, BlobKind, r1, r2, r3)
	r := newJsonArrayReader(a, cs)

	m := r.readTopLevelValue()
	_, ok := m.(compoundBlob)
	assert.True(ok)
	m2 := newCompoundBlob([]metaTuple{
		newMetaTuple(Uint64(20), nil, newRef(r1, MakeRefType(typeForBlob))),
		newMetaTuple(Uint64(40), nil, newRef(r2, MakeRefType(typeForBlob))),
		newMetaTuple(Uint64(60), nil, newRef(r3, MakeRefType(typeForBlob))),
	}, cs)

	assert.True(m.Type().Equals(m2.Type()))
	assert.Equal(m.Ref().String(), m2.Ref().String())
}
コード例 #16
0
ファイル: handlers.go プロジェクト: arv/noms-old
func HandleRootPost(w http.ResponseWriter, req *http.Request, ps URLParams, ds DataStore) {
	err := d.Try(func() {
		d.Exp.Equal("POST", req.Method)

		params := req.URL.Query()
		tokens := params["last"]
		d.Exp.Len(tokens, 1)
		last := ref.Parse(tokens[0])
		tokens = params["current"]
		d.Exp.Len(tokens, 1)
		current := ref.Parse(tokens[0])

		if !ds.transitionalChunkStore().UpdateRoot(current, last) {
			w.WriteHeader(http.StatusConflict)
			return
		}
	})

	if err != nil {
		http.Error(w, fmt.Sprintf("Error: %v", err), http.StatusBadRequest)
		return
	}
}
コード例 #17
0
ファイル: photo.noms.go プロジェクト: arv/noms-old
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
	p := types.NewPackage([]types.Type{
		types.MakeStructType("RemotePhoto",
			[]types.Field{
				types.Field{"Id", types.MakePrimitiveType(types.StringKind), false},
				types.Field{"Title", types.MakePrimitiveType(types.StringKind), false},
				types.Field{"Date", types.MakeType(ref.Parse("sha1-0b4ac7cb0583d7fecd71a1584a3f846e5d8b08eb"), 0), false},
				types.Field{"Geoposition", types.MakeType(ref.Parse("sha1-0cac0f1ed4777b6965548b0dfe6965a9f23af76c"), 0), false},
				types.Field{"Sizes", types.MakeCompoundType(types.MapKind, types.MakeType(ref.Ref{}, 2), types.MakePrimitiveType(types.StringKind)), false},
				types.Field{"Tags", types.MakeCompoundType(types.SetKind, types.MakePrimitiveType(types.StringKind)), false},
				types.Field{"Faces", types.MakeCompoundType(types.SetKind, types.MakeType(ref.Ref{}, 1)), false},
			},
			types.Choices{},
		),
		types.MakeStructType("Face",
			[]types.Field{
				types.Field{"Top", types.MakePrimitiveType(types.Float32Kind), false},
				types.Field{"Left", types.MakePrimitiveType(types.Float32Kind), false},
				types.Field{"Width", types.MakePrimitiveType(types.Float32Kind), false},
				types.Field{"Height", types.MakePrimitiveType(types.Float32Kind), false},
				types.Field{"PersonName", types.MakePrimitiveType(types.StringKind), false},
			},
			types.Choices{},
		),
		types.MakeStructType("Size",
			[]types.Field{
				types.Field{"Width", types.MakePrimitiveType(types.Uint32Kind), false},
				types.Field{"Height", types.MakePrimitiveType(types.Uint32Kind), false},
			},
			types.Choices{},
		),
	}, []ref.Ref{
		ref.Parse("sha1-0b4ac7cb0583d7fecd71a1584a3f846e5d8b08eb"),
		ref.Parse("sha1-0cac0f1ed4777b6965548b0dfe6965a9f23af76c"),
	})
	__commonPackageInFile_photo_CachedRef = types.RegisterPackage(&p)
}
コード例 #18
0
ファイル: facebook.noms.go プロジェクト: arv/noms-old
// This function builds up a Noms value that describes the type
// package implemented by this file and registers it with the global
// type package definition cache.
func init() {
	p := types.NewPackage([]types.Type{
		types.MakeStructType("User",
			[]types.Field{
				types.Field{"Id", types.MakePrimitiveType(types.StringKind), false},
				types.Field{"Name", types.MakePrimitiveType(types.StringKind), false},
				types.Field{"Photos", types.MakeCompoundType(types.SetKind, types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-10004087fdbc623873c649d28aa59f4e066d374e"), 0))), false},
			},
			types.Choices{},
		),
	}, []ref.Ref{
		ref.Parse("sha1-10004087fdbc623873c649d28aa59f4e066d374e"),
	})
	__mainPackageInFile_facebook_CachedRef = types.RegisterPackage(&p)
}
コード例 #19
0
func TestReadTypeAsTag(t *testing.T) {
	cs := NewTestValueStore()

	test := func(expected Type, s string, vs ...interface{}) {
		a := parseJson(s, vs...)
		r := newJsonArrayReader(a, cs)
		tr := r.readTypeAsTag()
		assert.True(t, expected.Equals(tr))
	}

	test(MakePrimitiveType(BoolKind), "[%d, true]", BoolKind)
	test(MakePrimitiveType(TypeKind), "[%d, %d]", TypeKind, BoolKind)
	test(MakeCompoundType(ListKind, MakePrimitiveType(BoolKind)), "[%d, %d, true, false]", ListKind, BoolKind)

	pkgRef := ref.Parse("sha1-a9993e364706816aba3e25717850c26c9cd0d89d")
	test(MakeType(pkgRef, 42), `[%d, "%s", "42"]`, UnresolvedKind, pkgRef.String())

	test(MakePrimitiveType(TypeKind), `[%d, %d, "%s", "12"]`, TypeKind, TypeKind, pkgRef.String())
}
コード例 #20
0
func TestReadTypeValue(t *testing.T) {
	assert := assert.New(t)
	cs := NewTestValueStore()

	test := func(expected Type, json string, vs ...interface{}) {
		a := parseJson(json, vs...)
		r := newJsonArrayReader(a, cs)
		tr := r.readTopLevelValue()
		assert.True(expected.Equals(tr))
	}

	test(MakePrimitiveType(Int32Kind),
		`[%d, %d]`, TypeKind, Int32Kind)
	test(MakeCompoundType(ListKind, MakePrimitiveType(BoolKind)),
		`[%d, %d, [%d]]`, TypeKind, ListKind, BoolKind)
	test(MakeCompoundType(MapKind, MakePrimitiveType(BoolKind), MakePrimitiveType(StringKind)),
		`[%d, %d, [%d, %d]]`, TypeKind, MapKind, BoolKind, StringKind)
	test(MakeEnumType("E", "a", "b", "c"),
		`[%d, %d, "E", ["a", "b", "c"]]`, TypeKind, EnumKind)

	test(MakeStructType("S", []Field{
		Field{"x", MakePrimitiveType(Int16Kind), false},
		Field{"v", MakePrimitiveType(ValueKind), true},
	}, Choices{}),
		`[%d, %d, "S", ["x", %d, false, "v", %d, true], []]`, TypeKind, StructKind, Int16Kind, ValueKind)

	test(MakeStructType("S", []Field{}, Choices{
		Field{"x", MakePrimitiveType(Int16Kind), false},
		Field{"v", MakePrimitiveType(ValueKind), false},
	}),
		`[%d, %d, "S", [], ["x", %d, false, "v", %d, false]]`, TypeKind, StructKind, Int16Kind, ValueKind)

	pkgRef := ref.Parse("sha1-0123456789abcdef0123456789abcdef01234567")
	test(MakeType(pkgRef, 123), `[%d, %d, "%s", "123"]`, TypeKind, UnresolvedKind, pkgRef.String())

	test(MakeStructType("S", []Field{
		Field{"e", MakeType(pkgRef, 123), false},
		Field{"x", MakePrimitiveType(Int64Kind), false},
	}, Choices{}),
		`[%d, %d, "S", ["e", %d, "%s", "123", false, "x", %d, false], []]`, TypeKind, StructKind, UnresolvedKind, pkgRef.String(), Int64Kind)

	test(MakeUnresolvedType("ns", "n"), `[%d, %d, "%s", "-1", "ns", "n"]`, TypeKind, UnresolvedKind, ref.Ref{}.String())
}
コード例 #21
0
func TestWriteTypeValue(t *testing.T) {
	assert := assert.New(t)

	test := func(expected []interface{}, v Type) {
		w := newJsonArrayWriter(NewTestValueStore())
		w.writeTopLevelValue(v)
		assert.EqualValues(expected, w.toArray())
	}

	test([]interface{}{TypeKind, Int32Kind}, MakePrimitiveType(Int32Kind))
	test([]interface{}{TypeKind, ListKind, []interface{}{BoolKind}},
		MakeCompoundType(ListKind, MakePrimitiveType(BoolKind)))
	test([]interface{}{TypeKind, MapKind, []interface{}{BoolKind, StringKind}},
		MakeCompoundType(MapKind, MakePrimitiveType(BoolKind), MakePrimitiveType(StringKind)))
	test([]interface{}{TypeKind, EnumKind, "E", []interface{}{"a", "b", "c"}},
		MakeEnumType("E", "a", "b", "c"))

	test([]interface{}{TypeKind, StructKind, "S", []interface{}{"x", Int16Kind, false, "v", ValueKind, true}, []interface{}{}},
		MakeStructType("S", []Field{
			Field{"x", MakePrimitiveType(Int16Kind), false},
			Field{"v", MakePrimitiveType(ValueKind), true},
		}, Choices{}))

	test([]interface{}{TypeKind, StructKind, "S", []interface{}{}, []interface{}{"x", Int16Kind, false, "v", ValueKind, false}},
		MakeStructType("S", []Field{}, Choices{
			Field{"x", MakePrimitiveType(Int16Kind), false},
			Field{"v", MakePrimitiveType(ValueKind), false},
		}))

	pkgRef := ref.Parse("sha1-0123456789abcdef0123456789abcdef01234567")
	test([]interface{}{TypeKind, UnresolvedKind, pkgRef.String(), "123"},
		MakeType(pkgRef, 123))

	test([]interface{}{TypeKind, StructKind, "S", []interface{}{"e", UnresolvedKind, pkgRef.String(), "123", false, "x", Int64Kind, false}, []interface{}{}},
		MakeStructType("S", []Field{
			Field{"e", MakeType(pkgRef, 123), false},
			Field{"x", MakePrimitiveType(Int64Kind), false},
		}, Choices{}))

	test([]interface{}{TypeKind, UnresolvedKind, ref.Ref{}.String(), "-1", "ns", "n"},
		MakeUnresolvedType("ns", "n"))
}
コード例 #22
0
ファイル: handlers.go プロジェクト: arv/noms-old
func HandleRef(w http.ResponseWriter, req *http.Request, ps URLParams, ds DataStore) {
	err := d.Try(func() {
		d.Exp.Equal("GET", req.Method)
		r := ref.Parse(ps.ByName("ref"))
		chunk := ds.transitionalChunkStore().Get(r)
		if chunk.IsEmpty() {
			w.WriteHeader(http.StatusNotFound)
			return
		}

		_, err := io.Copy(w, bytes.NewReader(chunk.Data()))
		d.Chk.NoError(err)
		w.Header().Add("Content-Type", "application/octet-stream")
		w.Header().Add("Cache-Control", "max-age=31536000") // 1 year
	})

	if err != nil {
		http.Error(w, fmt.Sprintf("Error: %v", err), http.StatusBadRequest)
		return
	}
}
コード例 #23
0
ファイル: http_store.go プロジェクト: arv/noms-old
func (h *HTTPStore) getHasRefs(refs map[ref.Ref]bool, reqs hasBatch) {
	// POST http://<host>/getHasRefs/. Post body: ref=sha1---&ref=sha1---& Response will be text of lines containing "|ref| |bool|"
	u := *h.host
	u.Path = httprouter.CleanPath(h.host.Path + constants.GetHasPath)
	values := &url.Values{}
	for r, _ := range refs {
		values.Add("ref", r.String())
	}

	req := h.newRequest("POST", u.String(), strings.NewReader(values.Encode()), http.Header{
		"Accept-Encoding": {"gzip"},
		"Content-Type":    {"application/x-www-form-urlencoded"},
	})

	res, err := h.httpClient.Do(req)
	d.Chk.NoError(err)
	defer closeResponse(res)
	d.Chk.Equal(http.StatusOK, res.StatusCode, "Unexpected response: %s", http.StatusText(res.StatusCode))

	reader := res.Body
	if strings.Contains(res.Header.Get("Content-Encoding"), "gzip") {
		gr, err := gzip.NewReader(reader)
		d.Chk.NoError(err)
		defer gr.Close()
		reader = gr
	}

	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	for scanner.Scan() {
		r := ref.Parse(scanner.Text())
		scanner.Scan()
		has := scanner.Text() == "true"
		for _, ch := range reqs[r] {
			ch <- has
		}
	}
}
コード例 #24
0
ファイル: imports.go プロジェクト: arv/noms-old
func resolveImports(aliases map[string]string, includePath string, vrw types.ValueReadWriter) map[string]ref.Ref {
	canonicalize := func(path string) string {
		if filepath.IsAbs(path) {
			return path
		}
		return filepath.Join(includePath, path)
	}
	imports := map[string]ref.Ref{}

	for alias, target := range aliases {
		var r ref.Ref
		if d.Try(func() { r = ref.Parse(target) }) != nil {
			canonical := canonicalize(target)
			inFile, err := os.Open(canonical)
			d.Chk.NoError(err)
			defer inFile.Close()
			parsedDep := ParseNomDL(alias, inFile, filepath.Dir(canonical), vrw)
			imports[alias] = vrw.WriteValue(parsedDep.Package).TargetRef()
		} else {
			imports[alias] = r
		}
	}
	return imports
}
コード例 #25
0
ファイル: facebook.noms.go プロジェクト: arv/noms-old
func init() {
	__typeForRefOfRemotePhoto = types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-10004087fdbc623873c649d28aa59f4e066d374e"), 0))
	types.RegisterRef(__typeForRefOfRemotePhoto, builderForRefOfRemotePhoto)
}
コード例 #26
0
func init() {
	__typeForListOfD = types.MakeCompoundType(types.ListKind, types.MakeType(ref.Parse("sha1-eda4273cba9d5d4a1bccf41bcaec64743863cde0"), 0))
	types.RegisterValue(__typeForListOfD, builderForListOfD, readerForListOfD)
}
コード例 #27
0
ファイル: index.noms.go プロジェクト: arv/noms-old
func init() {
	__typeForMapOfRefOfKeyToSetOfRefOfRound = types.MakeCompoundType(types.MapKind, types.MakeCompoundType(types.RefKind, types.MakeType(__mainPackageInFile_index_CachedRef, 2)), types.MakeCompoundType(types.SetKind, types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-91ae65b19b4817fc15d4e2c5c7472c68b4950b77"), 1))))
	types.RegisterValue(__typeForMapOfRefOfKeyToSetOfRefOfRound, builderForMapOfRefOfKeyToSetOfRefOfRound, readerForMapOfRefOfKeyToSetOfRefOfRound)
}
コード例 #28
0
ファイル: remote_requests_test.go プロジェクト: arv/noms-old
func TestGetRequestBatch(t *testing.T) {
	assert := assert.New(t)
	r0 := ref.Parse("sha1-0000000000000000000000000000000000000000")
	c1 := NewChunk([]byte("abc"))
	r1 := c1.Ref()
	c2 := NewChunk([]byte("123"))
	r2 := c2.Ref()

	tally := func(b bool, trueCnt, falseCnt *int) {
		if b {
			*trueCnt++
		} else {
			*falseCnt++
		}
	}

	req0chan := make(chan bool, 1)
	req1chan := make(chan Chunk, 1)
	req2chan := make(chan bool, 1)
	req3chan := make(chan bool, 1)
	req4chan := make(chan Chunk, 1)

	batch := readBatch{
		r0: []outstandingRequest{outstandingHas(req0chan), outstandingGet(req1chan)},
		r1: []outstandingRequest{outstandingHas(req2chan)},
		r2: []outstandingRequest{outstandingHas(req3chan), outstandingGet(req4chan)},
	}
	go func() {
		for requestedRef, reqs := range batch {
			for _, req := range reqs {
				if requestedRef == r1 {
					req.Satisfy(c1)
					delete(batch, r1)
				} else if requestedRef == r2 {
					req.Satisfy(c2)
					delete(batch, r2)
				}
			}
		}
	}()
	var r1True, r1False, r2True, r2False int
	for b := range req2chan {
		tally(b, &r1True, &r1False)
	}
	for b := range req3chan {
		tally(b, &r2True, &r2False)
	}
	for c := range req4chan {
		assert.EqualValues(c2.Ref(), c.Ref())
	}

	assert.Equal(1, r1True)
	assert.Equal(0, r1False)
	assert.Equal(1, r2True)
	assert.Equal(0, r2False)

	go batch.Close()
	var r0True, r0False int
	for b := range req0chan {
		tally(b, &r0True, &r0False)
	}
	for c := range req1chan {
		assert.EqualValues(EmptyChunk.Ref(), c.Ref())
	}
	assert.Equal(0, r0True)
	assert.Equal(1, r0False)
}
コード例 #29
0
ファイル: sha1_6c64b08.go プロジェクト: arv/noms-old
func init() {
	__typeForMapOfStringToRefOfCompany = types.MakeCompoundType(types.MapKind, types.MakePrimitiveType(types.StringKind), types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-91ae65b19b4817fc15d4e2c5c7472c68b4950b77"), 0)))
	types.RegisterValue(__typeForMapOfStringToRefOfCompany, builderForMapOfStringToRefOfCompany, readerForMapOfStringToRefOfCompany)
}
コード例 #30
0
ファイル: sha1_6c64b08.go プロジェクト: arv/noms-old
func init() {
	__typeForRefOfCompany = types.MakeCompoundType(types.RefKind, types.MakeType(ref.Parse("sha1-91ae65b19b4817fc15d4e2c5c7472c68b4950b77"), 0))
	types.RegisterRef(__typeForRefOfCompany, builderForRefOfCompany)
}