Beispiel #1
0
func getPoolInfo(repo *redis.RemoteRepository) Pool {
	pool := Pool{}

	availableNodes := []string{}
	for _, instance := range repo.AvailableInstances() {
		availableNodes = append(availableNodes, instance.Host)
	}

	pool.Count = len(availableNodes)

	for _, node := range availableNodes {
		cluster := []string{node}
		pool.Clusters = append(pool.Clusters, cluster)
	}

	return pool
}
					allocatedInstances, err := repo.AllInstances()
					Expect(err).ToNot(HaveOccurred())
					Expect(repo.InstanceLimit()).To(Equal(3))
					Expect(len(allocatedInstances)).To(Equal(1))
					Expect(*allocatedInstances[0]).To(Equal(*statefile.AllocatedInstances[0]))
				})

				It("adds new nodes from config", func() {
					nodes := append(config.RedisConfiguration.Dedicated.Nodes, "10.0.0.4")
					config.RedisConfiguration.Dedicated.Nodes = nodes

					repo, err := redis.NewRemoteRepository(fakeAgentClient, config, logger)
					Expect(err).ToNot(HaveOccurred())

					availableInstances := repo.AvailableInstances()
					Expect(len(availableInstances)).To(Equal(3))
					Expect(availableInstances[2].Host).To(Equal("10.0.0.4"))
				})

				It("saves the statefile", func() {
					nodes := append(config.RedisConfiguration.Dedicated.Nodes, "10.0.0.4")
					config.RedisConfiguration.Dedicated.Nodes = nodes

					_, err := redis.NewRemoteRepository(fakeAgentClient, config, logger)
					Expect(err).ToNot(HaveOccurred())

					state := getStatefileContents(statefilePath)
					Expect(len(state.AvailableInstances)).To(Equal(3))
					Expect(state.AvailableInstances[2].Host).To(Equal("10.0.0.4"))
				})