Skip to content
This repository has been archived by the owner on Oct 17, 2018. It is now read-only.

Commit

Permalink
v
Browse files Browse the repository at this point in the history
  • Loading branch information
Chao Wang committed May 17, 2017
1 parent 9c7a88a commit 5fea0ab
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 223 deletions.
18 changes: 9 additions & 9 deletions policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func NewPolicyFromSchema(p *schema.Policy) (UnaggregatedPolicy, error) {
return EmptyUnaggregatedPolicy, err
}

return NewUnaggregatedPolicyWith(Policy{
return NewUnaggregatedPolicy(Policy{
resolution: Resolution{
Window: time.Duration(p.Resolution.WindowSize),
Precision: unit,
Expand Down Expand Up @@ -178,16 +178,11 @@ type UnaggregatedPolicy struct {
compressedAggTypes CompressedAggregationTypes
}

// NewUnaggregatedPolicyWith creates an UnaggregatedPolicy
func NewUnaggregatedPolicyWith(p Policy, aggTypes CompressedAggregationTypes) UnaggregatedPolicy {
// NewUnaggregatedPolicy creates an UnaggregatedPolicy
func NewUnaggregatedPolicy(p Policy, aggTypes CompressedAggregationTypes) UnaggregatedPolicy {
return UnaggregatedPolicy{policy: p, compressedAggTypes: aggTypes}
}

// String is the string representation of an UnaggregatedPolicy.
func (p UnaggregatedPolicy) String() string {
return p.policy.String() + p.compressedAggTypes.String()
}

// Policy return the policy.
func (p UnaggregatedPolicy) Policy() Policy {
return p.policy
Expand All @@ -198,6 +193,11 @@ func (p UnaggregatedPolicy) CompressedAggregationTypes() CompressedAggregationTy
return p.compressedAggTypes
}

// String is the string representation of an UnaggregatedPolicy.
func (p UnaggregatedPolicy) String() string {
return p.policy.String() + p.compressedAggTypes.String()
}

// ByResolutionAsc implements the sort.Sort interface to sort
// policies by resolution in ascending order, finest resolution first.
// If two policies have the same resolution, the one with longer
Expand Down Expand Up @@ -310,7 +310,7 @@ func (l PoliciesList) WithDefaultAggregation() PoliciesList {
for _, sp := range l {
for j := range sp.policies {
if !sp.policies[j].compressedAggTypes.IsDefault() {
sp.policies[j] = NewUnaggregatedPolicyWith(sp.policies[j].policy, EmptyCompressedAggregationTypes)
sp.policies[j] = NewUnaggregatedPolicy(sp.policies[j].policy, EmptyCompressedAggregationTypes)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions policy/policy_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
var (
testNowNanos = time.Now().UnixNano()
testPolicies = []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 2*24*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(time.Minute, xtime.Minute, 30*24*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 2*24*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(time.Minute, xtime.Minute, 30*24*time.Hour), EmptyCompressedAggregationTypes),
}
)

Expand Down
76 changes: 38 additions & 38 deletions policy/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func TestUnaggregatedPolicyString(t *testing.T) {
p UnaggregatedPolicy
expected string
}{
{p: NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, time.Hour), EmptyCompressedAggregationTypes), expected: "10s@1s:1h0m0s"},
{p: NewUnaggregatedPolicyWith(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), mustCompress([]AggregationType{Min, Max})), expected: "1m0s@1m:12h0m0s[Min,Max]"},
{p: NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, time.Hour), EmptyCompressedAggregationTypes), expected: "10s@1s:1h0m0s"},
{p: NewUnaggregatedPolicy(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), mustCompress([]AggregationType{Min, Max})), expected: "1m0s@1m:12h0m0s[Min,Max]"},
}
for _, input := range inputs {
require.Equal(t, input.expected, input.p.String())
Expand Down Expand Up @@ -181,13 +181,13 @@ func TestPolicyUnmarshalYAMLErrors(t *testing.T) {

func TestPoliciesByResolutionAsc(t *testing.T) {
inputs := []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 2*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 12*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(5*time.Minute, xtime.Minute, 48*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(time.Minute, xtime.Minute, time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(time.Minute, xtime.Minute, 24*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(10*time.Minute, xtime.Minute, 48*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 2*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 12*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(5*time.Minute, xtime.Minute, 48*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(time.Minute, xtime.Minute, time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(time.Minute, xtime.Minute, 24*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Minute, xtime.Minute, 48*time.Hour), EmptyCompressedAggregationTypes),
}
expected := []UnaggregatedPolicy{inputs[2], inputs[0], inputs[1], inputs[5], inputs[4], inputs[3], inputs[6]}
sort.Sort(ByResolutionAsc(inputs))
Expand All @@ -203,8 +203,8 @@ func TestStagedPoliciesHasDefaultPolicies(t *testing.T) {

func TestStagedPoliciesHasCustomPolicies(t *testing.T) {
policies := []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
}
sp := NewStagedPolicies(testNowNanos, false, policies)
require.Equal(t, testNowNanos, sp.CutoverNanos)
Expand All @@ -228,32 +228,32 @@ func TestStagedPoliciesSamePoliciesDefaultPolicies(t *testing.T) {
{
sp: [2]StagedPolicies{
NewStagedPolicies(0, false, []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), mustCompress([]AggregationType{Min, Max})),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), mustCompress([]AggregationType{Min, Max})),
}),
NewStagedPolicies(0, false, []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), mustCompress([]AggregationType{Max, Min})),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), mustCompress([]AggregationType{Max, Min})),
}),
},
expected: true,
},
{
sp: [2]StagedPolicies{
NewStagedPolicies(0, false, []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), mustCompress([]AggregationType{Max})),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), mustCompress([]AggregationType{Max})),
}),
NewStagedPolicies(0, false, []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), mustCompress([]AggregationType{Last})),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), mustCompress([]AggregationType{Last})),
}),
},
expected: false,
},
{
sp: [2]StagedPolicies{
NewStagedPolicies(0, false, []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), mustCompress([]AggregationType{Max})),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), mustCompress([]AggregationType{Max})),
}),
NewStagedPolicies(0, false, []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), mustCompress([]AggregationType{Max, Min})),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), mustCompress([]AggregationType{Max, Min})),
}),
},
expected: false,
Expand All @@ -262,49 +262,49 @@ func TestStagedPoliciesSamePoliciesDefaultPolicies(t *testing.T) {
sp: [2]StagedPolicies{
NewStagedPolicies(0, false, nil),
NewStagedPolicies(0, true, []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
}),
},
expected: false,
},
{
sp: [2]StagedPolicies{
NewStagedPolicies(1000, false, []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
}),
NewStagedPolicies(0, true, []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
}),
},
expected: true,
},
{
sp: [2]StagedPolicies{
NewStagedPolicies(1000, false, []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
}),
NewStagedPolicies(0, true, []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(10*time.Minute, xtime.Minute, 24*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Minute, xtime.Minute, 24*time.Hour), EmptyCompressedAggregationTypes),
}),
},
expected: false,
},
{
sp: [2]StagedPolicies{
NewStagedPolicies(0, true, []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(10*time.Minute, xtime.Minute, 24*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Minute, xtime.Minute, 24*time.Hour), EmptyCompressedAggregationTypes),
}),
NewStagedPolicies(1000, false, []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
}),
},
expected: false,
Expand Down Expand Up @@ -338,8 +338,8 @@ func TestStagedPoliciesIsEmpty(t *testing.T) {
},
{
sp: NewStagedPolicies(0, true, []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
}),
expected: false,
},
Expand All @@ -364,8 +364,8 @@ func TestPoliciesListIsDefault(t *testing.T) {
},
{
pl: []StagedPolicies{NewStagedPolicies(0, true, []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicyWith(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(10*time.Second, xtime.Second, 6*time.Hour), EmptyCompressedAggregationTypes),
NewUnaggregatedPolicy(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), EmptyCompressedAggregationTypes),
})},
expected: false,
},
Expand All @@ -383,7 +383,7 @@ func TestPoliciesListWithDefaultAggregation(t *testing.T) {
pl := PoliciesList(
[]StagedPolicies{
NewStagedPolicies(100, true, []UnaggregatedPolicy{
NewUnaggregatedPolicyWith(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), mustCompress([]AggregationType{Max})),
NewUnaggregatedPolicy(NewPolicy(time.Minute, xtime.Minute, 12*time.Hour), mustCompress([]AggregationType{Max})),
}),
},
)
Expand Down
2 changes: 1 addition & 1 deletion protocol/msgpack/base_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (it *baseIterator) decodeUnaggregatedPolicy() policy.UnaggregatedPolicy {
p := it.decodePolicy()
aggTypes := it.decodeCompressedAggregationTypes()
it.skip(numActualFields - numExpectedFields)
return policy.NewUnaggregatedPolicyWith(p, aggTypes)
return policy.NewUnaggregatedPolicy(p, aggTypes)
}

func (it *baseIterator) decodeCompressedAggregationTypes() policy.CompressedAggregationTypes {
Expand Down
6 changes: 3 additions & 3 deletions protocol/msgpack/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ func TestAggregationTypesRoundTrip(t *testing.T) {

func TestUnaggregatedPolicyRoundTrip(t *testing.T) {
inputs := []policy.UnaggregatedPolicy{
policy.NewUnaggregatedPolicyWith(policy.NewPolicy(10*time.Second, xtime.Second, 24*time.Hour), policy.EmptyCompressedAggregationTypes),
policy.NewUnaggregatedPolicyWith(policy.NewPolicy(10*time.Second, xtime.Second, 2*24*time.Hour), policy.CompressedAggregationTypes{8}),
policy.NewUnaggregatedPolicyWith(policy.NewPolicy(10*time.Second, xtime.Second, 24*time.Hour), policy.CompressedAggregationTypes{100}),
policy.NewUnaggregatedPolicy(policy.NewPolicy(10*time.Second, xtime.Second, 24*time.Hour), policy.EmptyCompressedAggregationTypes),
policy.NewUnaggregatedPolicy(policy.NewPolicy(10*time.Second, xtime.Second, 2*24*time.Hour), policy.CompressedAggregationTypes{8}),
policy.NewUnaggregatedPolicy(policy.NewPolicy(10*time.Second, xtime.Second, 24*time.Hour), policy.CompressedAggregationTypes{100}),
}

for _, input := range inputs {
Expand Down
2 changes: 1 addition & 1 deletion protocol/msgpack/unaggregated_encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func TestUnaggregatedEncodeArrayLenError(t *testing.T) {
time.Now().UnixNano(),
false,
[]policy.UnaggregatedPolicy{
policy.NewUnaggregatedPolicyWith(policy.NewPolicy(time.Second, xtime.Second, time.Hour), policy.EmptyCompressedAggregationTypes),
policy.NewUnaggregatedPolicy(policy.NewPolicy(time.Second, xtime.Second, time.Hour), policy.EmptyCompressedAggregationTypes),
},
),
}
Expand Down
6 changes: 3 additions & 3 deletions protocol/msgpack/unaggregated_iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ func TestUnaggregatedIteratorDecodePolicyWithCustomResolution(t *testing.T) {
time.Now().UnixNano(),
false,
[]policy.UnaggregatedPolicy{
policy.NewUnaggregatedPolicyWith(policy.NewPolicy(3*time.Second, xtime.Second, time.Hour), policy.EmptyCompressedAggregationTypes),
policy.NewUnaggregatedPolicy(policy.NewPolicy(3*time.Second, xtime.Second, time.Hour), policy.EmptyCompressedAggregationTypes),
},
),
},
Expand All @@ -471,7 +471,7 @@ func TestUnaggregatedIteratorDecodePolicyWithCustomRetention(t *testing.T) {
time.Now().UnixNano(),
false,
[]policy.UnaggregatedPolicy{
policy.NewUnaggregatedPolicyWith(policy.NewPolicy(time.Second, xtime.Second, 289*time.Hour), policy.EmptyCompressedAggregationTypes),
policy.NewUnaggregatedPolicy(policy.NewPolicy(time.Second, xtime.Second, 289*time.Hour), policy.EmptyCompressedAggregationTypes),
},
),
},
Expand All @@ -493,7 +493,7 @@ func TestUnaggregatedIteratorDecodePolicyMoreFieldsThanExpected(t *testing.T) {
time.Now().UnixNano(),
true,
[]policy.UnaggregatedPolicy{
policy.NewUnaggregatedPolicyWith(policy.NewPolicy(time.Second, xtime.Second, time.Hour), policy.EmptyCompressedAggregationTypes),
policy.NewUnaggregatedPolicy(policy.NewPolicy(time.Second, xtime.Second, time.Hour), policy.EmptyCompressedAggregationTypes),
},
),
},
Expand Down
Loading

0 comments on commit 5fea0ab

Please sign in to comment.