Exemplo n.º 1
0
	})

	Describe("Next", func() {
		It("performs round-robin through the endpoints", func() {
			e1 := route.NewEndpoint("", "1.2.3.4", 5678, "", nil, -1, "")
			e2 := route.NewEndpoint("", "5.6.7.8", 1234, "", nil, -1, "")
			e3 := route.NewEndpoint("", "1.2.7.8", 1234, "", nil, -1, "")
			endpoints := []*route.Endpoint{e1, e2, e3}

			for _, e := range endpoints {
				pool.Put(e)
			}

			counts := make([]int, len(endpoints))

			iter := pool.Endpoints("")

			loops := 50
			for i := 0; i < len(endpoints)*loops; i += 1 {
				n := iter.Next()
				for j, e := range endpoints {
					if e == n {
						counts[j]++
						break
					}
				}
			}

			for i := 0; i < len(endpoints); i++ {
				Expect(counts[i]).To(Equal(loops))
			}
Exemplo n.º 2
0
			Expect(pool.Put(endpoint2)).To(BeTrue())
		})

		Context("with modification tags", func() {
			var modTag2 models.ModificationTag

			BeforeEach(func() {
				modTag2 = models.ModificationTag{Guid: "abc"}
				endpoint1 := route.NewEndpoint("", "1.2.3.4", 5678, "", nil, -1, "", modTag)
				Expect(pool.Put(endpoint1)).To(BeTrue())
			})

			It("updates an endpoint with modification tag", func() {
				endpoint := route.NewEndpoint("", "1.2.3.4", 5678, "", nil, -1, "", modTag2)
				Expect(pool.Put(endpoint)).To(BeTrue())
				Expect(pool.Endpoints("").Next().ModificationTag).To(Equal(modTag2))
			})

			Context("when modification_tag is older", func() {
				BeforeEach(func() {
					modTag.Increment()
					endpoint := route.NewEndpoint("", "1.2.3.4", 5678, "", nil, -1, "", modTag2)
					pool.Put(endpoint)
				})

				It("doesnt update an endpoint", func() {
					olderModTag := models.ModificationTag{Guid: "abc"}
					endpoint := route.NewEndpoint("", "1.2.3.4", 5678, "", nil, -1, "", olderModTag)

					Expect(pool.Put(endpoint)).To(BeFalse())
					Expect(pool.Endpoints("").Next().ModificationTag).To(Equal(modTag2))