Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate cassandra-all to use testContainers #703

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changes
## Version 5.0.5

* Deprecate cassandra-all to use testContainers instead - Issue #701
* Updata Mockito and JUnit versions - Issue #687
* Metric status logger for troubleshooting - Issue #397

Expand Down
22 changes: 14 additions & 8 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<scope>test</scope>
</dependency>

<!-- Test -->
<dependency>
<groupId>org.junit.vintage</groupId>
Expand Down Expand Up @@ -117,15 +129,9 @@
</dependency>

<dependency>
<groupId>org.apache.cassandra</groupId>
<artifactId>cassandra-all</artifactId>
<groupId>org.testcontainers</groupId>
<artifactId>cassandra</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018 Telefonaktiebolaget LM Ericsson
* Copyright 2024 Telefonaktiebolaget LM Ericsson
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -14,50 +14,46 @@
*/
package com.ericsson.bss.cassandra.ecchronos.core;

import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.metadata.Node;
import com.ericsson.bss.cassandra.ecchronos.connection.NativeConnectionProvider;
import net.jcip.annotations.NotThreadSafe;
import java.net.InetSocketAddress;
import java.util.Collection;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.testcontainers.containers.CassandraContainer;
import org.testcontainers.utility.DockerImageName;

import java.io.IOException;
import java.net.InetAddress;
import com.datastax.oss.driver.api.core.CqlSession;
import com.datastax.oss.driver.api.core.metadata.Node;
import com.ericsson.bss.cassandra.ecchronos.connection.NativeConnectionProvider;

@NotThreadSafe
public abstract class AbstractCassandraTest
public class AbstractCassandraContainerTest
{
protected static CassandraDaemonForECChronos myCassandraDaemon;
protected static CqlSession mySession;

private static NativeConnectionProvider myNativeConnectionProvider;
private static CassandraContainer<?> node;

@SuppressWarnings("resource")
@BeforeClass
public static void setupCassandra() throws IOException
public static void setUpCluster()
{
myCassandraDaemon = CassandraDaemonForECChronos.getInstance();

mySession = myCassandraDaemon.getSession();

Node tmpNode = null;

InetAddress localhostAddress = InetAddress.getByName("localhost");

for (Node node : mySession.getMetadata().getNodes().values())
{
if (node.getBroadcastAddress().get().getAddress().equals(localhostAddress))
{
tmpNode = node;
}
}

if (tmpNode == null)
{
throw new IllegalArgumentException("Local host not found among cassandra hosts");
}

final Node finalNode = tmpNode;

node = new CassandraContainer<>(DockerImageName.parse("cassandra:4.1.5"))
.withExposedPorts(9042, 7000, 7199)
.withEnv("CASSANDRA_DC", "DC1")
.withEnv("CASSANDRA_ENDPOINT_SNITCH", "GossipingPropertyFileSnitch")
.withEnv("CASSANDRA_CLUSTER_NAME", "TestCluster")
.withEnv("JMX_PORT", "7199");
node.start();
String containerIpAddress = node.getHost();
Integer containerPort = node.getMappedPort(9042);

mySession = CqlSession.builder()
.addContactPoint(new InetSocketAddress(containerIpAddress, containerPort))
.withLocalDatacenter("DC1")
.build();

Collection<Node> nodesList = mySession.getMetadata().getNodes().values();
Node finalNode = nodesList.iterator().next();
myNativeConnectionProvider = new NativeConnectionProvider()
{
@Override
Expand All @@ -81,16 +77,22 @@ public boolean getRemoteRouting()
}

@AfterClass
public static void cleanupCassandra()
public static void tearDownCluster()
{
if (mySession != null)
{
mySession.close();
}
node.stop();
}

public static NativeConnectionProvider getNativeConnectionProvider()
{
return myNativeConnectionProvider;
}

public static CassandraContainer<?> getContainerNode()
{
return node;
}
}
Loading
Loading