예제 #1
0
	BeforeEach(func() {
		routingTable = models.NewRoutingTable()
	})

	Describe("Set", func() {
		Context("when a new entry is added", func() {
			It("adds the entry", func() {
				routingKey := models.RoutingKey{12}
				routingTableEntry := models.RoutingTableEntry{
					Backends: map[models.BackendServerInfo]struct{}{
						models.BackendServerInfo{"some-ip", 1234}: struct{}{},
					},
				}
				ok := routingTable.Set(routingKey, routingTableEntry)
				Expect(ok).To(BeTrue())
				Expect(routingTable.Get(routingKey)).To(Equal(routingTableEntry))
				Expect(routingTable.Size()).To(Equal(1))
			})
		})

		Context("when setting pre-existing routing key", func() {
			var (
				routingKey                models.RoutingKey
				existingRoutingTableEntry models.RoutingTableEntry
			)
			BeforeEach(func() {
				routingKey = models.RoutingKey{12}
				existingRoutingTableEntry = models.RoutingTableEntry{
					Backends: map[models.BackendServerInfo]struct{}{
						models.BackendServerInfo{"some-ip-1", 1234}: struct{}{},
						models.BackendServerInfo{"some-ip-2", 1234}: struct{}{},
예제 #2
0
	)
	var (
		routingTable               *models.RoutingTable
		existingRoutingKey1        models.RoutingKey
		existingRoutingTableEntry1 models.RoutingTableEntry
		existingRoutingKey2        models.RoutingKey
		existingRoutingTableEntry2 models.RoutingTableEntry
		updater                    routing_table.Updater
		fakeConfigurer             *fakes.FakeRouterConfigurer
		fakeRoutingApiClient       *fake_routing_api.FakeClient
		fakeTokenFetcher           *testTokenFetcher.FakeTokenFetcher
		tcpEvent                   routing_api.TcpEvent
	)

	verifyRoutingTableEntry := func(key models.RoutingKey, entry models.RoutingTableEntry) {
		existingEntry := routingTable.Get(key)
		Expect(existingEntry).NotTo(BeZero())
		Expect(existingEntry).Should(Equal(entry))
	}

	BeforeEach(func() {
		fakeConfigurer = new(fakes.FakeRouterConfigurer)
		fakeRoutingApiClient = new(fake_routing_api.FakeClient)
		fakeTokenFetcher = &testTokenFetcher.FakeTokenFetcher{}
		token := &token_fetcher.Token{
			AccessToken: "access_token",
			ExpireTime:  5,
		}
		fakeTokenFetcher.FetchTokenReturns(token, nil)
		tmpRoutingTable := models.NewRoutingTable()
		routingTable = &tmpRoutingTable