How to use SpannerEmulatorContainer method of org.testcontainers.containers.SpannerEmulatorContainer class

Best Testcontainers-java code snippet using org.testcontainers.containers.SpannerEmulatorContainer.SpannerEmulatorContainer

Source:SpannerContainerTester.java Github

copy

Full Screen

...12import java.util.List;13import java.util.concurrent.ExecutionException;14import java.util.concurrent.TimeUnit;15import java.util.concurrent.TimeoutException;16import org.testcontainers.containers.SpannerEmulatorContainer;17import org.testcontainers.utility.DockerImageName;18import com.force.formula.DisplayField;19import com.google.api.gax.longrunning.OperationFuture;20import com.google.cloud.spanner.Instance;21import com.google.cloud.spanner.InstanceAdminClient;22import com.google.cloud.spanner.InstanceConfigId;23import com.google.cloud.spanner.InstanceId;24import com.google.cloud.spanner.InstanceInfo;25import com.google.cloud.spanner.Spanner;26import com.google.cloud.spanner.SpannerOptions;27import com.google.spanner.admin.instance.v1.CreateInstanceMetadata;28/**29 * Spanner tester that uses a container with the latest emulator 30 * @author stamm31 * @since 0.332 */33public class SpannerContainerTester extends GoogleContainerTester<SpannerEmulatorContainer> {34 /**35 * @throws IOException36 */37 public SpannerContainerTester() throws IOException {38 }39 @Override40 public String getDbTypeName() {41 return "spanner";42 }43 @Override44 protected SpannerEmulatorContainer constructDb() throws IOException {45 return new SpannerEmulatorContainer(DockerImageName.parse("gcr.io/cloud-spanner-emulator/emulator"));46 }47 private static final String PROJECT_ID = "test-project";48 private static final String INSTANCE_ID = "test-instance";49 private static final String DATABASE_ID = "test-database";50 @Override51 protected Connection constructConnection(SpannerEmulatorContainer db) throws SQLException, IOException {52 String host = db.getEmulatorGrpcEndpoint();53 SpannerOptions options = SpannerOptions.newBuilder()54 .setEmulatorHost(host)55 .setProjectId(PROJECT_ID)56 .build();57 Spanner spanner = options.getService();58 59 try {60 // Create a Spanner instance61 InstanceAdminClient instanceAdminClient = spanner.getInstanceAdminClient();62 InstanceId instanceId = InstanceId.of(PROJECT_ID, INSTANCE_ID);63 OperationFuture<Instance, CreateInstanceMetadata> instanceFuture =64 instanceAdminClient.createInstance(65 InstanceInfo.newBuilder(instanceId)...

Full Screen

Full Screen

Source:AbstractIntegrationTest.java Github

copy

Full Screen

...12import org.springframework.test.context.ActiveProfiles;13import org.springframework.test.context.DynamicPropertyRegistry;14import org.springframework.test.context.DynamicPropertySource;15import org.springframework.test.web.servlet.MockMvc;16import org.testcontainers.containers.SpannerEmulatorContainer;17import org.testcontainers.junit.jupiter.Container;18import org.testcontainers.junit.jupiter.Testcontainers;19import org.testcontainers.utility.DockerImageName;20@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)21@Import({TestSpannerConfiguration.class})22@ActiveProfiles("integration")23@Testcontainers24@DirtiesContext25@AutoConfigureMockMvc26public abstract class AbstractIntegrationTest {27 static final String QUERY_SEPARATOR = ";";28 static final String SPANNER_EMULATOR_IMAGE = "gcr.io/cloud-spanner-emulator/emulator:1.1.1";29 static final String SPANNER_EMULATOR_HOST = "spring.cloud.gcp.spanner.emulator-host";30 private static final String DDL_CREATION_FILE = "sql/schema.sql";31 private static final String DDL_DROPPING_FILE = "sql/cleanup.sql";32 @Container33 private static final SpannerEmulatorContainer spannerEmulator =34 new SpannerEmulatorContainer(DockerImageName.parse(SPANNER_EMULATOR_IMAGE));35 @DynamicPropertySource36 private static void emulatorProperties(DynamicPropertyRegistry registry) {37 registry.add(SPANNER_EMULATOR_HOST, spannerEmulator::getEmulatorGrpcEndpoint);38 }39 @Autowired40 MockMvc mockMvc;41 @Autowired42 SpannerDatabaseAdminTemplate spannerDatabaseAdminTemplate;43 void createTables() {44 List<String> ddl = Stream45 .of(FileUtils.readFileAsString(DDL_CREATION_FILE).split(QUERY_SEPARATOR))46 .collect(toList());47 spannerDatabaseAdminTemplate.executeDdlStrings(ddl, true);48 }...

Full Screen

Full Screen

Source:SpannerResourceTest.java Github

copy

Full Screen

...8import javax.inject.Inject;9import org.junit.jupiter.api.AfterAll;10import org.junit.jupiter.api.BeforeAll;11import org.junit.jupiter.api.Test;12import org.testcontainers.containers.SpannerEmulatorContainer;13import org.testcontainers.utility.DockerImageName;14import com.google.cloud.spanner.InstanceConfigId;15import com.google.cloud.spanner.InstanceId;16import com.google.cloud.spanner.InstanceInfo;17import com.google.cloud.spanner.Spanner;18import io.quarkus.test.junit.QuarkusTest;19@QuarkusTest20public class SpannerResourceTest {21 private static final SpannerEmulatorContainer EMULATOR = new SpannerEmulatorContainer(22 DockerImageName.parse("gcr.io/cloud-spanner-emulator/emulator"));23 @Inject24 Spanner spanner;25 @BeforeAll26 public static void startGcloudContainer() {27 List<String> portBindings = new ArrayList<>();28 portBindings.add("9010:9010");29 portBindings.add("9020:9020");30 EMULATOR.setPortBindings(portBindings);31 EMULATOR.start();32 }33 @AfterAll34 public static void stopGcloudContainer() {35 EMULATOR.stop();...

Full Screen

Full Screen

SpannerEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.SpannerEmulatorContainer;2public class SpannerEmulatorContainerTest {3 public static void main(String[] args) {4 try (SpannerEmulatorContainer container = new SpannerEmulatorContainer()) {5 container.start();6 System.out.println("SpannerEmulatorContainer started");7 }8 }9}

Full Screen

Full Screen

SpannerEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.SpannerEmulatorContainer;2public class TestSpannerEmulatorContainer {3 public static void main(String[] args) {4 try (SpannerEmulatorContainer container = new SpannerEmulatorContainer()) {5 container.start();6 System.out.println("SpannerEmulatorContainer started");7 System.out.println("getEmulatorEndpoint() = " + container.getEmulatorEndpoint());8 System.out.println("getEmulatorGrpcEndpoint() = " + container.getEmulatorGrpcEndpoint());9 System.out.println("getEmulatorHost() = " + container.getEmulatorHost());10 System.out.println("getEmulatorPort() = " + container.getEmulatorPort());11 System.out.println("getEmulatorGrpcPort() = " + container.getEmulatorGrpcPort());12 System.out.println("getEmulatorGrpcHost() = " + container.getEmulatorGrpcHost());13 System.out.println("getHost() = " + container.getHost());14 System.out.println("getPort() = " + container.getPort());15 System.out.println("getGrpcPort() = " + container.getGrpcPort());16 System.out.println("getGrpcHost() = " + container.getGrpcHost());17 System.out.println("getProjectId() = " + container.getProjectId());18 System.out.println("getCredentials() = " + container.getCredentials());19 System.out.println("getDatabaseName() = " + container.getDatabaseName());20 System.out.println("getInstanceName() = " + container.getInstanceName());21 System.out.println("getDatabaseId() = " + container.getDatabaseId());22 System.out.println("getInstanceId() = " + container.getInstanceId());23 System.out.println("getDatabasePath() = " + container.getDatabasePath());24 System.out.println("getInstancePath() = " + container.getInstancePath());25 System.out.println("getDsn() = " + container.getDsn());26 System.out.println("getJdbcUrl() = " + container.getJdbcUrl());27 System.out.println("getJdbcDriverClassName() = " + container.getJdbcDriverClassName());28 System.out.println("getJdbcDriverJarUrl() = " + container.getJdbcDriverJarUrl());29 System.out.println("getJdbcDriverMavenCoordinates() = " + container.getJdbcDriverMavenCoordinates());30 System.out.println("getJdbcDriverTest

Full Screen

Full Screen

SpannerEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.SpannerEmulatorContainer;2import org.testcontainers.junit.jupiter.Container;3import org.testcontainers.junit.jupiter.Testcontainers;4public class SpannerEmulatorContainerExample {5 public static SpannerEmulatorContainer spannerEmulator = new SpannerEmulatorContainer();6}7import org.testcontainers.containers.SpannerEmulatorContainer;8import org.testcontainers.junit.jupiter.Container;9import org.testcontainers.junit.jupiter.Testcontainers;10public class SpannerEmulatorContainerExample {11 public static SpannerEmulatorContainer spannerEmulator = new SpannerEmulatorContainer();12}

Full Screen

Full Screen

SpannerEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.SpannerEmulatorContainer;2import org.testcontainers.utility.DockerImageName;3public class MyTest {4 public static void main(String[] args) {5 SpannerEmulatorContainer spannerEmulatorContainer = new SpannerEmulatorContainer(DockerImageName.parse("gcr.io/cloud-spanner-emulator/emulator:latest"));6 spannerEmulatorContainer.start();7 }8}9at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:208)10at org.testcontainers.DockerClientFactory.instance(DockerClientFactory.java:190)11at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:176)12at org.testcontainers.DockerClientFactory.client(DockerClientFactory.java:166)13at org.testcontainers.containers.GenericContainer.getDockerClient(GenericContainer.java:1322)14at org.testcontainers.containers.GenericContainer.logger(GenericContainer.java:1316)15at org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:325)16at org.testcontainers.containers.GenericContainer.start(GenericContainer.java:311)17at MyTest.main(MyTest.java:7)18$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Full Screen

Full Screen

SpannerEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import com.google.cloud.spanner.Database;2import com.google.cloud.spanner.DatabaseAdminClient;3import com.google.cloud.spanner.DatabaseId;4import com.google.cloud.spanner.Spanner;5import com.google.cloud.spanner.SpannerOptions;6import org.testcontainers.containers.SpannerEmulatorContainer;7public class 1 {8 public static void main(String[] args) {9 SpannerEmulatorContainer emulator = new SpannerEmulatorContainer();10 emulator.start();11 SpannerOptions options = SpannerOptions.newBuilder()12 .setHost(emulator.getHost())13 .setEmulatorHost(emulator.getEmulatorEndpoint())14 .build();15 Spanner spanner = options.getService();16 DatabaseAdminClient adminClient = spanner.getDatabaseAdminClient();17 DatabaseId db = DatabaseId.of(options.getProjectId(), "test-instance", "test-database");18 Database database = adminClient.createDatabase(db.getInstanceId().getInstance(), db.getDatabase(), "CREATE TABLE test_table (id INT64, name STRING(100)) PRIMARY KEY (id)").get();19 System.out.println(database);20 }21}22import com.google.cloud.spanner.Database;23import com.google.cloud.spanner.DatabaseAdminClient;24import com.google.cloud.spanner.DatabaseId;25import com.google.cloud.spanner.Spanner;26import com.google.cloud.spanner.SpannerOptions;27import org.testcontainers.containers.SpannerEmulatorContainer;28public class 2 {29 public static void main(String[] args) {30 SpannerEmulatorContainer emulator = new SpannerEmulatorContainer();31 emulator.start();32 SpannerOptions options = SpannerOptions.newBuilder()33 .setHost(emulator.getHost())34 .setEmulatorHost(emulator.getEmulatorEndpoint())35 .build();36 Spanner spanner = options.getService();

Full Screen

Full Screen

SpannerEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.SpannerEmulatorContainer;2public class SpannerEmulatorContainerDemo {3 public static void main(String[] args) {4 SpannerEmulatorContainer spannerEmulatorContainer = new SpannerEmulatorContainer();5 spannerEmulatorContainer.start();6 String emulatorEndpoint = spannerEmulatorContainer.getEmulatorEndpoint();7 System.out.println("emulator endpoint is: " + emulatorEndpoint);8 String emulatorGrpcEndpoint = spannerEmulatorContainer.getEmulatorGrpcEndpoint();9 System.out.println("emulator grpc endpoint is: " + emulatorGrpcEndpoint);10 String emulatorGrpcHost = spannerEmulatorContainer.getEmulatorGrpcHost();11 System.out.println("emulator grpc host is: " + emulatorGrpcHost);12 int emulatorGrpcPort = spannerEmulatorContainer.getEmulatorGrpcPort();13 System.out.println("emulator grpc port is: " + emulatorGrpcPort);14 String emulatorHttpHost = spannerEmulatorContainer.getEmulatorHttpHost();15 System.out.println("emulator http host is: " + emulatorHttpHost);

Full Screen

Full Screen

SpannerEmulatorContainer

Using AI Code Generation

copy

Full Screen

1import com.google.cloud.spanner.DatabaseClient;2import com.google.cloud.spanner.DatabaseId;3import com.google.cloud.spanner.Spanner;4import com.google.cloud.spanner.SpannerOptions;5import com.google.cloud.spanner.Statement;6import org.testcontainers.containers.SpannerEmulatorContainer;7public class SpannerEmulatorContainerExample {8 public static void main(String[] args) {9 SpannerEmulatorContainer emulator = new SpannerEmulatorContainer();10 emulator.start();11 String host = emulator.getHost();12 int port = emulator.getPort();13 SpannerOptions options = SpannerOptions.newBuilder().setHost(host + ":" + port).build();14 Spanner spanner = options.getService();15 DatabaseClient dbClient = spanner.getDatabaseClient(DatabaseId.of("test-project", "test-instance", "test-database"));16 dbClient.executeUpdate(Statement.of("CREATE TABLE TestTable (Id INT64 NOT NULL, Name STRING(100)) PRIMARY KEY (Id)"));17 emulator.stop();18 }19}20SpannerEmulatorContainerExample.java:33: warning: [deprecation] SpannerOptions.Builder.setHost(String) in SpannerOptions.Builder has been deprecated21 SpannerOptions options = SpannerOptions.newBuilder().setHost(host + ":" + port).build();

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 method in SpannerEmulatorContainer

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful