public class Spy<C extends Spy<C>> extends Object implements Closeable
Sniffer.spy()
,
Sniffer.expect(int)
Modifier and Type | Class and Description |
---|---|
static interface |
Spy.Expectation |
Modifier and Type | Method and Description |
---|---|
protected void |
addExecutedStatement(StatementMetaData statementMetaData,
long elapsedTime,
int bytesDown,
int bytesUp,
int rowsUpdated) |
protected void |
addReturnedRow(StatementMetaData statementMetaData) |
protected void |
addSocketOperation(SocketMetaData socketMetaData,
long elapsedTime,
int bytesDown,
int bytesUp) |
<V> SpyWithValue<V> |
call(Callable<V> callable)
Executes the
Callable.call() method on provided argument and verifies the expectations |
void |
close()
Alias for
verify() method; it is useful for try-with-resource API: |
C |
execute(Sniffer.Executable executable)
Executes the
Sniffer.Executable.execute() method on provided argument and verifies the expectations |
int |
executedStatements() |
int |
executedStatements(Threads threadMatcher) |
int |
executedStatements(Threads threadMatcher,
Query query) |
C |
expect(int allowedStatements)
Deprecated.
|
C |
expect(int allowedStatements,
Query query)
Deprecated.
|
C |
expect(int allowedStatements,
Query query,
Threads threadMatcher)
Deprecated.
|
C |
expect(int allowedStatements,
Threads threadMatcher)
Deprecated.
|
C |
expect(int allowedStatements,
Threads threadMatcher,
Query query)
Deprecated.
|
C |
expect(Spy.Expectation expectation) |
C |
expectAtLeast(int allowedStatements)
Deprecated.
|
C |
expectAtLeast(int allowedStatements,
Query query)
Deprecated.
|
C |
expectAtLeast(int allowedStatements,
Query query,
Threads threadMatcher)
Deprecated.
|
C |
expectAtLeast(int allowedStatements,
Threads threadMatcher)
Deprecated.
|
C |
expectAtLeast(int allowedStatements,
Threads threadMatcher,
Query query)
Deprecated.
|
C |
expectAtMost(int allowedStatements)
Deprecated.
|
C |
expectAtMost(int allowedStatements,
Query query)
Deprecated.
|
C |
expectAtMost(int allowedStatements,
Query query,
Threads threadMatcher)
Deprecated.
|
C |
expectAtMost(int allowedStatements,
Threads threadMatcher)
Deprecated.
|
C |
expectAtMost(int allowedStatements,
Threads threadMatcher,
Query query)
Deprecated.
|
C |
expectAtMostOnce()
Deprecated.
|
C |
expectAtMostOnce(Query query)
Deprecated.
|
C |
expectAtMostOnce(Query query,
Threads threadMatcher)
Deprecated.
|
C |
expectAtMostOnce(Threads threadMatcher)
Deprecated.
|
C |
expectAtMostOnce(Threads threadMatcher,
Query query)
Deprecated.
|
C |
expectBetween(int minAllowedStatements,
int maxAllowedStatements)
Deprecated.
|
C |
expectBetween(int minAllowedStatements,
int maxAllowedStatements,
Query query)
Deprecated.
|
C |
expectBetween(int minAllowedStatements,
int maxAllowedStatements,
Query query,
Threads threadMatcher)
Deprecated.
|
C |
expectBetween(int minAllowedStatements,
int maxAllowedStatements,
Threads threadMatcher)
Deprecated.
|
C |
expectBetween(int minAllowedStatements,
int maxAllowedStatements,
Threads threadMatcher,
Query query)
Deprecated.
|
C |
expectNever()
Deprecated.
|
C |
expectNever(Query query)
Deprecated.
|
C |
expectNever(Query query,
Threads threadMatcher)
Deprecated.
|
C |
expectNever(Threads threadMatcher)
Deprecated.
|
C |
expectNever(Threads threadMatcher,
Query query)
Deprecated.
|
Map<StatementMetaData,SqlStats> |
getExecutedStatements(Threads threadMatcher,
boolean removeStackTraces) |
Map<SocketMetaData,SocketStats> |
getSocketOperations(Threads threadMatcher,
String address,
boolean removeStackTraces) |
WrongNumberOfQueriesError |
getWrongNumberOfQueriesError() |
Spy |
reset()
Wrapper for
Sniffer.spy() method; useful for chaining |
protected void |
resetExecutedStatements() |
protected void |
resetSocketOpertions() |
C |
run(Runnable runnable)
Executes the
Runnable.run() method on provided argument and verifies the expectations |
void |
verify()
Verifies all expectations added previously using
expect methods family |
C |
verify(int allowedStatements)
Deprecated.
|
C |
verify(int allowedStatements,
Query query)
Deprecated.
|
C |
verify(int allowedStatements,
Query query,
Threads threadMatcher)
Deprecated.
|
C |
verify(int allowedStatements,
Threads threadMatcher)
Deprecated.
|
C |
verify(int allowedStatements,
Threads threadMatcher,
Query query)
Deprecated.
|
C |
verify(Spy.Expectation expectation) |
C |
verifyAtLeast(int allowedStatements)
Deprecated.
|
C |
verifyAtLeast(int allowedStatements,
Query query)
Deprecated.
|
C |
verifyAtLeast(int allowedStatements,
Query query,
Threads threadMatcher)
Deprecated.
|
C |
verifyAtLeast(int allowedStatements,
Threads threadMatcher)
Deprecated.
|
C |
verifyAtLeast(int allowedStatements,
Threads threadMatcher,
Query query)
Deprecated.
|
C |
verifyAtMost(int allowedStatements)
Deprecated.
|
C |
verifyAtMost(int allowedStatements,
Query query)
Deprecated.
|
C |
verifyAtMost(int allowedStatements,
Query query,
Threads threadMatcher)
Deprecated.
|
C |
verifyAtMost(int allowedStatements,
Threads threadMatcher)
Deprecated.
|
C |
verifyAtMost(int allowedStatements,
Threads threadMatcher,
Query query)
Deprecated.
|
C |
verifyAtMostOnce()
Deprecated.
|
C |
verifyAtMostOnce(Query query)
Deprecated.
|
C |
verifyAtMostOnce(Query query,
Threads threadMatcher)
Deprecated.
|
C |
verifyAtMostOnce(Threads threadMatcher)
Deprecated.
|
C |
verifyAtMostOnce(Threads threadMatcher,
Query query)
Deprecated.
|
C |
verifyBetween(int minAllowedStatements,
int maxAllowedStatements)
Deprecated.
|
C |
verifyBetween(int minAllowedStatements,
int maxAllowedStatements,
Query query)
Deprecated.
|
C |
verifyBetween(int minAllowedStatements,
int maxAllowedStatements,
Query query,
Threads threadMatcher)
Deprecated.
|
C |
verifyBetween(int minAllowedStatements,
int maxAllowedStatements,
Threads threadMatcher)
Deprecated.
|
C |
verifyBetween(int minAllowedStatements,
int maxAllowedStatements,
Threads threadMatcher,
Query query)
Deprecated.
|
C |
verifyNever()
Deprecated.
|
C |
verifyNever(Query query)
Deprecated.
|
C |
verifyNever(Query query,
Threads threadMatcher)
Deprecated.
|
C |
verifyNever(Threads threadMatcher)
Deprecated.
|
C |
verifyNever(Threads threadMatcher,
Query query)
Deprecated.
|
protected void addExecutedStatement(StatementMetaData statementMetaData, long elapsedTime, int bytesDown, int bytesUp, int rowsUpdated)
protected void addReturnedRow(StatementMetaData statementMetaData)
protected void addSocketOperation(SocketMetaData socketMetaData, long elapsedTime, int bytesDown, int bytesUp)
protected void resetExecutedStatements()
protected void resetSocketOpertions()
public Map<StatementMetaData,SqlStats> getExecutedStatements(Threads threadMatcher, boolean removeStackTraces)
public Spy reset()
Sniffer.spy()
method; useful for chainingSpy
instancepublic Map<SocketMetaData,SocketStats> getSocketOperations(Threads threadMatcher, String address, boolean removeStackTraces)
public int executedStatements()
public int executedStatements(Threads threadMatcher)
threadMatcher
- chooses Thread
s for calculating the number of executed queriespublic int executedStatements(Threads threadMatcher, Query query)
threadMatcher
- chooses Thread
s for calculating the number of executed queriespublic C expect(Spy.Expectation expectation)
expectation
- public C verify(Spy.Expectation expectation)
expectation
- public void verify() throws WrongNumberOfQueriesError
expect
methods familyWrongNumberOfQueriesError
- if wrong number of queries was executedpublic WrongNumberOfQueriesError getWrongNumberOfQueriesError()
public void close()
verify()
method; it is useful for try-with-resource API:
@Test
public void testTryWithResourceApi() throws SQLException {
final Connection connection = DriverManager.getConnection("sniffer:jdbc:h2:mem:", "sa", "sa");
try (@SuppressWarnings("unused") Spy s = Sniffer.expectAtMostOnce();
Statement statement = connection.createStatement()) {
statement.execute("SELECT 1 FROM DUAL");
}
}
}
close
in interface Closeable
close
in interface AutoCloseable
public C execute(Sniffer.Executable executable)
Sniffer.Executable.execute()
method on provided argument and verifies the expectationsWrongNumberOfQueriesError
- if wrong number of queries was executedpublic C run(Runnable runnable)
Runnable.run()
method on provided argument and verifies the expectationsWrongNumberOfQueriesError
- if wrong number of queries was executedpublic <V> SpyWithValue<V> call(Callable<V> callable)
Callable.call()
method on provided argument and verifies the expectationsWrongNumberOfQueriesError
- if wrong number of queries was executed@Deprecated public C expectNever()
@Deprecated public C expectNever(Threads threadMatcher)
@Deprecated public C expectNever(Query query)
@Deprecated public C expectNever(Threads threadMatcher, Query query)
@Deprecated public C expectNever(Query query, Threads threadMatcher)
@Deprecated public C verifyNever() throws WrongNumberOfQueriesError
WrongNumberOfQueriesError
@Deprecated public C verifyNever(Threads threadMatcher) throws WrongNumberOfQueriesError
WrongNumberOfQueriesError
@Deprecated public C verifyNever(Query query) throws WrongNumberOfQueriesError
WrongNumberOfQueriesError
@Deprecated public C verifyNever(Threads threadMatcher, Query query) throws WrongNumberOfQueriesError
WrongNumberOfQueriesError
@Deprecated public C verifyNever(Query query, Threads threadMatcher) throws WrongNumberOfQueriesError
WrongNumberOfQueriesError
@Deprecated public C expectAtMostOnce()
@Deprecated public C expectAtMostOnce(Threads threadMatcher)
@Deprecated public C expectAtMostOnce(Query query)
@Deprecated public C expectAtMostOnce(Threads threadMatcher, Query query)
@Deprecated public C expectAtMostOnce(Query query, Threads threadMatcher)
@Deprecated public C verifyAtMostOnce() throws WrongNumberOfQueriesError
WrongNumberOfQueriesError
@Deprecated public C verifyAtMostOnce(Threads threadMatcher) throws WrongNumberOfQueriesError
WrongNumberOfQueriesError
@Deprecated public C verifyAtMostOnce(Query query) throws WrongNumberOfQueriesError
WrongNumberOfQueriesError
@Deprecated public C verifyAtMostOnce(Threads threadMatcher, Query query) throws WrongNumberOfQueriesError
WrongNumberOfQueriesError
@Deprecated public C verifyAtMostOnce(Query query, Threads threadMatcher) throws WrongNumberOfQueriesError
WrongNumberOfQueriesError
@Deprecated public C expectAtMost(int allowedStatements)
expectBetween(int, int, Threads, Query)
with arguments 0, allowedStatements
, Threads.CURRENT
, Query.ANY
@Deprecated public C expectAtMost(int allowedStatements, Threads threadMatcher)
expectBetween(int, int, Threads, Query)
with arguments 0, allowedStatements
, threads
, Query.ANY
@Deprecated public C expectAtMost(int allowedStatements, Query query)
expectBetween(int, int, Threads, Query)
with arguments 0, allowedStatements
, Threads.CURRENT
, queryType
@Deprecated public C expectAtMost(int allowedStatements, Threads threadMatcher, Query query)
expectBetween(int, int, Threads, Query)
with arguments 0, allowedStatements
, threads
, queryType
@Deprecated public C expectAtMost(int allowedStatements, Query query, Threads threadMatcher)
expectBetween(int, int, Threads, Query)
with arguments 0, allowedStatements
, threads
, queryType
@Deprecated public C verifyAtMost(int allowedStatements) throws WrongNumberOfQueriesError
verifyBetween(int, int, Threads, Query)
with arguments 0, allowedStatements
, Threads.CURRENT
, Query.ANY
WrongNumberOfQueriesError
@Deprecated public C verifyAtMost(int allowedStatements, Threads threadMatcher) throws WrongNumberOfQueriesError
verifyBetween(int, int, Threads, Query)
with arguments 0, allowedStatements
, threads
, Query.ANY
WrongNumberOfQueriesError
@Deprecated public C verifyAtMost(int allowedStatements, Query query) throws WrongNumberOfQueriesError
verifyBetween(int, int, Threads, Query)
with arguments 0, allowedStatements
, Threads.CURRENT
, queryType
WrongNumberOfQueriesError
@Deprecated public C verifyAtMost(int allowedStatements, Threads threadMatcher, Query query) throws WrongNumberOfQueriesError
verifyBetween(int, int, Threads, Query)
with arguments 0, allowedStatements
, threads
, queryType
WrongNumberOfQueriesError
@Deprecated public C verifyAtMost(int allowedStatements, Query query, Threads threadMatcher) throws WrongNumberOfQueriesError
verifyBetween(int, int, Threads, Query)
with arguments 0, allowedStatements
, threads
, queryType
WrongNumberOfQueriesError
@Deprecated public C expect(int allowedStatements)
expectBetween(int, int, Threads, Query)
with arguments allowedStatements
, allowedStatements
, Threads.CURRENT
, Query.ANY
@Deprecated public C expect(int allowedStatements, Threads threadMatcher)
expectBetween(int, int, Threads, Query)
with arguments allowedStatements
, allowedStatements
, threads
, Query.ANY
@Deprecated public C expect(int allowedStatements, Query query)
expectBetween(int, int, Threads, Query)
with arguments allowedStatements
, allowedStatements
, Threads.CURRENT
, queryType
@Deprecated public C expect(int allowedStatements, Threads threadMatcher, Query query)
expectBetween(int, int, Threads, Query)
with arguments allowedStatements
, allowedStatements
, threads
, queryType
@Deprecated public C expect(int allowedStatements, Query query, Threads threadMatcher)
expectBetween(int, int, Threads, Query)
with arguments allowedStatements
, allowedStatements
, threads
, queryType
@Deprecated public C verify(int allowedStatements) throws WrongNumberOfQueriesError
verifyBetween(int, int, Threads, Query)
with arguments allowedStatements
, allowedStatements
, Threads.CURRENT
, Query.ANY
WrongNumberOfQueriesError
@Deprecated public C verify(int allowedStatements, Threads threadMatcher) throws WrongNumberOfQueriesError
verifyBetween(int, int, Threads, Query)
with arguments allowedStatements
, allowedStatements
, threads
, Query.ANY
WrongNumberOfQueriesError
@Deprecated public C verify(int allowedStatements, Query query) throws WrongNumberOfQueriesError
verifyBetween(int, int, Threads, Query)
with arguments allowedStatements
, allowedStatements
, Threads.CURRENT
, queryType
WrongNumberOfQueriesError
@Deprecated public C verify(int allowedStatements, Threads threadMatcher, Query query) throws WrongNumberOfQueriesError
verifyBetween(int, int, Threads, Query)
with arguments allowedStatements
, allowedStatements
, threads
, queryType
WrongNumberOfQueriesError
@Deprecated public C verify(int allowedStatements, Query query, Threads threadMatcher) throws WrongNumberOfQueriesError
verifyBetween(int, int, Threads, Query)
with arguments allowedStatements
, allowedStatements
, threads
, queryType
WrongNumberOfQueriesError
@Deprecated public C expectAtLeast(int allowedStatements)
expectBetween(int, int, Threads, Query)
with arguments allowedStatements
, Integer.MAX_VALUE
, Threads.CURRENT
, Query.ANY
@Deprecated public C expectAtLeast(int allowedStatements, Threads threadMatcher)
expectBetween(int, int, Threads, Query)
with arguments allowedStatements
, Integer.MAX_VALUE
, threads
, Query.ANY
@Deprecated public C expectAtLeast(int allowedStatements, Query query)
expectBetween(int, int, Threads, Query)
with arguments allowedStatements
, Integer.MAX_VALUE
, Threads.CURRENT
, queryType
@Deprecated public C expectAtLeast(int allowedStatements, Threads threadMatcher, Query query)
expectBetween(int, int, Threads, Query)
with arguments allowedStatements
, Integer.MAX_VALUE
, threads
, queryType
@Deprecated public C expectAtLeast(int allowedStatements, Query query, Threads threadMatcher)
expectBetween(int, int, Threads, Query)
with arguments allowedStatements
, Integer.MAX_VALUE
, threads
, queryType
@Deprecated public C verifyAtLeast(int allowedStatements) throws WrongNumberOfQueriesError
verifyBetween(int, int, Threads, Query)
with arguments allowedStatements
, Integer.MAX_VALUE
, Threads.CURRENT
, Query.ANY
WrongNumberOfQueriesError
@Deprecated public C verifyAtLeast(int allowedStatements, Threads threadMatcher) throws WrongNumberOfQueriesError
verifyBetween(int, int, Threads, Query)
with arguments allowedStatements
, Integer.MAX_VALUE
, threads
, Query.ANY
WrongNumberOfQueriesError
@Deprecated public C verifyAtLeast(int allowedStatements, Query query) throws WrongNumberOfQueriesError
verifyBetween(int, int, Threads, Query)
with arguments allowedStatements
, Integer.MAX_VALUE
, Threads.CURRENT
, queryType
WrongNumberOfQueriesError
@Deprecated public C verifyAtLeast(int allowedStatements, Threads threadMatcher, Query query) throws WrongNumberOfQueriesError
verifyBetween(int, int, Threads, Query)
with arguments allowedStatements
, Integer.MAX_VALUE
, threads
, queryType
WrongNumberOfQueriesError
@Deprecated public C verifyAtLeast(int allowedStatements, Query query, Threads threadMatcher) throws WrongNumberOfQueriesError
verifyBetween(int, int, Threads, Query)
with arguments allowedStatements
, Integer.MAX_VALUE
, threads
, queryType
WrongNumberOfQueriesError
@Deprecated public C expectBetween(int minAllowedStatements, int maxAllowedStatements)
expectBetween(int, int, Threads, Query)
with arguments minAllowedStatements
, maxAllowedStatements
, Threads.CURRENT
, Query.ANY
@Deprecated public C expectBetween(int minAllowedStatements, int maxAllowedStatements, Threads threadMatcher)
minAllowedStatements
and at most
maxAllowedStatements
were called between the creation of the current instance
and a call to verify()
method@Deprecated public C expectBetween(int minAllowedStatements, int maxAllowedStatements, Query query)
minAllowedStatements
and at most
maxAllowedStatements
were called between the creation of the current instance
and a call to verify()
method@Deprecated public C expectBetween(int minAllowedStatements, int maxAllowedStatements, Threads threadMatcher, Query query)
minAllowedStatements
and at most
maxAllowedStatements
were called between the creation of the current instance
and a call to verify()
method@Deprecated public C expectBetween(int minAllowedStatements, int maxAllowedStatements, Query query, Threads threadMatcher)
minAllowedStatements
and at most
maxAllowedStatements
were called between the creation of the current instance
and a call to verify()
method@Deprecated public C verifyBetween(int minAllowedStatements, int maxAllowedStatements) throws WrongNumberOfQueriesError
verifyBetween(int, int, Threads)
with arguments minAllowedStatements
, Threads.CURRENT
, Query.ANY
WrongNumberOfQueriesError
@Deprecated public C verifyBetween(int minAllowedStatements, int maxAllowedStatements, Threads threadMatcher) throws WrongNumberOfQueriesError
minAllowedStatements
and at most
maxAllowedStatements
were called between the creation of the current instance
and a call to verify()
methodWrongNumberOfQueriesError
- if wrong number of queries was executed@Deprecated public C verifyBetween(int minAllowedStatements, int maxAllowedStatements, Query query) throws WrongNumberOfQueriesError
minAllowedStatements
and at most
maxAllowedStatements
were called between the creation of the current instance
and a call to verify()
methodWrongNumberOfQueriesError
- if wrong number of queries was executed@Deprecated public C verifyBetween(int minAllowedStatements, int maxAllowedStatements, Threads threadMatcher, Query query) throws WrongNumberOfQueriesError
minAllowedStatements
and at most
maxAllowedStatements
were called between the creation of the current instance
and a call to verify()
methodWrongNumberOfQueriesError
- if wrong number of queries was executed@Deprecated public C verifyBetween(int minAllowedStatements, int maxAllowedStatements, Query query, Threads threadMatcher) throws WrongNumberOfQueriesError
minAllowedStatements
and at most
maxAllowedStatements
were called between the creation of the current instance
and a call to verify()
methodWrongNumberOfQueriesError
- if wrong number of queries was executedCopyright © 2016. All rights reserved.