github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/state/presence/export_test.go (about) 1 // Copyright 2012, 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package presence 5 6 import ( 7 "gopkg.in/mgo.v2" 8 "gopkg.in/mgo.v2/bson" 9 ) 10 11 func FakeTimeSlot(offset int) { 12 fakeTimeSlot(offset) 13 } 14 15 func RealTimeSlot() { 16 realTimeSlot() 17 } 18 19 func FakePeriod(seconds int64) { 20 period = seconds 21 } 22 23 var realPeriod = period 24 25 func RealPeriod() { 26 period = realPeriod 27 } 28 29 func DirectRecordFunc(base *mgo.Collection) PingRecorder { 30 return &directRecorder{pings: pingsC(base)} 31 } 32 33 type directRecorder struct { 34 pings *mgo.Collection 35 } 36 37 func (dr *directRecorder) Ping(modelUUID string, slot int64, fieldKey string, fieldBit uint64) error { 38 session := dr.pings.Database.Session.Copy() 39 defer session.Close() 40 pings := dr.pings.With(session) 41 _, err := pings.UpsertId( 42 docIDInt64(modelUUID, slot), 43 bson.D{ 44 {"$set", bson.D{{"slot", slot}}}, 45 {"$inc", bson.D{{"alive." + fieldKey, fieldBit}}}, 46 }) 47 return err 48 } 49 50 // ForceInc forces the PingBatcher to use $inc instead of $bit operations 51 // This exists to test the code path that runs when using Mongo 2.4 and older. 52 func (pb *PingBatcher) ForceUpdatesUsingInc() { 53 logger.Debugf("forcing $inc operations from (was %t)", pb.useInc) 54 pb.useInc = true 55 } 56 57 func (w *Watcher) BeingLoads() uint64 { 58 return w.beingLoads 59 }