Skip to content

Commit

Permalink
fix and polish
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Dec 12, 2024
1 parent 3c27488 commit 9b979cd
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 41 deletions.
5 changes: 5 additions & 0 deletions batch-boot-jpa-sample/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ services:
- POSTGRES_USER=appuser
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=appdb
healthcheck:
test: ["CMD-SHELL", "pg_isready -U appuser -d appdb"]
interval: 10s
timeout: 5s
retries: 5
ports:
- "5432:5432"
networks:
Expand Down
2 changes: 1 addition & 1 deletion batch-boot-jpa-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.24.0</version>
<version>1.25.0</version>
<style>AOSP</style>
</googleJavaFormat>
<importOrder />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

@SpringBootApplication
@EnableConfigurationProperties({ApplicationProperties.class})
public class Application {
public class BatchApplication {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
SpringApplication.run(BatchApplication.class, args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.*;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.core.job.builder.JobBuilder;
Expand Down Expand Up @@ -60,7 +65,6 @@ Job allCustomersJob(
.start(step)
.incrementer(new RunIdIncrementer())
.listener(this)
.start(step)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ public void run(String... args) {
List<Customer> customerList =
Instancio.ofList(Customer.class)
.size(1000)
.ignore(field(Customer.class, "id"))
.generate(
field(Customer.class, "gender"), gen -> gen.oneOf("male", "female"))
.create();
log.info("Saving Customers of size :{}", customerList.size());
customerList = customerRepository.saveAllAndFlush(customerList);
customerList = customerRepository.saveAll(customerList);
log.info("Inserted customers of size :{}", customerList.size());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.bootbatchjpa;

import com.example.bootbatchjpa.common.ContainersConfig;
import org.springframework.boot.SpringApplication;

public class TestBatchApplication {

public static void main(String[] args) {
SpringApplication.from(BatchApplication::main).with(ContainersConfig.class).run(args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static com.example.bootbatchjpa.utils.AppConstants.PROFILE_TEST;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

import com.example.bootbatchjpa.TestApplication;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
Expand All @@ -14,7 +13,7 @@
@ActiveProfiles({PROFILE_TEST})
@SpringBootTest(
webEnvironment = RANDOM_PORT,
classes = {TestApplication.class})
classes = {ContainersConfig.class})
@AutoConfigureMockMvc
public abstract class AbstractIntegrationTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.bootbatchjpa.common;

import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
public class ContainersConfig {

@Bean
@ServiceConnection
PostgreSQLContainer<?> postgreSQLContainer() {
return new PostgreSQLContainer<>(DockerImageName.parse("postgres").withTag("17.2-alpine"));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

import static org.assertj.core.api.Assertions.assertThat;

import com.example.bootbatchjpa.common.TestContainersConfig;
import com.example.bootbatchjpa.common.ContainersConfig;
import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.testcontainers.context.ImportTestcontainers;
import org.springframework.context.annotation.Import;

@DataJpaTest(properties = {"spring.jpa.hibernate.ddl-auto=validate"})
@ImportTestcontainers(TestContainersConfig.class)
@Import(ContainersConfig.class)
@AutoConfigureTestDatabase
class SchemaValidationTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void setUp() {
field(Customer.class, "gender"), gen -> gen.oneOf("male", "female"))
.create();

customerList = customerRepository.saveAllAndFlush(customerList);
customerList = customerRepository.saveAll(customerList);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
class TestApplication {

public static void main(String[] args) {
SpringApplication.from(Application::main).with(ContainersConfig.class).run(args);
SpringApplication.from(BatchApplication::main).with(ContainersConfig.class).run(args);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
class TestApplication {

public static void main(String[] args) {
SpringApplication.from(Application::main).with(ContainersConfig.class).run(args);
SpringApplication.from(BatchApplication::main).with(ContainersConfig.class).run(args);
}
}

0 comments on commit 9b979cd

Please sign in to comment.