Skip to content

Instantly share code, notes, and snippets.

@ttddyy
ttddyy / AsyncResourceRetriever.java
Last active February 22, 2024 22:14
Async JWKS retriever
/*
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ttddyy
ttddyy / TransactionTest.java
Created December 22, 2020 19:02
Class level rollback TestExecutionListener
package com.example;
import javax.sql.DataSource;
import com.example.TransactionTest.MyTestExecutionListener;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
@ttddyy
ttddyy / MyImageNameSubstitutor.java
Created November 13, 2020 00:29
MyImageNameSubstitutor.java
@Slf4j
public class MyImageNameSubstitutor extends ImageNameSubstitutor {
public static final String ENV_VAR_KEY = "MY_TESTCONTAINERS_REGISTRY";
public static final String SYSTEM_PROP_KEY = "my.testcontainers.registry";
public static final String DEFAULT_REGISTRY = "sample.com/";
protected String registryUrl;
@ttddyy
ttddyy / PropertyValidationListener.java
Created November 8, 2020 22:45
Check the usage of deprecated properties at start up
package com.example.analysis;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ttddyy
ttddyy / gist:4b3beb9806ded3b02c2b909e5044b989
Created January 17, 2020 21:19
ConcurrentModificationException with "r2dbc-postgresql=0.8.0"
java.util.ConcurrentModificationException: null
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1134) ~[na:na]
Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException:
Error has been observed at the following site(s):
|_ checkpoint ⇢ SQL "INSERT INTO city (name, country) VALUES ($1, $2)" [DatabaseClient]
Stack trace:
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1134) ~[na:na]
at io.r2dbc.postgresql.IndefiniteStatementCache.getName(IndefiniteStatementCache.java:49) ~[r2dbc-postgresql-0.8.0.RELEASE.jar:0.8.0.RELEASE]
at io.r2dbc.postgresql.ExtendedQueryPostgresqlStatement.execute(ExtendedQueryPostgresqlStatement.java:184) ~[r2dbc-postgresql-0.8.0.RELEASE.jar:0.8.0.RELEASE]
at io.r2dbc.postgresql.ExtendedQueryPostgresqlStatement.execute(ExtendedQueryPostgresqlStatement.java:123) ~[r2dbc-postgresql-0.8.0.RELEASE.jar:0.8.0.RELEASE]
@ttddyy
ttddyy / Application.java
Created May 2, 2019 00:58
bind parameter converter sample
/**
* @author Tadaya Tsuyukubo
*/
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication app = new SpringApplication(Application.class);
app.setWebApplicationType(WebApplicationType.NONE);
app.run(args);
@ttddyy
ttddyy / ByteBuddyProxyFactory.java
Created February 7, 2019 06:58
ProxyFactory implementation with Byte Buddy
package io.r2dbc.examples;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import io.r2dbc.proxy.callback.BatchCallbackHandler;
import io.r2dbc.proxy.callback.CallbackHandler;
import io.r2dbc.proxy.callback.ConnectionCallbackHandler;
import io.r2dbc.proxy.callback.ConnectionFactoryCallbackHandler;
import io.r2dbc.proxy.callback.ProxyConfig;
@ttddyy
ttddyy / pointcut.java
Created February 4, 2019 22:54
Wrap result of ConnectionFactory#create()
class Pointcut {
// pointcut for ConnectionFactory#create() method
public Publisher<? extends Connection> pointcut() {
Publisher<? extends Connection> result = null; // actual result of "ConnectionFactory#create()"
ProxyFactory proxyFactory = null; // need to construct
// return wrapped one
return Flux.from(result)
public class MyLogEntryCreator extends DefaultQueryLogEntryCreator {
private boolean writeDataSourcename = false;
private boolean writeConnectionId = true;
public String getLogEntry(String sessionId, ExecutionInfo execInfo, List<QueryInfo> queryInfoList) {
StringBuilder sb = new StringBuilder();
sb.append("SessionId=" + sessionId);
sb.append(" ");
sb.append(super.getLogEntry(execInfo, queryInfoList, this.writeDataSourcename, this.writeConnectionId));
@ttddyy
ttddyy / TestContext.java
Created August 3, 2016 04:30
test wait for async framework(vmware/xenon)
public class TestContext {
private CountDownLatch latch;
private LocalDateTime expireAt;
private volatile Throwable error;
public TestContext(int count) {
this(count, XenonTestConfig.timeoutStrategy.getTimeout());
}
public TestContext(int count, Duration duration) {