@Test public void testNoViolations() throws Throwable { when ( fig.getQueryBreakerErrorSortPredicateCount() ).thenReturn( 5 ); when ( fig.getQueryBreakerErrorOperandCount() ).thenReturn( 5 ); when ( fig.getQueryBreakerErrorIndexSizeBytes() ).thenReturn( 5L ); when ( fig.getQueryBreakerErrorCollectionSizeBytes() ).thenReturn( 5L ); ParsedQuery parsedQuery; List<Map<String,Object>> violations; parsedQuery = ParsedQueryBuilder.build("select * order by created asc"); violations = QueryAnalyzer.analyze(parsedQuery, 1, 1, fig ); assertEquals(0, violations.size()); parsedQuery = ParsedQueryBuilder.build("select name='value' order by created asc"); violations = QueryAnalyzer.analyze(parsedQuery, 1, 1, fig ); assertEquals(0, violations.size()); parsedQuery = ParsedQueryBuilder.build("where name='value'"); violations = QueryAnalyzer.analyze(parsedQuery, 1, 1, fig ); assertEquals(0, violations.size()); }
@Test public void collectionSizeViolation() throws Throwable { // the sort violation is only tripped when the collection size warning is tripped when ( fig.getQueryBreakerErrorCollectionSizeBytes() ).thenReturn( 0L ); ParsedQuery parsedQuery = ParsedQueryBuilder.build("select created order by created asc"); List<Map<String,Object>> violations; violations = QueryAnalyzer.analyze(parsedQuery, 1, 1, fig ); boolean violationExists = violationExists(violations, QueryAnalyzer.v_large_collection); if(!violationExists){ fail("Collection Size Violation should be present"); } }
@Test public void operandCountViolation() throws Throwable { ParsedQuery parsedQuery = ParsedQueryBuilder.build("where name='value'"); List<Map<String,Object>> violations; violations = QueryAnalyzer.analyze(parsedQuery, 0, 0, fig ); boolean violationExists = violationExists(violations, QueryAnalyzer.v_operand_count); if(!violationExists){ fail("Operand Count Violation should be present"); } }
@Test public void predicateCountViolation() throws Throwable { ParsedQuery parsedQuery = ParsedQueryBuilder.build("where name='value'"); List<Map<String,Object>> violations; violations = QueryAnalyzer.analyze(parsedQuery, 0, 0, fig ); boolean violationExists = violationExists(violations, QueryAnalyzer.v_operand_count); if(!violationExists){ fail("Operand Count Violation should be present"); } }
@Test public void IndexSizeViolation() throws Throwable { ParsedQuery parsedQuery = ParsedQueryBuilder.build("select created order by created asc"); List<Map<String,Object>> violations; violations = QueryAnalyzer.analyze(parsedQuery, 0, 1, fig ); boolean violationExists = violationExists(violations, QueryAnalyzer.v_large_index); if(!violationExists){ fail("Index Size Violation should be present"); } }
@Test public void fullSortViolation() throws Throwable { ParsedQuery parsedQuery = ParsedQueryBuilder.build("select * order by created asc"); List<Map<String,Object>> violations; violations = QueryAnalyzer.analyze(parsedQuery, 1, 1, fig ); boolean violationExists = violationExists(violations, QueryAnalyzer.v_full_collection_sort); if(!violationExists){ fail("Full Collection Sort Violation should be present"); } }
List<Map<String, Object>> violations = QueryAnalyzer.analyze(parsedQuery, totalEdgeSizeInBytes, totalIndexSizeInBytes, indexFig); if(indexFig.enforceQueryBreaker() && violations.size() > 0){ throw new QueryAnalyzerEnforcementException(violations, parsedQuery.getOriginalQuery());