示例#1
0
func GetClientAndService() (*api.ReportClient, *MetricsService) {
	address := dns.Address{Address: "localhost", Port: uint16(rando.Port())}

	server := ophttp.NewServer(fmt.Sprintf("%s:%d", address.Address, address.Port))
	svc := &MetricsService{
		Server: server,
	}

	client := &api.ReportClient{
		Address: address.String(),
	}
	return client, svc
}
示例#2
0
func TestServerStops(t *testing.T) {
	port := uint16(rando.Port())
	add := fmt.Sprintf(":%d", port)
	a := NewApp(add)
	go a.Start()

	r, err := http.Get("http://golang.org/")
	if err != nil {
		t.Errorf("%s", err)
	}
	if r.StatusCode != 200 {
		t.Errorf("%s", err)
	}
	a.Stop()

	a2 := NewApp(add)
	go a2.Start()
	a2.Stop()
}
func (s *TestSuite) SetUpSuite(c *C) {
	var cfg struct {
		Database string
	}

	var _ = config.Bind("../test.yaml", &cfg)

	host := fmt.Sprintf("localhost:%d", rando.Port())

	db, _ := DbOpen(cfg.Database)

	s.s = &LocationService{
		Db:            db,
		Bind:          host,
		WeatherClient: &WeatherClientStub{},
	}
	go s.s.Run()

	s.host = "http://" + host
}
示例#4
0
func GetClientAndService() (*TodoClient, *TodoService) {
	address := dns.Address{Address: "localhost", Port: uint16(rando.Port())}

	dbStr := "root:@tcp(localhost:3306)/Todo?charset=utf8&parseTime=True"

	db, err := vault.NewStaticDbProvider(dbStr)
	if err != nil {
		panic(err)
	}
	server := ophttp.NewServer(fmt.Sprintf("%s:%d", address.Address, address.Port))
	svc := &TodoService{
		Server: server,
		Db:     db,
	}

	client := &TodoClient{
		Lb:      &StubAddressGetter{Val: address},
		Address: ServiceAddress,
	}
	return client, svc
}
示例#5
0
func GetServices() (*ep.EndpointApp, *ex.Server, *ex.Publisher, *ex.Publisher) {
	port := uint16(rando.Port())

	server := ex.NewServer(fmt.Sprintf(":%d", port))

	epCfg := config.EndpointConfig{
		Name:        "Foo",
		ServiceHost: fmt.Sprintf("http://localhost:%d", port),
		Uri:         "/foo",
		Method:      "POST",
		QueueConfig: map[interface{}]interface{}{
			"queuename": "test.foo",
		},
	}
	epCfg2 := config.EndpointConfig{
		Name:        "Bar",
		ServiceHost: fmt.Sprintf("http://localhost:%d", port),
		Uri:         "/bar",
		Method:      "POST",
		QueueConfig: map[interface{}]interface{}{
			"queuename": "test.bar",
		},
	}

	p := GetPublisher(&epCfg)
	p2 := GetPublisher(&epCfg2)

	repo := &config.StaticRepo{
		Address: config.RabbitAddress{
			User:     "******",
			Password: "******",
			Host:     "localhost",
			Port:     5672,
		},
		Endpoints: []config.EndpointConfig{epCfg, epCfg2},
	}

	mgr := ep.NewApp(repo, repo)
	return mgr, server, p, p2
}