Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mrserverless/98602ced01dc7d774378 to your computer and use it in GitHub Desktop.
Save mrserverless/98602ced01dc7d774378 to your computer and use it in GitHub Desktop.
Prevent Dropwizard Database or Integration Tests running out of Connections, by removing abandoned connections not cleaned up by the test runner. Discovered by @leeAtTrunk and @nagliyvred
public class AbandonedConnectionsAwareDatasourceFactory extends DataSourceFactory {
private int removeAbandonedTimeout = 60;
private boolean removeAbandoned = false;
@Override
public ManagedDataSource build(MetricRegistry metricRegistry, String name) {
ManagedPooledDataSource build = (ManagedPooledDataSource) super.build(metricRegistry, name);
build.setRemoveAbandonedTimeout(removeAbandonedTimeout);
build.setRemoveAbandoned(removeAbandoned);
return build;
}
public int getRemoveAbandonedTimeout() {
return removeAbandonedTimeout;
}
public void setRemoveAbandonedTimeout(int removeAbandonedTimeout) {
this.removeAbandonedTimeout = removeAbandonedTimeout;
}
public boolean isRemoveAbandoned() {
return removeAbandoned;
}
public void setRemoveAbandoned(boolean removeAbandoned) {
this.removeAbandoned = removeAbandoned;
}
}
dataSource:
abandonWhenPercentageFull: 9
removeAbandonedTimeout: 2
removeAbandoned: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment