Skip to content

Instantly share code, notes, and snippets.

View ben-manes's full-sized avatar

Ben Manes ben-manes

View GitHub Profile
@ben-manes
ben-manes / HttpPort.java
Created July 12, 2015 18:40
Jetty module
/**
* A qualifier for the server http port.
*
* @author [email protected] (Ben Manes)
*/
@BindingAnnotation
@Retention(RUNTIME)
@Target({ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD})
public @interface HttpPort {}
@ben-manes
ben-manes / ApiOriginFilter.java
Last active August 11, 2017 07:13
Swagger 1.5.1-M1 + RestEasy 3.x + Guice 4
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
public final class FinalizeBenchmark extends Benchmark {
public int timeFinalize(int reps) {
int dummy = 0;
for (int i = 0; i < reps; i++) {
Object o = new Object() {
@Override protected void finalize() {
toString();
}
};
23:36:18.125 [main] DEBUG o.s.jdbc.datasource.DataSourceUtils - Fetching JDBC Connection from DataSource
23:36:18.129 [main] DEBUG o.s.j.d.LazyConnectionDataSourceProxy - Connecting to database for operation 'getMetaData'
23:36:18.132 [main] DEBUG c.g.f.c.dbsupport.DbSupportFactory - Database: H2 1.3
23:36:18.134 [main] DEBUG com.googlecode.flyway.core.Flyway - DDL Transactions Supported: false
23:36:18.134 [main] DEBUG com.googlecode.flyway.core.Flyway - Schema: file_vault
23:36:18.139 [main] DEBUG o.s.j.d.LazyConnectionDataSourceProxy - Using existing database connection for operation 'setAutoCommit'
23:36:18.139 [main] DEBUG o.s.j.d.LazyConnectionDataSourceProxy - Using existing database connection for operation 'prepareStatement'
23:36:18.141 [main] DEBUG c.g.flyway.core.command.DbSchemas - Schema "file_vault" already exists. Skipping schema creation.
23:36:18.141 [main] DEBUG o.s.j.d.LazyConnectionDataSourceProxy - Using existing database connection for operation 'commit'
23:36:18.142 [main] DEBUG o.s.j.
/**
* A validator to verify that the jOOQ generated tables match the database table metadata.
*
* @author Ben Manes ([email protected])
*/
final class SchemaValidator {
private static final Logger logger = LoggerFactory.getLogger(SchemaValidator.class);
private final List<Schema> schemas;
private final DSLContext db;
/**
* A test for the connection life-cycle management within jOOQ managed operations.
*
* @author Ben Manes ([email protected])
*/
@Guice(modules = {JooqTestModule.class, TestModule.class})
public class ConnectionLifecycleTest {
final AtomicInteger counter = new AtomicInteger();
@Inject CountingExecuteListener countingExecuteListener;
apply from: "${rootDir}/gradle/java.gradle"
dependencies {
compile libraries.guava
compile libraries.guice
compile libraries.jooq
}
buildscript {
repositories {
apply from: "${rootDir}/coverage.gradle"
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.ajoberstar:gradle-jacoco:0.1.0"
}
}
@ben-manes
ben-manes / gist:4248735
Created December 10, 2012 06:02
WebDriverTestingTemplate fatJar
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'eu.appsatori:gradle-fatjar-plugin:0.2-rc1'
}
}
package com.googlecode.concurrentlinkedhashmap.benchmark;
import com.google.caliper.Runner;
import com.google.caliper.SimpleBenchmark;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;