func TestReservoirSample(t *testing.T) {
	clock := &utils.MockClock{
		NowTime: 1500000000,
	}
	r := &reservoir{
		capacity:     10,
		used:         5,
		currentEpoch: 1500000000,
	}
	lr := &Reservoir{
		clock:     clock,
		reservoir: r,
	}
	lsr := &Rule{
		reservoir: lr,
	}
	sd := lsr.Sample()
	assert.True(t, sd.Sample)
	assert.Nil(t, sd.Rule)
	assert.Equal(t, int64(6), lsr.reservoir.used)
}
Test sampling from local reservoir
package sampling
import (
	"testing"
	"time"
	"github.com/aws/aws-xray-sdk-go/utils"
	"github.com/stretchr/testify/assert"
)
func TestStaleRule(t *testing.T) {
	cr := &CentralizedRule{
		requests: 5,
		reservoir: &CentralizedReservoir{
			refreshedAt: 1500000000,
			interval:    10,
		},
	}
	s := cr.stale(1500000010)
	assert.True(t, s)
}
func TestFreshRule(t *testing.T) {
	cr := &CentralizedRule{
		requests: 5,
		reservoir: &CentralizedReservoir{
			refreshedAt: 1500000000,
			interval:    10,
		},
	}
	s := cr.stale(1500000009)
	assert.False(t, s)
}
func TestInactiveRule(t *testing.T) {
	cr := &CentralizedRule{
		requests: 0,
		reservoir: &CentralizedReservoir{
			refreshedAt: 1500000000,
			interval:    10,
		},
	}
	s := cr.stale(1500000011)
	assert.False(t, s)
}
func TestExpiredReservoirBernoulliSample(t *testing.T) {
	clock := &utils.MockClock{
		NowTime: 1500000061,
	}
	rand := &utils.MockRand{
		F64: 0.05,
	}
	p := &Properties{
		Rate: 0.06,
	}
	cr := &CentralizedReservoir{
		expiresAt: 1500000060,
		borrowed:  true,
		reservoir: &reservoir{
			used:         0,
			capacity:     10,
			currentEpoch: 1500000061,
		},
	}
	csr := &CentralizedRule{
		ruleName:   "r1",
		reservoir:  cr,
		Properties: p,
		clock:      clock,
		rand:       rand,
	}
	sd := csr.Sample()
	assert.True(t, sd.Sample)
	assert.Equal(t, "r1", *sd.Rule)
	assert.Equal(t, int64(1), csr.sampled)
	assert.Equal(t, int64(1), csr.requests)
}
func TestTakeFromQuotaSample(t *testing.T) {
	clock := &utils.MockClock{
		NowTime: 1500000000,
	}
	r := &reservoir{
		currentEpoch: clock.Now().Unix(),
		used:         0,
	}
	cr := &CentralizedReservoir{
		quota:     10,
		expiresAt: 1500000060,
		reservoir: r,
	}
	csr := &CentralizedRule{
		ruleName:  "r1",
		reservoir: cr,
		clock:     clock,
	}
	sd := csr.Sample()
	assert.True(t, sd.Sample)
	assert.Equal(t, "r1", *sd.Rule)
	assert.Equal(t, int64(1), csr.sampled)
	assert.Equal(t, int64(1), csr.requests)
	assert.Equal(t, int64(1), csr.reservoir.used)
}
func TestBernoulliSamplePositve(t *testing.T) {
	clock := &utils.MockClock{
		NowTime: 1500000000,
	}
	r := &reservoir{
		currentEpoch: clock.Now().Unix(),
		used:         10,
	}
	rand := &utils.MockRand{
		F64: 0.05,
	}
	p := &Properties{
		Rate: 0.06,
	}
	cr := &CentralizedReservoir{
		quota:     10,
		expiresAt: 1500000060,
		reservoir: r,
	}
	csr := &CentralizedRule{
		ruleName:   "r1",
		reservoir:  cr,
		Properties: p,
		rand:       rand,
		clock:      clock,
	}
	sd := csr.Sample()
	assert.True(t, sd.Sample)
	assert.Equal(t, "r1", *sd.Rule)
	assert.Equal(t, int64(1), csr.sampled)
	assert.Equal(t, int64(1), csr.requests)
	assert.Equal(t, int64(10), csr.reservoir.used)
}
func TestBernoulliSampleNegative(t *testing.T) {
	clock := &utils.MockClock{
		NowTime: 1500000000,
	}
	r := &reservoir{
		currentEpoch: clock.Now().Unix(),
		used:         10,
	}
	rand := &utils.MockRand{
		F64: 0.07,
	}
	p := &Properties{
		Rate: 0.06,
	}
	cr := &CentralizedReservoir{
		quota:     10,
		expiresAt: 1500000060,
		reservoir: r,
	}
	csr := &CentralizedRule{
		ruleName:   "r1",
		reservoir:  cr,
		Properties: p,
		rand:       rand,
		clock:      clock,
	}
	sd := csr.Sample()
	assert.False(t, sd.Sample)
	assert.Equal(t, "r1", *sd.Rule)
	assert.Equal(t, int64(0), csr.sampled)
	assert.Equal(t, int64(1), csr.requests)
	assert.Equal(t, int64(10), csr.reservoir.used)
}