Exemplo n.º 1
0
func main() {
	t, _ := thrift.NewTHttpPostClient("http://localhost:8080/foo")

	cl := test.NewTestClientFactory(t, thrift.NewTBinaryProtocolFactoryDefault())

	success := 0
	failed := 0
	for i := 0; i < 1000; i++ {
		_, err := cl.Add(int16(i), int16(i+1))

		if err != nil {
			failed++
		} else {
			success++
		}
	}

	log.Printf("Success: %d, Failure: %d", success, failed)

	if failed > 2 {
		os.Exit(1)
	} else {
		os.Exit(0)
	}
}
Exemplo n.º 2
0
func checkService(config ThriftServiceConfiguration) bool {
	amqpURL := defaultAMQPURL
	timeout := defaultTimeout

	if os.Getenv("TIMEOUT") != "" {
		if t, err := strconv.Atoi(os.Getenv("TIMEOUT")); err == nil {
			timeout = t
		}
	}

	if os.Getenv("RABBITMQ_URL") != "" {
		amqpURL = os.Getenv("RABBITMQ_URL")
	}

	log.Println(fmt.Sprintf("URL: %s", amqpURL))
	log.Println(fmt.Sprintf("exchange: %s", config.TransportConfig["exchange"]))
	log.Println(fmt.Sprintf("routing: %s", config.TransportConfig["routing"]))

	trans, _ := amqp_thrift.NewTAMQPClient(
		amqpURL,
		config.TransportConfig["exchange"],
		config.TransportConfig["routing"],
	)

	trans.Open()
	defer trans.Close()

	var protocol thrift.TProtocolFactory
	protocol = thrift.NewTBinaryProtocolFactoryDefault()

	if config.Protocol == "json" {
		protocol = thrift.NewTJSONProtocolFactory()
	}

	client := base_service.NewBaseServiceClientFactory(
		trans,
		protocol,
	)

	c := make(chan base_service.Status, 1)

	go func() {
		s, err := client.GetStatus()
		if err != nil {
			log.Println(err.Error())
		}

		c <- s
	}()

	select {
	case r := <-c:
		if r == base_service.Status_STARTING || r == base_service.Status_ALIVE {
			return true
		} else {
			return false
		}
	case <-time.After(time.Duration(timeout) * time.Second):
		return false
	}
}