Example #1
0
func setUp() {
	// Start a QuotaService server.
	cfg := config.NewDefaultServiceConfig()
	cfg.GlobalDefaultBucket = config.NewDefaultBucketConfig(config.DefaultBucketName)
	nsc := config.NewDefaultNamespaceConfig("delaying")
	bc := config.NewDefaultBucketConfig("delaying")
	bc.Size = 1 // Very small.
	bc.FillRate = 100
	config.AddBucket(nsc, bc)
	config.AddNamespace(cfg, nsc)

	server = quotaservice.New(memory.NewBucketFactory(), config.NewMemoryConfig(cfg), qsgrpc.New(target))
	server.Start()
}
Example #2
0
func main() {
	cfg := config.NewDefaultServiceConfig()
	ns := config.NewDefaultNamespaceConfig("test.namespace")
	ns.DynamicBucketTemplate = config.NewDefaultBucketConfig(config.DynamicBucketTemplateName)
	ns.DynamicBucketTemplate.Size = 100000000000
	ns.DynamicBucketTemplate.FillRate = 100000000
	b := config.NewDefaultBucketConfig("xyz")
	config.AddBucket(ns, b)
	config.AddNamespace(cfg, ns)

	ns = config.NewDefaultNamespaceConfig("test.namespace2")
	ns.DefaultBucket = config.NewDefaultBucketConfig(config.DefaultBucketName)
	b = config.NewDefaultBucketConfig("xyz")
	config.AddBucket(ns, b)
	config.AddNamespace(cfg, ns)

	server := quotaservice.New(memory.NewBucketFactory(),
		config.NewMemoryConfig(cfg),
		grpc.New(GRPC_SERVER))
	server.SetStatsListener(stats.NewMemoryStatsListener())
	server.Start()

	// Serve Admin Console
	logging.Printf("Starting admin server on %v\n", ADMIN_SERVER)
	sm := http.NewServeMux()
	server.ServeAdminConsole(sm, "admin/public", true)
	go func() {
		http.ListenAndServe(ADMIN_SERVER, sm)
	}()

	// Block until SIGTERM, SIGKILL or SIGINT
	sigs := make(chan os.Signal, 1)
	signal.Notify(sigs, syscall.SIGTERM, syscall.SIGKILL, syscall.SIGINT)

	var shutdown sync.WaitGroup
	shutdown.Add(1)

	go func() {
		<-sigs
		shutdown.Done()
	}()

	shutdown.Wait()
	server.Stop()
}
Example #3
0
func setUp() {
	cfg := config.NewDefaultServiceConfig()
	cfg.GlobalDefaultBucket = config.NewDefaultBucketConfig(config.DefaultBucketName)

	// Namespace "dyn"
	ns := config.NewDefaultNamespaceConfig("dyn")
	tpl := config.NewDefaultBucketConfig("")
	tpl.MaxTokensPerRequest = 5
	tpl.MaxIdleMillis = -1
	config.SetDynamicBucketTemplate(ns, tpl)
	ns.MaxDynamicBuckets = 2
	config.AddNamespace(cfg, ns)

	// Namespace "dyn_gc"
	ns = config.NewDefaultNamespaceConfig("dyn_gc")
	tpl = config.NewDefaultBucketConfig("")
	tpl.MaxTokensPerRequest = 5
	tpl.MaxIdleMillis = 100
	config.SetDynamicBucketTemplate(ns, tpl)
	ns.MaxDynamicBuckets = 3
	config.AddNamespace(cfg, ns)

	// Namespace "nodyn"
	ns = config.NewDefaultNamespaceConfig("nodyn")
	b := config.NewDefaultBucketConfig("b")
	b.MaxTokensPerRequest = 10
	config.AddBucket(ns, b)
	config.AddNamespace(cfg, ns)

	mbf = &MockBucketFactory{}
	me := &MockEndpoint{}
	p := config.NewMemoryConfig(cfg)
	s = New(mbf, p, me)
	eventsChan = make(chan events.Event, 100)
	s.SetListener(func(e events.Event) {
		eventsChan <- e
	}, 100)
	s.Start()
	qs = me.QuotaService
	// EVENTS_BUCKET_CREATED event
	_ = <-eventsChan
}
Example #4
0
func NewWithDefaultConfig(bucketFactory BucketFactory, rpcEndpoints ...RpcEndpoint) Server {
	return New(bucketFactory,
		config.NewMemoryConfig(config.NewDefaultServiceConfig()),
		rpcEndpoints...)
}