JMeter and SpringBoot REST services
It is important to ensure effective performance for software applications, and software testing is often required to ensure that the application runs without any failures. This blog on JMeter will provide in-depth knowledge about this load testing tool for analyzing and measuring the performance in the following sequence.
- DZone JMeter Tutorial for Beginners
- Baeldung, performance testing with JMeter
- Configure Jenkins to Run and Show JMeter Tests
- Testing Microservices With JMeter
- mutual two way ssl
- How to use windows certificate store
- user defined variables
- keystore configurations
- REST API Testing with JMeter (step by step)
- Building a Web Test Plan
- JMeter Tutorial: Testing REST Web Services
- How to Load Test: A developer’s guide to performance testing
Recording with JMeter
If you need to simulate uploading a file to application under test, the fastest way of creating a JMeter test plan is recording the corresponding request via the HTTP(S) Test Script Recorder. JMeter comes with a proxy server which captures all traffic between the browser and the application under test, and converts it into the relevant HTTP Request samplers.
- Recording File Uploads with JMeter
- JMeter's Superpower: The HTTP Proxy Server
- Apache JMeter HTTP(S) Test Script Recorder
Spring the ultimate guides
Whatever you're building, these guides are designed to get you productive as quickly as possible – using the latest Spring project releases and techniques as recommended by the Spring team.
All the Spring Guides Together
SpringBoot Milestones
- Spring Projects and versions
- Track the project stack with JavaTpoint
- JournalDev updates on Springboot
- JavaTpoint and technical interviews
- Spring Interview Questions and Answers
Spring, Swagger uploading files
-
Manage upload/download of files using REST and Spring Boot at masterspringboot.com
- Handling File Upload Exceptions
So what is the entity fetching strategy anyway?
When JPA loads an entity, it also loads all the EAGER or “join fetch” associations too. As long as the persistence context is opened, navigating the LAZY association results in fetching those as well, through additionally executed queries.Planning your fetching strategy from the very beginning, and adjusting it all along the development cycle isn’t a “premature optimization”; it’s just a natural part of any ORM design.
- Read
- The best way to handle the LazyInitializationException
- Understanding JPA/Hibernate Persistence Context
The LazyInitializationException
is undoubtedly one of the most common exceptions you can get when using Hibernate. Unfortunately, JPA 1.0 decided that @ManyToOne
and @OneToOne
should default to FetchType.EAGER
, so now you have to explicitly mark these two associations as FetchType.LAZY
:
The solution, DTO projections with Spring Data Projections and Open Projections and the most beautiful Dynamic Projections
- Dynamic Projects on Spring Data JPA from the source
- SPRING DATA JPA PROJECTIONS – 5 WAYS TO RETURN CUSTOM RESPONSE
- Partial Data Update with Spring Data
- JPA join types
Spring Data JPA Specification
Spring Data JPA was created primarily to allow easy query creation with query generation by method name. However, sometimes, we need to create complex queries and cannot take advantage of a query generator. The Spring Data JPA provides a repository programming model that starts with an interface per managed domain object. Defining these interfaces serves two purposes: first, by extending the JpaRepository, we get a bunch of generic CRUD methods, like save, findAll, delete, and so on.
To Create Complex Queries, Why Specification?
Yes, complex queries can be build using the Criteria API. For any complex-enough API – searching/filtering your resources by very simple fields is simply not enough. A query language is more flexible and allows you to filter down to exactly the resources you need.
- Baeldung about
- DZone about
- Spring Blog
- LogicBig about
- Spring Data JPA - Combining multiple Specifications
- Multiple Tables in Spring
- Example of a Specification Builder
- Building an Array of predicates
- Writing dynamic queries with Spring Data JPA
Specifications and Querydsl
To be able to define reusable predicates, Spring introduced the specification interface that is derived from concepts introduced in Eric Evans' Domain Driven Design book. It defines a specification as a predicate over an entity, which is exactly what our specification interface represents. This actually only consists of a single method:
and(…)
or(…)
Here are some benefits of specifications:
- All "basic" queries are already implemented, i.e. findById, save, and delete
- Pagination works out of the box. You can pass an object simply from the Controller to the Service to your Repository, and it just works (even sorting)!
Pageable
- Using Spring's API is a little bit more simple than plain JPA stuff because you just create predicates and don't have to mess around with the and .
Specification
EntityManager
PersistenceContext
Hibernate specifics
Strategy Design Pattern and Lambda's
Read this wonderful post about different classifications of patterns!!!
The idea of the strategy pattern is to define a family of algorithms, encapsulate what varies into separate classes and make their objects interchangeable in the context. Varies here means: may change over time due to the evolving requirements.
Lambda expressions have changed the world in Java, and we can effectively use lambda expressions to avoid writing a lot of ceremonial code. As far as the strategy design pattern is concerned we don't have to create a hierarchy of classes. Instead, we can directly pass the strategy implementation of the interface as a lambda expression to the context.
Take one functional interface that fits your family of algorithms, declare them all statically in one place (single class).
Micro-Services with Eureka and Zuul proxy with Feign Client
As an edge service, Zuul provides a lot of different functions. The main pieces we will talk about are the dynamic proxy and security.
Zuul will serve as our API gateway. This, along with the service discovery of Eureka, makes setting up new services a breeze. We will demonstrate a small Zuul application. It will register with a Eureka server and automatically set up dynamic routing based on other services that are also registered with Eureka to provide access to our APIs through one singular point. So Zuul wants to be configured with Spring Security in order to provide edge security across all our APIs.
-
Micro-Services with Eureka and Zuul proxy with Feign Client.
-
Spring Cloud: Zuul, Eureka Integration in SpringBoot Applications
- git rewriting history
All You Need To Know For Migrating To Java 11
We haven't fully immersed ourselves in Java 10 yet, and Java 11 is here. Java 11 is important for more than just a few reasons. Oracle has revamped its support model and come up with a release train that'll bring rapid updates, about every 6 months.
Negate a Predicate with Java 11
people.stream() .filter(Predicate.not(Person::isAdult)) .collect(Collectors.toList());
Mockito
- Any matchers and eq
- Baeldung argument matchers
- Mockito 2 examples
- Baeldung Mockito series
- Mocking Exception Throwing using Mockito
- Mock void methods with Mockito
- ArgumentCaptor
- verify Cookbook
MockMvc Testing
- Testing layers in Spring5 (SpringRunner, MockBean, WebMvcTest and TestConfiguration) - Since we're only focused on the Controller code, it's natural to mock the Service layer code for our unit tests:
- Testing Exceptions at Baeldung
- Testing RestControllers at refactoring
- REST Endpoint Testing With MockMvc
- How to test a JSON Array in jsonPath
- Baeldung about MockMvc and testing results with JsonPath
- Spring MVC Controllers Unit Test not calling @ControllerAdvice
Migrating from JUnit 4 to JUnit 5
Let's start with the previous version – JUnit 4 has some clear limitations:
- The entire framework was contained in a single jar library. The whole library needs to be imported even when only a particular feature is required. In JUnit 5, we get more granularity and can import only what is necessary
- One test runner can only execute tests in JUnit 4 at a time (e.g. SpringJUnit4ClassRunner or Parameterized ). JUnit 5 allows multiple runners to work simultaneously
- JUnit 4 never advanced beyond Java 7, missing out on a lot of features from Java 8. JUnit 5 makes good use of Java 8 features
- Migrating from a JUnit4-Based Runner
- junit 5 migration for Springboot applications
- Junit5 and @RunWith
- Guide to JUnit5
- how to integrate Mockito with the JUnit 5 extension model
- Unit testing with JUnit 5, Mockito, and Hamcrest
Java 8 Date – LocalDate, LocalDateTime, Instant
Java 8 Date Time API is one of the most sought after change for developers. Java has been missing a consistent approach for Date and Time from start and Java 8 Date Time API is a welcome addition to the core Java APIs.
Time Complexity of Java Collections
we'll talk about the performance of different collections from the Java Collection API. Usually, when we talk about time complexity, we refer to Big-O notation. Simply put, the notation describes how the time to perform the algorithm grows with the size of the input. This notation approximately describes how the time to do a given task grows with the size of the input. ... Roughly speaking, on one end we have O(1) which is “constant time” and on the opposite end we have O(xn) which is “exponential time”.
- Constant means that the time is always the same, it doesn't matter the length of the List
- Linear time means the longer the
ArrayList
is (more object it contains) the longer time the op will take, linear means that the more the List grows, the longer is the time, but in a linear way, so for example to perform a linear operation on a list that contains 20 elements it will take two times the time needed for a list with 10 elements.
- If you need fast access to elements using index, ArrayList should be choice.
- If you need fast access to elements using a key, use HashMap.
- If you need fast add and removal of elements, use LinkedList (but it has a very poor seeking performance).
ML Machine Learning and Springboot
"A computer program is said to learn from experience E with respect to some task T and some performance measure P, if its performance on T, as measured by P, improves with experience E". So if you want your program to predict, for example, traffic patterns at a busy intersection (task T), you can run it through a machine learning algorithm with data about past traffic patterns (experience E) and, if it has successfully “learned”, it will then do better at predicting future traffic patterns (performance measure P).
- Introduction on Machine Learning
- Deep Learning with Spring Boot and DJL
- geeks for geeks on ML
- How to Start Learning Machine Learning?
Intellij Java and Springboot
- What are Monads in Java development
- basic Intellij
- Intellij Springboot
- learning Springboot in Intellij
- Jetbrains special on Springboot and Intellij
- From this example
Java interview questions
How to write Clean Java Code
Besides studying hard, to become a good software developer in Java or any other language, you must master concepts and code conventions to make a clean code and easy to maintain.
-
Do you have time to talk about best coding practices with Java?
- 10 Tips To Keep Your Code Clean
- Even bad code can function. But if code isn’t clean, it can bring a development organization to its knees. Every year, countless hours and significant resources are lost because of poorly written code. But it doesn’t have to be that way.
About Maps and EntrySets
Literally initialize HashMap
// this works for up to 10 elements:
Map<String, String> test1 = Map.of(
"a", "b",
"c", "d"
);
// this works for any number of elements:
import static java.util.Map.entry;
Map<String, String> test2 = Map.ofEntries(
entry("a", "b"),
entry("c", "d")
);
Streams
Characteristics:
- Does not store data, never modifies the underlying data source
- Apply functions to sequences of objects
- Lazy initialization, because intermediate operations are not evaluated until terminal operation is invoke.
- Does not safe data.
- Each intermediate operation creates a new stream to operate on
Good links
- Java 8 stream tutorial
- for geeks
- stackify about streams
- and of course Baeldung
- Steams and Intellij Live Templates
- More about Java 8
- Java Concurrency tutorial
- Java 8 forEach examples mkyong
- Changing elements on forEach
- Working With Maps Using Streams
However, while there is no problem with doing this using either Collection.forEach() or stream().forEach(), Java requires an operation on a stream to be non-interfering. This means that elements shouldn't be modified during the execution of the stream pipeline.
The reason behind this is that the stream should facilitate parallel execution. Here, modifying elements of a stream could lead to unexpected behavior.