This file contains hidden or 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
| @Test | |
| public void testReadCommittedIsolationLevel_withMultipleThreads() { | |
| UUID orderId = saveOrder(); | |
| ExecutorService executorService = Executors.newFixedThreadPool(2); | |
| executorService.execute(thread2(orderId)); | |
| executorService.execute(thread1(orderId)); | |
| gracefullyShutdown(executorService); | |
| } | |
| @NotNull |
This file contains hidden or 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
| @Test | |
| public void testReadCommittedIsolationLevel_withSingleTransaction() { | |
| UUID orderId = saveOrder(); | |
| ExecutorService executorService = Executors.newFixedThreadPool(1); | |
| executorService.execute(thread1(orderId)); | |
| gracefullyShutdown(executorService); | |
| } | |
| @NotNull | |
| private UUID saveOrder() { |
This file contains hidden or 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
| @Override | |
| public void save(Order order) { | |
| String insertSql = "INSERT INTO " + TABLE + " VALUES(:id, :name, :order_status, :create_time, :update_time)"; | |
| SqlParameterSource sqlParameterSource = createSqlParameterSource(order); | |
| transactionTemplate.executeWithoutResult( | |
| transactionStatus -> getNamedParameterJdbcTemplate().update(insertSql, sqlParameterSource)); | |
| } | |
| @Override | |
| public void update(Order order) { |
This file contains hidden or 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
| import org.junit.Test; | |
| import org.junit.runner.RunWith; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.boot.test.context.SpringBootTest; | |
| import org.springframework.boot.test.web.client.TestRestTemplate; | |
| import org.springframework.boot.test.web.server.LocalServerPort; | |
| import org.springframework.http.HttpEntity; | |
| import org.springframework.http.HttpHeaders; | |
| import org.springframework.http.HttpMethod; | |
| import org.springframework.http.HttpStatus; |
This file contains hidden or 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
| server: | |
| max-http-header-size: 10KB | |
| spring: | |
| config: | |
| activate: | |
| on-profile: dev | |
| environment: dev | |
| --- |
This file contains hidden or 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
| @RunWith(SpringRunner.class) | |
| public class CrudProductServiceIntegrationTest extends BaseIntegrationTest { | |
| @Autowired | |
| private ProductRepository productRepository; | |
| @Test | |
| public void returnProductName_ifProductSavedBefore() { | |
| String productName = "product001"; | |
| PersistantProduct product = new PersistantProduct(productName); |
This file contains hidden or 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
| package com.softwarelabs.config; | |
| import com.softwarelabs.App; | |
| import org.springframework.boot.test.context.SpringBootTest; | |
| import org.springframework.test.context.ActiveProfiles; | |
| @SpringBootTest(classes = App.class) | |
| @ActiveProfiles("integration") | |
| public abstract class BaseIntegrationTest { | |
| } |
This file contains hidden or 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
| CREATE SEQUENCE IF NOT EXISTS hibernate_sequence START 1; | |
| create table if not exists product | |
| ( | |
| id bigint not null constraint product_pkey primary key, | |
| name varchar(255) UNIQUE | |
| ); |
This file contains hidden or 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
| @Configuration | |
| public class IntegrationTestConfiguration { | |
| private static final String DB_NAME = "store"; | |
| private static final String USERNAME = "dbuser"; | |
| private static final String PASSWORD = "password"; | |
| private static final String PORT = "5432"; | |
| private static final String INIT_SCRIPT_PATH="db/embedded-postgres-init.sql"; | |
This file contains hidden or 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
| abstract class Cat { | |
| String name = "The Cat"; | |
| void clean() {} | |
| } | |
| class Lion extends Cat { | |
| void clean() {} | |
| } |
NewerOlder