Here is a small example that: Uses @DataJpaTest annotation to bring in only configuration relevant for JPA tests (entities, repos etc...)Uses @TestMethodOrder(MethodOrderer.OrderAnnotation.class) and @Order annotations to enforce order of method executionUses @ComponentScan(basePackages = {"tech.dimitar.rosdjpaint.bootstrap"}) annotation to bring in the component that bootstraps the dataUses @Commit annotation on test to enforce transaction does not roll back … Continue reading Spring Boot JPA Test Splice
Spring Boot – Enable SQL logging
Enable sql logging, format and show bind parameters values, add to application.properties: # spring.jpa.show-sql=true # Show SQL spring.jpa.properties.hibernate.show_sql = true # Format SQL spring.jpa.properties.hibernate.format_sql=true # Show bind values! logging.level.org.hibernate.type.descriptor.sql=trace Example output (insert): Hibernate: call next value for hibernate_sequence Hibernate: insert into book (isbn, publisher, title, id) values (?, ?, ?, ?) 2022-05-17 19:57:10.916 TRACE 44505 … Continue reading Spring Boot – Enable SQL logging
NPM – Installing a local module
Just something I do not do on a regular basis, but might come in handy. Source: https://stackoverflow.com/questions/8088795/installing-a-local-module-using-npm Steps: STEP 1. npm install STEP 2. npm run build STEP 3. npm pack Builds a <package-name>-<version>.tar.gz file. STEP 4: Move the file to the consumer project STEP 5: Refer it in your package.json: "dependencies": { "my-package": "file:/./tmp/my-package-1.3.3.tar.gz" … Continue reading NPM – Installing a local module
Initialize a Database Using Hibernate – profile and db based
You want to initialize a database with different data depending on the data source? Should be straight forward: https://docs.spring.io/spring-boot/docs/current/reference/html/howto.html#howto.data-initialization Spring Boot can automatically create the schema (DDL scripts) of your JDBC DataSource or R2DBC ConnectionFactory and initialize it (DML scripts). It loads SQL from the standard root classpath locations: schema.sql and data.sql, respectively. In addition, … Continue reading Initialize a Database Using Hibernate – profile and db based
Distributed lock on GCP Datastore
So, I needed a distributed lock on the GCP Datastore. In theory, it is all very simple: Get the lockDo what you need to doRelease the lock And, when I started thinking about it, it became clear that I need to have some kind of transaction mechanism in order to obtain the lock. Basically, when … Continue reading Distributed lock on GCP Datastore
Docker image layers
Docker images are layer based - layer based architecture. Each step (instruction) from a Dockerfile creates a layer. These layers are cached and reused next time the image is built. Lets see one Docker file for a node.js app: FROM node:12 WORKDIR /app COPY . /app RUN npm install EXPOSE 80 CMD [ "node", "server.js" … Continue reading Docker image layers
Thread.sleep()
To continue with writing integration tests. When testing asynchronous operations, such as sending message to a queue, waiting for a response and completing some task, we need to introduce some kind of wait time in the test. Instead of using Thread.sleep(), we can use something called Awaitility... Documentation is pretty self explanatory... Testing asynchronous systems … Continue reading Thread.sleep()
Spring Integration Testing – WireMock and MQ
When writing integration tests for parts of the application that talk to other applications, for example calling REST APIs or sending JMS messages, sometimes we just want to test the application and not do end to end test. In this case, we would need to mock these other applications or their behavior. Mocking REST For … Continue reading Spring Integration Testing – WireMock and MQ
IntelliJ auto import on copy-paste
Very nice feature of IntelliJ is auto-importing dependencies and dependencies cleanup (optimize imports), especially useful when copy pasting entire code blocks, deleting stuff etc... Here is a screenshot of where to enable the settings and a link to IntelliJ docs... Auto import Optimize imports
Multiple projects inside one IntelliJ instance
When you are working with multiple projects, for example a number of microservices, it becomes problematic to have an IntelliJ instance open for each of those. There is a trick that allows us to have multiple projects open inside one IntelliJ instance (this saves time, space and RAM :)). Basics steps are as follows: Create … Continue reading Multiple projects inside one IntelliJ instance