-
Notifications
You must be signed in to change notification settings - Fork 260
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
340 additions
and
473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...springframework/batch/extensions/bigquery/emulator/reader/BaseEmulatorItemReaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.springframework.batch.extensions.bigquery.emulator.reader; | ||
|
||
import com.google.cloud.NoCredentials; | ||
import com.google.cloud.bigquery.BigQuery; | ||
import com.google.cloud.bigquery.BigQueryOptions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.junit.jupiter.Container; | ||
import org.testcontainers.junit.jupiter.Testcontainers; | ||
import org.testcontainers.utility.MountableFile; | ||
|
||
@Testcontainers | ||
abstract class BaseEmulatorItemReaderTest { | ||
private static final int PORT = 9050; | ||
|
||
private static final String PROJECT = "batch-test"; | ||
|
||
@Container | ||
private static final GenericContainer<?> CONTAINER = new GenericContainer<>("ghcr.io/goccy/bigquery-emulator") | ||
.withExposedPorts(PORT) | ||
.withCommand("--project=" + PROJECT, "--data-from-yaml=/test-data.yaml") | ||
.withCopyFileToContainer(MountableFile.forClasspathResource("test-data.yaml"), "/test-data.yaml"); | ||
|
||
protected static BigQuery bigQuery; | ||
|
||
@BeforeAll | ||
static void init() { | ||
bigQuery = BigQueryOptions | ||
.newBuilder() | ||
.setHost("http://%s:%d".formatted(CONTAINER.getHost(), CONTAINER.getMappedPort(PORT))) | ||
.setProjectId(PROJECT) | ||
.setCredentials(NoCredentials.getInstance()) | ||
.build() | ||
.getService(); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...ngframework/batch/extensions/bigquery/emulator/reader/BigQueryEmulatorItemReaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.springframework.batch.extensions.bigquery.emulator.reader; | ||
|
||
import com.google.cloud.bigquery.*; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.batch.extensions.bigquery.common.PersonDto; | ||
import org.springframework.batch.extensions.bigquery.common.TestConstants; | ||
import org.springframework.batch.extensions.bigquery.reader.BigQueryQueryItemReader; | ||
import org.springframework.batch.extensions.bigquery.reader.builder.BigQueryQueryItemReaderBuilder; | ||
|
||
class BigQueryEmulatorItemReaderTest extends BaseEmulatorItemReaderTest { | ||
|
||
@Test | ||
void testBatchReader() throws Exception { | ||
QueryJobConfiguration jobConfiguration = QueryJobConfiguration | ||
.newBuilder("SELECT p.name, p.age FROM spring_batch_extensions.csv p ORDER BY p.name LIMIT 2") | ||
.setDestinationTable(TableId.of(TestConstants.DATASET, TestConstants.CSV)) | ||
.setPriority(QueryJobConfiguration.Priority.BATCH) | ||
.build(); | ||
|
||
BigQueryQueryItemReader<PersonDto> reader = new BigQueryQueryItemReaderBuilder<PersonDto>() | ||
.bigQuery(bigQuery) | ||
.rowMapper(TestConstants.PERSON_MAPPER) | ||
.jobConfiguration(jobConfiguration) | ||
.build(); | ||
|
||
reader.afterPropertiesSet(); | ||
|
||
verifyResult(reader); | ||
} | ||
|
||
@Test | ||
void testInteractiveReader() throws Exception { | ||
QueryJobConfiguration jobConfiguration = QueryJobConfiguration | ||
.newBuilder("SELECT p.name, p.age FROM spring_batch_extensions.csv p ORDER BY p.name LIMIT 2") | ||
.setDestinationTable(TableId.of(TestConstants.DATASET, TestConstants.CSV)) | ||
.build(); | ||
|
||
BigQueryQueryItemReader<PersonDto> reader = new BigQueryQueryItemReaderBuilder<PersonDto>() | ||
.bigQuery(bigQuery) | ||
.rowMapper(TestConstants.PERSON_MAPPER) | ||
.jobConfiguration(jobConfiguration) | ||
.build(); | ||
|
||
reader.afterPropertiesSet(); | ||
|
||
verifyResult(reader); | ||
} | ||
|
||
private void verifyResult(BigQueryQueryItemReader<PersonDto> reader) throws Exception { | ||
PersonDto actual1 = reader.read(); | ||
Assertions.assertEquals("Volodymyr", actual1.name()); | ||
Assertions.assertEquals(27, actual1.age()); | ||
|
||
PersonDto actual2 = reader.read(); | ||
Assertions.assertEquals("Oleksandra", actual2.name()); | ||
Assertions.assertEquals(26, actual2.age()); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...st/java/org/springframework/batch/extensions/bigquery/emulator/writer/JsonWriterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.springframework.batch.extensions.bigquery.emulator.writer; | ||
|
||
// TODO | ||
public class JsonWriterTest { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.