From 31e293a5cb1ee9dd956491c8bec6d2a3f7d5a4ef Mon Sep 17 00:00:00 2001 From: jakubs <jakubs> Date: Tue, 12 Jun 2012 13:50:19 +0000 Subject: [PATCH] BIS-21 SP-108 happy testcase for the jython processing retry SVN: 25659 --- .../v2/JythonTopLevelDataSetHandlerV2.java | 2 +- .../JythonDropboxRecoveryTest.java | 62 +++++++++++++++++++ .../etlserver/registrator/v2-retry-process.py | 18 ++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/v2-retry-process.py diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/JythonTopLevelDataSetHandlerV2.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/JythonTopLevelDataSetHandlerV2.java index a89c7482116..0b1563110ec 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/JythonTopLevelDataSetHandlerV2.java +++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/registrator/api/v2/JythonTopLevelDataSetHandlerV2.java @@ -151,7 +151,7 @@ public class JythonTopLevelDataSetHandlerV2<T extends DataSetInformation> extend } } - private static final int MAX_RETRY_COUNT = 3; + private static final int MAX_RETRY_COUNT = 50; private static final int RETRY_SLEEP = 100; diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/JythonDropboxRecoveryTest.java b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/JythonDropboxRecoveryTest.java index 4c08a05e468..66440d00bd2 100644 --- a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/JythonDropboxRecoveryTest.java +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/JythonDropboxRecoveryTest.java @@ -904,6 +904,68 @@ public class JythonDropboxRecoveryTest extends AbstractJythonDataSetHandlerTest } } + // INFO: testcase that verifies the repeating of the jython process works. + @Test + public void testRetryProcessing() + { + RecoveryTestCase testCase = new RecoveryTestCase("No name"); + setUpHomeDataBaseExpectations(); + + createData(); + + Properties properties = + createThreadPropertiesRelativeToScriptsFolder("v2-retry-process.py", + testCase.overrideProperties); + + createHandler(properties, true, false); + + final RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails> atomicatOperationDetails = + new RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>(); + + // create expectations + context.checking(new RetryProcessExpectations(atomicatOperationDetails, 20)); + + handler.handle(markerFile); + + JythonHookTestTool.assertMessagesInWorkingDirectory(workingDirectory, + "pre_metadata_registration", "post_metadata_registration", "post_storage"); + + assertStorageProcess(atomicatOperationDetails.getRecordedObjects().get(0), DATA_SET_CODE, + "sub_data_set_1", 0); + + assertNoOriginalMarkerFileExists(); + assertNoRecoveryMarkerFile(); + + assertDirEmpty(precommitDirectory); + } + + class RetryProcessExpectations extends AbstractExpectations + { + public RetryProcessExpectations( + final RecordingMatcher<AtomicEntityOperationDetails> atomicatOperationDetails, int retryCount) + { + super(atomicatOperationDetails); + prepareExpectations(retryCount); + } + + private void prepareExpectations(int retryCount) + { + // create dataset + for (int i = 0; i < retryCount; i++) + { + one(openBisService).createDataSetCode(); + will(returnValue(DATA_SET_CODE + i)); // this dataset will never get done anything + // about + } + + initialExpectations(); + + registerDataSetsAndSucceed(); + + setStorageConfirmed(false); + } + } + // INFO: the test that checks all possible recovery points one by one in single registration @DataProvider(name = "multipleCheckpointsDataProvider") public Object[][] multipleCheckpointsData() diff --git a/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/v2-retry-process.py b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/v2-retry-process.py new file mode 100644 index 00000000000..d2db7e16112 --- /dev/null +++ b/datastore_server/sourceTest/java/ch/systemsx/cisd/etlserver/registrator/v2-retry-process.py @@ -0,0 +1,18 @@ +execfile("sourceTest/java/ch/systemsx/cisd/etlserver/registrator/all-hooks.py") + +def should_retry_processing(map, error): + lastResult = transaction.getPersistentMap().get("RETRY_COUNT") + if (lastResult == None): + lastResult = 0 + transaction.getPersistentMap().put("RETRY_COUNT", lastResult + 1) + print "RETRY TRANSACTION PUTS THE SCORE %d" % (lastResult + 1) + +def process(): + key = transaction.getPersistentMap().get("RETRY_COUNT"); + dataSet = transaction.createNewDataSet() + transaction.moveFile(incoming.getPath() + '/sub_data_set_1', dataSet) + dataSet.setDataSetType('O1') + dataSet.setExperiment(transaction.getExperiment('/SPACE/PROJECT/EXP')) + if (key < 20): + # do here the real throwing of the exception + raise Exception("error in the script at the retry %d" % key) \ No newline at end of file -- GitLab