How to use createConnection method of org.testcontainers.containers.PrestoContainer class

Best Testcontainers-java code snippet using org.testcontainers.containers.PrestoContainer.createConnection

Source:PrestoContainerTest.java Github

copy

Full Screen

...23 @Test24 public void testSimple() throws Exception {25 try (PrestoContainer<?> prestoSql = new PrestoContainer<>(PrestoTestImages.PRESTO_TEST_IMAGE)) {26 prestoSql.start();27 try (Connection connection = prestoSql.createConnection();28 Statement statement = connection.createStatement();29 ResultSet resultSet = statement.executeQuery("SELECT DISTINCT node_version FROM system.runtime.nodes")) {30 assertTrue("No result", resultSet.next());31 assertEquals("Presto version", PrestoContainer.DEFAULT_TAG, resultSet.getString("node_version"));32 }33 }34 }35 @Test36 public void testSpecificVersion() throws Exception {37 try (PrestoContainer<?> prestoSql = new PrestoContainer<>(PrestoTestImages.PRESTO_PREVIOUS_VERSION_TEST_IMAGE)) {38 prestoSql.start();39 try (Connection connection = prestoSql.createConnection();40 Statement statement = connection.createStatement();41 ResultSet resultSet = statement.executeQuery("SELECT DISTINCT node_version FROM system.runtime.nodes")) {42 assertTrue("No result", resultSet.next());43 assertEquals("Presto version", PrestoTestImages.PRESTO_PREVIOUS_VERSION_TEST_IMAGE.getVersionPart(), resultSet.getString("node_version"));44 }45 }46 }47 @Test48 public void testQueryMemoryAndTpch() throws SQLException {49 try (PrestoContainer<?> prestoSql = new PrestoContainer<>(PrestoTestImages.PRESTO_TEST_IMAGE)) {50 prestoSql.start();51 try (Connection connection = prestoSql.createConnection();52 Statement statement = connection.createStatement()) {53 // Prepare data54 statement.execute("CREATE TABLE memory.default.table_with_array AS SELECT 1 id, ARRAY[1, 42, 2, 42, 4, 42] my_array");55 // Query Presto using newly created table and a builtin connector56 try (ResultSet resultSet = statement.executeQuery("" +57 "SELECT nationkey, element " +58 "FROM tpch.tiny.nation " +59 "JOIN memory.default.table_with_array twa ON nationkey = twa.id " +60 "LEFT JOIN UNNEST(my_array) a(element) ON true " +61 "ORDER BY element OFFSET 1 FETCH NEXT 3 ROWS WITH TIES ")) {62 List<Integer> actualElements = new ArrayList<>();63 while (resultSet.next()) {64 actualElements.add(resultSet.getInt("element"));65 }66 Assert.assertEquals(Arrays.asList(2, 4, 42, 42, 42), actualElements);67 }68 }69 }70 }71 @Test72 public void testInitScript() throws Exception {73 try (PrestoContainer<?> prestoSql = new PrestoContainer<>(PrestoTestImages.PRESTO_TEST_IMAGE)) {74 prestoSql.withInitScript("initial.sql");75 prestoSql.start();76 try (Connection connection = prestoSql.createConnection();77 Statement statement = connection.createStatement();78 ResultSet resultSet = statement.executeQuery("SELECT a FROM memory.default.test_table")) {79 assertTrue("No result", resultSet.next());80 assertEquals("Value", 12345678909324L, resultSet.getObject("a"));81 assertFalse("Too many result", resultSet.next());82 }83 }84 }85 @Test86 public void testTcJdbcUri() throws Exception {87 try (Connection connection = DriverManager.getConnection(format("jdbc:tc:presto:%s://hostname/", PrestoContainer.DEFAULT_TAG))) {88 // Verify metadata with tc: JDBC connection URI89 assertEquals(connection.getMetaData().getDatabaseMajorVersion(), parseInt(PrestoContainer.DEFAULT_TAG));90 // Verify transactions with tc: JDBC connection URI...

Full Screen

Full Screen

Source:PrestoContainer.java Github

copy

Full Screen

...88 public SELF withDatabaseName(String dbName) {89 this.catalog = dbName;90 return self();91 }92 public Connection createConnection() throws SQLException, NoDriverFoundException {93 return createConnection("");94 }95}...

Full Screen

Full Screen

createConnection

Using AI Code Generation

copy

Full Screen

1package org.example;2import org.testcontainers.containers.PrestoContainer;3public class App {4 public static void main(String[] args) {5 PrestoContainer container = new PrestoContainer();6 container.start();7 container.createConnection("default");8 container.stop();9 }10}11package org.example;12import org.testcontainers.containers.PrestoContainer;13public class App {14 public static void main(String[] args) {15 PrestoContainer container = new PrestoContainer();16 container.start();17 container.stop();18 }19}20package org.example;21import org.testcontainers.containers.PrestoContainer;22public class App {23 public static void main(String[] args) {24 PrestoContainer container = new PrestoContainer();25 container.start();26 container.stop();27 }28}29package org.example;30import org.testcontainers.containers.PrestoContainer;31public class App {32 public static void main(String[] args) {33 PrestoContainer container = new PrestoContainer();34 container.start();35 container.stop();36 }37}38package org.example;39import org.testcontainers.containers.PrestoContainer;40public class App {41 public static void main(String[] args) {42 PrestoContainer container = new PrestoContainer();43 container.start();44 container.stop();45 }46}47package org.example;48import org.test

Full Screen

Full Screen

createConnection

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.containers;2import java.sql.Connection;3import java.sql.DriverManager;4import java.sql.ResultSet;5import java.sql.SQLException;6import java.sql.Statement;7import java.util.Properties;8import org.junit.Test;9import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals;10import static org.rnorth.visibleassertions.VisibleAssertions.assertTrue;11import org.testcontainers.containers.output.Slf4jLogConsumer;12public class PrestoContainerTest {13 public void testSimple() throws Exception {14 try (PrestoContainer prestoContainer = new PrestoContainer()) {15 prestoContainer.start();16 String jdbcUrl = prestoContainer.getJdbcUrl();17 assertTrue("JDBC URL should start with 'jdbc:presto:'", jdbcUrl.startsWith("jdbc:presto:"));18 try (Connection connection = DriverManager.getConnection(jdbcUrl, "test", null)) {19 try (Statement statement = connection.createStatement()) {20 ResultSet resultSet = statement.executeQuery("SELECT 123 x");21 assertTrue("A result should be returned", resultSet.next());22 assertEquals("A result should have value 123", 123, resultSet.getInt(1));23 }24 }25 }26 }27 public void testWithCustomConfig() throws Exception {28 try (PrestoContainer prestoContainer = new PrestoContainer()) {29 prestoContainer.withConfig("node.environment", "test");30 prestoContainer.start();31 String jdbcUrl = prestoContainer.getJdbcUrl();32 assertTrue("JDBC URL should start with 'jdbc:presto:'", jdbcUrl.startsWith("jdbc:presto:"));33 try (Connection connection = DriverManager.getConnection(jdbcUrl, "test", null)) {34 try (Statement statement = connection.createStatement()) {35 ResultSet resultSet = statement.executeQuery("SELECT current_environment()");36 assertTrue("A result should be returned", resultSet.next());37 assertEquals("A result should have value 'test'", "test", resultSet.getString(1));38 }39 }40 }41 }42 public void testWithCustomConfigMap() throws Exception {43 try (PrestoContainer prestoContainer = new PrestoContainer()) {44 prestoContainer.withConfigurationOverride("node.environment", "test");45 prestoContainer.start();46 String jdbcUrl = prestoContainer.getJdbcUrl();47 assertTrue("JDBC URL should start with 'jdbc:presto:'", jdbcUrl.startsWith("jdbc:presto

Full Screen

Full Screen

createConnection

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.PrestoContainer;2import java.sql.Connection;3import java.sql.DriverManager;4import java.sql.SQLException;5public class Test1 {6 public static void main(String[] args) throws SQLException {7 PrestoContainer presto = new PrestoContainer()8 .withDatabaseName("test")9 .withUsername("test")10 .withPassword("test");11 presto.start();12 Connection conn = presto.createConnection("");13 System.out.println("Connection created");14 conn.close();15 presto.stop();16 }17}

Full Screen

Full Screen

createConnection

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.containers;2import org.testcontainers.containers.PrestoContainer;3import org.testcontainers.utility.DockerImageName;4import java.sql.Connection;5import java.sql.DriverManager;6import java.sql.SQLException;7public class PrestoContainerTest {8 public static void main(String[] args) throws SQLException {9 PrestoContainer presto = new PrestoContainer(DockerImageName.parse("prestosql/presto:latest"));10 presto.start();11 Connection connection = presto.createConnection("");12 presto.stop();13 }14}15package org.testcontainers.containers;16import org.testcontainers.containers.PrestoContainer;17import org.testcontainers.utility.DockerImageName;18import java.sql.Connection;19import java.sql.DriverManager;20import java.sql.SQLException;21public class PrestoContainerTest {22 public static void main(String[] args) throws SQLException {23 PrestoContainer presto = new PrestoContainer(DockerImageName.parse("prestosql/presto:latest"));24 presto.start();25 presto.stop();26 }27}28package org.testcontainers.containers;29import org.testcontainers.containers.PrestoContainer;30import org.testcontainers.utility.DockerImageName;31import java.sql.Connection;32import java.sql.DriverManager;33import java.sql.SQLException;34public class PrestoContainerTest {35 public static void main(String[] args) throws SQLException {36 PrestoContainer presto = new PrestoContainer(Docker

Full Screen

Full Screen

createConnection

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.PrestoContainer;2import java.sql.Connection;3import java.sql.DriverManager;4import java.sql.ResultSet;5import java.sql.ResultSetMetaData;6import java.sql.SQLException;7import java.sql.Statement;8public class 1 {9 public static void main(String[] args) throws SQLException {10 PrestoContainer presto = new PrestoContainer();11 presto.start();12 Connection connection = presto.createConnection("");13 Statement statement = connection.createStatement();14 ResultSet resultSet = statement.executeQuery("SELECT * FROM tpch.sf1000.orders LIMIT 10");15 ResultSetMetaData metaData = resultSet.getMetaData();16 int columnCount = metaData.getColumnCount();17 while (resultSet.next()) {18 for (int i = 1; i <= columnCount; i++) {19 System.out.print(resultSet.getString(i) + " ");20 }21 System.out.println();22 }23 presto.stop();24 }25}

Full Screen

Full Screen

createConnection

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.PrestoContainer;2import java.sql.Connection;3import java.sql.ResultSet;4import java.sql.SQLException;5import java.sql.Statement;6public class Main {7 public static void main(String[] args) throws SQLException {8 PrestoContainer prestoContainer = new PrestoContainer();9 prestoContainer.start();10 Connection conn = prestoContainer.createConnection();11 Statement stmt = conn.createStatement();12 ResultSet rs = stmt.executeQuery("show catalogs");13 while (rs.next()) {14 System.out.println(rs.getString(1));15 }16 prestoContainer.stop();17 }18}

Full Screen

Full Screen

createConnection

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.PrestoContainer;2import java.sql.*;3public class 1 {4 public static void main(String[] args) throws SQLException {5 PrestoContainer presto = new PrestoContainer();6 presto.start();7 Connection connection = presto.createConnection("default");8 Statement statement = connection.createStatement();9 ResultSet resultSet = statement.executeQuery("SELECT 1");10 while (resultSet.next()) {11 System.out.println(resultSet.getString(1));12 }13 presto.close();14 }15}16import org.testcontainers.containers.PrestoContainer;17import java.sql.*;18public class 2 {19 public static void main(String[] args) throws SQLException {20 PrestoContainer presto = new PrestoContainer();21 presto.start();22 Connection connection = presto.createConnection("default");23 Statement statement = connection.createStatement();24 ResultSet resultSet = statement.executeQuery("SELECT 1");25 while (resultSet.next()) {26 System.out.println(resultSet.getString(1));27 }28 presto.close();29 }30}31import org.testcontainers.containers.PrestoContainer;32import java.sql.*;33public class 3 {34 public static void main(String[] args) throws SQLException {35 PrestoContainer presto = new PrestoContainer();36 presto.start();37 Connection connection = presto.createConnection("default");38 Statement statement = connection.createStatement();39 ResultSet resultSet = statement.executeQuery("SELECT 1");40 while (resultSet.next()) {41 System.out.println(resultSet.getString(1));42 }43 presto.close();44 }45}

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful