Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spark
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs525-sp18-g07
spark
Commits
e080588f
Commit
e080588f
authored
11 years ago
by
jerryshao
Browse files
Options
Downloads
Patches
Plain Diff
Add metrics system unit test
parent
5ce5dc9f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/src/test/scala/spark/metrics/MetricsConfigSuite.scala
+92
-0
92 additions, 0 deletions
core/src/test/scala/spark/metrics/MetricsConfigSuite.scala
core/src/test/scala/spark/metrics/MetricsSystemSuite.scala
+65
-0
65 additions, 0 deletions
core/src/test/scala/spark/metrics/MetricsSystemSuite.scala
with
157 additions
and
0 deletions
core/src/test/scala/spark/metrics/MetricsConfigSuite.scala
0 → 100644
+
92
−
0
View file @
e080588f
package
spark.metrics
import
java.util.Properties
import
java.io.
{
File
,
FileOutputStream
}
import
org.scalatest.
{
BeforeAndAfter
,
FunSuite
}
import
spark.metrics._
class
MetricsConfigSuite
extends
FunSuite
with
BeforeAndAfter
{
var
filePath
:
String
=
_
before
{
val
prop
=
new
Properties
()
prop
.
setProperty
(
"*.sink.console.period"
,
"10"
)
prop
.
setProperty
(
"*.sink.console.unit"
,
"second"
)
prop
.
setProperty
(
"*.source.jvm.class"
,
"spark.metrics.source.JvmSource"
)
prop
.
setProperty
(
"master.sink.console.period"
,
"20"
)
prop
.
setProperty
(
"master.sink.console.unit"
,
"minute"
)
val
dir
=
new
File
(
"/tmp"
)
filePath
=
if
(
dir
.
isDirectory
()
&&
dir
.
exists
()
&&
dir
.
canWrite
())
{
"/tmp/test_metrics.properties"
}
else
{
"./test_metrics.properties"
}
val
os
=
new
FileOutputStream
(
new
File
(
filePath
))
prop
.
store
(
os
,
"for test"
)
os
.
close
()
}
test
(
"MetricsConfig with default properties"
)
{
val
conf
=
new
MetricsConfig
(
"dummy-file"
)
assert
(
conf
.
properties
.
size
()
===
2
)
assert
(
conf
.
properties
.
getProperty
(
"*.sink.jmx.enabled"
)
===
"default"
)
assert
(
conf
.
properties
.
getProperty
(
"*.source.jvm.class"
)
===
"spark.metrics.source.JvmSource"
)
assert
(
conf
.
properties
.
getProperty
(
"test-for-dummy"
)
===
null
)
val
property
=
conf
.
getInstance
(
"random"
)
assert
(
property
.
size
()
===
2
)
assert
(
property
.
getProperty
(
"sink.jmx.enabled"
)
===
"default"
)
assert
(
property
.
getProperty
(
"source.jvm.class"
)
===
"spark.metrics.source.JvmSource"
)
}
test
(
"MetricsConfig with properties set"
)
{
val
conf
=
new
MetricsConfig
(
filePath
)
val
masterProp
=
conf
.
getInstance
(
"master"
)
assert
(
masterProp
.
size
()
===
4
)
assert
(
masterProp
.
getProperty
(
"sink.console.period"
)
===
"20"
)
assert
(
masterProp
.
getProperty
(
"sink.console.unit"
)
===
"minute"
)
assert
(
masterProp
.
getProperty
(
"sink.jmx.enabled"
)
===
"default"
)
assert
(
masterProp
.
getProperty
(
"source.jvm.class"
)
==
"spark.metrics.source.JvmSource"
)
val
workerProp
=
conf
.
getInstance
(
"worker"
)
assert
(
workerProp
.
size
()
===
4
)
assert
(
workerProp
.
getProperty
(
"sink.console.period"
)
===
"10"
)
assert
(
workerProp
.
getProperty
(
"sink.console.unit"
)
===
"second"
)
}
test
(
"MetricsConfig with subProperties"
)
{
val
conf
=
new
MetricsConfig
(
filePath
)
val
propCategories
=
conf
.
propertyCategories
assert
(
propCategories
.
size
===
2
)
val
masterProp
=
conf
.
getInstance
(
"master"
)
val
sourceProps
=
MetricsConfig
.
subProperties
(
masterProp
,
MetricsSystem
.
SOURCE_REGEX
)
assert
(
sourceProps
.
size
===
1
)
assert
(
sourceProps
(
"jvm"
).
getProperty
(
"class"
)
===
"spark.metrics.source.JvmSource"
)
val
sinkProps
=
MetricsConfig
.
subProperties
(
masterProp
,
MetricsSystem
.
SINK_REGEX
)
assert
(
sinkProps
.
size
===
2
)
assert
(
sinkProps
.
contains
(
"console"
))
assert
(
sinkProps
.
contains
(
"jmx"
))
val
consoleProps
=
sinkProps
(
"console"
)
assert
(
consoleProps
.
size
()
===
2
)
val
jmxProps
=
sinkProps
(
"jmx"
)
assert
(
jmxProps
.
size
()
===
1
)
}
after
{
val
file
=
new
File
(
filePath
)
if
(
file
.
exists
())
{
file
.
delete
()
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
core/src/test/scala/spark/metrics/MetricsSystemSuite.scala
0 → 100644
+
65
−
0
View file @
e080588f
package
spark.metrics
import
java.util.Properties
import
java.io.
{
File
,
FileOutputStream
}
import
org.scalatest.
{
BeforeAndAfter
,
FunSuite
}
import
spark.metrics._
class
MetricsSystemSuite
extends
FunSuite
with
BeforeAndAfter
{
var
filePath
:
String
=
_
before
{
val
props
=
new
Properties
()
props
.
setProperty
(
"*.sink.console.period"
,
"10"
)
props
.
setProperty
(
"*.sink.console.unit"
,
"second"
)
props
.
setProperty
(
"test.sink.console.class"
,
"spark.metrics.sink.ConsoleSink"
)
props
.
setProperty
(
"test.sink.dummy.class"
,
"spark.metrics.sink.DummySink"
)
props
.
setProperty
(
"test.source.dummy.class"
,
"spark.metrics.source.DummySource"
)
props
.
setProperty
(
"test.sink.console.period"
,
"20"
)
props
.
setProperty
(
"test.sink.console.unit"
,
"minute"
)
val
dir
=
new
File
(
"/tmp"
)
filePath
=
if
(
dir
.
isDirectory
()
&&
dir
.
exists
()
&&
dir
.
canWrite
())
{
"/tmp/test_metrics.properties"
}
else
{
"./test_metrics.properties"
}
val
os
=
new
FileOutputStream
(
new
File
(
filePath
))
props
.
store
(
os
,
"for test"
)
os
.
close
()
System
.
setProperty
(
"spark.metrics.conf.file"
,
filePath
)
}
test
(
"MetricsSystem with default config"
)
{
val
metricsSystem
=
MetricsSystem
.
createMetricsSystem
(
"default"
)
val
sources
=
metricsSystem
.
sources
val
sinks
=
metricsSystem
.
sinks
assert
(
sources
.
length
===
1
)
assert
(
sinks
.
length
===
1
)
assert
(
sources
(
0
).
sourceName
===
"jvm"
)
}
test
(
"MetricsSystem with sources add"
)
{
val
metricsSystem
=
MetricsSystem
.
createMetricsSystem
(
"test"
)
val
sources
=
metricsSystem
.
sources
val
sinks
=
metricsSystem
.
sinks
assert
(
sources
.
length
===
1
)
assert
(
sinks
.
length
===
2
)
val
source
=
new
spark
.
deploy
.
master
.
MasterInstrumentation
(
null
)
metricsSystem
.
registerSource
(
source
)
assert
(
sources
.
length
===
2
)
}
after
{
val
file
=
new
File
(
filePath
)
if
(
file
.
exists
())
{
file
.
delete
()
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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