Example #1
0
func TestPublishEvent(t *testing.T) {
	db := redisdb.New(dburl)
	if err := db.Connect(); err != nil {
		t.Fatalf("Failed to connect to redis: %s", err.Error())
	}

	c, err := redis.Dial("tcp", dburl)
	if err != nil {
		t.Fatalf("Failed to connect to redis2: %s", err.Error())
	}

	ps := pubsub.NewSubClient(c)
	ps.Subscribe("thechan")

	wg := sync.WaitGroup{}
	wg.Add(1)

	go func() {
		resp := ps.Receive()
		if resp.Message != "moar" {
			t.Errorf("Expected moar but got %s", resp.Message)
		}
		wg.Done()
	}()

	go func() {
		buf := bytes.NewBufferString("moar")
		if err := db.PublishEvent("thechan", buf); err != nil {
			t.Fatalf("Should have have errored publishing: %s", err.Error())
		}
	}()
	wg.Wait()
}
Example #2
0
func TestConnect(t *testing.T) {
	db := redisdb.New(dburl)
	if err := db.Connect(); err != nil {
		t.Fatalf("Failed to connect to redis: %s", err.Error())
	}
	db.Disconnect()
}
Example #3
0
func main() {
	db = redisdb.New("apppath:6379")
	if err := db.Connect(); err != nil {
		log.Fatalf("Failed to connect to database: %s", err.Error())
	}
	defer db.Disconnect()

	log.Info("Command handler started on :8082")

	log.Fatal(http.ListenAndServe(":8082", nil))
}
Example #4
0
func main() {
	db = redisdb.New("apppath:6379")
	if err := db.Connect(); err != nil {
		log.Fatalf("Failed to connect to database: %s", err.Error())
	}
	defer db.Disconnect()

	log.Info("Query handler started on :8000")

	games := wsocket.NewRoom()
	go games.Run()
	http.Handle("/ws/game", games)

	http.HandleFunc("/game", addOrigin(queryGames))

	log.Fatal(http.ListenAndServe(":8000", nil))
}
Example #5
0
func TestSaveEvent(t *testing.T) {
	db := redisdb.New(dburl)
	if err := db.Connect(); err != nil {
		t.Fatalf("Failed to connect to redis: %s", err.Error())
	}
	defer db.Disconnect()

	sid, _ := db.NextStoreID()

	buf := bytes.NewBufferString("test1")
	db.SaveEvent(sid, buf)
	buf = bytes.NewBufferString("test2")
	db.SaveEvent(sid, buf)
	buf = bytes.NewBufferString("test3")
	db.SaveEvent(sid, buf)

	// Get and validate events in store
	evts, err := db.GetEvents(sid)
	if err != nil {
		t.Fatalf("Should not have errored getting events: %s", err.Error())
	}

	if len(evts) != 3 {
		t.Errorf("Expected 1 event but found %d", len(evts))
	}

	if evts[0].String() != "test1" {
		t.Errorf("Expected test1 to be stored but got %s", evts[0].String())
	}
	if evts[1].String() != "test2" {
		t.Errorf("Expected test2 to be stored but got %s", evts[1].String())
	}
	if evts[2].String() != "test3" {
		t.Errorf("Expected test3 to be stored but got %s", evts[2].String())
	}
}