本文整理汇总了Golang中github.com/aws/amazon-ecs-agent/agent/statemanager.NewNoopStateManager函数的典型用法代码示例。如果您正苦于以下问题:Golang NewNoopStateManager函数的具体用法?Golang NewNoopStateManager怎么用?Golang NewNoopStateManager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewNoopStateManager函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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")
}
}
示例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")
}
}
示例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()
}
示例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)
}
示例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())
}
}
示例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
}
示例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():
}
}
示例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)
}
}
示例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")
}
}
示例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")
}
}
示例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():
}
}
示例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")
}
}
示例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
}
示例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
}
示例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),
})
}