Commit 39ed6689 authored by Nils Christian Ehmke's avatar Nils Christian Ehmke

Added some tests

parent 8247ef2f
......@@ -3,6 +3,8 @@ package kieker.diagnosis.service.data;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.nullValue;
import static org.hamcrest.number.IsCloseTo.closeTo;
import static org.hamcrest.number.OrderingComparison.greaterThan;
import static org.junit.Assert.assertThat;
......@@ -283,6 +285,55 @@ public class MonitoringLogServiceTest {
ivService.importMonitoringLog( directory );
}
@Test
public void testTraceInDetail( ) throws Exception {
// Prepare the data
writeRecord( new TraceMetadata( 1L, 0L, "0", "host", 0L, 0 ) );
writeRecord( new BeforeOperationEvent( 1000000L, 1L, 0, "op1", "class1" ) );
writeRecord( new BeforeOperationEvent( 2000000L, 1L, 0, "op2", "class2" ) );
writeRecord( new AfterOperationEvent( 2500000L, 1L, 0, "op2", "class2" ) );
writeRecord( new AfterOperationFailedEvent( 4000000L, 1L, 0, "op1", "class1", "cause" ) );
writeMappingFile( );
finishWriting( );
// Import the directory
final File directory = ivTemporaryFolder.getRoot( );
ivService.importMonitoringLog( directory );
// Make sure that the import worked as intended
assertThat( ivService.getMethods( ), hasSize( 2 ) );
assertThat( ivService.getAggreatedMethods( ), hasSize( 2 ) );
assertThat( ivService.getTraceRoots( ), hasSize( 1 ) );
assertThat( ivService.getProcessedBytes( ), is( greaterThan( 0L ) ) );
// Now some advanced checks
final MethodCall firstMethod = ivService.getMethods( ).get( 0 );
assertThat( firstMethod.getHost( ), is( "host" ) );
assertThat( firstMethod.getClazz( ), is( "class1" ) );
assertThat( firstMethod.getMethod( ), is( "op1" ) );
assertThat( firstMethod.getException( ), is( "cause" ) );
assertThat( firstMethod.getTimestamp( ), is( 1L ) );
assertThat( firstMethod.getDuration( ), is( 3000000L ) );
assertThat( (double) firstMethod.getPercent( ), is( closeTo( 100.0, 0.01 ) ) );
assertThat( firstMethod.getTraceDepth( ), is( 2 ) );
assertThat( firstMethod.getTraceId( ), is( 1L ) );
assertThat( firstMethod.getTraceSize( ), is( 2 ) );
final MethodCall secondMethod = ivService.getMethods( ).get( 1 );
assertThat( secondMethod.getHost( ), is( "host" ) );
assertThat( secondMethod.getClazz( ), is( "class2" ) );
assertThat( secondMethod.getMethod( ), is( "op2" ) );
assertThat( secondMethod.getException( ), is( nullValue( ) ) );
assertThat( secondMethod.getTimestamp( ), is( 2L ) );
assertThat( secondMethod.getDuration( ), is( 500000L ) );
assertThat( (double) secondMethod.getPercent( ), is( closeTo( 16.66, 0.01 ) ) );
assertThat( secondMethod.getTraceDepth( ), is( 1 ) );
assertThat( secondMethod.getTraceId( ), is( 1L ) );
assertThat( secondMethod.getTraceSize( ), is( 1 ) );
assertThat( ivService.getTraceRoots( ).get( 0 ), is( firstMethod ) );
}
private void writeRecord( final AbstractMonitoringRecord aRecord ) {
// Register the record name
final int recordKey = ivStringRegistry.get( aRecord.getClass( ).getName( ) );
......
package kieker.diagnosis.service.methods;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import org.junit.Before;
import org.junit.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
import kieker.diagnosis.KiekerTraceDiagnosisModule;
import kieker.diagnosis.service.data.MethodCall;
import kieker.diagnosis.service.data.MonitoringLogService;
public class MethodsServiceTest {
private MethodsService ivMethodsService;
private MonitoringLogService ivDataService;
@Before
public void setUp( ) {
final Injector injector = Guice.createInjector( new KiekerTraceDiagnosisModule( ) );
ivMethodsService = injector.getInstance( MethodsService.class );
ivDataService = injector.getInstance( MonitoringLogService.class );
}
@Test
public void testSimpleSearch( ) {
// Prepare some data for the search
createMethodCall( "host1", "class1", "op1", "cause1" );
createMethodCall( "host1", "class2", "op1", "cause1" );
createMethodCall( "host1", "class1", "op3", "cause1" );
createMethodCall( "host1", "class1", "op3", "cause4" );
assertThat( ivMethodsService.countMethods( ), is( 4 ) );
// Now search with a filter
final MethodsFilter methodsFilter = new MethodsFilter( );
methodsFilter.setHost( "host1" );
assertThat( ivMethodsService.searchMethods( methodsFilter ).size( ), is( 4 ) );
methodsFilter.setClazz( "class1" );
assertThat( ivMethodsService.searchMethods( methodsFilter ).size( ), is( 3 ) );
methodsFilter.setMethod( "op3" );
assertThat( ivMethodsService.searchMethods( methodsFilter ).size( ), is( 2 ) );
methodsFilter.setException( "cause4" );
assertThat( ivMethodsService.searchMethods( methodsFilter ).size( ), is( 1 ) );
}
@Test
public void testSearchTypeFilter( ) {
// Prepare some data for the search
createMethodCall( "host1", "class1", "op1", "cause1" );
createMethodCall( "host1", "class2", "op1", null );
createMethodCall( "host1", "class1", "op3", "cause1" );
createMethodCall( "host1", "class1", "op3", "cause4" );
assertThat( ivMethodsService.countMethods( ), is( 4 ) );
// Now search with a filter
final MethodsFilter methodsFilter = new MethodsFilter( );
methodsFilter.setSearchType( SearchType.ALL );
assertThat( ivMethodsService.searchMethods( methodsFilter ).size( ), is( 4 ) );
methodsFilter.setSearchType( SearchType.ONLY_FAILED );
assertThat( ivMethodsService.searchMethods( methodsFilter ).size( ), is( 3 ) );
methodsFilter.setSearchType( SearchType.ONLY_SUCCESSFUL );
assertThat( ivMethodsService.searchMethods( methodsFilter ).size( ), is( 1 ) );
}
private void createMethodCall( final String aHost, final String aClazz, final String aMethod, final String aException ) {
final MethodCall methodCall = new MethodCall( );
methodCall.setHost( aHost );
methodCall.setClazz( aClazz );
methodCall.setMethod( aMethod );
methodCall.setException( aException );
ivDataService.getMethods( ).add( methodCall );
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment