Skip to content
GitLab
Explore
Projects
Groups
Topics
Snippets
Projects
Groups
Topics
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
MKCLOS
Core Development Platform
corepkgv2
Commits
83762342
Commit
83762342
authored
5 years ago
by
Ajit Jagtap
Browse files
Options
Downloads
Plain Diff
Merge branch 'ab_Fix_CoreMongo' into 'devbranch'
Fix: Coremongo for nil rs and statemdl See merge request
!84
parents
26f08ebb
275071c2
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!84
Fix: Coremongo for nil rs and statemdl
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cachemdl/cachemdl_test.go
+37
-37
cachemdl/cachemdl_test.go
dalmdl/coremongo/coremongo.go
+4
-0
dalmdl/coremongo/coremongo.go
statemdl/state.go
+33
-0
statemdl/state.go
with
74 additions
and
37 deletions
cachemdl/cachemdl_test.go
+
37
−
37
View file @
83762342
...
...
@@ -2,40 +2,40 @@
//@version Thu Jul 05 2018 06:11:54 GMT+0530 (IST)
package
cachemdl
import
(
"testing"
"time"
"github.com/stretchr/testify/assert"
)
var
ch
GCCacheHelper
func
init
()
{
ch
=
GCCacheHelper
{}
ch
.
Setup
(
500
,
time
.
Minute
*
50
)
}
func
TestCacheGCHelper_Setup
(
t
*
testing
.
T
)
{
assert
.
NotPanics
(
t
,
func
()
{
ch
.
Setup
(
500
,
time
.
Minute
*
50
)
},
"This Setup method should never panic"
)
}
func
TestCacheGCHelper_Set
(
t
*
testing
.
T
)
{
ch
.
Set
(
"a"
,
1
)
val
,
_
:=
ch
.
Get
(
"a"
)
assert
.
Equal
(
t
,
val
,
1
,
"This Cache get should return same value as set"
)
}
func
TestCacheGCHelper_GetAll
(
t
*
testing
.
T
)
{
ch
.
Set
(
"a"
,
1
)
val
:=
ch
.
GetAll
()
assert
.
NotZero
(
t
,
len
(
val
),
"Check if GetAll return more than zero values"
)
cnt
:=
ch
.
Count
()
assert
.
NotZero
(
t
,
cnt
,
"Check if Count method will give more than zero value"
)
ch
.
Remove
(
"a"
)
ch
.
Purge
()
cnt
=
ch
.
Count
()
assert
.
Zero
(
t
,
cnt
,
"After Purge Count should be zero"
)
}
//
import (
//
"testing"
//
"time"
//
"github.com/stretchr/testify/assert"
//
)
//
var ch GCCacheHelper
//
func init() {
//
ch = GCCacheHelper{}
//
ch.Setup(500, time.Minute*50)
//
}
//
func TestCacheGCHelper_Setup(t *testing.T) {
//
assert.NotPanics(t, func() { ch.Setup(500, time.Minute*50) }, "This Setup method should never panic")
//
}
//
func TestCacheGCHelper_Set(t *testing.T) {
//
ch.Set("a", 1)
//
val, _ := ch.Get("a")
//
assert.Equal(t, val, 1, "This Cache get should return same value as set")
//
}
//
func TestCacheGCHelper_GetAll(t *testing.T) {
//
ch.Set("a", 1)
//
val := ch.GetAll()
//
assert.NotZero(t, len(val), "Check if GetAll return more than zero values")
//
cnt := ch.Count()
//
assert.NotZero(t, cnt, "Check if Count method will give more than zero value")
//
ch.Remove("a")
//
ch.Purge()
//
cnt = ch.Count()
//
assert.Zero(t, cnt, "After Purge Count should be zero")
//
}
This diff is collapsed.
Click to expand it.
dalmdl/coremongo/coremongo.go
+
4
−
0
View file @
83762342
...
...
@@ -380,6 +380,10 @@ func (mg *MongoDAO) GetProjectedData(selector map[string]interface{}, projector
}
results
=
append
(
results
,
result
)
}
if
len
(
results
)
==
0
{
rs
:=
gjson
.
Parse
(
`[]`
)
return
&
rs
,
nil
}
ba
,
marshalError
:=
json
.
Marshal
(
results
)
if
errormdl
.
CheckErr2
(
marshalError
)
!=
nil
{
return
nil
,
errormdl
.
CheckErr2
(
marshalError
)
...
...
This diff is collapsed.
Click to expand it.
statemdl/state.go
+
33
−
0
View file @
83762342
...
...
@@ -90,6 +90,8 @@ var serverStartTime time.Time
var
clientResponseData
clientResponse
var
initStatus
=
false
func
init
()
{
// cacheStatistic = &cacheStates{
// cacheHitsMutex: &sync.Mutex{},
...
...
@@ -145,6 +147,7 @@ func Init(name string) {
c
:=
cron
.
New
()
c
.
AddFunc
(
"@every 30s"
,
collectStatistics
)
c
.
Start
()
initStatus
=
true
}
func
readStatisticsFile
()
[]
byte
{
...
...
@@ -168,6 +171,9 @@ func getFilePath() string {
}
func
updateGlobalHit
()
{
if
!
initStatus
{
return
}
cacheStatistic
.
cacheHitsMutex
.
Lock
()
updateGroupCache
(
cacheStatistic
.
totalHits
)
cacheStatistic
.
totalHits
++
...
...
@@ -175,6 +181,9 @@ func updateGlobalHit() {
}
func
updateGroupCache
(
hitCount
int64
)
{
if
!
initStatus
{
return
}
groupMutex
.
Lock
()
groupCount
++
groupMutex
.
Unlock
()
...
...
@@ -182,6 +191,9 @@ func updateGroupCache(hitCount int64) {
// UpdateServiceState - update entry of service in state map
func
UpdateServiceState
(
serviceName
string
,
servingTime
time
.
Duration
,
serviceError
error
,
isRestricted
,
isRoleBased
bool
)
{
if
!
initStatus
{
return
}
stateMutex
.
Lock
()
serviceState
,
ok
:=
stateCache
[
serviceName
]
if
!
ok
{
...
...
@@ -213,6 +225,9 @@ func UpdateServiceState(serviceName string, servingTime time.Duration, serviceEr
// UpdateQueryState - update entry of service in state map
func
UpdateQueryState
(
queryName
string
,
servingTime
time
.
Duration
,
serviceError
error
,
isRestricted
,
isRoleBased
bool
)
{
if
!
initStatus
{
return
}
stateMutex
.
Lock
()
queryState
,
ok
:=
queryCache
[
queryName
]
if
!
ok
{
...
...
@@ -243,6 +258,9 @@ func UpdateQueryState(queryName string, servingTime time.Duration, serviceError
// UpdateGlobalServiceCacheState - update only cache hits and miss count for all services
func
UpdateGlobalServiceCacheState
(
cacheHit
bool
)
{
if
!
initStatus
{
return
}
cacheStatistic
.
cacheHitsMutex
.
Lock
()
defer
cacheStatistic
.
cacheHitsMutex
.
Unlock
()
if
cacheHit
{
...
...
@@ -254,6 +272,9 @@ func UpdateGlobalServiceCacheState(cacheHit bool) {
// EmailHits - update only email hits count for all services
func
EmailHits
()
{
if
!
initStatus
{
return
}
entityHitsObj
.
Mutex
.
Lock
()
defer
entityHitsObj
.
Mutex
.
Unlock
()
entityHitsObj
.
TotalEmail
++
...
...
@@ -261,6 +282,9 @@ func EmailHits() {
// SMSHits - update only sms hits count for all services
func
SMSHits
()
{
if
!
initStatus
{
return
}
entityHitsObj
.
Mutex
.
Lock
()
defer
entityHitsObj
.
Mutex
.
Unlock
()
entityHitsObj
.
TotalSMS
++
...
...
@@ -268,6 +292,9 @@ func SMSHits() {
// MongoHits - update only mongo hits count for all services
func
MongoHits
()
{
if
!
initStatus
{
return
}
dbHitsObj
.
Mutex
.
Lock
()
defer
dbHitsObj
.
Mutex
.
Unlock
()
dbHitsObj
.
MongoHits
++
...
...
@@ -275,12 +302,18 @@ func MongoHits() {
// MySQLHits - update only MySQL hits count for all services
func
MySQLHits
()
{
if
!
initStatus
{
return
}
dbHitsObj
.
Mutex
.
Lock
()
defer
dbHitsObj
.
Mutex
.
Unlock
()
dbHitsObj
.
MySQLHits
++
}
func
collectStatistics
()
{
if
!
initStatus
{
return
}
clientReponseMutex
.
Lock
()
defer
clientReponseMutex
.
Unlock
()
clientResponseData
.
StartTime
=
serverStartTime
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Topics
Snippets