How to use assertHasCorrectExposedAndLivenessCheckPorts method of org.testcontainers.containers.PrestoContainerTest class

Best Testcontainers-java code snippet using org.testcontainers.containers.PrestoContainerTest.assertHasCorrectExposedAndLivenessCheckPorts

Source:PrestoContainerTest.java Github

copy

Full Screen

...26 assertThat(resultSet.next()).as("has result").isTrue();27 assertThat(resultSet.getString("node_version"))28 .as("Presto version")29 .isEqualTo(PrestoContainer.DEFAULT_TAG);30 assertHasCorrectExposedAndLivenessCheckPorts(prestoSql);31 }32 }33 }34 @Test35 public void testSpecificVersion() throws Exception {36 try (37 PrestoContainer<?> prestoSql = new PrestoContainer<>(PrestoTestImages.PRESTO_PREVIOUS_VERSION_TEST_IMAGE)38 ) {39 prestoSql.start();40 try (41 Connection connection = prestoSql.createConnection();42 Statement statement = connection.createStatement();43 ResultSet resultSet = statement.executeQuery("SELECT DISTINCT node_version FROM system.runtime.nodes")44 ) {45 assertThat(resultSet.next()).as("has result").isTrue();46 assertThat(resultSet.getString("node_version"))47 .as("Presto version")48 .isEqualTo(PrestoTestImages.PRESTO_PREVIOUS_VERSION_TEST_IMAGE.getVersionPart());49 }50 }51 }52 @Test53 public void testQueryMemoryAndTpch() throws SQLException {54 try (PrestoContainer<?> prestoSql = new PrestoContainer<>(PrestoTestImages.PRESTO_TEST_IMAGE)) {55 prestoSql.start();56 try (57 Connection connection = prestoSql.createConnection();58 Statement statement = connection.createStatement()59 ) {60 // Prepare data61 statement.execute(62 "CREATE TABLE memory.default.table_with_array AS SELECT 1 id, ARRAY[1, 42, 2, 42, 4, 42] my_array"63 );64 // Query Presto using newly created table and a builtin connector65 try (66 ResultSet resultSet = statement.executeQuery(67 "" +68 "SELECT nationkey, element " +69 "FROM tpch.tiny.nation " +70 "JOIN memory.default.table_with_array twa ON nationkey = twa.id " +71 "LEFT JOIN UNNEST(my_array) a(element) ON true " +72 "ORDER BY element OFFSET 1 FETCH NEXT 3 ROWS WITH TIES "73 )74 ) {75 List<Integer> actualElements = new ArrayList<>();76 while (resultSet.next()) {77 actualElements.add(resultSet.getInt("element"));78 }79 assertThat(actualElements).isEqualTo(Arrays.asList(2, 4, 42, 42, 42));80 }81 }82 }83 }84 @Test85 public void testInitScript() throws Exception {86 try (PrestoContainer<?> prestoSql = new PrestoContainer<>(PrestoTestImages.PRESTO_TEST_IMAGE)) {87 prestoSql.withInitScript("initial.sql");88 prestoSql.start();89 try (90 Connection connection = prestoSql.createConnection();91 Statement statement = connection.createStatement();92 ResultSet resultSet = statement.executeQuery("SELECT a FROM memory.default.test_table")93 ) {94 assertThat(resultSet.next()).as("has result").isTrue();95 assertThat(resultSet.getObject("a")).as("Value").isEqualTo(12345678909324L);96 assertThat(resultSet.next()).as("only has one result").isFalse();97 }98 }99 }100 @Test101 public void testTcJdbcUri() throws Exception {102 try (103 Connection connection = DriverManager.getConnection(104 String.format("jdbc:tc:presto:%s://hostname/", PrestoContainer.DEFAULT_TAG)105 )106 ) {107 // Verify metadata with tc: JDBC connection URI108 assertThat(Integer.parseInt(PrestoContainer.DEFAULT_TAG))109 .isEqualTo(connection.getMetaData().getDatabaseMajorVersion());110 // Verify transactions with tc: JDBC connection URI111 assertThat(connection.getAutoCommit()).as("Is autocommit").isTrue();112 connection.setAutoCommit(false);113 assertThat(connection.getAutoCommit()).as("Is autocommit").isFalse();114 assertThat(connection.getTransactionIsolation())115 .as("Transaction isolation")116 .isEqualTo(Connection.TRANSACTION_READ_UNCOMMITTED);117 try (Statement statement = connection.createStatement()) {118 assertThat(statement.executeUpdate("CREATE TABLE memory.default.test_tc(a bigint)"))119 .as("Update result")120 .isEqualTo(0);121 try (122 ResultSet resultSet = statement.executeQuery(123 "SELECT sum(cast(node_version AS bigint)) AS v FROM system.runtime.nodes"124 )125 ) {126 assertThat(resultSet.next()).isTrue();127 assertThat(resultSet.getString("v")).isEqualTo(PrestoContainer.DEFAULT_TAG);128 assertThat(resultSet.next()).isFalse();129 }130 connection.commit();131 } finally {132 connection.rollback();133 }134 connection.setAutoCommit(true);135 assertThat(connection.getAutoCommit()).as("Is autocommit").isTrue();136 assertThat(connection.getTransactionIsolation())137 .as("Transaction isolation should be retained")138 .isEqualTo(Connection.TRANSACTION_READ_UNCOMMITTED);139 }140 }141 private void assertHasCorrectExposedAndLivenessCheckPorts(PrestoContainer<?> prestoSql) {142 assertThat(prestoSql.getExposedPorts()).containsExactly(PrestoContainer.PRESTO_PORT);143 assertThat(prestoSql.getLivenessCheckPortNumbers())144 .containsExactly(prestoSql.getMappedPort(PrestoContainer.PRESTO_PORT));145 }146}...

Full Screen

Full Screen

assertHasCorrectExposedAndLivenessCheckPorts

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.containers;2import org.junit.jupiter.api.Test;3import static org.testcontainers.containers.PrestoContainer.*;4class PrestoContainerTest {5 void assertHasCorrectExposedAndLivenessCheckPorts() {6 PrestoContainer<?> container = new PrestoContainer<>("prestosql/presto:latest");7 container.start();8 container.assertHasCorrectExposedAndLivenessCheckPorts();9 }10}11[Pipeline] }12[Pipeline] { (Declarative: Post Actions)13[Pipeline] {

Full Screen

Full Screen

assertHasCorrectExposedAndLivenessCheckPorts

Using AI Code Generation

copy

Full Screen

1 fn test_presto_check_ports() {2 let port = 8080;3 let mut container = PrestoContainer::default();4 container.with_exposed_ports(vec![port]);5 container.with_liveness_check(Some(6 LivenessCheck::TcpSocket {7 port: Some(port),8 ..Default::default()9 }10 ));11 container.start().unwrap();12 container.assert_has_correct_exposed_and_liveness_check_ports();13 }14 fn test_presto_check_ports_fail() {15 let mut container = PrestoContainer::default();16 container.with_exposed_ports(vec![8080]);17 container.with_liveness_check(Some(18 LivenessCheck::TcpSocket {19 port: Some(8081),20 ..Default::default()21 }22 ));23 container.start().unwrap();24 assert!(container.assert_has_correct_exposed_and_liveness_check_ports().is_err());25 }26 fn test_presto_check_ports_fail_no_liveness_check() {27 let mut container = PrestoContainer::default();28 container.with_exposed_ports(vec![8080]);29 container.start().unwrap();30 assert!(container.assert_has_correct_exposed_and_liveness_check_ports().is_err());31 }32 fn test_presto_check_ports_fail_no_exposed_ports() {33 let mut container = PrestoContainer::default();34 container.with_liveness_check(Some(35 LivenessCheck::TcpSocket {36 port: Some(8080),37 ..Default::default()38 }39 ));40 container.start().unwrap();41 assert!(container.assert_has_correct_exposed_and_liveness_check_ports().is_err());42 }43 fn test_presto_check_ports_fail_no_exposed_ports_no_liveness_check() {44 let mut container = PrestoContainer::default();45 container.start().unwrap();46 assert!(container.assert_has_correct_exposed_and_liveness_check_ports().is_err());47 }48 fn test_presto_check_ports_fail_no_exposed_ports_liveness_check_on_different_port() {49 let mut container = PrestoContainer::default();50 container.with_liveness_check(Some(51 LivenessCheck::TcpSocket {52 port: Some(8081),53 ..Default::default()54 }55 ));56 container.start().unwrap();57 assert!(container

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