Skip to content

Commit

Permalink
Add a couple of chaos testing resources.
Browse files Browse the repository at this point in the history
  • Loading branch information
swaldman committed May 6, 2024
1 parent ca50283 commit d2d6f0d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/resources-local-rough/c3p0.properties
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ c3p0.acquireIncrement=10
#c3p0.acquireRetryDelay=1000
#c3p0.acquireRetryAttempts=60
#c3p0.connectionTesterClassName=com.mchange.v2.c3p0.test.AlwaysFailConnectionTester
#c3p0.connectionTesterClassName=com.mchange.v2.c3p0.test.Percent80FailConnectionTester
c3p0.connectionTesterClassName=com.mchange.v2.c3p0.test.Percent20FailConnectionTester
c3p0.initialPoolSize=15
c3p0.attemptResurrectOnCheckin=true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.mchange.v2.c3p0.test;

import java.sql.Connection;
import com.mchange.v2.c3p0.QueryConnectionTester;
import com.mchange.v2.log.MLevel;
import com.mchange.v2.log.MLog;
import com.mchange.v2.log.MLogger;

public final class Percent80FailConnectionTester implements QueryConnectionTester
{
final static MLogger logger = MLog.getLogger( Percent80FailConnectionTester.class );

{
//logger.log(MLevel.WARNING, "Instantiated: " + this, new Exception("Instantiation Stack Trace.") );
}

private int roulette()
{
if (Math.random() < 0.80d)
return CONNECTION_IS_INVALID;
else
return CONNECTION_IS_OKAY;
}

public int activeCheckConnection(Connection c)
{
//logger.warning(this + ": activeCheckConnection(Connection c)");
return roulette();
}

public int statusOnException(Connection c, Throwable t)
{
//logger.warning(this + ": statusOnException(Connection c, Throwable t)");
return roulette();
}

public int activeCheckConnection(Connection c, String preferredTestQuery)
{
//logger.warning(this + ": activeCheckConnection(Connection c, String preferredTestQuery)");
return roulette();
}

public boolean equals( Object o ) { return this.getClass().equals( o.getClass() ); }
public int hashCode() { return this.getClass().getName().hashCode(); }
}

0 comments on commit d2d6f0d

Please sign in to comment.