Skip to content

Commit

Permalink
Deprecate cassandra-all to use testContainers (#703)
Browse files Browse the repository at this point in the history
* Deprecate cassandra-all and update jackson/snakeyaml

* Undo update for jackson/snakeyaml
  • Loading branch information
VictorCavichioli authored Aug 27, 2024
1 parent 036b32f commit c6fd1e9
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 1,854 deletions.
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

0 comments on commit c6fd1e9

Please sign in to comment.