diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/AbstractQueryFacadeTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/AbstractQueryFacadeTest.java index b355a471f4be3eaca8755681d362df4a3c97c75f..26e58935c6c136901b1f50c2bb463b7554085ab8 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/AbstractQueryFacadeTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/AbstractQueryFacadeTest.java @@ -17,7 +17,6 @@ package ch.systemsx.cisd.openbis.datastoreserver.systemtests; import java.io.File; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.EnumSet; @@ -27,12 +26,9 @@ import java.util.Map; import java.util.UUID; import org.apache.log4j.Level; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import ch.systemsx.cisd.common.filesystem.FileUtilities; -import ch.systemsx.cisd.common.logging.BufferedAppender; import ch.systemsx.cisd.openbis.dss.generic.shared.api.v1.IDssServiceRpcGeneric; import ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Sample; @@ -82,16 +78,10 @@ public abstract class AbstractQueryFacadeTest extends SystemTestCase */ public abstract String getTestId(); - @BeforeMethod - public void beforeMethod(Method method) + @Override + protected Level getLogLevel() { - logAppender = new BufferedAppender("%-5p %c - %m%n", Level.DEBUG); - } - - @AfterMethod - public void afterMethod(Method method) - { - logAppender.reset(); + return Level.DEBUG; } public AggregationServiceDescription getAggregationServiceDescription(String key) @@ -257,7 +247,7 @@ public abstract class AbstractQueryFacadeTest extends SystemTestCase { if (code.equalsIgnoreCase(sample.getCode())) { - waitUntilIndexedByLucene(SamplePE.class, sample.getId()); + waitUntilDataSetImported(new ContainsCondition("REINDEX " + SamplePE.class.getName() + ": [" + sample.getId() + "]")); foundSample = true; } } diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/FinishedPostRegistrationCondition.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/AlwaysStopCondition.java similarity index 71% rename from datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/FinishedPostRegistrationCondition.java rename to datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/AlwaysStopCondition.java index 94758de7eda5be4b9388392fd2ada26afda4cf4c..2d5dc421f91cc2c020f8b933da00486b950abd08 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/FinishedPostRegistrationCondition.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/AlwaysStopCondition.java @@ -16,23 +16,25 @@ package ch.systemsx.cisd.openbis.datastoreserver.systemtests; -import java.util.regex.Pattern; - /** - * + * Stop condition returning always <code>true</code>. * * @author Franz-Josef Elmer */ -public class FinishedPostRegistrationCondition implements ILogMonitoringStopCondition +public class AlwaysStopCondition implements ILogMonitoringStopCondition { - public static final ILogMonitoringStopCondition INSTANCE = new FinishedPostRegistrationCondition(); - - private static Pattern PATTERN = Pattern.compile(".*Post registration of (\\d*). of \\1 data sets: (.*)"); - + public static final ILogMonitoringStopCondition INSTANCE = new AlwaysStopCondition(); + @Override public boolean stopConditionFulfilled(ParsedLogEntry logEntry) { - return PATTERN.matcher(logEntry.getLogMessage()).matches(); + return true; + } + + @Override + public String toString() + { + return "Always stops"; } } diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/AndStopCondition.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/AndStopCondition.java new file mode 100644 index 0000000000000000000000000000000000000000..6725249c1fcd0de1735c42cfe53a8eb1d442e4e0 --- /dev/null +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/AndStopCondition.java @@ -0,0 +1,47 @@ +/* + * Copyright 2014 ETH Zuerich, SIS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.datastoreserver.systemtests; + +/** + * Condition which is fulfilled if both wrapped conditions are fulfilled. + * + * @author Franz-Josef Elmer + */ +public class AndStopCondition implements ILogMonitoringStopCondition +{ + private ILogMonitoringStopCondition condition1; + private ILogMonitoringStopCondition condition2; + + public AndStopCondition(ILogMonitoringStopCondition condition1, ILogMonitoringStopCondition condition2) + { + this.condition1 = condition1; + this.condition2 = condition2; + } + + @Override + public boolean stopConditionFulfilled(ParsedLogEntry logEntry) + { + return condition1.stopConditionFulfilled(logEntry) && condition2.stopConditionFulfilled(logEntry); + } + + @Override + public String toString() + { + return "(" + condition1 + ") and (" + condition2 + ")"; + } + +} diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/AttachmentsDropboxTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/AttachmentsDropboxTest.java index f746108c1e9993e54cf46f2b9dcf517c5313130f..7e3a11767a4984214d2adef7b9e1ba1d72c661fd 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/AttachmentsDropboxTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/AttachmentsDropboxTest.java @@ -17,19 +17,15 @@ package ch.systemsx.cisd.openbis.datastoreserver.systemtests; import java.io.File; -import java.lang.reflect.Method; +import java.util.List; import org.apache.log4j.Level; import org.apache.log4j.Logger; -import org.testng.Assert; import org.testng.annotations.AfterClass; -import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; -import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import ch.systemsx.cisd.common.filesystem.FileUtilities; -import ch.systemsx.cisd.common.logging.BufferedAppender; /** * @author pkupczyk @@ -51,23 +47,12 @@ public class AttachmentsDropboxTest extends SystemTestCase Logger.getLogger("OPERATION.Resources").setLevel(Level.INFO); } - @BeforeMethod - public void beforeMethod(Method method) - { - logAppender = new BufferedAppender("%-5p %c - %m%n", Level.DEBUG); - } - - @AfterMethod - public void afterMethod(Method method) - { - logAppender.reset(); - } - @Test public void testAttachmentsWithSuccess() throws Exception { createData("success"); - waitUntilDataSetImported(); + waitUntilDataSetImported(new LogMonitoringStopConditionBuilder(new DropBoxNameCondition("attachments-test")) + .and(new ContainsCondition("Successfully committed transaction")).getCondition()); assertStreamsReleased(3); } @@ -75,7 +60,9 @@ public class AttachmentsDropboxTest extends SystemTestCase public void testAttachmentsWithFailure() throws Exception { createData("failure"); - waitUntilDataSetImportedWithError("attachments-test"); + waitUntilDataSetImported(new LogMonitoringStopConditionBuilder(ErrorStopCondition.INSTANCE) + .and(new DropBoxNameCondition("attachments-test")) + .and(new ContainsCondition("Data set registration failed")).getCondition()); assertStreamsReleased(3); } @@ -89,18 +76,25 @@ public class AttachmentsDropboxTest extends SystemTestCase private void assertStreamsReleased(int expectedCount) { - String[] lines = logAppender.getLogContent().split("\n"); int count = 0; - - for (String line : lines) + List<ParsedLogEntry> logEntries = getLogEntries(); + for (ParsedLogEntry logEntry : logEntries) { - if (line.contains("DEBUG OPERATION.Resources - Successfully released a resource") && line.contains("ReleasableStream")) + String logMessage = logEntry.getLogMessage(); + if (logEntry.getLogLevel().equals("DEBUG") + && logMessage.contains("OPERATION.Resources - Successfully released a resource") + && logMessage.contains("ReleasableStream")) { count++; } } + assertEquals(expectedCount, count); + } - Assert.assertEquals(count, expectedCount); + @Override + protected Level getLogLevel() + { + return Level.DEBUG; } @Override diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/ContainsCondition.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/ContainsCondition.java new file mode 100644 index 0000000000000000000000000000000000000000..20a425cbcc43ff9b60a32a7cb2fe0000b1159735 --- /dev/null +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/ContainsCondition.java @@ -0,0 +1,45 @@ +/* + * Copyright 2014 ETH Zuerich, SIS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.datastoreserver.systemtests; + +/** + * Condition which is fulfilled if the log message contains the specified snippet. + * + * @author Franz-Josef Elmer + */ +public class ContainsCondition implements ILogMonitoringStopCondition +{ + private String logMessageSnippet; + + public ContainsCondition(String logMessageSnippet) + { + this.logMessageSnippet = logMessageSnippet; + } + + @Override + public boolean stopConditionFulfilled(ParsedLogEntry logEntry) + { + return logEntry.getLogMessage().contains(logMessageSnippet); + } + + @Override + public String toString() + { + return "Contains: " + logMessageSnippet; + } + +} diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/DropBoxNameCondition.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/DropBoxNameCondition.java new file mode 100644 index 0000000000000000000000000000000000000000..5d4b547b02b7576a8c85c6df342b2ac045b6dee6 --- /dev/null +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/DropBoxNameCondition.java @@ -0,0 +1,45 @@ +/* + * Copyright 2014 ETH Zuerich, SIS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.datastoreserver.systemtests; + +/** + * Condition which is fulfilled if the thread name reads '<drop box name> - Incoming Data Monitor'. + * + * @author Franz-Josef Elmer + */ +public class DropBoxNameCondition implements ILogMonitoringStopCondition +{ + private String dropBoxName; + + public DropBoxNameCondition(String dropBoxName) + { + this.dropBoxName = dropBoxName; + } + + @Override + public boolean stopConditionFulfilled(ParsedLogEntry logEntry) + { + return logEntry.getThreadName().equals(dropBoxName + " - Incoming Data Monitor"); + } + + @Override + public String toString() + { + return "Drop box: " + dropBoxName; + } + +} diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/ErrorStopCondition.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/ErrorStopCondition.java new file mode 100644 index 0000000000000000000000000000000000000000..0ba8618f8beef29bc29b734d6d3e68f7165ef895 --- /dev/null +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/ErrorStopCondition.java @@ -0,0 +1,40 @@ +/* + * Copyright 2014 ETH Zuerich, SIS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.datastoreserver.systemtests; + +/** + * Condition which is fulfilled in case of an ERROR log. + * + * @author Franz-Josef Elmer + */ +public class ErrorStopCondition implements ILogMonitoringStopCondition +{ + public static final ILogMonitoringStopCondition INSTANCE = new ErrorStopCondition(); + + @Override + public boolean stopConditionFulfilled(ParsedLogEntry logEntry) + { + return logEntry.getLogLevel().equals("ERROR"); + } + + @Override + public String toString() + { + return "ERROR"; + } + +} diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/LogMonitoringStopConditionBuilder.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/LogMonitoringStopConditionBuilder.java new file mode 100644 index 0000000000000000000000000000000000000000..97db928709546fa4a692d5e748e3dace946c289e --- /dev/null +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/LogMonitoringStopConditionBuilder.java @@ -0,0 +1,64 @@ +/* + * Copyright 2014 ETH Zuerich, SIS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.datastoreserver.systemtests; + +/** + * Helper class to build {@link ILogMonitoringStopCondition} expressions. + * + * @author Franz-Josef Elmer + */ +public class LogMonitoringStopConditionBuilder +{ + private ILogMonitoringStopCondition condition; + + public LogMonitoringStopConditionBuilder() + { + this(AlwaysStopCondition.INSTANCE); + } + + public LogMonitoringStopConditionBuilder(ILogMonitoringStopCondition condition) + { + this.condition = condition; + } + + public ILogMonitoringStopCondition getCondition() + { + return condition; + } + + public LogMonitoringStopConditionBuilder and(ILogMonitoringStopCondition stopCondition) + { + condition = new AndStopCondition(condition, stopCondition); + return this; + } + + public LogMonitoringStopConditionBuilder and(LogMonitoringStopConditionBuilder conditionBuilder) + { + return and(conditionBuilder.getCondition()); + } + + public LogMonitoringStopConditionBuilder or(ILogMonitoringStopCondition stopCondition) + { + condition = new OrStopCondition(condition, stopCondition); + return this; + } + + public LogMonitoringStopConditionBuilder or(LogMonitoringStopConditionBuilder conditionBuilder) + { + return or(conditionBuilder.getCondition()); + } +} diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/MutableTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/MutableTest.java index d1db52e9e869adeaa93555fdbcf5b82288af1103..09c4aa6969b375792d5174eba46089fe74f3bf75 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/MutableTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/MutableTest.java @@ -17,7 +17,6 @@ package ch.systemsx.cisd.openbis.datastoreserver.systemtests; import java.io.File; -import java.lang.reflect.Method; import java.util.Collections; import java.util.List; @@ -31,7 +30,6 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import ch.systemsx.cisd.common.filesystem.FileUtilities; -import ch.systemsx.cisd.common.logging.BufferedAppender; import ch.systemsx.cisd.common.spring.HttpInvokerUtils; import ch.systemsx.cisd.openbis.generic.shared.api.v1.IGeneralInformationService; import ch.systemsx.cisd.openbis.generic.shared.api.v1.dto.Attachment; @@ -88,16 +86,10 @@ public abstract class MutableTest extends SystemTestCase Logger.getLogger("OPERATION.Resources").setLevel(Level.INFO); } - @BeforeMethod - public void beforeMethod(Method method) - { - logAppender = new BufferedAppender("%-5p %c - %m%n", Level.DEBUG); - } - - @AfterMethod - public void afterMethod(Method method) + @Override + protected Level getLogLevel() { - logAppender.reset(); + return Level.DEBUG; } @Test diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/MutableV2Test.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/MutableV2Test.java index b7ffacf136937e7d3585c9a0785738f4d5847943..f46350d19c12de2633ac36f12d37a6938ab9280d 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/MutableV2Test.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/MutableV2Test.java @@ -17,11 +17,10 @@ package ch.systemsx.cisd.openbis.datastoreserver.systemtests; import java.io.File; +import java.util.List; import org.testng.annotations.Test; -import ch.systemsx.cisd.common.test.AssertionUtil; - /** * @author pkupczyk */ @@ -46,9 +45,16 @@ public class MutableV2Test extends MutableTest @Override protected void assertAfter() { - AssertionUtil.assertContainsLines( - "Projects updated: 1\nMaterials updated: 1\nExperiments updated: 1\nSamples updated: 1\nData sets updated: 1", - logAppender.getLogContent()); + List<ParsedLogEntry> logEntries = getLogEntries(); + for (ParsedLogEntry logEntry : logEntries) + { + if (logEntry.getLogMessage().contains("Projects updated: 1\nMaterials updated: 1\n" + + "Experiments updated: 1\nSamples updated: 1\nData sets updated: 1")) + { + return; + } + } + fail("Missing Projects update log message."); } } diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/OrStopCondition.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/OrStopCondition.java new file mode 100644 index 0000000000000000000000000000000000000000..f468b99b5baab5620f388a4cc08527cb8a2b7f99 --- /dev/null +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/OrStopCondition.java @@ -0,0 +1,47 @@ +/* + * Copyright 2014 ETH Zuerich, SIS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.datastoreserver.systemtests; + +/** + * Condition which is fulfilled if at least one of both wrapped conditions is fulfilled. + * + * @author Franz-Josef Elmer + */ +public class OrStopCondition implements ILogMonitoringStopCondition +{ + private ILogMonitoringStopCondition condition1; + private ILogMonitoringStopCondition condition2; + + public OrStopCondition(ILogMonitoringStopCondition condition1, ILogMonitoringStopCondition condition2) + { + this.condition1 = condition1; + this.condition2 = condition2; + } + + @Override + public boolean stopConditionFulfilled(ParsedLogEntry logEntry) + { + return condition1.stopConditionFulfilled(logEntry) || condition2.stopConditionFulfilled(logEntry); + } + + @Override + public String toString() + { + return "(" + condition1 + ") or (" + condition2 + ")"; + } + +} diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/ParsedLogEntry.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/ParsedLogEntry.java index 389c7b781c06424735b5171de616e9af8bf062d1..d49e5b1521b596e2a25b0a9b2ad780b45754dfc8 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/ParsedLogEntry.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/ParsedLogEntry.java @@ -23,7 +23,7 @@ import ch.systemsx.cisd.openbis.generic.shared.basic.BasicConstant; public final class ParsedLogEntry { - private static final String FORMAT_TEMPLATE = "{0,date," + BasicConstant.DATE_WITHOUT_TIMEZONE_PATTERN + "} {1} [{2}] {3}"; + private static final String FORMAT_TEMPLATE = "[{0,date," + BasicConstant.DATE_WITHOUT_TIMEZONE_PATTERN + "}][{1}][{2}][{3}]"; private Date timestamp; private String logLevel; @@ -37,6 +37,11 @@ public final class ParsedLogEntry this.threadName = threadName; this.logMessage = logMessage; } + + public void appendToMessage(String logLine) + { + logMessage += "\n" + logLine; + } public Date getTimestamp() { diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/RegexCondition.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/RegexCondition.java new file mode 100644 index 0000000000000000000000000000000000000000..0ace6522ef9b05ade0b82d29104ff16df181925d --- /dev/null +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/RegexCondition.java @@ -0,0 +1,47 @@ +/* + * Copyright 2014 ETH Zuerich, SIS + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.openbis.datastoreserver.systemtests; + +import java.util.regex.Pattern; + +/** + * Stop condition using a regular expression for the log message. + * + * @author Franz-Josef Elmer + */ +public class RegexCondition implements ILogMonitoringStopCondition +{ + private Pattern pattern; + + public RegexCondition(String regex) + { + pattern = Pattern.compile(regex); + } + + @Override + public boolean stopConditionFulfilled(ParsedLogEntry logEntry) + { + return pattern.matcher(logEntry.getLogMessage()).matches(); + } + + @Override + public String toString() + { + return "Regex: " + pattern.pattern(); + } + +} diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/SystemTestCase.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/SystemTestCase.java index 3fc696f52fda10d36f2e863c349a44d1b4a34786..3760e8dadad9440d24d897f649e0f65856deb17c 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/SystemTestCase.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/openbis/datastoreserver/systemtests/SystemTestCase.java @@ -93,6 +93,9 @@ public abstract class SystemTestCase extends AssertJUnit private static final String ROOT_DIR_KEY = "root-dir"; private static final String DATA_SET_IMPORTED_LOG_MARKER = "Successfully registered data set"; + + public static final ILogMonitoringStopCondition FINISHED_POST_REGISTRATION_CONDITION + = new RegexCondition(".*Post registration of (\\d*). of \\1 data sets: (.*)"); // this message appears if the dropbox has successfully completed the registration, even if no // datasets have been imported @@ -107,7 +110,7 @@ public abstract class SystemTestCase extends AssertJUnit protected File store; - protected BufferedAppender logAppender; + private BufferedAppender logAppender; protected SystemTestCase() { @@ -138,6 +141,7 @@ public abstract class SystemTestCase extends AssertJUnit public void beforeTest(Method method) { System.out.println("BEFORE " + render(method)); + getLogAppender().resetLogContent(); } @AfterMethod @@ -265,6 +269,13 @@ public abstract class SystemTestCase extends AssertJUnit return logMessage.contains(DATA_SET_IMPORTED_LOG_MARKER) || logMessage.contains(REGISTRATION_FINISHED_LOG_MARKER); } + + @Override + public String toString() + { + return "Log message contains '" + DATA_SET_IMPORTED_LOG_MARKER + + "' or '" + REGISTRATION_FINISHED_LOG_MARKER + "'"; + } }); } @@ -285,16 +296,17 @@ public abstract class SystemTestCase extends AssertJUnit } } } - fail("Log monitoring stop condition (" + stopCondition + ") never fulfilled after " + maxLoops + " seconds."); + fail("Log monitoring stop condition [" + stopCondition + "] never fulfilled after " + maxLoops + " seconds."); } - private List<ParsedLogEntry> getLogEntries() + protected List<ParsedLogEntry> getLogEntries() { List<ParsedLogEntry> result = new ArrayList<ParsedLogEntry>(); String[] logLines = getLogAppender().getLogContent().split("\n"); - Pattern pattern = Pattern.compile("^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}),\\d{3} ([^ ]*) \\[(.*)\\] (.*)$"); + Pattern pattern = Pattern.compile("^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}),\\d{3} ([^ ]*) \\[([^\\]]*)\\] (.*)$"); SimpleDateFormat dateFormat = new SimpleDateFormat(BasicConstant.DATE_WITHOUT_TIMEZONE_PATTERN); + ParsedLogEntry logEntry = null; for (String logLine : logLines) { Matcher matcher = pattern.matcher(logLine); @@ -306,52 +318,19 @@ public abstract class SystemTestCase extends AssertJUnit String logLevel = matcher.group(2); String threadName = matcher.group(3); String logMessage = matcher.group(4); - result.add(new ParsedLogEntry(timestamp, logLevel, threadName, logMessage)); + logEntry = new ParsedLogEntry(timestamp, logLevel, threadName, logMessage); + result.add(logEntry); +// System.out.println("LOG ENTRY: " + logEntry); } catch (ParseException ex) { throw CheckedExceptionTunnel.wrapIfNecessary(ex); } - } - } - return result; - } - - protected void waitUntilDataSetImportedWithError(String dropboxName) throws Exception - { - final int maxLoops = dataSetImportWaitDurationInSeconds(); - - for (int loops = 0; loops < maxLoops; loops++) - { - Thread.sleep(1000); - - String logContent = getLogAppender().getLogContent(); - if (logContent.contains("ERROR") && logContent.contains(dropboxName)) + } else if (logEntry != null) { - return; + logEntry.appendToMessage(logLine); } } - - fail("Failed to determine whether data set import was executed with error"); - } - - protected void waitUntilIndexedByLucene(Class<?> entityPeClass, Long entityId) throws Exception - { - operationLog.info("Waiting for " + entityPeClass.getName() + " with id: " + entityId + " to be indexed by Lucene"); - - final int maxLoops = indexByLuceneWaitDurationInSeconds(); - - for (int loops = 0; loops < maxLoops; loops++) - { - Thread.sleep(1000); - - if (getLogAppender().getLogContent().contains("REINDEX " + entityPeClass.getName() + ": [" + entityId + "]")) - { - operationLog.info("Stopped waiting for " + entityPeClass.getName() + " with id: " + entityId + " to be indexed by Lucene"); - return; - } - } - - fail("Failed to determine whether enity: " + entityPeClass.getName() + " with id: " + entityId + " was indexed by Lucene"); + return result; } /** @@ -362,11 +341,6 @@ public abstract class SystemTestCase extends AssertJUnit return 20; } - protected int indexByLuceneWaitDurationInSeconds() - { - return 20; - } - protected void moveFileToIncoming(File exampleDataSet) throws IOException { FileUtils.moveDirectoryToDirectory(exampleDataSet, getIncomingDirectory(), false); @@ -376,11 +350,16 @@ public abstract class SystemTestCase extends AssertJUnit { if (logAppender == null) { - logAppender = new BufferedAppender("%d %p [%t] %c - %m%n", Level.INFO); + logAppender = new BufferedAppender("%d %p [%t] %c - %m%n", getLogLevel()); } return logAppender; } + protected Level getLogLevel() + { + return Level.INFO; + } + @SuppressWarnings("unchecked") protected static <T> T getBean(String beanName) { diff --git a/screening/sourceTest/java/ch/systemsx/cisd/openbis/screening/systemtests/FeatureVectorsDropboxTest.java b/screening/sourceTest/java/ch/systemsx/cisd/openbis/screening/systemtests/FeatureVectorsDropboxTest.java index b146dabec49b77615ccbbb26e62949649098ad51..e334ba601f91b702ca1cbf22f99089c774f1ca81 100644 --- a/screening/sourceTest/java/ch/systemsx/cisd/openbis/screening/systemtests/FeatureVectorsDropboxTest.java +++ b/screening/sourceTest/java/ch/systemsx/cisd/openbis/screening/systemtests/FeatureVectorsDropboxTest.java @@ -32,7 +32,6 @@ import org.testng.annotations.Test; import ch.systemsx.cisd.common.filesystem.FileUtilities; import ch.systemsx.cisd.common.servlet.SpringRequestContextProvider; -import ch.systemsx.cisd.openbis.datastoreserver.systemtests.FinishedPostRegistrationCondition; import ch.systemsx.cisd.openbis.generic.shared.util.TestInstanceHostUtils; import ch.systemsx.cisd.openbis.plugin.screening.client.api.v1.IScreeningOpenbisServiceFacade; import ch.systemsx.cisd.openbis.plugin.screening.client.api.v1.ScreeningOpenbisServiceFacade; @@ -67,7 +66,7 @@ public class FeatureVectorsDropboxTest extends AbstractScreeningSystemTestCase { File exampleDataSet = createTestDataContents(); moveFileToIncoming(exampleDataSet); - waitUntilDataSetImported(FinishedPostRegistrationCondition.INSTANCE); + waitUntilDataSetImported(FINISHED_POST_REGISTRATION_CONDITION); } @BeforeMethod diff --git a/screening/sourceTest/java/ch/systemsx/cisd/openbis/screening/systemtests/ImageBase64EncodingTest.java b/screening/sourceTest/java/ch/systemsx/cisd/openbis/screening/systemtests/ImageBase64EncodingTest.java index 75c45dbf62c33bb7ada62ceaa4302555f4fd443b..114cfe94328df73acd532badf08bb6d365e27cbf 100644 --- a/screening/sourceTest/java/ch/systemsx/cisd/openbis/screening/systemtests/ImageBase64EncodingTest.java +++ b/screening/sourceTest/java/ch/systemsx/cisd/openbis/screening/systemtests/ImageBase64EncodingTest.java @@ -43,7 +43,6 @@ import com.googlecode.jsonrpc4j.ProxyUtil; import ch.systemsx.cisd.common.collection.IModifiable; import ch.systemsx.cisd.common.filesystem.FileUtilities; import ch.systemsx.cisd.common.servlet.SpringRequestContextProvider; -import ch.systemsx.cisd.openbis.datastoreserver.systemtests.FinishedPostRegistrationCondition; import ch.systemsx.cisd.openbis.dss.screening.shared.api.v1.IDssServiceRpcScreening; import ch.systemsx.cisd.openbis.generic.shared.util.TestInstanceHostUtils; import ch.systemsx.cisd.openbis.plugin.screening.client.api.v1.IScreeningOpenbisServiceFacade; @@ -83,7 +82,7 @@ public class ImageBase64EncodingTest extends AbstractScreeningSystemTestCase { File exampleDataSet = createTestDataContents(); moveFileToIncoming(exampleDataSet); - waitUntilDataSetImported(FinishedPostRegistrationCondition.INSTANCE); + waitUntilDataSetImported(FINISHED_POST_REGISTRATION_CONDITION); } @BeforeMethod diff --git a/screening/sourceTest/java/ch/systemsx/cisd/openbis/screening/systemtests/TransformedImageRepresentationsTest.java b/screening/sourceTest/java/ch/systemsx/cisd/openbis/screening/systemtests/TransformedImageRepresentationsTest.java index aba9fe9b05e65f4ff349a8f0e843cfbf7d4e792f..3776495ac3ff6184c46b830bf6a567015363fd61 100644 --- a/screening/sourceTest/java/ch/systemsx/cisd/openbis/screening/systemtests/TransformedImageRepresentationsTest.java +++ b/screening/sourceTest/java/ch/systemsx/cisd/openbis/screening/systemtests/TransformedImageRepresentationsTest.java @@ -39,7 +39,6 @@ import com.googlecode.jsonrpc4j.ProxyUtil; import ch.systemsx.cisd.common.filesystem.FileUtilities; import ch.systemsx.cisd.common.servlet.SpringRequestContextProvider; -import ch.systemsx.cisd.openbis.datastoreserver.systemtests.FinishedPostRegistrationCondition; import ch.systemsx.cisd.openbis.dss.client.api.v1.IDataSetDss; import ch.systemsx.cisd.openbis.dss.screening.shared.api.v1.IDssServiceRpcScreening; import ch.systemsx.cisd.openbis.generic.shared.util.TestInstanceHostUtils; @@ -81,7 +80,7 @@ public class TransformedImageRepresentationsTest extends AbstractScreeningSystem { File exampleDataSet = createTestDataContents(); moveFileToIncoming(exampleDataSet); - waitUntilDataSetImported(FinishedPostRegistrationCondition.INSTANCE); + waitUntilDataSetImported(FINISHED_POST_REGISTRATION_CONDITION); } @BeforeMethod