From acddacf7b6a456277852e00465f3c38de206db5b Mon Sep 17 00:00:00 2001 From: ribeaudc <ribeaudc> Date: Tue, 29 Jul 2008 01:05:06 +0000 Subject: [PATCH] fix: - Integration tests. SVN: 7547 --- .../common/logging/LogInvocationHandler.java | 83 ++++++++++++------- integration-tests/run.sh | 10 +-- .../etlserver-all/etc/service.properties | 4 +- 3 files changed, 63 insertions(+), 34 deletions(-) diff --git a/common/source/java/ch/systemsx/cisd/common/logging/LogInvocationHandler.java b/common/source/java/ch/systemsx/cisd/common/logging/LogInvocationHandler.java index 88fa7dbc3d4..d39451b957a 100644 --- a/common/source/java/ch/systemsx/cisd/common/logging/LogInvocationHandler.java +++ b/common/source/java/ch/systemsx/cisd/common/logging/LogInvocationHandler.java @@ -39,6 +39,8 @@ public final class LogInvocationHandler implements InvocationHandler private final Class<?> classUsedToNameLogger; + private final boolean onlyIfAnnotated; + /** * Creates a new instance. * @@ -49,11 +51,28 @@ public final class LogInvocationHandler implements InvocationHandler */ public LogInvocationHandler(final Object object, final String name, final Level logLevel, final Class<?> classUsedToNameLogger) + { + this(object, name, logLevel, classUsedToNameLogger, false); + } + + /** + * Creates a new instance. + * + * @param object Object whose invocations should be logged. + * @param name Meaningful name of <code>object</code>. Will be used in the log message. + * @param logLevel The log level to use for normal (successful) events. + * @param classUsedToNameLogger Class used to specify the name of the logger. + * @param onlyIfAnnotated whether the log should be activated only if method is annotated with + * {@link LogAnnotation}. + */ + public LogInvocationHandler(final Object object, final String name, final Level logLevel, + final Class<?> classUsedToNameLogger, final boolean onlyIfAnnotated) { this.object = object; this.name = name; this.defaultLogLevel = logLevel; this.classUsedToNameLogger = classUsedToNameLogger; + this.onlyIfAnnotated = onlyIfAnnotated; } public Object invoke(final Object proxy, final Method method, final Object[] args) @@ -78,57 +97,65 @@ public final class LogInvocationHandler implements InvocationHandler throw t; } finally { - final Level logLevel = getLogLevel(method); - final Logger logger = createLogger(method); - if (throwable != null || logger.isEnabledFor(logLevel)) + final LogAnnotation logAnnotationOrNull = tryGetAnnotation(method); + if (onlyIfAnnotated == false || logAnnotationOrNull != null) { - final StringBuilder builder = - new StringBuilder(throwable == null ? "Successful" : "Failed"); - builder.append(" invocation of "); - builder.append(name).append('.').append(method.getName()).append('('); - if (args != null) + final Level logLevel = getLogLevel(method, logAnnotationOrNull); + final Logger logger = createLogger(method, logAnnotationOrNull); + if (throwable != null || logger.isEnabledFor(logLevel)) { - for (int i = 0; i < args.length; i++) + final StringBuilder builder = + new StringBuilder(throwable == null ? "Successful" : "Failed"); + builder.append(" invocation of "); + builder.append(name).append('.').append(method.getName()).append('('); + if (args != null) { - builder.append(args[i]); - if (i < args.length - 1) + for (int i = 0; i < args.length; i++) { - builder.append(", "); + builder.append(args[i]); + if (i < args.length - 1) + { + builder.append(", "); + } } } - } - builder.append(") took ").append(System.currentTimeMillis() - time).append(" msec"); - if (throwable == null) - { - logger.log(logLevel, builder.toString()); - } else - { - logger.error(builder.toString(), throwable); + builder.append(") took ").append(System.currentTimeMillis() - time).append( + " msec"); + if (throwable == null) + { + logger.log(logLevel, builder.toString()); + } else + { + logger.error(builder.toString(), throwable); + } } } } } - private final Level getLogLevel(final Method method) + private final LogAnnotation tryGetAnnotation(final Method method) + { + return method.getAnnotation(LogAnnotation.class); + } + + private final Level getLogLevel(final Method method, final LogAnnotation annotationOrNull) { - final LogAnnotation annotation = method.getAnnotation(LogAnnotation.class); - if (annotation == null) + if (annotationOrNull == null) { return Level.DEBUG; - } else if (annotation.logLevel().equals(LogLevel.UNDEFINED)) + } else if (annotationOrNull.logLevel().equals(LogLevel.UNDEFINED)) { return defaultLogLevel; } else { - return Log4jSimpleLogger.toLog4jPriority(annotation.logLevel()); + return Log4jSimpleLogger.toLog4jPriority(annotationOrNull.logLevel()); } } - private final Logger createLogger(final Method method) + private final Logger createLogger(final Method method, final LogAnnotation annotationOrNull) { - final LogAnnotation annotation = method.getAnnotation(LogAnnotation.class); final LogCategory logCategory = - (annotation == null) ? LogCategory.OPERATION : annotation.logCategory(); + (annotationOrNull == null) ? LogCategory.OPERATION : annotationOrNull.logCategory(); return LogFactory.getLogger(logCategory, classUsedToNameLogger); } } \ No newline at end of file diff --git a/integration-tests/run.sh b/integration-tests/run.sh index cb1641d1b22..cf2daa994b6 100755 --- a/integration-tests/run.sh +++ b/integration-tests/run.sh @@ -597,7 +597,7 @@ function assert_correct_content_of_processing_dir { assert_same_content $TEST_DATA/3VCP1 $data_set assert_same_content $TEMPLATE/openBIS-client/testdata/register-experiments/processing-parameters.txt \ $DATA/processing-dir/processing-parameters-from-openbis - local bds_container=$DATA/main-store/Instance_integration-test/Group_CISD/Project_NEMO/Experiment_EXP1/ObservableType_HCS_IMAGE/Sample_3VCP1/ + local bds_container=$DATA/main-store/Instance_CISD/Group_CISD/Project_NEMO/Experiment_EXP1/ObservableType_HCS_IMAGE/Sample_3VCP1/ bds_container=$bds_container`ls -1 $bds_container | head -1` assert_dir_exists $bds_container local data_set2=$bds_container/data/original/microX_200801011213_3VCP1 @@ -609,7 +609,7 @@ function assert_correct_content_of_plate_3VCP1_in_store { local cell_plate=3VCP1 echo ==== assert correct content of plate 3VCP1 in store ==== - local main_dir=$DATA/main-store/Instance_integration-test/Group_CISD/Project_NEMO/Experiment_EXP1 + local main_dir=$DATA/main-store/Instance_CISD/Group_CISD/Project_NEMO/Experiment_EXP1 local raw_data_dir=$main_dir/ObservableType_HCS_IMAGE/Sample_3VCP1/ assert_dir_exists $raw_data_dir # Picks up the first directory found @@ -652,7 +652,7 @@ function assert_correct_content_of_plate_3VCP1_in_store { assert_equals_as_in_file microX $metadata_dir/data_set/producer_code assert_equals_as_in_file 3VCP1 $metadata_dir/sample/code assert_equals_as_in_file CELL_PLATE $metadata_dir/sample/type_code - assert_equals_as_in_file integration-test $metadata_dir/experiment_identifier/instance_code + assert_equals_as_in_file CISD $metadata_dir/experiment_identifier/instance_code assert_equals_as_in_file CISD $metadata_dir/experiment_identifier/group_code assert_equals_as_in_file NEMO $metadata_dir/experiment_identifier/project_code assert_equals_as_in_file EXP1 $metadata_dir/experiment_identifier/experiment_code @@ -692,14 +692,14 @@ function assert_correct_content_of_invalid_plate_in_store { local data_set=$error_dir/microX_200801011213_$cell_plate assert_same_content $TEST_DATA/$cell_plate $data_set assert_file_exists $data_set.exception - assert_dir_empty $DATA/main-store/Instance_integration-test/Group_CISD/Project_NEMO/Experiment_EXP1/ObservableType_HCS_IMAGE/Sample_$cell_plate + assert_dir_empty $DATA/main-store/Instance_CISD/Group_CISD/Project_NEMO/Experiment_EXP1/ObservableType_HCS_IMAGE/Sample_$cell_plate } function assert_correct_content_of_image_analysis_data { local cell_plate=$1 echo ==== check image analysis data for cell plate $cell_plate ==== - local img_analysis=$DATA/main-store/Instance_integration-test/Group_CISD/Project_NEMO/Experiment_EXP1/ObservableType_HCS_IMAGE_ANALYSIS_DATA/Sample_$cell_plate/ + local img_analysis=$DATA/main-store/Instance_CISD/Group_CISD/Project_NEMO/Experiment_EXP1/ObservableType_HCS_IMAGE_ANALYSIS_DATA/Sample_$cell_plate/ assert_dir_exists $img_analysis # Picks up the first directory found img_analysis=$img_analysis`ls -1 $img_analysis | head -1` diff --git a/integration-tests/templates/etlserver-all/etc/service.properties b/integration-tests/templates/etlserver-all/etc/service.properties index a17a44786a4..15c1a79db7e 100644 --- a/integration-tests/templates/etlserver-all/etc/service.properties +++ b/integration-tests/templates/etlserver-all/etc/service.properties @@ -1,5 +1,5 @@ # Code of openBIS instance -instance-code = integration-test +instance-code = CISD # The root directory of the data store storeroot-dir = ../data/main-store @@ -59,6 +59,7 @@ inputs=raw-data,image-analysis # --------------------------------------------------------------------------- # The directory to watch for incoming data. raw-data.incoming-dir = ../data/out-raw +raw-data.group-code = CISD # The extractor plugin class to use for data set information extraction raw-data.data-set-info-extractor = ch.systemsx.cisd.etlserver.threev.DataSetInfoExtractorForDataAcquisition @@ -94,6 +95,7 @@ raw-data.storage-processor.file-extractor = ch.systemsx.cisd.etlserver.imsb.HCSI # image-analysis thread # --------------------------------------------------------------------------- image-analysis.incoming-dir = ../data/out-analysis +image-analysis.group-code = CISD image-analysis.data-set-info-extractor = ch.systemsx.cisd.etlserver.threev.DataSetInfoExtractorForImageAnalysis # Separator used to extract the barcode in the data set file name -- GitLab