当前位置: 首页>>代码示例>>Golang>>正文


Golang testing.NewClock函数代码示例

本文整理汇总了Golang中github.com/juju/juju/testing.NewClock函数的典型用法代码示例。如果您正苦于以下问题:Golang NewClock函数的具体用法?Golang NewClock怎么用?Golang NewClock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewClock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestConfigValidation

func (s *IsolatedWorkerSuite) TestConfigValidation(c *gc.C) {
	tests := []struct {
		cfg      meterstatus.IsolatedConfig
		expected string
	}{{
		cfg: meterstatus.IsolatedConfig{
			Runner:    &stubRunner{stub: s.stub},
			StateFile: meterstatus.NewStateFile(path.Join(s.dataDir, "meter-status.yaml")),
		},
		expected: "clock not provided",
	}, {
		cfg: meterstatus.IsolatedConfig{
			Clock:     coretesting.NewClock(time.Now()),
			StateFile: meterstatus.NewStateFile(path.Join(s.dataDir, "meter-status.yaml")),
		},
		expected: "hook runner not provided",
	}, {
		cfg: meterstatus.IsolatedConfig{
			Clock:  coretesting.NewClock(time.Now()),
			Runner: &stubRunner{stub: s.stub},
		},
		expected: "state file not provided",
	}}
	for i, test := range tests {
		c.Logf("running test %d", i)
		err := test.cfg.Validate()
		c.Assert(err, gc.ErrorMatches, test.expected)
	}
}
开发者ID:imoapps,项目名称:juju,代码行数:29,代码来源:isolated_test.go

示例2: SetUpTest

func (s *ModelMigrationSuite) SetUpTest(c *gc.C) {
	s.ConnSuite.SetUpTest(c)
	s.clock = coretesting.NewClock(time.Now().Truncate(time.Second))
	s.PatchValue(&state.GetClock, func() clock.Clock {
		return s.clock
	})

	// Create a hosted model to migrate.
	s.State2 = s.Factory.MakeModel(c, nil)
	s.AddCleanup(func(*gc.C) { s.State2.Close() })

	targetControllerTag := names.NewModelTag(utils.MustNewUUID().String())

	// Plausible migration arguments to test with.
	s.stdSpec = state.ModelMigrationSpec{
		InitiatedBy: names.NewUserTag("admin"),
		TargetInfo: migration.TargetInfo{
			ControllerTag: targetControllerTag,
			Addrs:         []string{"1.2.3.4:5555", "4.3.2.1:6666"},
			CACert:        "cert",
			AuthTag:       names.NewUserTag("user"),
			Password:      "password",
		},
	}
}
开发者ID:makyo,项目名称:juju,代码行数:25,代码来源:modelmigration_test.go

示例3: SetUpTest

func (s *IsolatedWorkerSuite) SetUpTest(c *gc.C) {
	s.BaseSuite.SetUpTest(c)
	s.stub = &testing.Stub{}

	s.dataDir = c.MkDir()

	s.hookRan = make(chan struct{})
	s.triggersCreated = make(chan struct{})

	triggerFactory := func(state meterstatus.WorkerState, status string, disconectedAt time.Time, clk clock.Clock, amber time.Duration, red time.Duration) (<-chan time.Time, <-chan time.Time) {
		select {
		case s.triggersCreated <- struct{}{}:
		case <-time.After(coretesting.LongWait):
			c.Fatalf("failed to signal trigger creation")
		}
		return meterstatus.GetTriggers(state, status, disconectedAt, clk, amber, red)
	}

	s.clk = coretesting.NewClock(time.Now())
	wrk, err := meterstatus.NewIsolatedStatusWorker(
		meterstatus.IsolatedConfig{
			Runner:           &stubRunner{stub: s.stub, ran: s.hookRan},
			StateFile:        meterstatus.NewStateFile(path.Join(s.dataDir, "meter-status.yaml")),
			Clock:            s.clk,
			AmberGracePeriod: AmberGracePeriod,
			RedGracePeriod:   RedGracePeriod,
			TriggerFactory:   triggerFactory,
		})
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(wrk, gc.NotNil)
	s.worker = wrk
}
开发者ID:imoapps,项目名称:juju,代码行数:32,代码来源:isolated_test.go

示例4: newFixture

func newFixture(period time.Duration) workerFixture {
	return workerFixture{
		revisionUpdater: newMockRevisionUpdater(),
		clock:           coretesting.NewClock(time.Now()),
		period:          period,
	}
}
开发者ID:felicianotech,项目名称:juju,代码行数:7,代码来源:worker_test.go

示例5: TestMissingClient

func (s *ValidationSuite) TestMissingClient(c *gc.C) {
	manager, err := leadership.NewManager(leadership.ManagerConfig{
		Clock: coretesting.NewClock(time.Now()),
	})
	c.Check(err, gc.ErrorMatches, "missing client")
	c.Check(manager, gc.IsNil)
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:7,代码来源:manager_validation_test.go

示例6: TestAdd

func (*scheduleSuite) TestAdd(c *gc.C) {
	clock := coretesting.NewClock(time.Time{})
	s := schedule.NewSchedule(clock)

	op0 := operation{"k0", "v0", 3 * time.Second}
	op1 := operation{"k1", "v1", 1500 * time.Millisecond}
	op2 := operation{"k2", "v2", 2 * time.Second}

	s.Add(op0)
	s.Add(op1)
	s.Add(op2)

	clock.Advance(time.Second) // T+1
	assertReady(c, s, clock /* nothing */)

	clock.Advance(time.Second) // T+2
	assertReady(c, s, clock, op1, op2)
	assertReady(c, s, clock /* nothing */)

	clock.Advance(500 * time.Millisecond) // T+2.5
	assertReady(c, s, clock /* nothing */)

	clock.Advance(time.Second) // T+3.5
	assertReady(c, s, clock, op0)
}
开发者ID:axw,项目名称:juju-time,代码行数:25,代码来源:schedule_test.go

示例7: TestDeleteSecurityGroupFewCalls

func (s *SecurityGroupSuite) TestDeleteSecurityGroupFewCalls(c *gc.C) {
	t0 := time.Time{}
	clock := autoAdvancingClock{coretesting.NewClock(t0)}
	count := 0
	maxCalls := 4
	expectedTimes := []time.Time{
		t0,
		t0.Add(time.Second),
		t0.Add(3 * time.Second),
		t0.Add(7 * time.Second),
		t0.Add(15 * time.Second),
	}
	s.instanceStub.deleteSecurityGroup = func(group amzec2.SecurityGroup) (resp *amzec2.SimpleResp, err error) {
		c.Assert(clock.Now(), gc.Equals, expectedTimes[count])
		if count < maxCalls {
			count++
			return nil, &amzec2.Error{Code: "keep going"}
		}
		return nil, nil
	}
	err := s.deleteFunc(s.instanceStub, amzec2.SecurityGroup{}, clock)
	c.Assert(err, jc.ErrorIsNil)

	expectedCalls := make([]string, maxCalls+1)
	for i := 0; i < maxCalls+1; i++ {
		expectedCalls[i] = "DeleteSecurityGroup"
	}
	s.instanceStub.CheckCallNames(c, expectedCalls...)
}
开发者ID:xushiwei,项目名称:juju,代码行数:29,代码来源:securitygroups_test.go

示例8: TestNext

func (*scheduleSuite) TestNext(c *gc.C) {
	clock := coretesting.NewClock(time.Time{})
	s := schedule.NewSchedule(clock)

	op0 := operation{"k0", "v0", 3 * time.Second}
	op1 := operation{"k1", "v1", 1500 * time.Millisecond}
	op2 := operation{"k2", "v2", 2 * time.Second}
	op3 := operation{"k3", "v3", 2500 * time.Millisecond}

	s.Add(op0)
	s.Add(op1)
	s.Add(op2)
	s.Add(op3)

	assertNextOp(c, s, clock, 1500*time.Millisecond)
	clock.Advance(1500 * time.Millisecond)
	assertReady(c, s, clock, op1)

	clock.Advance(500 * time.Millisecond)
	assertNextOp(c, s, clock, 0)
	assertReady(c, s, clock, op2)

	s.Remove("k3")

	clock.Advance(2 * time.Second) // T+4
	assertNextOp(c, s, clock, 0)
	assertReady(c, s, clock, op0)
}
开发者ID:axw,项目名称:juju-time,代码行数:28,代码来源:schedule_test.go

示例9: SetUpTest

func (s *SingularSuite) SetUpTest(c *gc.C) {
	s.clock = coretesting.NewClock(time.Now())
	s.PatchValue(&state.GetClock, func() clock.Clock {
		return s.clock
	})
	s.ConnSuite.SetUpTest(c)
}
开发者ID:felicianotech,项目名称:juju,代码行数:7,代码来源:singular_test.go

示例10: TestSystemKillCallsEnvironDestroyOnHostedEnviron

func (s *cmdControllerSuite) TestSystemKillCallsEnvironDestroyOnHostedEnviron(c *gc.C) {
	st := s.Factory.MakeEnvironment(c, &factory.EnvParams{
		Name: "foo",
	})
	defer st.Close()

	st.SwitchBlockOn(state.DestroyBlock, "TestBlockDestroyEnvironment")
	st.Close()

	opc := make(chan dummy.Operation, 200)
	dummy.Listen(opc)

	conn, err := juju.NewAPIState(s.AdminUserTag(c), s.Environ, api.DialOpts{})
	c.Assert(err, jc.ErrorIsNil)
	s.AddCleanup(func(*gc.C) { conn.Close() })
	client := undertakerapi.NewClient(conn)

	startTime := time.Date(2015, time.September, 1, 17, 2, 1, 0, time.UTC)
	mClock := testing.NewClock(startTime)
	undertaker.NewUndertaker(client, mClock)

	store, err := configstore.Default()
	_, err = store.ReadInfo("dummyenv")
	c.Assert(err, jc.ErrorIsNil)

	s.run(c, "kill-controller", "dummyenv", "-y")

	// Ensure that Destroy was called on the hosted environment ...
	opRecvTimeout(c, st, opc, dummy.OpDestroy{})

	// ... and that the configstore was removed.
	_, err = store.ReadInfo("dummyenv")
	c.Assert(err, jc.Satisfies, errors.IsNotFound)
}
开发者ID:imoapps,项目名称:juju,代码行数:34,代码来源:cmd_juju_controller_test.go

示例11: TestDeleteSecurityGroupInvalidGroupNotFound

func (s *SecurityGroupSuite) TestDeleteSecurityGroupInvalidGroupNotFound(c *gc.C) {
	s.instanceStub.deleteSecurityGroup = func(group amzec2.SecurityGroup) (resp *amzec2.SimpleResp, err error) {
		return nil, &amzec2.Error{Code: "InvalidGroup.NotFound"}
	}
	err := s.deleteFunc(s.instanceStub, amzec2.SecurityGroup{}, coretesting.NewClock(time.Time{}))
	c.Assert(err, jc.ErrorIsNil)
	s.instanceStub.CheckCallNames(c, "DeleteSecurityGroup")
}
开发者ID:xushiwei,项目名称:juju,代码行数:8,代码来源:securitygroups_test.go

示例12: TestMissingMaxSleep

func (s *ValidationSuite) TestMissingMaxSleep(c *gc.C) {
	manager, err := leadership.NewManager(leadership.ManagerConfig{
		Client: NewClient(nil, nil),
		Clock:  coretesting.NewClock(time.Now()),
	})
	c.Check(err, gc.ErrorMatches, "non-positive MaxSleep not valid")
	c.Check(err, jc.Satisfies, errors.IsNotValid)
	c.Check(manager, gc.IsNil)
}
开发者ID:imoapps,项目名称:juju,代码行数:9,代码来源:manager_validation_test.go

示例13: TestMissingClient

func (s *ValidationSuite) TestMissingClient(c *gc.C) {
	manager, err := leadership.NewManager(leadership.ManagerConfig{
		Clock:    coretesting.NewClock(time.Now()),
		MaxSleep: time.Minute,
	})
	c.Check(err, gc.ErrorMatches, "nil Client not valid")
	c.Check(err, jc.Satisfies, errors.IsNotValid)
	c.Check(manager, gc.IsNil)
}
开发者ID:imoapps,项目名称:juju,代码行数:9,代码来源:manager_validation_test.go

示例14: SetUpTest

func (s *LeadershipSuite) SetUpTest(c *gc.C) {
	s.clock = coretesting.NewClock(time.Now())
	s.PatchValue(&state.GetClock, func() clock.Clock {
		return s.clock
	})
	s.ConnSuite.SetUpTest(c)

	s.checker = s.State.LeadershipChecker()
	s.claimer = s.State.LeadershipClaimer()
}
开发者ID:felicianotech,项目名称:juju,代码行数:10,代码来源:state_leader_test.go

示例15: TestNegativeMaxSleep

func (s *ValidationSuite) TestNegativeMaxSleep(c *gc.C) {
	manager, err := lease.NewManager(lease.ManagerConfig{
		Client:    NewClient(nil, nil),
		Clock:     coretesting.NewClock(time.Now()),
		Secretary: struct{ lease.Secretary }{},
		MaxSleep:  -time.Nanosecond,
	})
	c.Check(err, gc.ErrorMatches, "non-positive MaxSleep not valid")
	c.Check(err, jc.Satisfies, errors.IsNotValid)
	c.Check(manager, gc.IsNil)
}
开发者ID:exekias,项目名称:juju,代码行数:11,代码来源:manager_validation_test.go


注:本文中的github.com/juju/juju/testing.NewClock函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。