当前位置: 首页>>代码示例>>Golang>>正文


Golang hasher.NewHasher函数代码示例

本文整理汇总了Golang中trafficcontroller/hasher.NewHasher函数的典型用法代码示例。如果您正苦于以下问题:Golang NewHasher函数的具体用法?Golang NewHasher怎么用?Golang NewHasher使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewHasher函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestKeepAliveWithMultipleAZs

func TestKeepAliveWithMultipleAZs(t *testing.T) {
	keepAliveChan1 := make(chan []byte)
	keepAliveChan2 := make(chan []byte)
	go KeepAliveServer("localhost:62032", keepAliveChan1)
	go KeepAliveServer("localhost:62033", keepAliveChan2)

	proxy := NewProxy(
		"localhost:62034",
		[]*hasher.Hasher{
			hasher.NewHasher([]string{"localhost:62032"}),
			hasher.NewHasher([]string{"localhost:62033"}),
		},
		testhelpers.SuccessfulAuthorizer,
		loggertesthelper.Logger(),
	)
	go proxy.Start()
	WaitForServerStart("62032", "/")

	KeepAliveClient(t, "62034", "/?app=myServerApp1")

	select {
	case data := <-keepAliveChan1:
		assert.Equal(t, string(data), "keep alive")
	case <-time.After(1 * time.Second):
		t.Error("Did not receive response within one second")
	}
	select {
	case data := <-keepAliveChan2:
		assert.Equal(t, string(data), "keep alive")
	case <-time.After(1 * time.Second):
		t.Error("Did not receive response within one second")
	}
}
开发者ID:james-masson,项目名称:loggregator,代码行数:33,代码来源:output_proxy_test.go

示例2: TestProxyingWithMultipleAZs

func TestProxyingWithMultipleAZs(t *testing.T) {
	go Server("localhost:62027", "Hello World from the server 1 - AZ1", 1)
	go Server("localhost:62028", "Hello World from the server 2 - AZ1", 1)
	go Server("localhost:62029", "Hello World from the server 1 - AZ2", 1)
	go Server("localhost:62030", "Hello World from the server 2 - AZ2", 1)

	proxy := NewProxy(
		"localhost:62031",
		[]*hasher.Hasher{
			hasher.NewHasher([]string{"localhost:62027", "localhost:62028"}),
			hasher.NewHasher([]string{"localhost:62029", "localhost:62030"}),
		},
		testhelpers.SuccessfulAuthorizer,
		loggertesthelper.Logger(),
	)
	go proxy.Start()
	WaitForServerStart("62027", "/")

	receivedChan := Client(t, "62031", "/?app=0")
	messages := ""
	for message := range receivedChan {
		messages = messages + string(message)
	}
	assert.Contains(t, messages, "Hello World from the server 1 - AZ1")
	assert.Contains(t, messages, "Hello World from the server 1 - AZ2")

	receivedChan = Client(t, "62031", "/?app=1")
	messages = ""
	for message := range receivedChan {
		messages = messages + string(message)
	}
	assert.Contains(t, messages, "Hello World from the server 2 - AZ1")
	assert.Contains(t, messages, "Hello World from the server 2 - AZ2")
}
开发者ID:james-masson,项目名称:loggregator,代码行数:34,代码来源:output_proxy_test.go

示例3: TestProxyWhenAuthorizationFailsThroughQueryParams

func TestProxyWhenAuthorizationFailsThroughQueryParams(t *testing.T) {
	proxy := NewProxy(
		"localhost:62062",
		[]*hasher.Hasher{
			hasher.NewHasher([]string{"localhost:62032"}),
		},
		testhelpers.SuccessfulAuthorizer,
		loggertesthelper.Logger(),
	)
	go proxy.Start()
	time.Sleep(time.Millisecond * 50)

	config, err := websocket.NewConfig("ws://localhost:62061/?app=myApp&authorization="+url.QueryEscape(testhelpers.INVALID_AUTHENTICATION_TOKEN), "http://localhost")
	assert.NoError(t, err)
	receivedChan := ClientWithAuth(t, "62062", "/?app=myApp", config)

	select {
	case data := <-receivedChan:
		messagetesthelpers.AssertProtoBufferMessageEquals(t, "Error: Invalid authorization", data)
	case <-time.After(1 * time.Second):
		t.Error("Did not receive response within one second")
	}

	_, stillOpen := <-receivedChan
	assert.False(t, stillOpen)
}
开发者ID:james-masson,项目名称:loggregator,代码行数:26,代码来源:output_proxy_test.go

示例4: TestProxyWithoutAuthorization

func TestProxyWithoutAuthorization(t *testing.T) {
	proxy := NewProxy(
		"localhost:62061",
		[]*hasher.Hasher{
			hasher.NewHasher([]string{"localhost:62032"}),
		},
		testhelpers.SuccessfulAuthorizer,
		loggertesthelper.Logger(),
	)
	go proxy.Start()
	time.Sleep(time.Millisecond * 50)

	config, err := websocket.NewConfig("ws://localhost:62061/?app=myApp", "http://localhost")
	assert.NoError(t, err)
	receivedChan := ClientWithAuth(t, "62061", "/?app=myApp", config)

	select {
	case data := <-receivedChan:
		messagetesthelpers.AssertProtoBufferMessageEquals(t, "Error: Authorization not provided", data)
	case <-time.After(1 * time.Second):
		t.Error("Did not receive response within one second")
	}

	_, stillOpen := <-receivedChan
	assert.False(t, stillOpen)
}
开发者ID:james-masson,项目名称:loggregator,代码行数:26,代码来源:output_proxy_test.go

示例5: TestProxyingWithHashingBetweenServers

func TestProxyingWithHashingBetweenServers(t *testing.T) {
	go Server("localhost:62024", "Hello World from the server 1", 1)
	go Server("localhost:62025", "Hello World from the server 2", 1)

	proxy := NewProxy(
		"localhost:62026",
		[]*hasher.Hasher{hasher.NewHasher([]string{"localhost:62024", "localhost:62025"})},
		testhelpers.SuccessfulAuthorizer,
		loggertesthelper.Logger(),
	)
	go proxy.Start()
	WaitForServerStart("62024", "/")

	receivedChan := Client(t, "62026", "/?app=0")

	select {
	case data := <-receivedChan:
		assert.Equal(t, string(data), "Hello World from the server 1")
	case <-time.After(1 * time.Second):
		t.Error("Did not receive response within one second")
	}

	receivedChan = Client(t, "62026", "/?app=1")

	select {
	case data := <-receivedChan:
		assert.Equal(t, string(data), "Hello World from the server 2")
	case <-time.After(1 * time.Second):
		t.Error("Did not receive response within one second")
	}
}
开发者ID:james-masson,项目名称:loggregator,代码行数:31,代码来源:output_proxy_test.go

示例6: TestThatItIgnoresBadMessages

func TestThatItIgnoresBadMessages(t *testing.T) {
	listener, dataChannel := agentlistener.NewAgentListener("localhost:9996", logger)
	go listener.Start()

	loggregatorServers := []string{"localhost:9996"}
	hasher := hasher.NewHasher(loggregatorServers)
	r, err := NewRouter("localhost:3455", hasher, newCfConfig(), logger)
	assert.NoError(t, err)

	go r.Start(logger)
	time.Sleep(50 * time.Millisecond)

	lc := loggregatorclient.NewLoggregatorClient("localhost:3455", logger, loggregatorclient.DefaultBufferSize)
	lc.Send([]byte("This is poorly formatted"))

	logEmitter, _ := emitter.NewEmitter("localhost:3455", "ROUTER", "42", "secret", logger)
	logEmitter.Emit("my_awesome_app", "Hello World")

	received := <-dataChannel
	receivedEnvelope := &logmessage.LogEnvelope{}
	proto.Unmarshal(received, receivedEnvelope)

	assert.Equal(t, receivedEnvelope.GetLogMessage().GetAppId(), "my_awesome_app")
	assert.Equal(t, string(receivedEnvelope.GetLogMessage().GetMessage()), "Hello World")
}
开发者ID:nkuacac,项目名称:loggregator,代码行数:25,代码来源:input_router_test.go

示例7: TestThatItWorksWithTwoLoggregators

func TestThatItWorksWithTwoLoggregators(t *testing.T) {
	listener1, dataChan1 := agentlistener.NewAgentListener("localhost:9998", logger)
	go listener1.Start()

	listener2, dataChan2 := agentlistener.NewAgentListener("localhost:9997", logger)
	go listener2.Start()

	loggregatorServers := []string{"localhost:9998", "localhost:9997"}
	hasher := hasher.NewHasher(loggregatorServers)
	rt, err := NewRouter("localhost:3457", hasher, newCfConfig(), logger)
	assert.NoError(t, err)

	go rt.Start(logger)
	time.Sleep(50 * time.Millisecond)

	logEmitter, _ := emitter.NewEmitter("localhost:3457", "ROUTER", "42", "secret", logger)
	logEmitter.Emit("2", "My message")

	receivedData := <-dataChan1
	receivedEnvelope := &logmessage.LogEnvelope{}
	proto.Unmarshal(receivedData, receivedEnvelope)

	assert.Equal(t, receivedEnvelope.GetLogMessage().GetAppId(), "2")
	assert.Equal(t, string(receivedEnvelope.GetLogMessage().GetMessage()), "My message")

	logEmitter.Emit("1", "Another message")

	receivedData = <-dataChan2
	receivedEnvelope = &logmessage.LogEnvelope{}
	proto.Unmarshal(receivedData, receivedEnvelope)

	assert.Equal(t, receivedEnvelope.GetLogMessage().GetAppId(), "1")
	assert.Equal(t, string(receivedEnvelope.GetLogMessage().GetMessage()), "Another message")
}
开发者ID:nkuacac,项目名称:loggregator,代码行数:34,代码来源:input_router_test.go

示例8: makeIncomingRouter

func makeIncomingRouter(config *Config, logger *gosteno.Logger) *trafficcontroller.Router {
	serversForZone := config.Loggregators[config.Zone]
	servers := make([]string, len(serversForZone))
	for index, server := range serversForZone {
		logger.Debugf("Incoming Router Startup: Forwarding messages from source to loggregator server [%v] at %v", index, net.JoinHostPort(server, strconv.FormatUint(uint64(config.IncomingPort), 10)))
		servers[index] = net.JoinHostPort(serversForZone[index], strconv.FormatUint(uint64(config.IncomingPort), 10))
	}
	logger.Debugf("Incoming Router Startup: Loggregator Servers in the zone %s: %v", config.Zone, servers)

	h := hasher.NewHasher(servers)
	logger.Debugf("Incoming Router Startup: Hashed Loggregator Server in the zone: %v", h.LoggregatorServers())
	logger.Debugf("Incoming Router Startup: Going to start incoming router on %v", config.Host)
	router, err := trafficcontroller.NewRouter(config.Host, h, config.Config, logger)
	if err != nil {
		panic(err)
	}
	return router
}
开发者ID:uabassguy,项目名称:loggregator,代码行数:18,代码来源:main.go

示例9: makeHashers

func makeHashers(loggregators map[string][]string, outgoingPort uint32, logger *gosteno.Logger) []*hasher.Hasher {
	counter := 0
	hashers := make([]*hasher.Hasher, 0, len(loggregators))
	for _, servers := range loggregators {
		logger.Debugf("Output Proxy Startup: Hashing servers: %v  Length: %d", servers, len(servers))

		if len(servers) == 0 {
			continue
		}

		for index, server := range servers {
			logger.Debugf("Output Proxy Startup: Forwarding messages to client from loggregator server [%v] at %v", index, net.JoinHostPort(server, strconv.FormatUint(uint64(outgoingPort), 10)))
			servers[index] = net.JoinHostPort(server, strconv.FormatUint(uint64(outgoingPort), 10))
		}
		hashers = hashers[:(counter + 1)]
		hashers[counter] = hasher.NewHasher(servers)
		counter++
	}
	return hashers
}
开发者ID:uabassguy,项目名称:loggregator,代码行数:20,代码来源:main.go

示例10: TestProxyingWithTwoMessages

func TestProxyingWithTwoMessages(t *testing.T) {
	go Server("localhost:62020", "Hello World from the server", 2)

	proxy := NewProxy(
		"localhost:62021",
		[]*hasher.Hasher{hasher.NewHasher([]string{"localhost:62020"})},
		testhelpers.SuccessfulAuthorizer,
		loggertesthelper.Logger(),
	)
	go proxy.Start()
	WaitForServerStart("62020", "/")

	receivedChan := Client(t, "62021", "/?app=myApp")

	messages := ""
	for message := range receivedChan {
		messages = messages + string(message)
	}
	assert.Contains(t, messages, "Hello World from the serverHello World from the server")
}
开发者ID:james-masson,项目名称:loggregator,代码行数:20,代码来源:output_proxy_test.go

示例11: TestProxyingWithAuthThroughQueryParam

func TestProxyingWithAuthThroughQueryParam(t *testing.T) {
	go Server("localhost:62038", "Hello World from the server", 1)

	proxy := NewProxy(
		"localhost:62022",
		[]*hasher.Hasher{hasher.NewHasher([]string{"localhost:62038"})},
		testhelpers.SuccessfulAuthorizer,
		loggertesthelper.Logger(),
	)
	go proxy.Start()
	WaitForServerStart("62038", "/")

	receivedChan := ClientWithQueryParamAuth(t, "62022", "/?app=myApp")

	select {
	case data := <-receivedChan:
		assert.Equal(t, string(data), "Hello World from the server")
	case <-time.After(1 * time.Second):
		t.Error("Did not receive response within one second")
	}
}
开发者ID:james-masson,项目名称:loggregator,代码行数:21,代码来源:output_proxy_test.go

示例12: TestThatItWorksWithOneLoggregator

func TestThatItWorksWithOneLoggregator(t *testing.T) {
	listener, dataChannel := agentlistener.NewAgentListener("localhost:9999", logger)
	go listener.Start()

	loggregatorServers := []string{"localhost:9999"}
	hasher := hasher.NewHasher(loggregatorServers)
	r, err := NewRouter("localhost:3456", hasher, newCfConfig(), logger)
	assert.NoError(t, err)

	go r.Start(logger)
	time.Sleep(50 * time.Millisecond)

	logEmitter, _ := emitter.NewEmitter("localhost:3456", "ROUTER", "42", "secret", logger)
	logEmitter.Emit("my_awesome_app", "Hello World")

	received := <-dataChannel

	receivedEnvelope := &logmessage.LogEnvelope{}
	proto.Unmarshal(received, receivedEnvelope)

	assert.Equal(t, receivedEnvelope.GetLogMessage().GetAppId(), "my_awesome_app")
	assert.Equal(t, string(receivedEnvelope.GetLogMessage().GetMessage()), "Hello World")
}
开发者ID:nkuacac,项目名称:loggregator,代码行数:23,代码来源:input_router_test.go

示例13: TestProxyWhenLogTargetisinvalid

func TestProxyWhenLogTargetisinvalid(t *testing.T) {
	proxy := NewProxy(
		"localhost:62060",
		[]*hasher.Hasher{
			hasher.NewHasher([]string{"localhost:62032"}),
		},
		testhelpers.SuccessfulAuthorizer,
		loggertesthelper.Logger(),
	)
	go proxy.Start()
	time.Sleep(time.Millisecond * 50)

	receivedChan := Client(t, "62060", "/invalid_target")

	select {
	case data := <-receivedChan:
		messagetesthelpers.AssertProtoBufferMessageEquals(t, "Error: Invalid target", data)
	case <-time.After(1 * time.Second):
		t.Error("Did not receive response within one second")
	}

	_, stillOpen := <-receivedChan
	assert.False(t, stillOpen)
}
开发者ID:james-masson,项目名称:loggregator,代码行数:24,代码来源:output_proxy_test.go

示例14:

	f.WebsocketConnection.Close()
}

var _ = Describe("OutPutProxy", func() {

	var fph *fakeProxyHandler
	var hashers []*hasher.Hasher
	var PORT = "62022"

	BeforeEach(func() {
		fph = &fakeProxyHandler{callParams: make([][]interface{}, 0)}
		NewProxyHandlerProvider = func(ws *websocket.Conn, logger *gosteno.Logger) websocketHandler {
			fph.WebsocketConnection = ws
			return fph
		}
		hashers = []*hasher.Hasher{hasher.NewHasher([]string{"localhost:62038"})}
		proxy := NewProxy(
			"localhost:"+PORT,
			hashers,
			testhelpers.SuccessfulAuthorizer,
			loggertesthelper.Logger(),
		)
		go proxy.Start()
	})

	Context("Auth Params", func() {
		It("Should Authenticate with Auth Query Params", func() {
			ClientWithQueryParamAuth(PORT, "/?app=myApp", testhelpers.VALID_AUTHENTICATION_TOKEN)

			callParams := fph.CallParams()
			Expect(callParams).To(HaveLen(1))
开发者ID:popeye17,项目名称:loggregator,代码行数:31,代码来源:output_proxy_test.go

示例15:

		AfterEach(func() {
			fakeServer.Close()
		})

		It("Proxies multiple messages", func() {
			fakeClient := &fakeClient{}
			handler := NewProxyHandler(
				fakeClient,
				loggertesthelper.Logger(),
			)

			handler.HandleWebSocket(
				"appId",
				"/dump",
				[]*hasher.Hasher{hasher.NewHasher([]string{fakeServer.Listener.Addr().String()})})

			Expect(fakeClient.ReceivedMessageTypes()).To(HaveLen(2))
			Expect(fakeClient.ReceivedMessages()).To(Equal([]string{"Message1", "Message2"}))
			Expect(fakeClient.ReceivedMessageTypes()).To(ContainElement(websocket.BinaryMessage))

		})

		It("Uses the Correct Request URI", func() {
			handler := NewProxyHandler(
				&fakeClient{},
				loggertesthelper.Logger(),
			)

			handler.HandleWebSocket(
				"appId",
开发者ID:nkuacac,项目名称:loggregator,代码行数:30,代码来源:proxy_handler_test.go


注:本文中的trafficcontroller/hasher.NewHasher函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。