Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package io.stargate.sgv2.jsonapi.api.v1;

import static io.stargate.sgv2.jsonapi.api.v1.ResponseAssertions.*;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.stargate.sgv2.jsonapi.testresource.DseTestResource;
import io.stargate.sgv2.jsonapi.testresource.StargateTestResource;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;

@QuarkusIntegrationTest
@QuarkusTestResource(DseTestResource.class)
public class SessionEvictionIntegrationTest extends AbstractCollectionIntegrationTestBase {

@Test
public void testSessionEvictionOnAllNodesFailed() throws InterruptedException {

insertDoc(
"""
{
"insertOne": {
"document": {
"name": "before_crash"
}
}
}
""");

GenericContainer<?> dbContainer = StargateTestResource.getCassandraContainer();
if (dbContainer == null) {
throw new RuntimeException("Cannot find Cassandra container.");
}

System.out.println("Stopping Database Container to simulate failure...");
dbContainer.stop();

// Should get AllNodeFailedException
givenHeadersPostJsonThen(
"""
{
"insertOne": {
"document": {
"name": "after_crash"
}
}
}
""")
.statusCode(500)
.body("$", responseIsError());

// restart container
System.out.println("Starting Database Container to simulate recovery...");
dbContainer.start();

// wait
Thread.sleep(20000);

// restore
createKeyspace();
createDefaultCollection();

// verify
insertDoc(
"""
{
"insertOne": {
"document": {
"name": "after_crash"
}
}
}
""");

System.out.println("Test Passed: Session recovered after DB restart.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public abstract class StargateTestResource

private static final Logger LOG = LoggerFactory.getLogger(StargateTestResource.class);

/** The backend database container (Cassandra, DSE, or HCD). */
private static GenericContainer<?> cassandraContainer;

/**
* Network ID injected by Quarkus when running tests inside a container (e.g., CI/CD). Used to
* connect the database container to the same network as the test runner.
Expand All @@ -32,9 +35,6 @@ public abstract class StargateTestResource
*/
private Network network;

/** The backend database container (Cassandra, DSE, or HCD). */
private GenericContainer<?> cassandraContainer;

/**
* Called by Quarkus to inject the DevServicesContext, allowing us to detect if we are running
* inside a container network.
Expand Down Expand Up @@ -110,6 +110,10 @@ public static String getPersistenceModule() {
"testing.containers.cluster-persistence", "persistence-cassandra-4.0");
}

public static GenericContainer<?> getCassandraContainer() {
return cassandraContainer;
}

public static boolean isDse() {
String dse = System.getProperty("testing.containers.cluster-dse", null);
return "true".equals(dse);
Expand Down
Loading