@Test(expected = TcpConnectionsExpectationError.class) public void testMaxOneConnection_Exception() { try (Spy<?> s = Sniffy.expect(TcpConnections.max(1))) { performSocketOperation(); performSocketOperation(); } }
@Test(expected = TcpConnectionsExpectationError.class) public void testExactConnectionsCurrentThread_Exception() throws InterruptedException { try (Spy<?> s = Sniffy.expect(TcpConnections.exact(2).otherThreads())) { performSocketOperation(); performSocketOperationOtherThread(); } }
@Test(expected = TcpConnectionsExpectationError.class) public void testMinConnectionsHost_Exception() { try (Spy<?> s = Sniffy.expect(TcpConnections.min(2).host("google.com"))) { performSocketOperation(); performSocketOperation(); } }
@Test public void testMinConnectionsAnyThreads() throws InterruptedException { try (Spy<?> s = Sniffy.expect(TcpConnections.min(3).anyThreads())) { performSocketOperation(); performSocketOperation(); performSocketOperationOtherThread(); } }
@Test public void testExactTwoInsertQueries() { try (Spy $= Sniffy.expect(SqlQueries.exactQueries(2).insert())) { executeStatement(INSERT); executeStatement(INSERT); executeStatement(SELECT); } }
@Test public void testExactTwoMergeQueries() { try (Spy $= Sniffy.expect(SqlQueries.exactQueries(2).merge())) { executeStatement(MERGE); executeStatement(MERGE); executeStatement(SELECT); } }
@Test public void testExactTwoOtherQueries() { try (Spy $= Sniffy.expect(SqlQueries.exactQueries(2).other())) { executeStatement(OTHER); executeStatement(OTHER); executeStatement(SELECT); } }
@Test public void testExactTwoAnyThreadsInsertQueries() { try (Spy $= Sniffy.expect(SqlQueries.exactQueries(2).anyThreads().insert())) { executeStatement(INSERT); executeStatementInOtherThread(INSERT); } }
@Test public void testMinMaxRows() { try (@SuppressWarnings("unused") Spy $= Sniffy.expect(SqlQueries.minRows(2).maxRows(3))) { executeStatement(); executeStatement(); executeStatement(); } }
@Test public void testExactQueriesExactRows() { executeStatementsInOtherThread(1, Query.DELETE); try (@SuppressWarnings("unused") Spy $= Sniffy.expect(SqlQueries.exactQueries(2).exactRows(3))) { executeStatementsInOtherThread(3, Query.INSERT); executeStatements(2, Query.DELETE); } }
@Test public void testOneQueryOneRowCurrentThreadSelect() { try (@SuppressWarnings("unused") Spy $= Sniffy.expect(SqlQueries.exactQueries(1).exactRows(1).currentThread().select())) { executeStatement(Query.SELECT); } }
@Test(expected = TcpConnectionsExpectationError.class) public void testExactConnectionsCurrentThreadHostName_Exception() throws InterruptedException { try (Spy<?> s = Sniffy.expect(TcpConnections.exact(2).otherThreads().host("google.com"))) { performSocketOperationOtherThread(); performSocketOperationOtherThread(); } }
@Test public void testNoneRowsOtherQueriesBetweenTwoAndThree() { try (@SuppressWarnings("unused") Spy $= Sniffy.expect(SqlQueries.noneRows().other().queriesBetween(2,3).anyThreads())) { executeStatement(Query.OTHER); executeStatementInOtherThread(Query.OTHER); } }
@Test(expected = WrongNumberOfRowsError.class) public void testTwoQueryMinTwoRows_Exception() { executeStatement(Query.DELETE); try (@SuppressWarnings("unused") Spy $= Sniffy.expect(SqlQueries.exactQueries(2).minRows(2).delete().anyThreads())) { executeStatement(Query.DELETE); executeStatement(Query.DELETE); } }
@Test(expected = WrongNumberOfRowsError.class) public void testBetweenNineAndElevenRowSelectedAllQueries_Exception() { try (@SuppressWarnings("unused") Spy $= Sniffy.expect(SqlQueries.rowsBetween(9,11).select().anyThreads())) { executeStatements(2, Query.INSERT); executeStatementsInOtherThread(3, Query.INSERT); executeStatements(1, Query.SELECT); executeStatementsInOtherThread(1, Query.SELECT); } }
@Test public void testOneDeleteQueryCurrentThreadBetweenMinMaxRows() { executeStatement(Query.DELETE); executeStatements(2, Query.INSERT); try (@SuppressWarnings("unused") Spy $= Sniffy.expect(SqlQueries.atMostOneQuery().currentThread().minRows(2).maxRows(3))) { executeStatement(Query.DELETE); } }
@Test(expected = WrongNumberOfRowsError.class) public void testOneDeleteQueryCurrentThreadBetweenMaxMinRows_Exception() { executeStatement(Query.DELETE); executeStatements(2, Query.INSERT); try (@SuppressWarnings("unused") Spy $= Sniffy.expect(SqlQueries.atMostOneQuery().currentThread().maxRows(5).minRows(4))) { executeStatement(Query.DELETE); } }
@Test public void testMinConnectionsHostThreads() throws InterruptedException { try (Spy<?> s = Sniffy.expect(TcpConnections.min(3).host("localhost:" + echoServerRule.getBoundPort()).threads(Threads.ANY))) { performSocketOperation(); performSocketOperation(); performSocketOperationOtherThread(); } }
@Test public void testExactConnectionsHostCurrentThread() throws InterruptedException { try (Spy<?> s = Sniffy.expect(TcpConnections.exact(2).host("localhost:" + echoServerRule.getBoundPort()).currentThread())) { performSocketOperation(); performSocketOperation(); performSocketOperationOtherThread(); } }
@Test public void testTwoRowsAnyThreadUpdateMinMaxQueries() { executeStatement(Query.DELETE); executeStatements(2, Query.INSERT); try (@SuppressWarnings("unused") Spy $= Sniffy.expect(SqlQueries.maxRows(2).minRows(2).anyThreads().update().atMostOneQuery())) { executeStatementInOtherThread(Query.UPDATE); } }