How to use optionallyMapResourceParameterAsVolume method of org.testcontainers.containers.CassandraContainer class

Best Testcontainers-java code snippet using org.testcontainers.containers.CassandraContainer.optionallyMapResourceParameterAsVolume

Source:CassandraContainer.java Github

copy

Full Screen

...56 withEnv("MAX_HEAP_SIZE", "1024M");57 }58 @Override59 protected void configure() {60 optionallyMapResourceParameterAsVolume(CONTAINER_CONFIG_LOCATION, configLocation);61 }62 @Override63 protected void containerIsStarted(InspectContainerResponse containerInfo) {64 runInitScriptIfRequired();65 }66 /**67 * Load init script content and apply it to the database if initScriptPath is set68 */69 private void runInitScriptIfRequired() {70 if (initScriptPath != null) {71 try {72 URL resource = Thread.currentThread().getContextClassLoader().getResource(initScriptPath);73 if (resource == null) {74 logger().warn("Could not load classpath init script: {}", initScriptPath);75 throw new ScriptLoadException("Could not load classpath init script: " + initScriptPath + ". Resource not found.");76 }77 String cql = IOUtils.toString(resource, StandardCharsets.UTF_8);78 DatabaseDelegate databaseDelegate = getDatabaseDelegate();79 ScriptUtils.executeDatabaseScript(databaseDelegate, initScriptPath, cql);80 } catch (IOException e) {81 logger().warn("Could not load classpath init script: {}", initScriptPath);82 throw new ScriptLoadException("Could not load classpath init script: " + initScriptPath, e);83 } catch (ScriptException e) {84 logger().error("Error while executing init script: {}", initScriptPath, e);85 throw new ScriptUtils.UncategorizedScriptException("Error while executing init script: " + initScriptPath, e);86 }87 }88 }89 /**90 * Map (effectively replace) directory in Docker with the content of resourceLocation if resource location is not null91 *92 * Protected to allow for changing implementation by extending the class93 *94 * @param pathNameInContainer path in docker95 * @param resourceLocation relative classpath to resource96 */97 protected void optionallyMapResourceParameterAsVolume(String pathNameInContainer, String resourceLocation) {98 Optional.ofNullable(resourceLocation)99 .map(MountableFile::forClasspathResource)100 .ifPresent(mountableFile -> withCopyFileToContainer(mountableFile, pathNameInContainer));101 }102 /**103 * Initialize Cassandra with the custom overridden Cassandra configuration104 * <p>105 * Be aware, that Docker effectively replaces all /etc/cassandra content with the content of config location, so if106 * Cassandra.yaml in configLocation is absent or corrupted, then Cassandra just won't launch107 *108 * @param configLocation relative classpath with the directory that contains cassandra.yaml and other configuration files109 */110 public SELF withConfigurationOverride(String configLocation) {111 this.configLocation = configLocation;...

Full Screen

Full Screen

optionallyMapResourceParameterAsVolume

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.CassandraContainer2import org.testcontainers.containers.wait.strategy.Wait3CassandraContainer cassandra = new CassandraContainer()4cassandra.withEnv("CASSANDRA_START_RPC", "true")5cassandra.withExposedPorts(9042, 9160)6cassandra.waitingFor(Wait.forListeningPort())7cassandra.start()

Full Screen

Full Screen

optionallyMapResourceParameterAsVolume

Using AI Code Generation

copy

Full Screen

1 public void testOptionalMapResourceParameterAsVolume() throws IOException {2 try (CassandraContainer cassandraContainer = new CassandraContainer()) {3 cassandraContainer.optionalMapResourceParameterAsVolume("cassandra-migration", "/docker-entrypoint-initdb.d");4 cassandraContainer.start();5 String output = cassandraContainer.getLogs();6 assertThat(output, containsString("Executing /docker-entrypoint-initdb.d/cassandra-migration"));7 }8 }9}10at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:321)11at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:303)12at org.testcontainers.containers.CassandraContainer.start(CassandraContainer.java:18)13at org.testcontainers.containers.CassandraContainerTest.testOptionalMapResourceParameterAsVolume(CassandraContainerTest.java:26)14at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)15at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)16at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)17at java.lang.reflect.Method.invoke(Method.java:498)18at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)19at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)

Full Screen

Full Screen

optionallyMapResourceParameterAsVolume

Using AI Code Generation

copy

Full Screen

1import com.datastax.driver.core.Cluster2import com.datastax.driver.core.Session3import org.testcontainers.containers.CassandraContainer4import org.testcontainers.containers.wait.strategy.Wait5import org.testcontainers.utility.MountableFile6fun main() {7 CassandraContainer<Nothing>("cassandra:3.11.3").also { cassandraContainer ->8 cassandraContainer.withExposedPorts(9042)9 cassandraContainer.withEnv(mapOf("CASSANDRA_START_RPC" to "true"))10 cassandraContainer.waitingFor(Wait.forListeningPort())11 cassandraContainer.addFileSystemBind("src/main/resources", "/etc/cassandra", BindMode.READ_ONLY)12 cassandraContainer.start()13 val cluster = Cluster.builder()14 .addContactPoint(cassandraContainer.containerIpAddress)15 .withPort(cassandraContainer.getMappedPort(9042))16 .build()17 val session = cluster.connect()18 session.execute("CREATE KEYSPACE test WITH re

Full Screen

Full Screen

optionallyMapResourceParameterAsVolume

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.CassandraContainer;2import org.testcontainers.containers.GenericContainer;3import org.testcontainers.containers.wait.strategy.Wait;4public class CassandraContainerTest {5 public static void main(String[] args) throws InterruptedException {6 CassandraContainer cassandraContainer = new CassandraContainer("cassandra:3.11.3")7 .withExposedPorts(9042)8 .withEnv("CASSANDRA_START_RPC", "true")9 .waitingFor(Wait.forLogMessage(".*Created default superuser role 'cassandra'.*\\s", 1))10 .withStartupTimeoutSeconds(120);11 cassandraContainer.start();12 System.out.println("Cassandra container started with host " + cassandraContainer.getContainerIpAddress() + " and port " + cassandraContainer.getFirstMappedPort());13 cassandraContainer.stop();14 }15}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful