Last active
November 19, 2015 19:54
-
-
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
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
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; | |
} | |
} |
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
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