Skip to content

Instantly share code, notes, and snippets.

import kotlin.random.Random.Default.nextInt
fun main(args: Array<String>) {
val trialCount = 5
randomPrint(trialCount)
}
fun randomPrint(trialCount: Int) {
repeat(trialCount) {
@Component
public class GlobalErrorWebExceptionHandler implements ErrorWebExceptionHandler {
@Override
public Mono<Void> handle(ServerWebExchange serverWebExchange, Throwable throwable) {
ErrorAttribute errorAttribute = this.buildResponse(throwable);
serverWebExchange.getResponse().setStatusCode(errorAttribute.getStatus());
serverWebExchange.getResponse().getHeaders().setContentType(MediaType.APPLICATION_JSON);
public class ErrorResponseResolver {
public <T extends Throwable> void test(T t)
throws InvocationTargetException, IllegalAccessException {
Method[] methods = getClass().getDeclaredMethods();
for (Method method : methods) {
String clazzName = t.getClass().getName();
if (clazzName.equals(method.getParameterTypes()[0].getName())) {
method.invoke(t, t); // 실행한다!
}
@anny0739
anny0739 / TransactionService.java
Last active July 9, 2020 02:31
TransactionTest.java
public AService {
@Autowired private ARepository repository;
@Transactional
public void save(A a) {
repository.save(a);
// update(a); // update 트랜잭션 적용안됨 XXX
}
@Trnasaction(propagation = Propagation.REQURIES_NEW)
@anny0739
anny0739 / KubernetesLabels.java
Last active June 24, 2020 05:46
KubernetesLabels.java
public class KubernetesLables {
@JsonProperty("beta.kubernetes.io/arch")
private String betaArch;
@JsonProperty("beta.kubernetes.io/os")
private String betaOs;
@JsonProperty("kubernetes.io/arch")
private String arch;
@JsonProperty("kubernetes.io/hostname")
private String hostname;
@JsonProperty("kubernetes.io/os")
@anny0739
anny0739 / CircularReferenceTest.java
Created June 19, 2020 10:17
CircularReferenceTest.java
@Service
public class AService {
@Autowired
private BService bService;
public void doSomething() {
bService.doSomething();
}
}
@anny0739
anny0739 / SyncTest.java
Created June 5, 2020 15:08
SyncTest.java
@Inject
private RedissonClient redissonClient;
private Exception exception;
private final CountDownLatch latch = new CountDownLatch(2);
@Test
public void syncTest() {
List<Thread> threads = IntStream.range(0, 2)
.mapToObj(i -> new Thread1())
@anny0739
anny0739 / Assertion.java
Created May 12, 2020 04:51
Assertion.java
@Entity
public class Goods {
private int goodsId;
}
@Entity
public class GoodsDetail {
private Assertion<Goods> goodsId;
}
@anny0739
anny0739 / ConcurrentTest.java
Created April 27, 2020 05:58
ConcurrentTest.java
package com.benx.weply.core.spring.jpa;
import com.benx.weply.core.SpringTest;
import com.benx.weply.core.domain.enums.Shop;
import com.benx.weply.core.domain.user.User;
import com.benx.weply.core.domain.user.UserService;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.StaleObjectStateException;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import javax.persistence.EntityManager;
import javax.crypto.Mac
import javax.crypto.spec.SecretKeySpec
import kotlin.experimental.and
fun main(args: Array<String>) {
val hmacFromKomoju = "06cb40bd7c630613e41f874296eddd0153d023857a76a9de52daad5da6c2bbe4"
val algorithm = "HmacSHA256"