Esempio n. 1
0
func TestSmurfProcessor(t *testing.T) {
	//log.Println("runtime.GOMAXPROCS(16)", runtime.GOMAXPROCS(16))
	test_utils.DropAllCollections()

	const (
		pete = "pete"
		joe  = "joe"
	)

	// add some products in status a
	smurfOrders := map[string]int{
		pete: 1000,
		joe:  2000,
	}

	numberOfOrders := 0
	for smurf, smurfOrderCount := range smurfOrders {
		for i := 0; i < smurfOrderCount; i++ {
			mock.MakeMockOrder(smurf)

			numberOfOrders++
			if numberOfOrders%100 == 0 {
				log.Println(smurf, numberOfOrders)
			}
		}
	}

	log.Println("done writing orders")

	maxConcurrency := 16
	queue := queue.NewQueue()
	joeProcessor := examples.NewSmurfProcessor()
	joeProcessor.SetQuery(&bson.M{"custom.responsiblesmurf": joe})
	joeProcessor.SetMaxConcurrency(maxConcurrency)
	joeProcessor.SetJobsAssigned(smurfOrders[joe])
	peteProcessor := examples.NewSmurfProcessor()
	peteProcessor.SetQuery(&bson.M{"custom.responsiblesmurf": pete})
	peteProcessor.SetMaxConcurrency(maxConcurrency)
	peteProcessor.SetJobsAssigned(smurfOrders[pete])
	queue.AddProcessor(joeProcessor)
	queue.AddProcessor(peteProcessor)

	queue.Start()

	fmt.Println("number of orders:", numberOfOrders, ", processed by joe:", joeProcessor.CountProcessed, ", processed by pete:", peteProcessor.CountProcessed)
	// Output: number of orders: 300 , processed by joe: 2000 , processed by pete: 1000
	if numberOfOrders != smurfOrders["pete"]+smurfOrders["joe"] || joeProcessor.CountProcessed != smurfOrders["joe"] || peteProcessor.CountProcessed != smurfOrders["pete"] {
		t.Fatal("number of orders:", numberOfOrders, ", processed by joe:", joeProcessor.CountProcessed, ", processed by pete:", peteProcessor.CountProcessed)
	}

}
Esempio n. 2
0
File: mock.go Progetto: foomo/shop
func GetMockQueue() *queue.Queue {
	return queue.NewQueue()
}