コード例 #1
0
func main() {
	if len(os.Args) >= 2 && os.Args[1] == "client" {
		client.Run(os.Args[2:])
		return
	}
	runtime.GOMAXPROCS(runtime.NumCPU())
	registry := registry.NewRegistry()
	registry.Open()
	defer registry.Close()
	glog.Infof("Started in %v mode with Hash Width: %v and Window Size: %v", registry.Mode, registry.HashWidth, registry.WindowSize)
	sig := make(chan os.Signal, 1)
	signal.Notify(sig, os.Interrupt)
	go http.ListenAndServe("localhost:6060", nil)
	switch registry.Mode {
	case "posting":
		posting.Serve(registry)
	case "api":
		go queue.Start(registry)
		go api.MonitorFeeds(registry)
		go api.Serve(registry)
	case "standalone":
		posting.Serve(registry)
		go queue.Start(registry)
		go api.MonitorFeeds(registry)
		go api.Serve(registry)
	}
	<-sig
}
コード例 #2
0
func (s *QuerySuite) TestAssociate(c *C) {
	go Start(s.Registry)
	go posting.Serve(s.Registry)
	item, err := NewQueueItem(s.Registry, "Test Corpus", nil, nil, "", "", strings.NewReader(""))
	c.Check(err, IsNil)
	c.Check(waitForItem(item, s), IsNil)
	item, err = NewQueueItem(s.Registry, "Associate Document", nil, nil, "1", "2-10", strings.NewReader(""))
	c.Check(err, IsNil)
	c.Check(waitForItem(item, s), IsNil)
}
コード例 #3
0
func (s *QuerySuite) TestPayload(c *C) {
	go Start(s.Registry)
	go posting.Serve(s.Registry)
	item, err := NewQueueItem(s.Registry, "test", nil, nil, "", "", strings.NewReader("I am the payload"))
	c.Check(err, IsNil)
	var q QueueItem
	db := s.Registry.DB()
	defer db.Session.Close()
	db.C("queue").FindId(item.Id).One(&q)
	c.Check(q.Payload, NotNil)
	p, err := q.getPayload()
	c.Check(p, Equals, "I am the payload")
	c.Check(err, IsNil)
}
コード例 #4
0
func (s *QuerySuite) TestQueue(c *C) {
	go posting.Serve(s.Registry)
	go Start(s.Registry)
	var item *QueueItem
	var err error
	for i := uint32(1); i <= 20; i++ {
		target := document.DocumentID{Doctype: 1, Docid: i}
		item, err = NewQueueItem(s.Registry, "Add Document", nil, &target, "", "", strings.NewReader("title=Payload&text=PayloadWithsometextlongerthanwindowsize"))
		c.Check(item, NotNil)
		c.Check(err, IsNil)
	}
	waitForItem(item, s)
	stats, err := Stats(s.Registry)
	c.Check(err, IsNil)
	c.Check(stats["Completed"], Equals, 20)
	c.Check(stats["Queued"], Equals, 0)
	c.Check(stats["Failed"], Equals, 0)
	db := s.Registry.DB()
	defer db.Session.Close()
	count, err := db.C("documents").Count()
	c.Check(err, IsNil)
	c.Check(count, Equals, 20)
	for i := uint32(1); i <= 20; i++ {
		target := document.DocumentID{Doctype: 1, Docid: i}
		item, err = NewQueueItem(s.Registry, "Delete Document", nil, &target, "", "", strings.NewReader(""))
		c.Check(item, NotNil)
		c.Check(err, IsNil)
	}
	waitForItem(item, s)
	stats, err = Stats(s.Registry)
	c.Check(err, IsNil)
	c.Check(stats["Completed"], Equals, 40)
	c.Check(stats["Queued"], Equals, 0)
	c.Check(stats["Failed"], Equals, 0)
	count, err = db.C("documents").Count()
	c.Check(err, IsNil)
	c.Check(count, Equals, 0)
}