本文整理汇总了Golang中github.com/aws/amazon-ecs-agent/agent/statemanager.NewNoopStateManager函数的典型用法代码示例。如果您正苦于以下问题:Golang NewNoopStateManager函数的具体用法?Golang NewNoopStateManager怎么用?Golang NewNoopStateManager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewNoopStateManager函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestDeleteImageOtherRemoveImageErrors
func TestDeleteImageOtherRemoveImageErrors(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
client := NewMockDockerClient(ctrl)
imageManager := &dockerImageManager{client: client, state: dockerstate.NewDockerTaskEngineState()}
imageManager.SetSaver(statemanager.NewNoopStateManager())
container := &api.Container{
Name: "testContainer",
Image: "testContainerImage",
}
imageInspected := &docker.Image{
ID: "sha256:qwerty",
}
client.EXPECT().InspectImage(container.Image).Return(imageInspected, nil).AnyTimes()
err := imageManager.AddContainerReferenceToImageState(container)
if err != nil {
t.Error("Error in adding container to an existing image state")
}
imageState, _ := imageManager.getImageState(imageInspected.ID)
client.EXPECT().RemoveImage(container.Image, removeImageTimeout).Return(errors.New("container for this image exists"))
imageManager.deleteImage(container.Image, imageState)
if len(imageState.Image.Names) == 0 {
t.Error("Incorrectly removed Image name from image state")
}
if len(imageManager.getAllImageStates()) == 0 {
t.Error("Incorrecting removed image state from image manager before deletion")
}
}
开发者ID:umaptechnologies,项目名称:amazon-ecs-agent,代码行数:28,代码来源:docker_image_manager_test.go
示例2: TestHandlePayloadMessageWithNoMessageId
// TestHandlePayloadMessageWithNoMessageId tests that agent doesn't ack payload messages
// that do not contain message ids
func TestHandlePayloadMessageWithNoMessageId(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
taskEngine := engine.NewMockTaskEngine(ctrl)
ecsClient := mock_api.NewMockECSClient(ctrl)
stateManager := statemanager.NewNoopStateManager()
credentialsManager := credentials.NewManager()
ctx := context.Background()
buffer := newPayloadRequestHandler(ctx, taskEngine, ecsClient, clusterName, containerInstanceArn, nil, stateManager, refreshCredentialsHandler{}, credentialsManager)
// test adding a payload message without the MessageId field
payloadMessage := &ecsacs.PayloadMessage{
Tasks: []*ecsacs.Task{
&ecsacs.Task{
Arn: aws.String("t1"),
},
},
}
err := buffer.handleSingleMessage(payloadMessage)
if err == nil {
t.Error("Expected error while adding a task with no message id")
}
// test adding a payload message with blank MessageId
payloadMessage.MessageId = aws.String("")
err = buffer.handleSingleMessage(payloadMessage)
if err == nil {
t.Error("Expected error while adding a task with no message id")
}
}
开发者ID:witsoej,项目名称:amazon-ecs-agent,代码行数:35,代码来源:payload_handler_test.go
示例3: TestRemoveUnusedImagesNoImages
func TestRemoveUnusedImagesNoImages(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
client := NewMockDockerClient(ctrl)
imageManager := &dockerImageManager{client: client, state: dockerstate.NewDockerTaskEngineState()}
imageManager.SetSaver(statemanager.NewNoopStateManager())
imageManager.removeUnusedImages()
}
开发者ID:umaptechnologies,项目名称:amazon-ecs-agent,代码行数:8,代码来源:docker_image_manager_test.go
示例4: TestDeleteImageIDNull
func TestDeleteImageIDNull(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
client := NewMockDockerClient(ctrl)
imageManager := &dockerImageManager{client: client, state: dockerstate.NewDockerTaskEngineState()}
imageManager.SetSaver(statemanager.NewNoopStateManager())
imageManager.deleteImage("", nil)
}
开发者ID:umaptechnologies,项目名称:amazon-ecs-agent,代码行数:8,代码来源:docker_image_manager_test.go
示例5: TestAddPayloadTaskAddsNonStoppedTasksAfterStoppedTasks
// TestAddPayloadTaskAddsNonStoppedTasksAfterStoppedTasks tests if tasks with desired status
// 'RUNNING' are added after tasks with desired status 'STOPPED'
func TestAddPayloadTaskAddsNonStoppedTasksAfterStoppedTasks(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
ecsClient := mock_api.NewMockECSClient(ctrl)
taskEngine := engine.NewMockTaskEngine(ctrl)
credentialsManager := credentials.NewManager()
var tasksAddedToEngine []*api.Task
taskEngine.EXPECT().AddTask(gomock.Any()).Do(func(task *api.Task) {
tasksAddedToEngine = append(tasksAddedToEngine, task)
}).Times(2)
stoppedTaskArn := "stoppedTask"
runningTaskArn := "runningTask"
payloadMessage := &ecsacs.PayloadMessage{
Tasks: []*ecsacs.Task{
&ecsacs.Task{
Arn: aws.String(runningTaskArn),
DesiredStatus: aws.String("RUNNING"),
},
&ecsacs.Task{
Arn: aws.String(stoppedTaskArn),
DesiredStatus: aws.String("STOPPED"),
},
},
MessageId: aws.String(payloadMessageId),
}
ctx := context.Background()
stateManager := statemanager.NewNoopStateManager()
buffer := newPayloadRequestHandler(ctx, taskEngine, ecsClient, clusterName, containerInstanceArn, nil, stateManager, refreshCredentialsHandler{}, credentialsManager)
_, ok := buffer.addPayloadTasks(payloadMessage)
if !ok {
t.Error("addPayloadTasks returned false")
}
if len(tasksAddedToEngine) != 2 {
t.Errorf("Incorrect number of tasks added to the engine. Expected: %d, got: %d", 2, len(tasksAddedToEngine))
}
// Verify if stopped task is added before running task
firstTaskAdded := tasksAddedToEngine[0]
if firstTaskAdded.Arn != stoppedTaskArn {
t.Errorf("Expected first task arn: %s, got: %s", stoppedTaskArn, firstTaskAdded.Arn)
}
if firstTaskAdded.DesiredStatus != api.TaskStopped {
t.Errorf("Expected first task state be be: %s , got: %s", "STOPPED", firstTaskAdded.DesiredStatus.String())
}
secondTaskAdded := tasksAddedToEngine[1]
if secondTaskAdded.Arn != runningTaskArn {
t.Errorf("Expected second task arn: %s, got: %s", runningTaskArn, secondTaskAdded.Arn)
}
if secondTaskAdded.DesiredStatus != api.TaskRunning {
t.Errorf("Expected second task state be be: %s , got: %s", "RUNNNING", secondTaskAdded.DesiredStatus.String())
}
}
开发者ID:witsoej,项目名称:amazon-ecs-agent,代码行数:58,代码来源:payload_handler_test.go
示例6: TestHandlerReconnects
func TestHandlerReconnects(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
taskEngine := engine.NewMockTaskEngine(ctrl)
ecsclient := mock_api.NewMockECSClient(ctrl)
statemanager := statemanager.NewNoopStateManager()
closeWS := make(chan bool)
server, serverIn, requests, errs, err := startMockAcsServer(t, closeWS)
if err != nil {
t.Fatal(err)
}
go func() {
for {
select {
case <-requests:
case <-errs:
}
}
}()
ecsclient.EXPECT().DiscoverPollEndpoint("myArn").Return(server.URL, nil).Times(10)
taskEngine.EXPECT().Version().Return("Docker: 1.5.0", nil).AnyTimes()
ctx, cancel := context.WithCancel(context.Background())
ended := make(chan bool, 1)
go func() {
handler.StartSession(ctx, handler.StartSessionArguments{
ContainerInstanceArn: "myArn",
CredentialProvider: credentials.AnonymousCredentials,
Config: &config.Config{Cluster: "someCluster"},
TaskEngine: taskEngine,
ECSClient: ecsclient,
StateManager: statemanager,
AcceptInvalidCert: true,
})
// This should never return
ended <- true
}()
start := time.Now()
for i := 0; i < 10; i++ {
serverIn <- `{"type":"HeartbeatMessage","message":{"healthy":true}}`
closeWS <- true
}
if time.Since(start) > 2*time.Second {
t.Error("Test took longer than expected; backoff should not have occured for EOF")
}
select {
case <-ended:
t.Fatal("Should not have stopped session")
default:
}
cancel()
<-ended
}
开发者ID:bmanas,项目名称:amazon-ecs-agent,代码行数:56,代码来源:acs_handler_test.go
示例7: TestHandlerReconnectsCorrectlySetsSendCredentialsURLParameter
// TestHandlerReconnectsCorrectlySetsSendCredentialsURLParameter tests if
// the 'sendCredentials' URL parameter is set correctly for successive
// invocations of startACSSession
func TestHandlerReconnectsCorrectlySetsSendCredentialsURLParameter(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
taskEngine := engine.NewMockTaskEngine(ctrl)
ecsClient := mock_api.NewMockECSClient(ctrl)
statemanager := statemanager.NewNoopStateManager()
ctx, cancel := context.WithCancel(context.Background())
mockWsClient := mock_wsclient.NewMockClientServer(ctrl)
args := StartSessionArguments{
ContainerInstanceArn: "myArn",
CredentialProvider: credentials.AnonymousCredentials,
Config: &config.Config{Cluster: "someCluster"},
TaskEngine: taskEngine,
ECSClient: ecsClient,
StateManager: statemanager,
AcceptInvalidCert: true,
_heartbeatTimeout: 20 * time.Millisecond,
_heartbeatJitter: 10 * time.Millisecond,
}
session := newSessionResources(args)
mockWsClient.EXPECT().SetAnyRequestHandler(gomock.Any()).AnyTimes()
mockWsClient.EXPECT().AddRequestHandler(gomock.Any()).AnyTimes()
mockWsClient.EXPECT().Close().Return(nil).AnyTimes()
mockWsClient.EXPECT().Serve().Return(io.EOF).AnyTimes()
gomock.InOrder(
// When the websocket client connects to ACS for the first
// time, 'sendCredentials' should be set to true
mockWsClient.EXPECT().Connect().Do(func() {
validateSendCredentialsInSession(t, session, "true")
}).Return(nil),
// For all subsequent connections to ACS, 'sendCredentials'
// should be set to false
mockWsClient.EXPECT().Connect().Do(func() {
validateSendCredentialsInSession(t, session, "false")
}).Return(nil).AnyTimes(),
)
backoff := utils.NewSimpleBackoff(connectionBackoffMin, connectionBackoffMax, connectionBackoffJitter, connectionBackoffMultiplier)
timer := newDisconnectionTimer(mockWsClient, args.time(), args.heartbeatTimeout(), args.heartbeatJitter())
defer timer.Stop()
go func() {
for i := 0; i < 10; i++ {
startACSSession(ctx, mockWsClient, timer, args, backoff, session)
}
cancel()
}()
// Wait for context to be cancelled
select {
case <-ctx.Done():
}
}
开发者ID:witsoej,项目名称:amazon-ecs-agent,代码行数:58,代码来源:acs_handler_test.go
示例8: TestHandlePayloadMessageAckedWhenTaskAdded
// TestHandlePayloadMessageAckedWhenTaskAdded tests if the handler generates an ack
// after processing a payload message.
func TestHandlePayloadMessageAckedWhenTaskAdded(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
ecsClient := mock_api.NewMockECSClient(ctrl)
stateManager := statemanager.NewNoopStateManager()
credentialsManager := credentials.NewManager()
ctx, cancel := context.WithCancel(context.Background())
taskEngine := engine.NewMockTaskEngine(ctrl)
var addedTask *api.Task
taskEngine.EXPECT().AddTask(gomock.Any()).Do(func(task *api.Task) {
addedTask = task
}).Times(1)
var ackRequested *ecsacs.AckRequest
mockWsClient := mock_wsclient.NewMockClientServer(ctrl)
mockWsClient.EXPECT().MakeRequest(gomock.Any()).Do(func(ackRequest *ecsacs.AckRequest) {
ackRequested = ackRequest
cancel()
}).Times(1)
buffer := newPayloadRequestHandler(ctx, taskEngine, ecsClient, clusterName, containerInstanceArn, mockWsClient, stateManager, refreshCredentialsHandler{}, credentialsManager)
go buffer.start()
// Send a payload message
payloadMessage := &ecsacs.PayloadMessage{
Tasks: []*ecsacs.Task{
&ecsacs.Task{
Arn: aws.String("t1"),
},
},
MessageId: aws.String(payloadMessageId),
}
err := buffer.handleSingleMessage(payloadMessage)
if err != nil {
t.Errorf("Error handling payload message: %v", err)
}
// Wait till we get an ack from the ackBuffer
select {
case <-ctx.Done():
}
// Verify the message id acked
if aws.StringValue(ackRequested.MessageId) != payloadMessageId {
t.Errorf("Message Id mismatch. Expected: %s, got: %s", payloadMessageId, aws.StringValue(ackRequested.MessageId))
}
// Verify if task added == expected task
expectedTask := &api.Task{
Arn: "t1",
}
if !reflect.DeepEqual(addedTask, expectedTask) {
t.Errorf("Mismatch between expected and added tasks, expected: %v, added: %v", expectedTask, addedTask)
}
}
开发者ID:witsoej,项目名称:amazon-ecs-agent,代码行数:56,代码来源:payload_handler_test.go
示例9: TestRemoveLeastRecentlyUsedImageNoImage
func TestRemoveLeastRecentlyUsedImageNoImage(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
client := NewMockDockerClient(ctrl)
imageManager := &dockerImageManager{client: client, state: dockerstate.NewDockerTaskEngineState()}
imageManager.SetSaver(statemanager.NewNoopStateManager())
err := imageManager.removeLeastRecentlyUsedImage()
if err == nil {
t.Error("Expected Error for no LRU image to remove")
}
}
开发者ID:umaptechnologies,项目名称:amazon-ecs-agent,代码行数:11,代码来源:docker_image_manager_test.go
示例10: TestImageCleanupHappyPath
func TestImageCleanupHappyPath(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
client := NewMockDockerClient(ctrl)
imageManager := &dockerImageManager{
client: client,
state: dockerstate.NewDockerTaskEngineState(),
minimumAgeBeforeDeletion: 1 * time.Millisecond,
numImagesToDelete: config.DefaultNumImagesToDeletePerCycle,
imageCleanupTimeInterval: config.DefaultImageCleanupTimeInterval,
}
imageManager.SetSaver(statemanager.NewNoopStateManager())
container := &api.Container{
Name: "testContainer",
Image: "testContainerImage",
}
imageInspected := &docker.Image{
ID: "sha256:qwerty",
}
client.EXPECT().InspectImage(container.Image).Return(imageInspected, nil).AnyTimes()
err := imageManager.AddContainerReferenceToImageState(container)
if err != nil {
t.Error("Error in adding container to an existing image state")
}
err = imageManager.RemoveContainerReferenceFromImageState(container)
if err != nil {
t.Error("Error removing container reference from image state")
}
imageState, _ := imageManager.getImageState(imageInspected.ID)
imageState.PulledAt = time.Now().AddDate(0, -2, 0)
imageState.LastUsedAt = time.Now().AddDate(0, -2, 0)
imageState.AddImageName("anotherImage")
client.EXPECT().RemoveImage(container.Image, removeImageTimeout).Return(nil)
client.EXPECT().RemoveImage("anotherImage", removeImageTimeout).Return(nil)
parent := context.Background()
ctx, cancel := context.WithCancel(parent)
go imageManager.performPeriodicImageCleanup(ctx, 2*time.Millisecond)
time.Sleep(1 * time.Second)
cancel()
if len(imageState.Image.Names) != 0 {
t.Error("Error removing image name from state after the image is removed")
}
if len(imageManager.imageStates) != 0 {
t.Error("Error removing image state after the image is removed")
}
}
开发者ID:umaptechnologies,项目名称:amazon-ecs-agent,代码行数:51,代码来源:docker_image_manager_test.go
示例11: TestHandlerReconnectsOnServeErrors
// TestHandlerReconnectsOnServeErrors tests if the handler retries to
// to establish the session with ACS when ClientServer.Connect() returns errors
func TestHandlerReconnectsOnServeErrors(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
taskEngine := engine.NewMockTaskEngine(ctrl)
taskEngine.EXPECT().Version().Return("Docker: 1.5.0", nil).AnyTimes()
ecsClient := mock_api.NewMockECSClient(ctrl)
ecsClient.EXPECT().DiscoverPollEndpoint(gomock.Any()).Return(acsURL, nil).AnyTimes()
statemanager := statemanager.NewNoopStateManager()
ctx, cancel := context.WithCancel(context.Background())
mockWsClient := mock_wsclient.NewMockClientServer(ctrl)
mockWsClient.EXPECT().SetAnyRequestHandler(gomock.Any()).AnyTimes()
mockWsClient.EXPECT().AddRequestHandler(gomock.Any()).AnyTimes()
mockWsClient.EXPECT().Connect().Return(nil).AnyTimes()
mockWsClient.EXPECT().Close().Return(nil).AnyTimes()
gomock.InOrder(
// Serve fails 10 times
mockWsClient.EXPECT().Serve().Return(io.EOF).Times(10),
// Cancel trying to Serve ACS requests on the 11th attempt
// Failure to retry on Serve() errors should cause the
// test to time out as the context is never cancelled
mockWsClient.EXPECT().Serve().Do(func() {
cancel()
}).Return(io.EOF),
)
session := &mockSession{mockWsClient}
args := StartSessionArguments{
ContainerInstanceArn: "myArn",
CredentialProvider: credentials.AnonymousCredentials,
Config: &config.Config{Cluster: "someCluster"},
TaskEngine: taskEngine,
ECSClient: ecsClient,
StateManager: statemanager,
AcceptInvalidCert: true,
_heartbeatTimeout: 20 * time.Millisecond,
_heartbeatJitter: 10 * time.Millisecond,
}
backoff := utils.NewSimpleBackoff(connectionBackoffMin, connectionBackoffMax, connectionBackoffJitter, connectionBackoffMultiplier)
go func() {
startSession(ctx, args, backoff, session)
}()
// Wait for context to be cancelled
select {
case <-ctx.Done():
}
}
开发者ID:witsoej,项目名称:amazon-ecs-agent,代码行数:52,代码来源:acs_handler_test.go
示例12: TestImageCleanupCannotRemoveImage
func TestImageCleanupCannotRemoveImage(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
client := NewMockDockerClient(ctrl)
imageManager := &dockerImageManager{
client: client,
state: dockerstate.NewDockerTaskEngineState(),
minimumAgeBeforeDeletion: config.DefaultImageDeletionAge,
numImagesToDelete: config.DefaultNumImagesToDeletePerCycle,
imageCleanupTimeInterval: config.DefaultImageCleanupTimeInterval,
}
imageManager.SetSaver(statemanager.NewNoopStateManager())
container := &api.Container{
Name: "testContainer",
Image: "testContainerImage",
}
sourceImage := &image.Image{
ImageID: "sha256:qwerty",
}
sourceImage.Names = append(sourceImage.Names, container.Image)
imageInspected := &docker.Image{
ID: "sha256:qwerty",
}
client.EXPECT().InspectImage(container.Image).Return(imageInspected, nil).AnyTimes()
err := imageManager.AddContainerReferenceToImageState(container)
if err != nil {
t.Error("Error in adding container to an existing image state")
}
err = imageManager.RemoveContainerReferenceFromImageState(container)
if err != nil {
t.Error("Error removing container reference from image state")
}
imageState, _ := imageManager.getImageState(imageInspected.ID)
imageState.PulledAt = time.Now().AddDate(0, -2, 0)
imageState.LastUsedAt = time.Now().AddDate(0, -2, 0)
client.EXPECT().RemoveImage(container.Image, removeImageTimeout).Return(errors.New("error removing image")).AnyTimes()
imageManager.removeUnusedImages()
if len(imageState.Image.Names) == 0 {
t.Error("Error: image name should not be removed")
}
if len(imageManager.imageStates) == 0 {
t.Error("Error: image state should not be removed")
}
}
开发者ID:umaptechnologies,项目名称:amazon-ecs-agent,代码行数:49,代码来源:docker_image_manager_test.go
示例13: initializeStateManager
func initializeStateManager(cfg *config.Config, taskEngine engine.TaskEngine, cluster, containerInstanceArn, savedInstanceID *string, sequenceNumber *utilatomic.IncreasingInt64) (statemanager.StateManager, error) {
if !cfg.Checkpoint {
return statemanager.NewNoopStateManager(), nil
}
stateManager, err := statemanager.NewStateManager(cfg,
statemanager.AddSaveable("TaskEngine", taskEngine),
statemanager.AddSaveable("ContainerInstanceArn", containerInstanceArn),
statemanager.AddSaveable("Cluster", cluster),
statemanager.AddSaveable("EC2InstanceID", savedInstanceID),
statemanager.AddSaveable("ACSSeqNum", sequenceNumber),
)
if err != nil {
return nil, err
}
return stateManager, nil
}
开发者ID:dockerstack,项目名称:amazon-ecs-agent,代码行数:16,代码来源:agent.go
示例14: NewDockerTaskEngine
// NewDockerTaskEngine returns a created, but uninitialized, DockerTaskEngine.
// The distinction between created and initialized is that when created it may
// be serialized/deserialized, but it will not communicate with docker until it
// is also initialized.
func NewDockerTaskEngine(cfg *config.Config) *DockerTaskEngine {
dockerTaskEngine := &DockerTaskEngine{
client: nil,
saver: statemanager.NewNoopStateManager(),
state: dockerstate.NewDockerTaskEngineState(),
managedTasks: make(map[string]*managedTask),
taskStopGroup: utilsync.NewSequentialWaitGroup(),
containerEvents: make(chan api.ContainerStateChange),
taskEvents: make(chan api.TaskStateChange),
}
dockerauth.SetConfig(cfg)
return dockerTaskEngine
}
开发者ID:jdrusso,项目名称:amazon-ecs-agent,代码行数:20,代码来源:docker_task_engine.go
示例15: TestUndownloadedUpdate
func TestUndownloadedUpdate(t *testing.T) {
u, ctrl, cfg, _, mockacs, _ := mocks(t, nil)
defer ctrl.Finish()
mockacs.EXPECT().MakeRequest(&nackRequestMatcher{&ecsacs.NackRequest{
Cluster: ptr("cluster").(*string),
ContainerInstance: ptr("containerInstance").(*string),
MessageId: ptr("mid").(*string),
}})
u.performUpdateHandler(statemanager.NewNoopStateManager(), engine.NewTaskEngine(cfg))(&ecsacs.PerformUpdateMessage{
ClusterArn: ptr("cluster").(*string),
ContainerInstanceArn: ptr("containerInstance").(*string),
MessageId: ptr("mid").(*string),
})
}
开发者ID:dockerstack,项目名称:amazon-ecs-agent,代码行数:16,代码来源:updater_test.go
示例16: TestConnectionIsClosedOnIdle
// TestConnectionIsClosedOnIdle tests if the connection to ACS is closed
// when the channel is idle
func TestConnectionIsClosedOnIdle(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
taskEngine := engine.NewMockTaskEngine(ctrl)
taskEngine.EXPECT().Version().Return("Docker: 1.5.0", nil).AnyTimes()
ecsClient := mock_api.NewMockECSClient(ctrl)
statemanager := statemanager.NewNoopStateManager()
mockWsClient := mock_wsclient.NewMockClientServer(ctrl)
mockWsClient.EXPECT().SetAnyRequestHandler(gomock.Any()).Do(func(v interface{}) {}).AnyTimes()
mockWsClient.EXPECT().AddRequestHandler(gomock.Any()).Do(func(v interface{}) {}).AnyTimes()
mockWsClient.EXPECT().Connect().Return(nil)
mockWsClient.EXPECT().Serve().Do(func() {
// Pretend as if the maximum heartbeatTimeout duration has
// been breached while Serving requests
time.Sleep(30 * time.Millisecond)
}).Return(io.EOF)
connectionClosed := make(chan bool)
mockWsClient.EXPECT().Close().Do(func() {
// Record connection closed
connectionClosed <- true
}).Return(nil)
ctx := context.Background()
backoff := utils.NewSimpleBackoff(connectionBackoffMin, connectionBackoffMax, connectionBackoffJitter, connectionBackoffMultiplier)
args := StartSessionArguments{
ContainerInstanceArn: "myArn",
CredentialProvider: credentials.AnonymousCredentials,
Config: &config.Config{Cluster: "someCluster"},
TaskEngine: taskEngine,
ECSClient: ecsClient,
StateManager: statemanager,
AcceptInvalidCert: true,
_heartbeatTimeout: 20 * time.Millisecond,
_heartbeatJitter: 10 * time.Millisecond,
}
go func() {
timer := newDisconnectionTimer(mockWsClient, args.time(), args.heartbeatTimeout(), args.heartbeatJitter())
defer timer.Stop()
startACSSession(ctx, mockWsClient, timer, args, backoff, &mockSession{})
}()
// Wait for connection to be closed. If the connection is not closed
// due to inactivity, the test will time out
<-connectionClosed
}
开发者ID:witsoej,项目名称:amazon-ecs-agent,代码行数:49,代码来源:acs_handler_test.go
示例17: NewDockerTaskEngine
// NewDockerTaskEngine returns a created, but uninitialized, DockerTaskEngine.
// The distinction between created and initialized is that when created it may
// be serialized/deserialized, but it will not communicate with docker until it
// is also initialized.
func NewDockerTaskEngine(cfg *config.Config, acceptInsecureCert bool) *DockerTaskEngine {
dockerTaskEngine := &DockerTaskEngine{
cfg: cfg,
acceptInsecureCert: acceptInsecureCert,
client: nil,
saver: statemanager.NewNoopStateManager(),
state: dockerstate.NewDockerTaskEngineState(),
managedTasks: make(map[string]*managedTask),
taskStopGroup: utilsync.NewSequentialWaitGroup(),
containerEvents: make(chan api.ContainerStateChange),
taskEvents: make(chan api.TaskStateChange),
}
return dockerTaskEngine
}
开发者ID:appuri,项目名称:amazon-ecs-agent,代码行数:21,代码来源:docker_task_engine.go
示例18: TestFullUpdateFlow
func TestFullUpdateFlow(t *testing.T) {
u, ctrl, cfg, mockfs, mockacs, mockhttp := mocks(t, nil)
defer ctrl.Finish()
var writtenFile bytes.Buffer
gomock.InOrder(
mockhttp.EXPECT().RoundTrip(mock_http.NewHTTPSimpleMatcher("GET", "https://s3.amazonaws.com/amazon-ecs-agent/update.tar")).Return(mock_http.SuccessResponse("update-tar-data"), nil),
mockfs.EXPECT().Create(gomock.Any()).Return(mock_os.NopReadWriteCloser(&writtenFile), nil),
mockfs.EXPECT().WriteFile("/tmp/test/desired-image", gomock.Any(), gomock.Any()).Return(nil),
mockacs.EXPECT().MakeRequest(gomock.Eq(&ecsacs.AckRequest{
Cluster: ptr("cluster").(*string),
ContainerInstance: ptr("containerInstance").(*string),
MessageId: ptr("mid").(*string),
})),
mockacs.EXPECT().MakeRequest(gomock.Eq(&ecsacs.AckRequest{
Cluster: ptr("cluster").(*string),
ContainerInstance: ptr("containerInstance").(*string),
MessageId: ptr("mid2").(*string),
})),
mockfs.EXPECT().Exit(exitcodes.ExitUpdate),
)
u.stageUpdateHandler()(&ecsacs.StageUpdateMessage{
ClusterArn: ptr("cluster").(*string),
ContainerInstanceArn: ptr("containerInstance").(*string),
MessageId: ptr("mid").(*string),
UpdateInfo: &ecsacs.UpdateInfo{
Location: ptr("https://s3.amazonaws.com/amazon-ecs-agent/update.tar").(*string),
Signature: ptr("6caeef375a080e3241781725b357890758d94b15d7ce63f6b2ff1cb5589f2007").(*string),
},
})
if writtenFile.String() != "update-tar-data" {
t.Error("Incorrect data written")
}
u.performUpdateHandler(statemanager.NewNoopStateManager(), engine.NewTaskEngine(cfg))(&ecsacs.PerformUpdateMessage{
ClusterArn: ptr("cluster").(*string),
ContainerInstanceArn: ptr("containerInstance").(*string),
MessageId: ptr("mid2").(*string),
UpdateInfo: &ecsacs.UpdateInfo{
Location: ptr("https://s3.amazonaws.com/amazon-ecs-agent/update.tar").(*string),
Signature: ptr("c54518806ff4d14b680c35784113e1e7478491fe").(*string),
},
})
}
开发者ID:dockerstack,项目名称:amazon-ecs-agent,代码行数:46,代码来源:updater_test.go
示例19: NewDockerTaskEngine
// NewDockerTaskEngine returns a created, but uninitialized, DockerTaskEngine.
// The distinction between created and initialized is that when created it may
// be serialized/deserialized, but it will not communicate with docker until it
// is also initialized.
func NewDockerTaskEngine(cfg *config.Config, client DockerClient, credentialsManager credentials.Manager) *DockerTaskEngine {
dockerTaskEngine := &DockerTaskEngine{
cfg: cfg,
client: client,
saver: statemanager.NewNoopStateManager(),
state: dockerstate.NewDockerTaskEngineState(),
managedTasks: make(map[string]*managedTask),
taskStopGroup: utilsync.NewSequentialWaitGroup(),
containerEvents: make(chan api.ContainerStateChange),
taskEvents: make(chan api.TaskStateChange),
credentialsManager: credentialsManager,
}
return dockerTaskEngine
}
开发者ID:witsoej,项目名称:amazon-ecs-agent,代码行数:22,代码来源:docker_task_engine.go
示例20: initializeStateManager
func initializeStateManager(cfg *config.Config, taskEngine engine.TaskEngine, cluster, containerInstanceArn, savedInstanceID *string) (statemanager.StateManager, error) {
if !cfg.Checkpoint {
return statemanager.NewNoopStateManager(), nil
}
stateManager, err := statemanager.NewStateManager(cfg,
statemanager.AddSaveable("TaskEngine", taskEngine),
statemanager.AddSaveable("ContainerInstanceArn", containerInstanceArn),
statemanager.AddSaveable("Cluster", cluster),
statemanager.AddSaveable("EC2InstanceID", savedInstanceID),
//The ACSSeqNum field is retained for compatibility with statemanager.EcsDataVersion 4 and
//can be removed in the future with a version bump.
statemanager.AddSaveable("ACSSeqNum", 1),
)
if err != nil {
return nil, err
}
return stateManager, nil
}
开发者ID:umaptechnologies,项目名称:amazon-ecs-agent,代码行数:18,代码来源:agent.go
注:本文中的github.com/aws/amazon-ecs-agent/agent/statemanager.NewNoopStateManager函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论