Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
Kieker-TeeTime-Stages
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeeTime
Kieker-TeeTime-Stages
Commits
9bb2705c
Commit
9bb2705c
authored
8 years ago
by
Lars Erik Blümke
Browse files
Options
Downloads
Patches
Plain Diff
first try on JMSReaderTest
parent
822fd3f6
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/kieker/analysis/plugin/reader/jms/JMSReaderTest.java
+113
-0
113 additions, 0 deletions
...java/kieker/analysis/plugin/reader/jms/JMSReaderTest.java
with
113 additions
and
0 deletions
src/test/java/kieker/analysis/plugin/reader/jms/JMSReaderTest.java
0 → 100644
+
113
−
0
View file @
9bb2705c
package
kieker.analysis.plugin.reader.jms
;
import
static
teetime
.
framework
.
test
.
StageTester
.
test
;
import
java.util.Hashtable
;
import
java.util.List
;
import
javax.jms.Connection
;
import
javax.jms.ConnectionFactory
;
import
javax.jms.Destination
;
import
javax.jms.JMSException
;
import
javax.jms.MessageProducer
;
import
javax.jms.ObjectMessage
;
import
javax.jms.Session
;
import
javax.naming.Context
;
import
javax.naming.InitialContext
;
import
javax.naming.NameNotFoundException
;
import
javax.naming.NamingException
;
import
org.junit.Before
;
import
org.junit.Test
;
import
kieker.common.logging.Log
;
import
kieker.common.logging.LogFactory
;
import
kieker.common.record.system.CPUUtilizationRecord
;
public
class
JMSReaderTest
{
private
CPUUtilizationRecord
record
;
private
JMSReader
jmsReader
;
// JMSReader constructor arguments
private
final
String
jmsProviderUrl
=
"tcp://localhost:3035/"
;
private
final
String
jmsDestination
=
"queue1"
;
private
final
String
jmsFactoryLookupName
=
"org.exolab.jms.jndi.InitialContextFactory"
;
private
final
Log
log
=
LogFactory
.
getLog
(
this
.
getClass
().
getName
());;
// Record data
private
final
long
timestamp
=
1L
;
private
final
String
hostname
=
"test_host"
;
private
final
String
cpuID
=
"cpu_1"
;
private
final
double
user
=
2.0
;
private
final
double
system
=
3.0
;
private
final
double
wait
=
4.0
;
private
final
double
nice
=
5.0
;
private
final
double
irq
=
6.0
;
private
final
double
totalUtilisation
=
7.0
;
private
final
double
idle
=
8.0
;
@Before
public
void
initializeJMSReader
()
{
jmsReader
=
new
JMSReader
(
jmsProviderUrl
,
jmsDestination
,
jmsFactoryLookupName
,
log
);
record
=
new
CPUUtilizationRecord
(
timestamp
,
hostname
,
cpuID
,
user
,
system
,
wait
,
nice
,
irq
,
totalUtilisation
,
idle
);
}
@Test
public
void
jmsReaderShouldReadCorrectRecords
()
{
produceJMSMessage
();
List
<
Object
>
outputList
=
null
;
test
(
jmsReader
).
and
().
receive
(
outputList
).
from
(
jmsReader
.
getOutputPort
()).
start
();
if
(
outputList
!=
null
)
{
for
(
Object
elem
:
outputList
)
{
System
.
out
.
println
(
"Received"
+
elem
);
}
}
}
public
void
produceJMSMessage
()
{
try
{
final
Hashtable
<
String
,
String
>
properties
=
new
Hashtable
<
String
,
String
>();
// NOPMD NOCS (InitialContext expects Hashtable)
properties
.
put
(
Context
.
INITIAL_CONTEXT_FACTORY
,
this
.
jmsFactoryLookupName
);
// JMS initialization
properties
.
put
(
Context
.
PROVIDER_URL
,
this
.
jmsProviderUrl
);
final
Context
context
=
new
InitialContext
(
properties
);
final
ConnectionFactory
factory
=
(
ConnectionFactory
)
context
.
lookup
(
"ConnectionFactory"
);
Connection
connection
;
connection
=
factory
.
createConnection
();
final
Session
session
=
connection
.
createSession
(
false
,
Session
.
AUTO_ACKNOWLEDGE
);
Destination
destination
;
try
{
// As a first step, try a JNDI lookup (this seems to fail with ActiveMQ sometimes)
destination
=
(
Destination
)
context
.
lookup
(
this
.
jmsDestination
);
}
catch
(
final
NameNotFoundException
exc
)
{
// JNDI lookup failed, try manual creation (this seems to fail with ActiveMQ/HornetQ sometimes)
destination
=
session
.
createQueue
(
this
.
jmsDestination
);
if
(
destination
==
null
)
{
//
this
.
log
.
error
(
"Failed to lookup queue '"
+
this
.
jmsDestination
+
"' via JNDI: "
+
exc
.
getMessage
()
+
" AND failed to create queue"
);
throw
exc
;
// will be catched below to abort the read method
}
}
// Send a monitoring record
ObjectMessage
msg
=
session
.
createObjectMessage
(
record
);
MessageProducer
producer
=
session
.
createProducer
(
destination
);
producer
.
send
(
msg
);
connection
.
close
();
}
catch
(
NamingException
ne
)
{
ne
.
printStackTrace
();
}
catch
(
JMSException
e
)
{
e
.
printStackTrace
();
}
}
}
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