-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#8965] Apply SharedTestLifeCycle to Cassandra
- Loading branch information
Showing
9 changed files
with
120 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...t/cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.navercorp.pinpoint.plugin.cassandra; | ||
|
||
import com.datastax.driver.core.Cluster; | ||
import com.datastax.driver.core.Session; | ||
import com.navercorp.pinpoint.test.plugin.shared.SharedTestLifeCycle; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.junit.Assume; | ||
import org.testcontainers.DockerClientFactory; | ||
import org.testcontainers.containers.CassandraContainer; | ||
|
||
import java.util.Objects; | ||
import java.util.Properties; | ||
|
||
public class CassandraServer implements SharedTestLifeCycle { | ||
private final Logger logger = LogManager.getLogger(getClass()); | ||
|
||
private final String dockerImageVersion; | ||
|
||
public CassandraContainer cassandra; | ||
private Cluster cluster; | ||
|
||
public CassandraServer(String dockerImageVersion) { | ||
this.dockerImageVersion = Objects.requireNonNull(dockerImageVersion, "dockerImageVersion"); | ||
} | ||
|
||
@Override | ||
public Properties beforeAll() { | ||
Assume.assumeTrue("Docker not enabled", DockerClientFactory.instance().isDockerAvailable()); | ||
|
||
cassandra = new CassandraContainer(dockerImageVersion); | ||
cassandra.start(); | ||
|
||
final Integer port = cassandra.getMappedPort(CassandraContainer.CQL_PORT); | ||
|
||
this.cluster = newCluster("127.0.0.1", port); | ||
init(cluster); | ||
cluster.close(); | ||
|
||
Properties properties = new Properties(); | ||
properties.setProperty("PORT", port.toString()); | ||
return properties; | ||
} | ||
|
||
public void init(Cluster cluster) { | ||
try (Session systemSession = cluster.connect()) { | ||
String createKeyspace = String.format("CREATE KEYSPACE IF NOT EXISTS %s WITH replication = " + | ||
"{'class':'SimpleStrategy','replication_factor':'1'};", CassandraITConstants.TEST_KEYSPACE); | ||
systemSession.execute(createKeyspace); | ||
String createTable = String.format("CREATE TABLE %s.%s (id text, value text, PRIMARY KEY(id))", | ||
CassandraITConstants.TEST_KEYSPACE, CassandraITConstants.TEST_TABLE); | ||
systemSession.execute(createTable); | ||
} | ||
} | ||
|
||
public static Cluster newCluster(String host, int port) { | ||
Cluster.Builder builder = Cluster.builder(); | ||
builder.addContactPoint(host); | ||
builder.withPort(port); | ||
builder.withoutMetrics(); | ||
return builder.build(); | ||
} | ||
|
||
@Override | ||
public void afterAll() { | ||
if (cassandra != null) { | ||
cassandra.stop(); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraServer2X.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.navercorp.pinpoint.plugin.cassandra; | ||
|
||
public class CassandraServer2X extends CassandraServer { | ||
|
||
public CassandraServer2X() { | ||
super(CassandraITConstants.CASSANDRA_2_X_IMAGE); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...cassandra-it/src/test/java/com/navercorp/pinpoint/plugin/cassandra/CassandraServer3X.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.navercorp.pinpoint.plugin.cassandra; | ||
|
||
public class CassandraServer3X extends CassandraServer { | ||
|
||
public CassandraServer3X() { | ||
super(CassandraITConstants.CASSANDRA_3_X_IMAGE); | ||
} | ||
|
||
} |