How to use CassandraQueryWaitStrategy class of org.testcontainers.containers.wait package

Best Testcontainers-java code snippet using org.testcontainers.containers.wait.CassandraQueryWaitStrategy

Source:CassandraQueryWaitStrategy.java Github

copy

Full Screen

...10 * Waits until Cassandra returns its version11 *12 * @author Eugeny Karpov13 */14public class CassandraQueryWaitStrategy extends AbstractWaitStrategy {15 private static final String SELECT_VERSION_QUERY = "SELECT release_version FROM system.local";16 private static final String TIMEOUT_ERROR = "Timed out waiting for Cassandra to be accessible for query execution";17 @Override18 protected void waitUntilReady() {19 // execute select version query until success or timeout20 try {21 retryUntilSuccess((int) startupTimeout.getSeconds(), TimeUnit.SECONDS, () -> {22 getRateLimiter().doWhenReady(() -> {23 try (DatabaseDelegate databaseDelegate = getDatabaseDelegate()) {24 databaseDelegate.execute(SELECT_VERSION_QUERY, "", 1, false, false);25 }26 });27 return true;28 });...

Full Screen

Full Screen

Source:CassandraParallelIterationTest.java Github

copy

Full Screen

2import org.infinispan.configuration.cache.ConfigurationBuilder;3import org.infinispan.persistence.ParallelIterationTest;4import org.infinispan.persistence.cassandra.configuration.CassandraStoreConfigurationBuilder;5import org.testcontainers.containers.CassandraContainer;6import org.testcontainers.containers.wait.CassandraQueryWaitStrategy;7import org.testng.annotations.Test;8/**9 * @author wburns10 * @since 10.011 */12@Test(groups = "functional", testName = "persistence.cassandra.CassandraParallelIterationTest")13public class CassandraParallelIterationTest extends ParallelIterationTest {14 private CassandraContainer cassandraContainer;15 @Override16 public void setup() throws Exception {17 cassandraContainer = new CassandraContainer<>()18 .withExposedPorts(9042)19 .withEnv("CASSANDRA_DC", "dc1")20 .withEnv("CASSANDRA_ENDPOINT_SNITCH", "GossipingPropertyFileSnitch")21 .waitingFor(new CassandraQueryWaitStrategy());22 cassandraContainer.start();23 super.setup();24 }25 @Override26 protected void teardown() {27 cassandraContainer.stop();28 super.teardown();29 }30 @Override31 protected void configurePersistence(ConfigurationBuilder cb) {32 cb.persistence().addStore(CassandraStoreConfigurationBuilder.class)33 .segmented(false)34 .entryTable(this.getClass().getSimpleName())35 .autoCreateKeyspace(true)...

Full Screen

Full Screen

CassandraQueryWaitStrategy

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.containers.wait;2import org.testcontainers.containers.ContainerLaunchException;3import org.testcontainers.containers.GenericContainer;4import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy;5import org.testcontainers.containers.wait.strategy.WaitStrategy;6import java.util.concurrent.TimeUnit;7public class CassandraQueryWaitStrategy extends AbstractWaitStrategy {8 private final String query;9 public CassandraQueryWaitStrategy(String query) {10 this.query = query;11 }12 protected void waitUntilReady() {13 WaitStrategy waitStrategy = new CassandraQueryWaitStrategy(query);14 waitStrategy.waitUntilReady(new GenericContainer<>());15 }16 public static void main(String[] args) {17 CassandraQueryWaitStrategy cassandraQueryWaitStrategy = new CassandraQueryWaitStrategy("select * from system.local");18 cassandraQueryWaitStrategy.waitUntilReady();19 }20}21 at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:506)22 at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:321)23 at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)24 at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:319)25 at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:307)26 at org.testcontainers.containers.GenericContainer.starting(GenericContainer.java:1014)27 at org.testcontainers.containers.wait.strategy.AbstractWaitStrategy.waitUntilReady(AbstractWaitStrategy.java:41)28 at org.testcontainers.containers.wait.strategy.CassandraQueryWaitStrategy.main(CassandraQueryWaitStrategy.java:26)29Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for container port to open (

Full Screen

Full Screen

CassandraQueryWaitStrategy

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.wait.strategy.CassandraQueryWaitStrategy;2import com.datastax.oss.driver.api.core.CqlSession;3import com.datastax.oss.driver.api.core.CqlSessionBuilder;4import com.datastax.oss.driver.api.core.cql.Query;5import com.datastax.oss.driver.api.core.cql.SimpleStatement;6import org.testcontainers.containers.Container.ExecResult;7import org.testcontainers.containers.Container.ExecResult;8public class CassandraQueryWaitStrategyExample {9 public static void main(String[] args) {10 try (CqlSession session = CqlSession.builder().withKeyspace("system").build()) {11 CassandraQueryWaitStrategy strategy = new CassandraQueryWaitStrategy();12 strategy.withQuery("SELECT * FROM local");13 strategy.waitUntilReady(session);14 }15 }16}17CassandraQueryWaitStrategyExample.java:19: error: unreported exception Exception; must be caught or declared to be thrown18 strategy.waitUntilReady(session);

Full Screen

Full Screen

CassandraQueryWaitStrategy

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.containers.wait;2import org.testcontainers.containers.ContainerLaunchException;3import org.testcontainers.containers.GenericContainer;4import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy;5import java.io.IOException;6import java.util.concurrent.TimeUnit;7public class CassandraQueryWaitStrategy extends AbstractWaitStrategy {8 private static final String CQLSH_COMMAND = "cqlsh -e 'describe keyspaces;'";9 private final String query;10 public CassandraQueryWaitStrategy(String query) {11 this.query = query;12 }13 protected void waitUntilReady() {14 try {15 GenericContainer container = getContainer();16 container.execInContainer("cqlsh", "-e", query).getExitCode();17 } catch (InterruptedException | IOException e) {18 throw new ContainerLaunchException("Could not query Cassandra", e);19 }20 }21 public static CassandraQueryWaitStrategy forQuery(String query) {22 return new CassandraQueryWaitStrategy(query);23 }24}25package org.testcontainers.containers.wait;26import org.testcontainers.containers.GenericContainer;27import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy;28import java.io.IOException;29import java.util.concurrent.TimeUnit;30public class CassandraQueryWaitStrategy extends AbstractWaitStrategy {31 private static final String CQLSH_COMMAND = "cqlsh -e 'describe keyspaces;'";32 private final String query;33 public CassandraQueryWaitStrategy(String query) {34 this.query = query;35 }36 protected void waitUntilReady() {37 try {38 GenericContainer container = getContainer();39 container.execInContainer("cqlsh", "-e", query).getExitCode();40 } catch (InterruptedException | IOException e) {41 throw new ContainerLaunchException("Could not query Cassandra", e);42 }43 }44 public static CassandraQueryWaitStrategy forQuery(String query) {45 return new CassandraQueryWaitStrategy(query);46 }47}48package org.testcontainers.containers.wait;49import org.testcontainers.containers.GenericContainer;50import org.testcontainers.containers.wait.strategy.AbstractWaitStrategy;51import java.io.IOException;52import java.util.concurrent.TimeUnit;53public class CassandraQueryWaitStrategy extends AbstractWaitStrategy {

Full Screen

Full Screen

CassandraQueryWaitStrategy

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.CassandraContainer;2public class CassandraQueryWaitStrategy extends CassandraContainer {3 private String query;4 public CassandraQueryWaitStrategy(String query) {5 this.query = query;6 }7 protected void waitUntilContainerStarted() {8 getWaitStrategy().waitUntilReady(this);9 }10 public String getClusterName() {11 return "Test Cluster";12 }13}14public class CassandraTest {15 public void testCassandra() {16 CassandraQueryWaitStrategy cassandraContainer = new CassandraQueryWaitStrategy("SELECT * FROM system.local");17 cassandraContainer.start();18 assertThat(cassandraContainer.isRunning()).isTrue();19 cassandraContainer.stop();20 }21}22at org.testcontainers.containers.GenericContainer.waitUntilContainerStarted(GenericContainer.java:861)23at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:410)24at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:318)25at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)26at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:316)27at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:302)28at org.testcontainers.containers.CassandraContainer.start(CassandraContainer.java:42)29at org.testcontainers.containers.CassandraQueryWaitStrategy.waitUntilContainerStarted(CassandraQueryWaitStrategy.java:18)30at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:410)31at org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:318)32at org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)33at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:316)34at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:302)

Full Screen

Full Screen

CassandraQueryWaitStrategy

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.cassandra;2import org.testcontainers.containers.CassandraContainer;3public class CassandraQueryWaitStrategyExample {4 public static void main(String[] args) {5 CassandraContainer cassandraContainer = new CassandraContainer("cassandra:3.11");6 cassandraContainer.withQueryWaitStrategy("SELECT NOW() FROM system.local");7 cassandraContainer.start();8 System.out.println("Cassandra container started successfully");9 cassandraContainer.stop();10 System.out.println("Cassandra container stopped successfully");11 }12}

Full Screen

Full Screen

CassandraQueryWaitStrategy

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.wait.strategy.CassandraQueryWaitStrategy;2import org.testcontainers.containers.wait.strategy.WaitStrategy;3import org.testcontainers.utility.DockerImageName;4public class CassandraQueryWaitStrategy extends AbstractWaitStrategy {5 private final String query;6 public CassandraQueryWaitStrategy(String query) {7 this.query = query;8 }9 protected void waitUntilReady() {10 getLivenessCheckPortNumbers().forEach(port -> {11 try {12 new SimpleWaitStrategy().waitUntilReady(this);13 try (CqlSession cqlSession = CqlSession.builder()14 .addContactPoint(new InetSocketAddress(getContainerIpAddress(), port))15 .withLocalDatacenter("datacenter1")16 .withConfigLoader(getCqlConfigLoader())17 .build()) {18 cqlSession.execute(query);19 }20 } catch (Exception e) {21 throw new IllegalStateException("Failed to execute CQL query: " + query, e);22 }23 });24 }25 protected ConfigLoader getCqlConfigLoader() {26 return ConfigLoaderBuilder.defaults()27 .withClass(DefaultDriverOption.PROTOCOL_VERSION, ProtocolVersion.class, () -> ProtocolVersion.V4)28 .withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(10))29 .withDuration(DefaultDriverOption.REQUEST_TRACE_INTERVAL, Duration.ofSeconds(10))30 .withDuration(DefaultDriverOption.REQUEST_PAGE_SIZE, Duration.ofSeconds(10))31 .withDuration(DefaultDriverOption.REQUEST_CONSISTENCY, Duration.ofSeconds(10))32 .withDuration(DefaultDriverOption.REQUEST_SERIAL_CONSISTENCY, Duration.ofSeconds(10))33 .withDuration(DefaultDriverOption.REQUEST_DEFAULT_IDEMPOTENCE, Duration.ofSeconds(10))34 .withDuration(DefaultDriverOption.REQUEST_DEFAULT_PAGE_SIZE, Duration.ofSeconds(10))35 .withDuration(DefaultDriverOption.REQUEST_DEFAULT_TIMEOUT, Duration.ofSeconds(10))36 .withDuration(DefaultDriverOption.REQUEST_DEFAULT_TIMESTAMP, Duration.ofSeconds(10))37 .withDuration(DefaultDriverOption.REQUEST_DEFAULT_IDEMPOTENCE, Duration.ofSeconds(10))38 .withDuration(DefaultDriverOption.REQUEST_DEFAULT_SERIAL_CONSISTENCY, Duration.ofSeconds(10))39 .withDuration(DefaultDriverOption.REQUEST_DEFAULT_NODE, Duration.ofSeconds(10))40 .withDuration(DefaultDriverOption.REQUEST_DEFAULT_RETRY_POLICY, Duration.ofSeconds(10))41 .withDuration(DefaultDriverOption.REQUEST_DEFAULT_LOAD_BALANCING_POLICY, Duration.of

Full Screen

Full Screen

CassandraQueryWaitStrategy

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.containers.wait;2import org.testcontainers.containers.ContainerLaunchException;3import java.util.concurrent.TimeUnit;4public class CassandraQueryWaitStrategy extends AbstractWaitStrategy {5 private static final String DEFAULT_QUERY = "SELECT release_version FROM system.local";6 private static final int DEFAULT_PORT = 9042;7 private static final int DEFAULT_TIMEOUT_IN_SECONDS = 30;8 private String query = DEFAULT_QUERY;9 private int port = DEFAULT_PORT;10 private int timeoutInSeconds = DEFAULT_TIMEOUT_IN_SECONDS;11 public CassandraQueryWaitStrategy() {12 withStartupTimeout(TimeUnit.SECONDS.toMillis(DEFAULT_TIMEOUT_IN_SECONDS));13 }14 public CassandraQueryWaitStrategy(String query) {15 this();16 this.query = query;17 }18 public CassandraQueryWaitStrategy(int port) {19 this();20 this.port = port;21 }22 public CassandraQueryWaitStrategy(String query, int port) {23 this();24 this.query = query;25 this.port = port;26 }27 public CassandraQueryWaitStrategy withQuery(String query) {28 this.query = query;29 return this;30 }31 public CassandraQueryWaitStrategy withPort(int port) {32 this.port = port;33 return this;34 }35 public CassandraQueryWaitStrategy withTimeoutInSeconds(int timeoutInSeconds) {36 this.timeoutInSeconds = timeoutInSeconds;37 return this;38 }39 protected void waitUntilReady() {40 try {41 getRateLimiter().doWhenReady(() -> {42 try {43 try (CqlSession session = CqlSession.builder().addContactPoint(new InetSocketAddress(getContainerIpAddress(), port)).build()) {44 ResultSet resultSet = session.execute(query);45 if (!resultSet.iterator().hasNext()) {46 throw new ContainerLaunchException("Cassandra is not ready yet");47 }48 }49 } catch (ContainerLaunchException e) {50 throw e;51 } catch (Exception e) {52 throw new ContainerLaunchException("Cassandra is not ready yet", e);53 }54 });55 } catch (RateLimiter.WaitTimeoutException e) {56 throw new ContainerLaunchException("Timed out waiting for Cassandra to be ready");57 }58 }59}60package org.testcontainers.containers.wait;61import org.testcontainers.containers.ContainerLaunchException;62import java.util.concurrent.TimeUnit;

Full Screen

Full Screen

CassandraQueryWaitStrategy

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.CassandraContainer;2import org.testcontainers.containers.wait.strategy.CassandraQueryWaitStrategy;3import org.testcontainers.containers.wait.strategy.Wait;4import org.testcontainers.utility.DockerImageName;5import org.testcontainers.containers.wait.strategy.WaitStrategy;6import java.time.Duration;7public class CassandraQueryWaitStrategyTest {8 public static void main(String[] args) {9 try (CassandraContainer cassandraContainer = new CassandraContainer(DockerImageName.parse("cassandra:3.11.10"))) {10 .withStartupTimeout(Duration.ofMinutes(5))11 .waitingFor(new CassandraQueryWaitStrategy());12 cassandraContainer.start();13 }14 }15}

Full Screen

Full Screen

CassandraQueryWaitStrategy

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.CassandraContainer;2import org.testcontainers.containers.wait.strategy.CassandraQueryWaitStrategy;3public class CassandraQueryWaitStrategyExample {4 public static void main(String[] args) {5 CassandraContainer cassandra = new CassandraContainer()6 .withWaitStrategy(new CassandraQueryWaitStrategy("select * from system.local"));7 cassandra.start();8 }9}10import org.testcontainers.containers.CassandraContainer;11import org.testcontainers.containers.wait.strategy.CassandraQueryWaitStrategy;12public class CassandraQueryWaitStrategyExample {13 public static void main(String[] args) {14 CassandraContainer cassandra = new CassandraContainer()15 .withWaitStrategy(new CassandraQueryWaitStrategy("select * from system.local", 1));16 cassandra.start();17 }18}19Recommended Posts: Cassandra | Cassandra Query Language (CQL)20Cassandra | Cassandra Data Definition Language (DDL)21Cassandra | Cassandra Data Manipulation Language (DML)22Cassandra | Cassandra Data Query Language (DQL)23Cassandra | Cassandra Data Control Language (DCL)24Cassandra | Cassandra Data Definition Language (DDL)25Cassandra | Cassandra Data Manipulation Language (DML)26Cassandra | Cassandra Data Query Language (DQL)27Cassandra | Cassandra Data Control Language (DCL)28Cassandra | Cassandra Query Language (CQL)29Cassandra | Cassandra Data Definition Language (DDL)30Cassandra | Cassandra Data Manipulation Language (DML)31Cassandra | Cassandra Data Query Language (DQL)32Cassandra | Cassandra Data Control Language (DCL)33Cassandra | Cassandra Data Definition Language (DDL)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcontainers-java automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in CassandraQueryWaitStrategy

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful