~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/state/export_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
        "github.com/juju/errors"
13
13
        "github.com/juju/loggo"
 
14
        "github.com/juju/testing"
14
15
        jc "github.com/juju/testing/checkers"
15
16
        jujutxn "github.com/juju/txn"
16
17
        txntesting "github.com/juju/txn/testing"
21
22
        "gopkg.in/mgo.v2/bson"
22
23
        "gopkg.in/mgo.v2/txn"
23
24
 
24
 
        "github.com/juju/juju/core/description"
25
25
        "github.com/juju/juju/core/lease"
26
26
        "github.com/juju/juju/mongo"
 
27
        "github.com/juju/juju/mongo/utils"
27
28
        "github.com/juju/juju/network"
 
29
        "github.com/juju/juju/permission"
 
30
        "github.com/juju/juju/status"
28
31
        "github.com/juju/juju/testcharms"
29
32
        "github.com/juju/juju/version"
30
33
)
49
52
        ControllerAvailable                  = &controllerAvailable
50
53
        GetOrCreatePorts                     = getOrCreatePorts
51
54
        GetPorts                             = getPorts
52
 
        NowToTheSecond                       = nowToTheSecond
53
55
        AddVolumeOps                         = (*State).addVolumeOps
54
56
        CombineMeterStatus                   = combineMeterStatus
55
57
        ApplicationGlobalKey                 = applicationGlobalKey
456
458
 
457
459
var ActionNotificationIdToActionId = actionNotificationIdToActionId
458
460
 
459
 
func UpdateModelUserLastConnection(st *State, e description.UserAccess, when time.Time) error {
 
461
func UpdateModelUserLastConnection(st *State, e permission.UserAccess, when time.Time) error {
460
462
        return st.updateLastModelConnection(e.UserTag, when)
461
463
}
462
464
 
509
511
        err := st.runTransaction(ops)
510
512
        c.Assert(err, jc.ErrorIsNil)
511
513
}
 
514
 
 
515
// PrimeUnitStatusHistory will add count history elements, advancing the test clock by
 
516
// one second for each entry.
 
517
func PrimeUnitStatusHistory(
 
518
        c *gc.C, clock *testing.Clock,
 
519
        unit *Unit, statusVal status.Status,
 
520
        count, batchSize int,
 
521
        nextData func(int) map[string]interface{},
 
522
) {
 
523
        globalKey := unit.globalKey()
 
524
 
 
525
        history, closer := unit.st.getCollection(statusesHistoryC)
 
526
        defer closer()
 
527
        historyW := history.Writeable()
 
528
 
 
529
        var data map[string]interface{}
 
530
        for i := 0; i < count; {
 
531
                var docs []interface{}
 
532
                for j := 0; j < batchSize && i < count; j++ {
 
533
                        clock.Advance(time.Second)
 
534
                        if nextData != nil {
 
535
                                data = utils.EscapeKeys(nextData(i))
 
536
                        }
 
537
                        docs = append(docs, &historicalStatusDoc{
 
538
                                Status:     statusVal,
 
539
                                StatusData: data,
 
540
                                Updated:    clock.Now().UnixNano(),
 
541
                                GlobalKey:  globalKey,
 
542
                        })
 
543
                        // Seems like you can't increment two values in one loop
 
544
                        i++
 
545
                }
 
546
                err := historyW.Insert(docs...)
 
547
                c.Assert(err, jc.ErrorIsNil)
 
548
        }
 
549
        // Set the status for the unit itself.
 
550
        doc := statusDoc{
 
551
                Status:     statusVal,
 
552
                StatusData: data,
 
553
                Updated:    clock.Now().UnixNano(),
 
554
        }
 
555
        buildTxn := updateStatusSource(unit.st, globalKey, doc)
 
556
        err := unit.st.run(buildTxn)
 
557
        c.Assert(err, jc.ErrorIsNil)
 
558
}