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


Golang StoreAdapter.List方法代碼示例

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


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

示例1: Walk

func Walk(store storeadapter.StoreAdapter, dirKey string, callback func(storeadapter.StoreNode)) {
	nodes, err := store.List(dirKey)
	if err != nil {
		return
	}

	for _, node := range nodes {
		if node.Key == "/_etcd" {
			continue
		}
		if node.Dir {
			Walk(store, node.Key, callback)
		} else {
			callback(node)
		}
	}
}
開發者ID:Zhann,項目名稱:hm9000,代碼行數:17,代碼來源:dump.go

示例2:

	AfterEach(func() {
		etcdAdapter.Disconnect()
	})

	Describe("Saving desired state ", func() {
		BeforeEach(func() {
			err := store.SaveDesiredState([]models.DesiredAppState{
				app1.DesiredState(0),
				app2.DesiredState(0),
			})
			Ω(err).ShouldNot(HaveOccured())
		})

		It("can stores the passed in desired state", func() {
			nodes, err := etcdAdapter.List("/desired")
			Ω(err).ShouldNot(HaveOccured())
			Ω(nodes).Should(HaveLen(2))
			Ω(nodes).Should(ContainElement(storeadapter.StoreNode{
				Key:   "/desired/" + app1.AppGuid + "-" + app1.AppVersion,
				Value: app1.DesiredState(0).ToJson(),
				TTL:   conf.DesiredStateTTL - 1,
			}))
			Ω(nodes).Should(ContainElement(storeadapter.StoreNode{
				Key:   "/desired/" + app2.AppGuid + "-" + app2.AppVersion,
				Value: app2.DesiredState(0).ToJson(),
				TTL:   conf.DesiredStateTTL - 1,
			}))
		})
	})
開發者ID:Zhann,項目名稱:hm9000,代碼行數:29,代碼來源:desired_state_test.go

示例3:

	AfterEach(func() {
		etcdAdapter.Disconnect()
	})

	Describe("Saving actual state ", func() {
		BeforeEach(func() {
			err := store.SaveActualState([]models.InstanceHeartbeat{
				heartbeat1,
				heartbeat2,
			})
			Ω(err).ShouldNot(HaveOccured())
		})

		It("can stores the passed in actual state", func() {
			nodes, err := etcdAdapter.List("/actual")
			Ω(err).ShouldNot(HaveOccured())
			Ω(nodes).Should(HaveLen(2))
			Ω(nodes).Should(ContainElement(storeadapter.StoreNode{
				Key:   "/actual/" + heartbeat1.InstanceGuid,
				Value: heartbeat1.ToJson(),
				TTL:   conf.HeartbeatTTL - 1,
			}))
			Ω(nodes).Should(ContainElement(storeadapter.StoreNode{
				Key:   "/actual/" + heartbeat2.InstanceGuid,
				Value: heartbeat2.ToJson(),
				TTL:   conf.HeartbeatTTL - 1,
			}))
		})
	})
開發者ID:Zhann,項目名稱:hm9000,代碼行數:29,代碼來源:actual_state_test.go

示例4:

							data[i] = storeadapter.StoreNode{
								Key:   "/actual/" + instanceHeartbeat.InstanceGuid,
								Value: instanceHeartbeat.ToJson(),
								TTL:   0,
							}
						}

						writeTime := b.Time("writing to the store", func() {
							err := storeAdapter.Set(data)
							Ω(err).ShouldNot(HaveOccured())
						}, StorePerformanceReport{StoreType: storeType, NumStoreNodes: nodes, NumApps: numApps, Subject: "write performance"})

						Ω(writeTime.Seconds()).Should(BeNumerically("<=", 30))

						readTime := b.Time("reading from the store", func() {
							values, err := storeAdapter.List("/actual")
							Ω(err).ShouldNot(HaveOccured())
							Ω(len(values)).Should(Equal(numApps), "Didn't find the correct number of entries in the store")
						}, StorePerformanceReport{StoreType: storeType, NumStoreNodes: nodes, NumApps: numApps, Subject: "read performance"})

						Ω(readTime.Seconds()).Should(BeNumerically("<=", 3))

						usage, err := storeRunner.DiskUsage()
						Ω(err).ShouldNot(HaveOccured())
						b.RecordValue("disk usage in MB", float64(usage)/1024.0/1024.0, StorePerformanceReport{StoreType: storeType, NumStoreNodes: nodes, NumApps: numApps, Subject: "disk usage"})
					}, 5)
				}
			})
		}
	}
})
開發者ID:Zhann,項目名稱:hm9000,代碼行數:31,代碼來源:store_performance_test.go


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