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
15534f23
Commit
15534f23
authored
Apr 11, 2018
by
Ashutosh Mestry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ATLAS-2470 - JanusGraph Cassandra . Updates to unit test.
parent
bf5f8ef0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
8 deletions
+41
-8
CassandraAuditRepositoryTest.java
.../atlas/repository/audit/CassandraAuditRepositoryTest.java
+41
-8
No files found.
repository/src/test/java/org/apache/atlas/repository/audit/CassandraAuditRepositoryTest.java
View file @
15534f23
...
...
@@ -18,13 +18,15 @@
package
org
.
apache
.
atlas
.
repository
.
audit
;
import
org.apache.atlas.ApplicationProperties
;
import
com.datastax.driver.core.Cluster
;
import
com.datastax.driver.core.Session
;
import
org.apache.atlas.AtlasException
;
import
org.apache.cassandra.exceptions.ConfigurationException
;
import
org.apache.commons.configuration.Configuration
;
import
org.apache.commons.configuration.MapConfiguration
;
import
org.apache.thrift.transport.TTransportException
;
import
org.cassandraunit.utils.EmbeddedCassandraServerHelper
;
import
org.testng.SkipException
;
import
org.testng.annotations.BeforeClass
;
import
java.io.IOException
;
...
...
@@ -32,22 +34,53 @@ import java.util.HashMap;
import
java.util.Map
;
public
class
CassandraAuditRepositoryTest
extends
AuditRepositoryTestBase
{
private
static
final
int
MAX_RETRIES
=
9
;
private
final
String
CLUSTER_HOST
=
"localhost"
;
private
final
String
CLUSTER_NAME_TEST
=
"Test Cluster"
;
private
final
int
CLUSTER_PORT
=
9042
;
@BeforeClass
public
void
setup
()
throws
InterruptedException
,
TTransportException
,
ConfigurationException
,
IOException
,
AtlasException
{
EmbeddedCassandraServerHelper
.
startEmbeddedCassandra
(
"cassandra_test.yml"
);
eventRepository
=
new
CassandraBasedAuditRepository
();
Configuration
atlasConf
=
new
MapConfiguration
(
getClusterProperties
());
((
CassandraBasedAuditRepository
)
eventRepository
).
setApplicationProperties
(
atlasConf
);
((
CassandraBasedAuditRepository
)
eventRepository
).
start
();
ensureClusterCreation
();
}
private
Map
<
String
,
Object
>
getClusterProperties
()
{
Map
<
String
,
Object
>
props
=
new
HashMap
<>();
props
.
put
(
CassandraBasedAuditRepository
.
MANAGE_EMBEDDED_CASSANDRA
,
Boolean
.
TRUE
);
props
.
put
(
CassandraBasedAuditRepository
.
CASSANDRA_CLUSTERNAME_PROPERTY
,
"Test Cluster"
);
props
.
put
(
CassandraBasedAuditRepository
.
CASSANDRA_HOSTNAME_PROPERTY
,
"localhost"
);
props
.
put
(
CassandraBasedAuditRepository
.
CASSANDRA_PORT_PROPERTY
,
9042
);
Configuration
atlasConf
=
new
MapConfiguration
(
props
);
((
CassandraBasedAuditRepository
)
eventRepository
).
setApplicationProperties
(
atlasConf
);
((
CassandraBasedAuditRepository
)
eventRepository
).
start
();
// Pause for a second to ensure that the embedded cluster has started
props
.
put
(
CassandraBasedAuditRepository
.
CASSANDRA_CLUSTERNAME_PROPERTY
,
CLUSTER_NAME_TEST
);
props
.
put
(
CassandraBasedAuditRepository
.
CASSANDRA_HOSTNAME_PROPERTY
,
CLUSTER_HOST
);
props
.
put
(
CassandraBasedAuditRepository
.
CASSANDRA_PORT_PROPERTY
,
CLUSTER_PORT
);
return
props
;
}
private
void
ensureClusterCreation
()
throws
InterruptedException
{
// Retry the connection until we either connect or timeout
Cluster
.
Builder
cassandraClusterBuilder
=
Cluster
.
builder
();
Cluster
cluster
=
cassandraClusterBuilder
.
addContactPoint
(
CLUSTER_HOST
).
withClusterName
(
CLUSTER_NAME_TEST
).
withPort
(
CLUSTER_PORT
)
.
build
();
int
retryCount
=
0
;
while
(
retryCount
<
MAX_RETRIES
)
{
try
{
Session
cassSession
=
cluster
.
connect
();
if
(
cassSession
.
getState
().
getConnectedHosts
().
size
()
>
0
)
{
cassSession
.
close
();
return
;
}
}
catch
(
Exception
e
)
{
Thread
.
sleep
(
1000
);
}
retryCount
++;
}
throw
new
SkipException
(
"Unable to connect to embedded Cassandra after "
+
MAX_RETRIES
+
" seconds."
);
}
}
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