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 main | |
import ( | |
"database/sql/driver" | |
"encoding/json" | |
"github.com/jinzhu/gorm" | |
_ "github.com/lib/pq" | |
) |
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
//Contents from https://spring.io/understanding/CORS | |
In the simplest scenario, cross-origin communications starts with a client making a GET, POST, or HEAD request against a resource on the server. | |
In this scenario, the content type of a POST request is limited to application/x-www-form-urlencoded, multipart/form-data, or text/plain. The request includes an Origin header that indicates the origin of the client code. | |
The server will consider the request's Origin and either allow or disallow the request. If the server allows the request, then it will respond with the requested resource and an Access-Control-Allow-Origin header in the response. This header will indicate to the client which client origins will be allowed to access the resource. Assuming that the Access-Control-Allow-Origin header matches the request's Origin, the browser will allow the request. | |
On the other hand, if Access-Control-Allow-Origin is missing in the response or if it doesn't match the request's Origin, the browser will disallow th |
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
version: "3" | |
services: | |
postgress: | |
.... | |
healthcheck: | |
test: ["CMD-SHELL", "pg_isready -U postgres"] | |
interval: 10s | |
timeout: 5s | |
retries: 5 | |
app: |
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
# Redis Cheatsheet | |
# All the commands you need to know | |
redis-server /path/redis.conf # start redis with the related configuration file | |
redis-cli # opens a redis prompt | |
# Strings. |
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
/* | |
@MockBean //or Mockito's @Mock | |
- it mocks the object and all its methods with do nothing and their result value will be null, | |
- use for example: when(...) methods to create mocked method behaviour | |
- use when you want to completely get rid of the object's normal behaviour | |
- caution: unmocked methods won't work -> can result in a RuntimeException during tests (@SpyBean is a remedy here apart from wider mocking) | |
@SpyBean //or Mockito's @Spy | |
- an object will behave like an @Autowired object | |
- all its methods will actually works, but we can define some custom behavior for its methods | |
- use doReturn(...) / doNothing(...) to add custom (mocked) method behaviour |
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
//-------------------------------------------------------- | |
//Service that we want to execute asynchroneously - consists of the following method: | |
public String execute() { | |
try { | |
Thread.sleep(5000); | |
logger.info("Slow task executed"); | |
return "Task finished"; | |
} catch (InterruptedException e) { | |
throw new RuntimeException(); | |
} |
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
GetMapping("/async-deferredresult") | |
public DeferredResult<ResponseEntity<?>> handleReqDefResult(Model model) { | |
LOG.info("Received async-deferredresult request"); | |
DeferredResult<ResponseEntity<?>> output = new DeferredResult<>(); //just a declaration | |
ForkJoinPool.commonPool().submit(() -> { //we pass a service method to an ExecutorService / thread pool | |
LOG.info("Processing in separate thread"); | |
try { | |
Thread.sleep(6000); | |
} catch (InterruptedException e) { |
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 java.io.IOException; | |
import java.net.URLClassLoader; | |
import java.nio.file.Files; | |
import java.nio.file.Paths; | |
import java.nio.file.Path; | |
/** | |
* Example demonstrating a ClassLoader leak. | |
* | |
* <p>To see it in action, copy this file to a temp directory somewhere, |
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
<project> | |
... | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.jacoco</groupId> | |
<artifactId>jacoco-maven-plugin</artifactId> | |
<executions> | |
<execution> | |
<id>default-prepare-agent</id> |