Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
atlas
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dataplatform
atlas
Commits
92d02817
Commit
92d02817
authored
Jan 25, 2017
by
apoorvnaik
Committed by
Madhan Neethiraj
Jan 26, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-1436: Metrics caching and UTs (Part 2)
Signed-off-by:
Madhan Neethiraj
<
madhan@apache.org
>
parent
bf377abb
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
1 deletion
+115
-1
atlas-application.properties
distro/src/conf/atlas-application.properties
+1
-0
AtlasMetrics.java
...ain/java/org/apache/atlas/model/metrics/AtlasMetrics.java
+1
-1
MetricsService.java
...c/main/java/org/apache/atlas/services/MetricsService.java
+0
-0
MetricsServiceTest.java
...st/java/org/apache/atlas/services/MetricsServiceTest.java
+113
-0
No files found.
distro/src/conf/atlas-application.properties
View file @
92d02817
...
@@ -207,6 +207,7 @@ atlas.feature.taxonomy.enable=true
...
@@ -207,6 +207,7 @@ atlas.feature.taxonomy.enable=true
############ Atlas Metric/Stats configs ################
############ Atlas Metric/Stats configs ################
# Format: atlas.metric.query.<key>.<name>
# Format: atlas.metric.query.<key>.<name>
atlas.metric.query.cache.ttlInSecs
=
900
#atlas.metric.query.general.typeCount=
#atlas.metric.query.general.typeCount=
#atlas.metric.query.general.typeUnusedCount=
#atlas.metric.query.general.typeUnusedCount=
#atlas.metric.query.general.entityCount=
#atlas.metric.query.general.entityCount=
...
...
intg/src/main/java/org/apache/atlas/model/metrics/AtlasMetrics.java
View file @
92d02817
...
@@ -61,7 +61,7 @@ public class AtlasMetrics {
...
@@ -61,7 +61,7 @@ public class AtlasMetrics {
}
}
@JsonIgnore
@JsonIgnore
public
void
addData
(
String
groupKey
,
String
key
,
Integ
er
value
)
{
public
void
addData
(
String
groupKey
,
String
key
,
Numb
er
value
)
{
Map
<
String
,
Map
<
String
,
Number
>>
data
=
this
.
data
;
Map
<
String
,
Map
<
String
,
Number
>>
data
=
this
.
data
;
if
(
data
==
null
)
{
if
(
data
==
null
)
{
data
=
new
HashMap
<>();
data
=
new
HashMap
<>();
...
...
repository/src/main/java/org/apache/atlas/services/MetricsService.java
View file @
92d02817
This diff is collapsed.
Click to expand it.
repository/src/test/java/org/apache/atlas/services/MetricsServiceTest.java
0 → 100644
View file @
92d02817
package
org
.
apache
.
atlas
.
services
;
import
org.apache.atlas.model.metrics.AtlasMetrics
;
import
org.apache.atlas.repository.graphdb.AtlasGraph
;
import
org.apache.atlas.type.AtlasTypeRegistry
;
import
org.apache.commons.configuration.Configuration
;
import
org.mockito.invocation.InvocationOnMock
;
import
org.mockito.stubbing.Answer
;
import
org.testng.annotations.BeforeClass
;
import
org.testng.annotations.Test
;
import
javax.script.ScriptException
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
static
org
.
mockito
.
Matchers
.
anyString
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.*;
import
static
org
.
testng
.
Assert
.
assertEquals
;
import
static
org
.
testng
.
Assert
.
assertNotNull
;
public
class
MetricsServiceTest
{
private
Configuration
mockConfig
=
mock
(
Configuration
.
class
);
private
AtlasTypeRegistry
mockTypeRegistry
=
mock
(
AtlasTypeRegistry
.
class
);
private
AtlasGraph
mockGraph
=
mock
(
AtlasGraph
.
class
);
private
MetricsService
metricsService
;
private
List
<
Map
>
mockMapList
=
new
ArrayList
<>();
private
Number
mockCount
=
10
;
@BeforeClass
public
void
init
()
throws
ScriptException
{
Map
<
String
,
Object
>
aMockMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
bMockMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
cMockMap
=
new
HashMap
<>();
aMockMap
.
put
(
"key"
,
"a"
);
aMockMap
.
put
(
"value"
,
1
);
bMockMap
.
put
(
"key"
,
"b"
);
bMockMap
.
put
(
"value"
,
2
);
cMockMap
.
put
(
"key"
,
"c"
);
cMockMap
.
put
(
"value"
,
3
);
mockMapList
.
add
(
aMockMap
);
mockMapList
.
add
(
bMockMap
);
mockMapList
.
add
(
cMockMap
);
when
(
mockConfig
.
getInt
(
anyString
(),
anyInt
())).
thenReturn
(
5
);
assertEquals
(
mockConfig
.
getInt
(
"test"
,
1
),
5
);
when
(
mockTypeRegistry
.
getAllEntityDefNames
()).
thenReturn
(
Arrays
.
asList
(
"a"
,
"b"
,
"c"
));
setupMockGraph
();
metricsService
=
new
MetricsService
(
mockConfig
,
mockGraph
,
mockTypeRegistry
);
}
private
void
setupMockGraph
()
throws
ScriptException
{
if
(
mockGraph
==
null
)
mockGraph
=
mock
(
AtlasGraph
.
class
);
when
(
mockGraph
.
executeGremlinScript
(
anyString
(),
eq
(
false
))).
thenAnswer
(
new
Answer
<
Object
>()
{
@Override
public
Object
answer
(
InvocationOnMock
invocationOnMock
)
throws
Throwable
{
if
(((
String
)
invocationOnMock
.
getArguments
()[
0
]).
contains
(
"count()"
))
{
return
mockCount
;
}
else
{
return
mockMapList
;
}
}
});
}
@Test
public
void
testGetMetrics
()
throws
InterruptedException
,
ScriptException
{
assertNotNull
(
metricsService
);
AtlasMetrics
metrics
=
metricsService
.
getMetrics
();
assertNotNull
(
metrics
);
Number
aCount
=
metrics
.
getMetric
(
"entity"
,
"a"
);
assertNotNull
(
aCount
);
assertEquals
(
aCount
,
10
);
Number
bCount
=
metrics
.
getMetric
(
"entity"
,
"b"
);
assertNotNull
(
bCount
);
assertEquals
(
bCount
,
10
);
Number
cCount
=
metrics
.
getMetric
(
"entity"
,
"c"
);
assertNotNull
(
cCount
);
assertEquals
(
cCount
,
10
);
Number
aTags
=
metrics
.
getMetric
(
"tag"
,
"a"
);
assertNotNull
(
aTags
);
assertEquals
(
aTags
,
1
);
Number
bTags
=
metrics
.
getMetric
(
"tag"
,
"b"
);
assertNotNull
(
bTags
);
assertEquals
(
bTags
,
2
);
Number
cTags
=
metrics
.
getMetric
(
"tag"
,
"c"
);
assertNotNull
(
cTags
);
assertEquals
(
cTags
,
3
);
verify
(
mockGraph
,
atLeastOnce
()).
executeGremlinScript
(
anyString
(),
anyBoolean
());
// Subsequent call within the cache timeout window
metricsService
.
getMetrics
();
verifyZeroInteractions
(
mockGraph
);
// Now test the cache refresh
Thread
.
sleep
(
6000
);
metricsService
.
getMetrics
();
verify
(
mockGraph
,
atLeastOnce
()).
executeGremlinScript
(
anyString
(),
anyBoolean
());
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment