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


Golang StateDriver.ClearState方法代碼示例

本文整理匯總了Golang中github.com/contiv/netplugin/core.StateDriver.ClearState方法的典型用法代碼示例。如果您正苦於以下問題:Golang StateDriver.ClearState方法的具體用法?Golang StateDriver.ClearState怎麽用?Golang StateDriver.ClearState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/contiv/netplugin/core.StateDriver的用法示例。


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

示例1: commonTestStateDriverWatchAllStateModify

func commonTestStateDriverWatchAllStateModify(t *testing.T, d core.StateDriver) {
	state := &testState{IntField: 1234, StrField: "testString"}
	modState := &testState{IntField: 5678, StrField: "modString"}
	baseKey := "modify"
	key := baseKey + "/testKeyWatchAll"

	err := d.WriteState(key, state, json.Marshal)
	if err != nil {
		t.Fatalf("failed to write state. Error: %s", err)
	}
	defer func() {
		d.ClearState(key)
	}()

	recvErr := make(chan error, 1)
	stateCh := make(chan core.WatchState, 1)
	timer := time.After(waitTimeout)

	go func(rsps chan core.WatchState, retErr chan error) {
		err := d.WatchAllState(baseKey, state, json.Unmarshal, stateCh)
		if err != nil {
			retErr <- err
			return
		}
	}(stateCh, recvErr)

	// trigger modify after a slight pause to ensure that events are not missed
	time.Sleep(time.Second)
	err = d.WriteState(key, modState, json.Marshal)
	if err != nil {
		t.Fatalf("failed to write state. Error: %s", err)
	}

for_label:
	for {
		select {
		case watchState := <-stateCh:
			s := watchState.Curr.(*testState)
			if s.IntField != modState.IntField || s.StrField != modState.StrField {
				t.Fatalf("Watch state mismatch. Expctd: %+v, Rcvd: %+v", modState, s)
			}
			if watchState.Prev == nil {
				t.Fatalf("Received a modify event without previous state value set.")
			}
			s = watchState.Prev.(*testState)
			if s.IntField != state.IntField || s.StrField != state.StrField {
				t.Fatalf("Watch state mismatch. Expctd: %+v, Rcvd: %+v", state, s)
			}
			break for_label
		case err := <-recvErr:
			t.Fatalf("Watch failed. Error: %s", err)
			break for_label
		case <-timer:
			t.Fatalf("timed out waiting for events")
			break for_label
		}
	}
}
開發者ID:rtrentin73,項目名稱:netplugin,代碼行數:58,代碼來源:etcdstatedriver_test.go

示例2: commonTestStateDriverClearState

func commonTestStateDriverClearState(t *testing.T, d core.StateDriver) {
	state := &testState{IntField: 1234, StrField: "testString"}
	key := "testKeyClear"

	err := d.WriteState(key, state, json.Marshal)
	if err != nil {
		t.Fatalf("failed to write state. Error: %s", err)
	}

	err = d.ClearState(key)
	if err != nil {
		t.Fatalf("failed to clear state. Error: %s", err)
	}
}
開發者ID:rtrentin73,項目名稱:netplugin,代碼行數:14,代碼來源:etcdstatedriver_test.go

示例3: commonTestStateDriverReadStateAfterClear

func commonTestStateDriverReadStateAfterClear(t *testing.T, d core.StateDriver) {
	state := &testState{IntField: 1234, StrField: "testString"}
	key := "testKeyReadClear"

	err := d.WriteState(key, state, json.Marshal)
	if err != nil {
		t.Fatalf("failed to write state. Error: %s", err)
	}

	err = d.ClearState(key)
	if err != nil {
		t.Fatalf("failed to clear state. Error: %s", err)
	}

	readState := &testState{}
	err = d.ReadState(key, readState, json.Unmarshal)
	if err == nil {
		t.Fatalf("Able to read cleared state!. Key: %s, Value: %v",
			key, readState)
	}
}
開發者ID:rtrentin73,項目名稱:netplugin,代碼行數:21,代碼來源:etcdstatedriver_test.go


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