Skip to content

Commit

Permalink
Add tests for aggregateSignals
Browse files Browse the repository at this point in the history
Remove aggregateSignalMap
  • Loading branch information
yuyufei authored and yufeiyu committed Feb 23, 2022
1 parent bcdf23e commit 24e4783
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 788 deletions.
14 changes: 8 additions & 6 deletions pkg/prediction/dsp/aggregate_signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ func (a *aggregateSignal) setPredictedTimeSeries(ts *common.TimeSeries) {
}

type aggregateSignals struct {
mu sync.Mutex
callerMap map[string]/*expr*/map[string/*caller*/]struct{}
signalMap map[string]/*expr*/map[string/*key*/]*aggregateSignal
mu sync.Mutex
callerMap map[string] /*expr*/ map[string] /*caller*/ struct{}
signalMap map[string] /*expr*/ map[string] /*key*/ *aggregateSignal
}

func newAggregateSignals() aggregateSignals {
return aggregateSignals{
mu: sync.Mutex{},
mu: sync.Mutex{},
callerMap: map[string]map[string]struct{}{},
signalMap: map[string]map[string]*aggregateSignal{},
}
Expand All @@ -58,12 +58,14 @@ func (a *aggregateSignals) Add(qc prediction.QueryExprWithCaller) bool {

if _, exists := a.signalMap[qc.QueryExpr]; !exists {
a.signalMap[qc.QueryExpr] = map[string]*aggregateSignal{}
} else {
return false
}

return true
}

func (a *aggregateSignals) Delete(qc prediction.QueryExprWithCaller) bool/*need clean or not*/ {
func (a *aggregateSignals) Delete(qc prediction.QueryExprWithCaller) bool /*need clean or not*/ {
a.mu.Lock()
defer a.mu.Unlock()

Expand Down Expand Up @@ -117,4 +119,4 @@ func (a *aggregateSignals) GetOrStoreSignal(queryExpr string, key string, signal

a.signalMap[queryExpr][key] = signal
return signal
}
}
Loading

0 comments on commit 24e4783

Please sign in to comment.