-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a couple of chaos testing resources.
- Loading branch information
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
46 changes: 46 additions & 0 deletions
46
test/src/com/mchange/v2/c3p0/test/Percent80FailConnectionTester.java
This file contains 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
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(); } | ||
} | ||
|