func TestDao_UpdateService(t *testing.T) { controlPlaneDao.RemoveService("default", &unused) service, _ := dao.NewService() service.Id = "default" controlPlaneDao.AddService(*service, &id) service.Name = "name" err := controlPlaneDao.UpdateService(*service, &unused) if err != nil { t.Errorf("Failure updating service %-v with error: %s", service, err) t.Fail() } result := dao.Service{} controlPlaneDao.GetService("default", &result) //XXX the time.Time types fail comparison despite being equal... // as far as I can tell this is a limitation with Go result.UpdatedAt = service.UpdatedAt result.CreatedAt = service.CreatedAt if !service.Equals(&result) { t.Errorf("Expected Service %+v, Actual Service %+v", result, *service) t.Fail() } }
func TestDao_GetService(t *testing.T) { controlPlaneDao.RemoveService("default", &unused) service, _ := dao.NewService() service.Id = "default" controlPlaneDao.AddService(*service, &id) var result dao.Service err := controlPlaneDao.GetService("default", &result) //XXX the time.Time types fail comparison despite being equal... // as far as I can tell this is a limitation with Go result.UpdatedAt = service.UpdatedAt result.CreatedAt = service.CreatedAt if err == nil { if !service.Equals(&result) { t.Errorf("GetService Failed: expected=%+v, actual=%+v", service, result) } } else { t.Errorf("Unexpected Error Retrieving Service: err=%s", err) } }
func startServiceInstances(conn *zk.Conn, service *dao.Service, pool_hosts []*dao.PoolHost, numToStart int) error { glog.V(1).Infof("Starting %d instances, choosing from %d hosts", numToStart, len(pool_hosts)) for i := 0; i < numToStart; i++ { // randomly select host service_host := pool_hosts[rand.Intn(len(pool_hosts))] glog.V(2).Info("Selected host ", service_host) serviceState, err := service.NewServiceState(service_host.HostId) if err != nil { glog.Errorf("Error creating ServiceState instance: %v", err) return err } serviceState.HostIp = service_host.HostIp err = zzk.AddServiceState(conn, serviceState) if err != nil { glog.Errorf("Leader unable to add service state: %v", err) return err } glog.V(2).Info("Started ", serviceState) } return nil }
func TestDao_NewService(t *testing.T) { service := dao.Service{} controlPlaneDao.RemoveService("default", &unused) err := controlPlaneDao.AddService(service, &id) if err == nil { t.Errorf("Expected failure to create service %-v", service) t.Fail() } service.Id = "default" err = controlPlaneDao.AddService(service, &id) if err != nil { t.Errorf("Failure creating service %-v with error: %s", service, err) t.Fail() } err = controlPlaneDao.AddService(service, &id) if err == nil { t.Errorf("Expected error creating redundant service %-v", service) t.Fail() } }
// Use the Context field of the given template to fill in all the templates in // the Command fields of the template's ServiceDefinitions func injectContext(s *dao.Service, cp dao.ControlPlane) error { return s.EvaluateStartupTemplate(cp) }