Ejemplo n.º 1
0
// set any missing global configuration on a new ServiceConfig.
// ServiceRegistry *must* be locked.
func (s *ServiceRegistry) setServiceDefaults(svc *client.ServiceConfig) {
	if svc.Balance == "" && s.cfg.Balance != "" {
		svc.Balance = s.cfg.Balance
	}
	if svc.CheckInterval == 0 && s.cfg.CheckInterval != 0 {
		svc.CheckInterval = s.cfg.CheckInterval
	}
	if svc.Fall == 0 && s.cfg.Fall != 0 {
		svc.Fall = s.cfg.Fall
	}
	if svc.Rise == 0 && s.cfg.Rise != 0 {
		svc.Rise = s.cfg.Rise
	}
	if svc.ClientTimeout == 0 && s.cfg.ClientTimeout != 0 {
		svc.ClientTimeout = s.cfg.ClientTimeout
	}
	if svc.ServerTimeout == 0 && s.cfg.ServerTimeout != 0 {
		svc.ServerTimeout = s.cfg.ServerTimeout
	}
	if svc.DialTimeout == 0 && s.cfg.DialTimeout != 0 {
		svc.DialTimeout = s.cfg.DialTimeout
	}
	if s.cfg.HTTPSRedirect {
		svc.HTTPSRedirect = true
	}
}
Ejemplo n.º 2
0
func (s *BasicSuite) TestInvalidUpdateService(c *C) {
	svcCfg := client.ServiceConfig{
		Name: "Update",
		Addr: "127.0.0.1:9324",
	}

	if err := Registry.AddService(svcCfg); err != nil {
		c.Fatal(err)
	}

	svc := Registry.GetService("Update")
	if svc == nil {
		c.Fatal(ErrNoService)
	}

	svcCfg.Addr = "127.0.0.1:9425"

	// Make sure we can't add the same service again
	if err := Registry.AddService(svcCfg); err == nil {
		c.Fatal(err)
	}

	// the update should fail, because it would require a new listener
	if err := Registry.UpdateService(svcCfg); err == nil {
		c.Fatal(err)
	}

	// change the addres back, and try to update ClientTimeout
	svcCfg.Addr = "127.0.0.1:9324"
	svcCfg.ClientTimeout = 1234

	// the update should fail, because it would require a new listener
	if err := Registry.UpdateService(svcCfg); err == nil {
		c.Fatal(err)
	}

	if err := Registry.RemoveService("Update"); err != nil {
		c.Fatal(err)
	}
}