Skip to content

Instantly share code, notes, and snippets.

@muzir
muzir / testReadCommittedIsolationLevel_withMultipleThreads.java
Created December 18, 2022 13:45
testReadCommittedIsolationLevel_withMultipleThreads
@Test
public void testReadCommittedIsolationLevel_withMultipleThreads() {
UUID orderId = saveOrder();
ExecutorService executorService = Executors.newFixedThreadPool(2);
executorService.execute(thread2(orderId));
executorService.execute(thread1(orderId));
gracefullyShutdown(executorService);
}
@NotNull
@muzir
muzir / testReadCommittedIsolationLevel_withSingleTransaction.java
Created December 18, 2022 13:24
testReadCommittedIsolationLevel_withSingleTransaction
@Test
public void testReadCommittedIsolationLevel_withSingleTransaction() {
UUID orderId = saveOrder();
ExecutorService executorService = Executors.newFixedThreadPool(1);
executorService.execute(thread1(orderId));
gracefullyShutdown(executorService);
}
@NotNull
private UUID saveOrder() {
@muzir
muzir / OrderRepositoryImpl.java
Created December 18, 2022 12:40
Save and update statements
@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) {
@muzir
muzir / HeaderSizeTest.java
Created December 4, 2022 12:39
HeaderSizeTest with Tomcat
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;
@muzir
muzir / application.yml
Created December 4, 2022 12:22
Spring boot integration test application.yml file
server:
max-http-header-size: 10KB
spring:
config:
activate:
on-profile: dev
environment: dev
---
@muzir
muzir / CrudProductServiceIntegrationTest.java
Created November 26, 2022 13:44
Spring-Boot-KafkaTestContainer.html#CrudProductServiceIntegrationTest
@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);
@muzir
muzir / gist:4ea085090b15c6a7e419fe4a801dadd4
Created November 26, 2022 13:43
Spring-Boot-KafkaTestContainer.html#BaseIntegrationTest.java
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 {
}
@muzir
muzir / embedded-postgres-init.sql
Created November 26, 2022 13:41
Spring-Boot-KafkaTestContainer.html#embedded-postgres-init.sql
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
);
@muzir
muzir / IntegrationTestConfiguration.java
Last active November 26, 2022 13:39
Spring-Boot-KafkaTestContainer.html#IntegrationTestConfiguration.java
@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";
abstract class Cat {
String name = "The Cat";
void clean() {}
}
class Lion extends Cat {
void clean() {}
}