Esempio n. 1
0
func (db *MongoDB) SetDebug(on bool) {
	mgo.SetDebug(on)
	if on {
		mgo.SetLogger(log.New(os.Stderr, "[db] ", log.LstdFlags))
	} else {
		mgo.SetLogger(nil)
	}
}
Esempio n. 2
0
File: mgo.go Progetto: jkary/core
func (s *MgoSuite) SetUpSuite(c *gc.C) {
	if MgoServer.addr == "" {
		c.Fatalf("No Mongo Server Address, MgoSuite tests must be run with MgoTestPackage")
	}
	mgo.SetDebug(true)
	mgo.SetStats(true)
	// Make tests that use password authentication faster.
	utils.FastInsecureHash = true
}
Esempio n. 3
0
func (s *S) SetUpSuite(c *C) {
	mgo.SetDebug(true)
	mgo.SetStats(true)
	s.StartAll()

	session, err := mgo.Dial("localhost:40001")
	c.Assert(err, IsNil)
	s.build, err = session.BuildInfo()
	c.Check(err, IsNil)
	session.Close()
}
Esempio n. 4
0
func main() {
	logout := log.New(os.Stdout, "MGO: ", log.Lshortfile)
	mgo.SetLogger(logout)
	mgo.SetDebug(false)
	session, err := mgo.Dial("localhost")
	if err != nil {
		panic(err)
	}
	defer session.Close()
	db := session.DB("bookdb")
	cbooks := db.C("bookcoll")
	cauthors := db.C("authorcoll")

	aids := []bson.ObjectId{bson.NewObjectId(), bson.NewObjectId()}
	authors := []Author{{
		aids[0],
		"Author 1",
	}, {
		aids[1],
		"Author 2",
	}}
	cauthors.Insert(authors[0])
	cauthors.Insert(authors[1])
	// Insert some books
	mine := Book{
		bson.NewObjectId(),
		"Gang of four thingy",
		aids,
	}
	cbooks.Insert(&mine)

	var assembl []AssembledBooks
	cauthors.Find(bson.M{}).All(&assembl)
	str1, _ := json.MarshalIndent(assembl, "", " ")
	fmt.Printf("%s\n", str1)

	var allauthors []Author
	cauthors.Find(bson.M{}).All(&allauthors)
	str, _ := json.MarshalIndent(allauthors, "", " ")
	fmt.Printf("%s\n", str)
	var allbooks []Book
	cbooks.Find(bson.M{}).All(&allbooks)
	str, _ = json.MarshalIndent(allbooks, "", " ")
	fmt.Printf("%s\n", str)

	fmt.Println("Dropping all collections...")
	cauthors.DropCollection()
	cbooks.DropCollection()
	fmt.Println("Done")
}
Esempio n. 5
0
func (s *MgoSuite) SetUpSuite(c *C) {
	mgo.SetDebug(true)
	mgo.SetStats(true)
	dbdir := c.MkDir()
	args := []string{
		"--dbpath", dbdir,
		"--bind_ip", "127.0.0.1",
		"--port", "50017",
		"--nssize", "1",
		"--noprealloc",
		"--smallfiles",
		"--nojournal",
	}
	s.server = exec.Command("mongod", args...)
	s.server.Stdout = &s.output
	s.server.Stderr = &s.output
	err := s.server.Start()
	c.Assert(err, IsNil)
}
Esempio n. 6
0
func main() {
	logout := log.New(os.Stdout, "MGO: ", log.Lshortfile)
	mgo.SetLogger(logout)
	mgo.SetDebug(false)
	session, err := mgo.Dial("localhost")
	if err != nil {
		panic(err)
	}
	defer session.Close()
	db := session.DB("bookdb")
	coll := db.C("bookcoll")

	// Insert some books
	mine := Book{
		bson.NewObjectId(),
		"I never wrote a book",
		bson.Now(),
	}
	coll.Insert(&mine)
	hpott := Book{
		bson.NewObjectId(),
		"Harry Potter",
		time.Now(),
	}
	coll.Insert(&hpott)

	var alldocs Books
	coll.Find(bson.M{}).All(&alldocs)
	str, _ := json.MarshalIndent(alldocs, "", " ")
	fmt.Printf("%s\n", str)

	c, err := coll.Count()
	fmt.Printf("Total documents: %d\n", c)

	fmt.Println("Dropping entire collection...")
	coll.DropCollection()
	fmt.Println("Done")
}
Esempio n. 7
0
func (this *FunServantImpl) createServants() {
	log.Info("creating servants...")

	// proxy can dynamically auto discover peers
	if this.conf.Proxy.Enabled() {
		log.Debug("creating servant: proxy")
		this.proxy = proxy.New(this.conf.Proxy)
	} else {
		panic("peers proxy required")
	}

	log.Debug("creating servant: idgen")
	var err error
	this.idgen, err = idgen.NewIdGenerator(this.conf.IdgenWorkerId)
	if err != nil {
		panic(err)
	}

	if this.conf.Lcache.Enabled() {
		log.Debug("creating servant: lcache")
		this.lc = cache.NewLruCache(this.conf.Lcache.MaxItems)
		this.lc.OnEvicted = this.onLcLruEvicted
	}

	if this.conf.Memcache.Enabled() {
		log.Debug("creating servant: memcache")
		this.mc = memcache.New(this.conf.Memcache)
	}

	if this.conf.Redis.Enabled() {
		log.Debug("creating servant: redis")
		this.rd = redis.New(this.conf.Redis)
	}

	if this.conf.Lock.Enabled() {
		log.Debug("creating servant: lock")
		this.lk = lock.New(this.conf.Lock)
	}

	if this.conf.Mysql.Enabled() {
		log.Debug("creating servant: mysql")
		this.my = mysql.New(this.conf.Mysql)

		switch this.conf.Mysql.CacheStore {
		case "mem":
			this.dbCacheStore = store.NewMemStore(this.conf.Mysql.CacheStoreMemMaxItems)

		case "redis":
			this.dbCacheStore = store.NewRedisStore(this.conf.Mysql.CacheStoreRedisPool,
				this.conf.Redis)

		default:
			panic("unknown mysql cache store")
		}
	}

	if this.conf.Mongodb.Enabled() {
		log.Debug("creating servant: mongodb")
		this.mg = mongo.New(this.conf.Mongodb)
		if this.conf.Mongodb.DebugProtocol ||
			this.conf.Mongodb.DebugHeartbeat {
			mgo.SetLogger(&mongoProtocolLogger{})
			mgo.SetDebug(this.conf.Mongodb.DebugProtocol)
		}
	}

	if this.conf.Couchbase.Enabled() {
		log.Debug("creating servant: couchbase")

		var err error
		// pool is always 'default'
		this.cb, err = couch.New(this.conf.Couchbase.Servers, "default")
		if err != nil {
			log.Error("couchbase: %s", err)
		}
	}

	log.Info("servants created")
}