Exemplo n.º 1
0
func (app *App) LoadServices() error {
	var err error

	app.StopChan = make(chan bool, 1)

	services := map[string](interface{}){
		"configProvider":  app.config,
		"httpServer":      server.New(),
		"commands":        commands.New(),
		"clientQueries":   queries.NewClientQueryService(),
		"systemQueries":   queries.NewSystemQueryService(),
		"users":           users.NewUsers(),
		"events":          events.NewEvents(),
		"gameCalculator":  game.NewGameCalculator(),
		"eventSubscriber": queries.NewQueryBuffer(),
		"fixtures":        fixtures.NewFixtures(),

		"stopChan": app.StopChan,
	}

	for name, value := range services {
		err = app.directory.AddService(name, value)
		if err != nil {
			msg := fmt.Sprintf("Adding %s service failed: %v", name, err)
			log.Error(msg)
		}
	}

	err = app.directory.Start()
	if err != nil {
		msg := fmt.Sprintf("Could not start directory: %v", err)
		log.Error(msg)
		return err
	}

	return err
}
Exemplo n.º 2
0
func (suite *IntegrationTestSuite) SetupTest() {
	configProvider := config.NewConfigProvider("testconfig", "./")

	suite.log = logger.Log("integration_test")

	suite.Commands = commands.New()
	suite.Queries = queries.NewClientQueryService()

	systemQueries := queries.NewSystemQueryService().(*queries.SystemQueryService)
	eventsService := events.NewEvents().(*events.EventsService)
	usersService := users.NewUsers().(*users.UsersService)

	d := directory.New()
	d.AddService("configProvider", configProvider)
	d.AddService("gameCalculator", game.NewGameCalculator())
	d.AddService("eventSubscriber", queries.NewQueryBuffer())

	d.AddService("systemQueries", systemQueries)
	d.AddService("events", eventsService)
	d.AddService("users", usersService)

	d.AddService("commands", suite.Commands)
	d.AddService("clientQueries", suite.Queries)

	err := d.Start()
	if err != nil {
		suite.log.Fatalf("Could not start directory: %v", err)
	}

	err = d.Start("eventSubscriber")
	if err != nil {
		msg := fmt.Sprintf("Could not start event subscriber: %v", err)
		log.Error(msg)
		return
	}

	usersService.ResetTestDB()
	eventsService.ResetTestDB()
	systemQueries.Cache.Flush()

	time.Sleep(1 * time.Second)

	white := users.User{
		Uuid:           users.NewId(),
		Name:           "whitePlayer",
		AuthIdentifier: "whiteAuthId",
	}
	usersService.Save(&white)

	black := users.User{
		Uuid:           users.NewId(),
		Name:           "blackPlayer",
		AuthIdentifier: "blackAuthId",
	}
	usersService.Save(&black)

	suite.log.Info("white UUID: %s", white.Uuid)
	suite.log.Info("black UUID: %s", black.Uuid)
	suite.whiteId = white.Uuid
	suite.blackId = black.Uuid
}