當前位置: 首頁>>代碼示例>>Golang>>正文


Golang watch.FakeWatcher類代碼示例

本文整理匯總了Golang中k8s/io/kubernetes/pkg/watch.FakeWatcher的典型用法代碼示例。如果您正苦於以下問題:Golang FakeWatcher類的具體用法?Golang FakeWatcher怎麽用?Golang FakeWatcher使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了FakeWatcher類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: register

func (wd *WatcherDispatcher) register(watcher *watch.FakeWatcher) {
    wd.Lock()
    defer wd.Unlock()
    wd.watchers = append(wd.watchers, watcher)
    for _, event := range wd.eventsSoFar {
        watcher.Action(event.Type, event.Object)
    }
}
開發者ID:bryk,項目名稱:kubernetes,代碼行數:8,代碼來源:test_helper.go

示例2: TestReflectorListAndWatch

func TestReflectorListAndWatch(t *testing.T) {
    createdFakes := make(chan *watch.FakeWatcher)

    // The ListFunc says that it's at revision 1. Therefore, we expect our WatchFunc
    // to get called at the beginning of the watch with 1, and again with 3 when we
    // inject an error.
    expectedRVs := []string{"1", "3"}
    lw := &testLW{
        WatchFunc: func(options api.ListOptions) (watch.Interface, error) {
            rv := options.ResourceVersion
            fw := watch.NewFake()
            if e, a := expectedRVs[0], rv; e != a {
                t.Errorf("Expected rv %v, but got %v", e, a)
            }
            expectedRVs = expectedRVs[1:]
            // channel is not buffered because the for loop below needs to block. But
            // we don't want to block here, so report the new fake via a go routine.
            go func() { createdFakes <- fw }()
            return fw, nil
        },
        ListFunc: func() (runtime.Object, error) {
            return &api.PodList{ListMeta: unversioned.ListMeta{ResourceVersion: "1"}}, nil
        },
    }
    s := NewFIFO(MetaNamespaceKeyFunc)
    r := NewReflector(lw, &api.Pod{}, s, 0)
    go r.ListAndWatch(wait.NeverStop)

    ids := []string{"foo", "bar", "baz", "qux", "zoo"}
    var fw *watch.FakeWatcher
    for i, id := range ids {
        if fw == nil {
            fw = <-createdFakes
        }
        sendingRV := strconv.FormatUint(uint64(i+2), 10)
        fw.Add(&api.Pod{ObjectMeta: api.ObjectMeta{Name: id, ResourceVersion: sendingRV}})
        if sendingRV == "3" {
            // Inject a failure.
            fw.Stop()
            fw = nil
        }
    }

    // Verify we received the right ids with the right resource versions.
    for i, id := range ids {
        pod := s.Pop().(*api.Pod)
        if e, a := id, pod.Name; e != a {
            t.Errorf("%v: Expected %v, got %v", i, e, a)
        }
        if e, a := strconv.FormatUint(uint64(i+2), 10), pod.ResourceVersion; e != a {
            t.Errorf("%v: Expected %v, got %v", i, e, a)
        }
    }

    if len(expectedRVs) != 0 {
        t.Error("called watchStarter an unexpected number of times")
    }
}
開發者ID:odacremolbap,項目名稱:kubernetes,代碼行數:58,代碼來源:reflector_test.go

示例3: RegisterCopyOnUpdate

func RegisterCopyOnUpdate(resource string, client *core.Fake, watcher *watch.FakeWatcher) chan runtime.Object {
    objChan := make(chan runtime.Object, 100)
    client.AddReactor("update", resource, func(action core.Action) (bool, runtime.Object, error) {
        updateAction := action.(core.UpdateAction)
        obj := updateAction.GetObject()
        go func() {
            watcher.Modify(obj)
            objChan <- obj
        }()
        return true, obj, nil
    })
    return objChan
}
開發者ID:astropuffin,項目名稱:kubernetes,代碼行數:13,代碼來源:secret_controller_test.go

示例4: RegisterCopyOnCreate

func RegisterCopyOnCreate(resource string, client *fake_federation_release_1_4.Clientset, watcher *watch.FakeWatcher) chan runtime.Object {
    objChan := make(chan runtime.Object, 100)
    client.AddReactor("create", resource, func(action core.Action) (bool, runtime.Object, error) {
        createAction := action.(core.CreateAction)
        obj := createAction.GetObject()
        go func() {
            watcher.Add(obj)
            objChan <- obj
        }()
        return true, obj, nil
    })
    return objChan
}
開發者ID:invenfantasy,項目名稱:kubernetes,代碼行數:13,代碼來源:namespace_controller_test.go

示例5: TestWatchRead


//.........這裏部分代碼省略.........
        },
        // TODO: yaml stream serialization requires that RawExtension.MarshalJSON
        // be able to understand nested encoding (since yaml calls json.Marshal
        // rather than yaml.Marshal, which results in the raw bytes being in yaml).
        // Same problem as thirdparty object.
        /*{
            Accept:              "application/yaml",
            ExpectedContentType: "application/yaml;stream=watch",
            MediaType:           "application/yaml",
        },*/
        {
            Accept:              "application/vnd.kubernetes.protobuf",
            ExpectedContentType: "application/vnd.kubernetes.protobuf;stream=watch",
            MediaType:           "application/vnd.kubernetes.protobuf",
        },
        {
            Accept:              "application/vnd.kubernetes.protobuf;stream=watch",
            ExpectedContentType: "application/vnd.kubernetes.protobuf;stream=watch",
            MediaType:           "application/vnd.kubernetes.protobuf",
        },
    }
    protocols := []struct {
        name        string
        selfFraming bool
        fn          func(string) (io.ReadCloser, string)
    }{
        {name: "http", fn: connectHTTP},
        {name: "websocket", selfFraming: true, fn: connectWebSocket},
    }

    for _, protocol := range protocols {
        for _, test := range testCases {
            serializer, ok := api.Codecs.StreamingSerializerForMediaType(test.MediaType, nil)
            if !ok {
                t.Fatal(serializer)
            }

            r, contentType := protocol.fn(test.Accept)
            defer r.Close()

            if contentType != "__default__" && contentType != test.ExpectedContentType {
                t.Errorf("Unexpected content type: %#v", contentType)
            }
            objectSerializer, ok := api.Codecs.SerializerForMediaType(test.MediaType, nil)
            if !ok {
                t.Fatal(objectSerializer)
            }
            objectCodec := api.Codecs.DecoderToVersion(objectSerializer, testInternalGroupVersion)

            var fr io.ReadCloser = r
            if !protocol.selfFraming {
                fr = serializer.Framer.NewFrameReader(r)
            }
            d := streaming.NewDecoder(fr, serializer)

            var w *watch.FakeWatcher
            for w == nil {
                w = simpleStorage.Watcher()
                time.Sleep(time.Millisecond)
            }

            for i, item := range podWatchTestTable {
                action, object := item.t, item.obj
                name := fmt.Sprintf("%s-%s-%d", protocol.name, test.MediaType, i)

                // Send
                w.Action(action, object)
                // Test receive
                var got versioned.Event
                _, _, err := d.Decode(nil, &got)
                if err != nil {
                    t.Fatalf("%s: Unexpected error: %v", name, err)
                }
                if got.Type != string(action) {
                    t.Errorf("%s: Unexpected type: %v", name, got.Type)
                }

                gotObj, err := runtime.Decode(objectCodec, got.Object.Raw)
                if err != nil {
                    t.Fatalf("%s: Decode error: %v", name, err)
                }
                if _, err := api.GetReference(gotObj); err != nil {
                    t.Errorf("%s: Unable to construct reference: %v", name, err)
                }
                if e, a := object, gotObj; !api.Semantic.DeepEqual(e, a) {
                    t.Errorf("%s: different: %s", name, diff.ObjectDiff(e, a))
                }
            }
            w.Stop()

            var got versioned.Event
            _, _, err := d.Decode(nil, &got)
            if err == nil {
                t.Errorf("Unexpected non-error")
            }

            r.Close()
        }
    }
}
開發者ID:ncdc,項目名稱:kubernetes,代碼行數:101,代碼來源:watch_test.go


注:本文中的k8s/io/kubernetes/pkg/watch.FakeWatcher類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。