How to use doAll method of org.jmock.AbstractExpectations class

Best Jmock-library code snippet using org.jmock.AbstractExpectations.doAll

Source:JythonDropboxRecoveryTest.java Github

copy

Full Screen

...293 private void returnSuccessAndChangeEnvironment()294 {295 if (testCase.shouldMakeFilesystemUnavailable)296 {297 will(doAll(makeFileSystemUnavailableAction(),298 returnValue(EntityOperationsState.OPERATION_SUCCEEDED)));299 } else300 {301 will(returnValue(EntityOperationsState.OPERATION_SUCCEEDED));302 }303 }304 }305 private void assertNoRecoveryTriggeredConstraints()306 {307 assertDataSetNotStoredProcess(DATA_SET_CODE);308 assertNoOriginalMarkerFileExists();309 assertNoRecoveryMarkerFile();310 JythonHookTestTool.assertMessagesInWorkingDirectory(workingDirectory,311 "pre_metadata_registration", "rollback_pre_registration");312 assertDirEmptyOrContainsEmptyDirs(precommitDirectory);313 assertNoRecoveryMarkerFile();314 }315 private void assertPostRecoveryConstraints(316 final RecoveryTestCase testCase,317 final RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails> atomicatOperationDetails)318 {319 JythonHookTestTool jythonHookTestTool =320 JythonHookTestTool.createFromWorkingDirectory(workingDirectory);321 if (testCase.registrationCheckResult == RegistrationCheckResult.REGISTRATION_SUCCEEDED)322 {323 jythonHookTestTool.assertLogged("post_metadata_registration");324 }325 int expectedRetryCount =326 testCase.recoveryRertyCount + (testCase.shouldIncrementTryCount ? 1 : 0);327 switch (testCase.recoveryResult)328 {329 case RECOVERY_SUCCEEDED:330 // item in store331 assertStorageProcess(atomicatOperationDetails.recordedObject(), DATA_SET_CODE,332 "sub_data_set_1", 0);333 assertDirEmpty(precommitDirectory);334 assertNoOriginalMarkerFileExists();335 assertNoRecoveryMarkerFile();336 // the hooks after successful registration337 jythonHookTestTool.assertLogged("post_storage");338 break;339 case RECOVERY_ROLLED_BACK:340 assertDataSetNotStoredProcess(DATA_SET_CODE);341 assertDirEmptyOrContainsEmptyDirs(precommitDirectory);342 assertNoOriginalMarkerFileExists();343 assertNoRecoveryMarkerFile();344 jythonHookTestTool.assertLogged("rollback_pre_registration");345 break;346 case RETRY_AT_CANT_CHECK_REGISTRATION_STATUS:347 case RETRY_AT_STORAGE_FAILURE:348 assertDataSetNotStoredProcess(DATA_SET_CODE);349 if (false == testCase.shouldMakeFilesystemUnavailable)350 {351 assertDirNotEmpty(precommitDirectory, "Precommit directory should not be empty");352 }353 assertRecoveryFile(expectedRetryCount, RecoveryInfoDateConstraint.AFTER_ORIGINAL,354 testCase.recoveryLastTry);355 assertOriginalMarkerFileExists();356 break;357 case RETRY_AT_STORAGE_CONFIRMED_FAILURE:358 assertStorageProcess(atomicatOperationDetails.recordedObject(), DATA_SET_CODE,359 "sub_data_set_1", 0);360 assertRecoveryFile(expectedRetryCount, RecoveryInfoDateConstraint.AFTER_ORIGINAL,361 testCase.recoveryLastTry);362 assertOriginalMarkerFileExists();363 break;364 case GIVE_UP:365 assertDataSetNotStoredProcess(DATA_SET_CODE);366 assertNoOriginalMarkerFileExists();367 assertNoRecoveryMarkerFile();368 assertDirNotEmpty(precommitDirectory, "precommit should not be empty");369 break;370 }371 jythonHookTestTool.assertNoMoreMessages();372 }373 /**374 * Use this method to update the retry count in the recovery info file.375 */376 private void setTheRecoveryInfo(int count, Date lastTryDate)377 {378 File file = getCreatedRecoveryMarkerFile();379 DataSetStorageRecoveryInfo recoveryInfo =380 handler.getGlobalState().getStorageRecoveryManager()381 .getRecoveryFileFromMarker(file);382 // as the interface allow only increment, and not setting - we implement addition using383 // increment384 while (recoveryInfo.getTryCount() < count)385 {386 recoveryInfo.increaseTryCount();387 }388 recoveryInfo.setLastTry(lastTryDate);389 recoveryInfo.writeToFile(file);390 }391 private void assertDirNotEmpty(File file, String message)392 {393 assertFalse(message, 0 == file.list().length);394 }395 private void assertDirEmpty(File file)396 {397 String contents = file.getAbsolutePath();398 assertEquals(contents, "[]", Arrays.asList(file.list()).toString());399 }400 private void assertDirEmptyOrContainsEmptyDirs(File file)401 {402 for (String s : file.list())403 {404 File subFile = new File(file, s);405 if (subFile.isFile())406 {407 fail("Directory " + file + " is not empty! It contains a file" + s);408 } else if (subFile.isDirectory())409 {410 assertDirEmptyOrContainsEmptyDirs(subFile);411 }412 }413 }414 private void assertOriginalMarkerFileExists()415 {416 assertTrue(417 "The original registration marker file should not be deleted when entering recovery mode",418 markerFile.exists());419 }420 private void assertNoOriginalMarkerFileExists()421 {422 assertFalse("The original registration marker " + markerFile + " file should be deleted",423 markerFile.exists());424 }425 private enum RecoveryInfoDateConstraint426 {427 /**428 * the last try date is the one of the original recovery file429 */430 ORIGINAL,431 /**432 * the last try date is later then the original recovery file433 */434 AFTER_ORIGINAL435 }436 /**437 * @param tryCount - the excepted stored number of tries in a recovery file438 */439 private File assertRecoveryFile(int tryCount, RecoveryInfoDateConstraint dateConstraint,440 Date originalLastTryDate)441 {442 File file = getCreatedRecoveryMarkerFile();443 assertTrue("The recovery marker file does not exist! " + file, file.exists());444 DataSetStorageRecoveryInfo recoveryInfo =445 handler.getGlobalState().getStorageRecoveryManager()446 .getRecoveryFileFromMarker(file);447 File recoveryFile = recoveryInfo.getRecoveryStateFile();448 assertTrue("The recovery serialized file does not exist! " + recoveryFile,449 recoveryFile.exists());450 assertEquals("The try count in a recovery file is incorrect", tryCount,451 recoveryInfo.getTryCount());452 switch (dateConstraint)453 {454 case ORIGINAL:455 assertEquals(originalLastTryDate, recoveryInfo.getLastTry());456 break;457 case AFTER_ORIGINAL:458 assertTrue(459 "" + originalLastTryDate + " should be before " + recoveryInfo.getLastTry(),460 originalLastTryDate.before(recoveryInfo.getLastTry()));461 break;462 }463 return file;464 }465 private void assertNoRecoveryMarkerFile()466 {467 File file = getCreatedRecoveryMarkerFile();468 assertTrue("The recovery marker file should not exist! " + file, false == file.exists());469 }470 private File getCreatedRecoveryMarkerFile()471 {472 File originalIncoming =473 FileUtilities.removePrefixFromFileName(markerFile, FileConstants.IS_FINISHED_PREFIX);474 File recoveryMarkerFile =475 handler.getGlobalState().getStorageRecoveryManager()476 .getProcessingMarkerFile(originalIncoming);477 return recoveryMarkerFile;478 }479 // INFO: test with recovery when storage failed480 @Test481 public void testRecoveryFailureAtStorage()482 {483 RecoveryTestCase testCase = new RecoveryTestCase("No name");484 setUpHomeDataBaseExpectations();485 createData();486 Properties properties =487 createThreadPropertiesRelativeToScriptsFolder(testCase.dropboxScriptPath, null,488 testCase.overrideProperties);489 createHandler(properties, true, false);490 final RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails> atomicatOperationDetails =491 new RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>();492 // create expectations493 context.checking(new StorageErrorExpectations(atomicatOperationDetails));494 handleAndMakeRecoverableImmediately(testCase);495 JythonHookTestTool.assertMessagesInWorkingDirectory(workingDirectory,496 "pre_metadata_registration", "post_metadata_registration");497 assertRecoveryFile(testCase.recoveryRertyCount, RecoveryInfoDateConstraint.ORIGINAL,498 testCase.recoveryLastTry);499 assertOriginalMarkerFileExists();500 makeFileSystemAvailable(workingDirectory);501 // this recovery should succeed502 handler.handle(markerFile);503 assertStorageProcess(atomicatOperationDetails.recordedObject(), DATA_SET_CODE,504 "sub_data_set_1", 0);505 assertNoOriginalMarkerFileExists();506 assertNoRecoveryMarkerFile();507 assertDirEmpty(precommitDirectory);508 //509 // // item in store510 //511 //512 JythonHookTestTool.assertMessagesInWorkingDirectory(workingDirectory, "post_storage");513 }514 class StorageErrorExpectations extends AbstractExpectations515 {516 public StorageErrorExpectations(517 final RecordingMatcher<AtomicEntityOperationDetails> atomicatOperationDetails)518 {519 super(atomicatOperationDetails);520 prepareExpecatations();521 }522 private void prepareExpecatations()523 {524 initialExpectations();525 registerDataSetsAndMakeFileSystemUnavailable();526 // the recovery should happen here527 setStorageConfirmed(false);528 }529 }530 // INFO: test with recovery from error in storage confirmed531 @Test532 public void testRecoveryFailureAtStorageConfirmed()533 {534 RecoveryTestCase testCase = new RecoveryTestCase("No name");535 setUpHomeDataBaseExpectations();536 createData();537 Properties properties =538 createThreadPropertiesRelativeToScriptsFolder(testCase.dropboxScriptPath, null,539 testCase.overrideProperties);540 createHandler(properties, true, false);541 final RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails> atomicatOperationDetails =542 new RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>();543 // create expectations544 context.checking(new StorageConfirmedErrorExpectations(atomicatOperationDetails));545 handler.handle(markerFile);546 JythonHookTestTool.assertMessagesInWorkingDirectory(workingDirectory,547 "pre_metadata_registration", "post_metadata_registration");548 //549 // // item already in store550 //551 assertStorageProcess(atomicatOperationDetails.recordedObject(), DATA_SET_CODE,552 "sub_data_set_1", 0);553 setTheRecoveryInfo(testCase.recoveryRertyCount, testCase.recoveryLastTry);554 assertRecoveryFile(testCase.recoveryRertyCount, RecoveryInfoDateConstraint.ORIGINAL,555 testCase.recoveryLastTry);556 assertOriginalMarkerFileExists();557 // this recovery should succeed558 handler.handle(markerFile);559 assertNoOriginalMarkerFileExists();560 assertNoRecoveryMarkerFile();561 assertDirEmpty(precommitDirectory);562 JythonHookTestTool.assertMessagesInWorkingDirectory(workingDirectory, "post_storage");563 }564 class StorageConfirmedErrorExpectations extends AbstractExpectations565 {566 public StorageConfirmedErrorExpectations(567 final RecordingMatcher<AtomicEntityOperationDetails> atomicatOperationDetails)568 {569 super(atomicatOperationDetails);570 prepareExpecatations();571 }572 private void prepareExpecatations()573 {574 initialExpectations();575 registerDataSetsAndSucceed();576 setStorageConfirmed(true);577 // the recovery should happen here578 setStorageConfirmed(false);579 }580 }581 // INFO: the test that checks the retry mechanism582 @DataProvider(name = "retryDP")583 public Object[][] retryCounters()584 {585 return new Object[][]586 {587 { 1 },588 { 5 },589 { 15 } };590 }591 /**592 * This test tests that when the perform entity operation fails with the recoverable error, it will repeat the registration N times, and then593 * fail.594 */595 @Test(dataProvider = "retryDP")596 public void testRetryRegistrationNTimesAndFail(Integer retryCount)597 {598 RecoveryTestCase testCase = new RecoveryTestCase("No name");599 setUpHomeDataBaseExpectations();600 createData();601 Properties properties =602 createThreadPropertiesRelativeToScriptsFolder(testCase.dropboxScriptPath, null,603 testCase.overrideProperties);604 properties.setProperty(ThreadParameters.DATASET_REGISTRATION_MAX_RETRY_COUNT,605 retryCount.toString());606 properties.setProperty(ThreadParameters.DATASET_REGISTRATION_RETRY_PAUSE_IN_SEC, "0"); // 1s607 createHandler(properties, true, false);608 final RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails> atomicatOperationDetails =609 new RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>();610 // create expectations611 context.checking(new RetryRegistrationFail(atomicatOperationDetails, retryCount));612 handler.handle(markerFile);613 setTheRecoveryInfo(testCase.recoveryRertyCount, testCase.recoveryLastTry);614 JythonHookTestTool.assertMessagesInWorkingDirectory(workingDirectory,615 "pre_metadata_registration");616 assertOriginalMarkerFileExists();617 handler.handle(markerFile);618 // the rollback has happened619 JythonHookTestTool.assertMessagesInWorkingDirectory(workingDirectory,620 "rollback_pre_registration");621 }622 class RetryRegistrationFail extends AbstractExpectations623 {624 private final int retryCount;625 public RetryRegistrationFail(626 final RecordingMatcher<AtomicEntityOperationDetails> atomicatOperationDetails,627 int retryCount)628 {629 super(atomicatOperationDetails);630 this.retryCount = retryCount;631 prepareExpecatations();632 }633 private void prepareExpecatations()634 {635 initialExpectations();636 registerDataSetsAndThrow(true, true, EntityOperationsState.NO_OPERATION);637 for (int i = 0; i < retryCount; i++)638 {639 registerDataSetsAndThrow(true, false, EntityOperationsState.NO_OPERATION);640 }641 // the recovery - will find that nothing has happened642 checkEntityOperationsSucceeded(EntityOperationsState.NO_OPERATION);643 }644 }645 enum RetrySuccessMethod646 {647 /**648 * perform entity operations executed successfully649 */650 OPERATIONS_SUCCEDED,651 /**652 * the later check if the operations succeeded has succeeded653 */654 CHECK_SUCCEEDED655 }656 @DataProvider(name = "retrySuccessDP")657 public Object[][] retrySuccessDP()658 {659 return new Object[][]660 {661 { 1, RetrySuccessMethod.OPERATIONS_SUCCEDED },662 { 1, RetrySuccessMethod.CHECK_SUCCEEDED },663 { 5, RetrySuccessMethod.OPERATIONS_SUCCEDED },664 { 15, RetrySuccessMethod.CHECK_SUCCEEDED } };665 }666 @Test(dataProvider = "retrySuccessDP")667 public void testRetryRegistrationSucceeded(Integer retryCount, RetrySuccessMethod rsm)668 {669 RecoveryTestCase testCase = new RecoveryTestCase("No name");670 setUpHomeDataBaseExpectations();671 createData();672 Properties properties =673 createThreadPropertiesRelativeToScriptsFolder(testCase.dropboxScriptPath, null,674 testCase.overrideProperties);675 properties.setProperty(ThreadParameters.DATASET_REGISTRATION_MAX_RETRY_COUNT,676 retryCount.toString());677 properties.setProperty(ThreadParameters.DATASET_REGISTRATION_RETRY_PAUSE_IN_SEC, "0"); // 1s678 createHandler(properties, true, false);679 final RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails> atomicatOperationDetails =680 new RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>();681 // create expectations682 context.checking(new RetryRegistrationSucceeded(atomicatOperationDetails, retryCount, rsm));683 handler.handle(markerFile);684 // the rollback has happened685 JythonHookTestTool.assertMessagesInWorkingDirectory(workingDirectory,686 "pre_metadata_registration", "post_metadata_registration", "post_storage");687 assertStorageProcess(atomicatOperationDetails.getRecordedObjects().get(0), DATA_SET_CODE,688 "sub_data_set_1", 0);689 assertNoOriginalMarkerFileExists();690 assertNoRecoveryMarkerFile();691 assertDirEmpty(precommitDirectory);692 }693 class RetryRegistrationSucceeded extends AbstractExpectations694 {695 private final int retryCount;696 private final RetrySuccessMethod retrySuccessMethod;697 public RetryRegistrationSucceeded(698 final RecordingMatcher<AtomicEntityOperationDetails> atomicatOperationDetails,699 int retryCount, RetrySuccessMethod retrySuccessMethod)700 {701 super(atomicatOperationDetails);702 this.retryCount = retryCount;703 this.retrySuccessMethod = retrySuccessMethod;704 prepareExpecatations();705 }706 private void prepareExpecatations()707 {708 initialExpectations();709 registerDataSetsAndThrow(true, true, EntityOperationsState.NO_OPERATION);710 for (int i = 0; i < retryCount - 1; i++)711 {712 registerDataSetsAndThrow(true, false, EntityOperationsState.NO_OPERATION);713 }714 if (retrySuccessMethod == RetrySuccessMethod.OPERATIONS_SUCCEDED)715 {716 performEntityOperations();717 } else if (retrySuccessMethod == RetrySuccessMethod.CHECK_SUCCEEDED)718 {719 registerDataSetsAndThrow(true, false, EntityOperationsState.IN_PROGRESS);720 for (int i = 0; i < 40; i++)721 {722 checkEntityOperationsSucceeded(EntityOperationsState.IN_PROGRESS);723 }724 checkEntityOperationsSucceeded(EntityOperationsState.OPERATION_SUCCEEDED);725 }726 setStorageConfirmed(false);727 }728 }729 // INFO: testcase that verifies the repeating of the jython process works.730 @Test731 public void testRetryProcessing()732 {733 RecoveryTestCase testCase = new RecoveryTestCase("No name");734 setUpHomeDataBaseExpectations();735 createData();736 Properties properties =737 createThreadPropertiesRelativeToScriptsFolder("v2-retry-process.py", null,738 testCase.overrideProperties);739 properties.setProperty(ThreadParameters.PROCESS_MAX_RETRY_COUNT, "100"); // we dont want it740 // to fail at all741 // in this testcase742 properties.setProperty(ThreadParameters.PROCESS_RETRY_PAUSE_IN_SEC, "0"); // continue743 // immediately to744 // not stop the745 // tests746 createHandler(properties, true, false);747 final RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails> atomicatOperationDetails =748 new RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>();749 // create expectations750 context.checking(new RetryProcessExpectations(atomicatOperationDetails, 20));751 handler.handle(markerFile);752 JythonHookTestTool.assertMessagesInWorkingDirectory(workingDirectory,753 "pre_metadata_registration", "post_metadata_registration", "post_storage");754 assertStorageProcess(atomicatOperationDetails.getRecordedObjects().get(0), DATA_SET_CODE,755 "sub_data_set_1", 0);756 assertNoOriginalMarkerFileExists();757 assertNoRecoveryMarkerFile();758 assertDirEmpty(precommitDirectory);759 }760 class RetryProcessExpectations extends AbstractExpectations761 {762 public RetryProcessExpectations(763 final RecordingMatcher<AtomicEntityOperationDetails> atomicatOperationDetails,764 int retryCount)765 {766 super(atomicatOperationDetails);767 prepareExpectations(retryCount);768 }769 private void prepareExpectations(int retryCount)770 {771 // create dataset772 for (int i = 0; i < retryCount; i++)773 {774 createPermId(DATA_SET_CODE + i);775 }776 initialExpectations();777 registerDataSetsAndSucceed();778 setStorageConfirmed(false);779 }780 }781 // INFO: testcase that verifies the repeating of the jython process works.782 @Test783 public void testRetryProcessingFailed()784 {785 RecoveryTestCase testCase = new RecoveryTestCase("No name");786 setUpHomeDataBaseExpectations();787 createData();788 Properties properties =789 createThreadPropertiesRelativeToScriptsFolder("v2-retry-process.py", null,790 testCase.overrideProperties);791 properties.setProperty(ThreadParameters.PROCESS_MAX_RETRY_COUNT, "10"); // we dont want it792 // to fail at all in793 // this testcase794 properties.setProperty(ThreadParameters.PROCESS_RETRY_PAUSE_IN_SEC, "0"); // continue795 // immediately to796 // not stop the797 // tests798 createHandler(properties, true, false);799 final RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails> atomicatOperationDetails =800 new RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>();801 // create expectations802 context.checking(new RetryProcessFailedExpectations(atomicatOperationDetails, 10));803 handler.handle(markerFile);804 assertDataSetNotStoredProcess(DATA_SET_CODE);805 // no recovery is triggered - files are moved to the faulty paths/marker file is deleted806 assertNoOriginalMarkerFileExists();807 assertNoRecoveryMarkerFile();808 assertDirEmpty(precommitDirectory);809 }810 class RetryProcessFailedExpectations extends AbstractExpectations811 {812 public RetryProcessFailedExpectations(813 final RecordingMatcher<AtomicEntityOperationDetails> atomicatOperationDetails,814 int retryCount)815 {816 super(atomicatOperationDetails);817 prepareExpectations(retryCount);818 }819 private void prepareExpectations(int retryCount)820 {821 ignoring(openBisService).heartbeat();822 // get experiment823 atLeast(1).of(openBisService).tryGetExperiment(824 new ExperimentIdentifierFactory(experiment.getIdentifier()).createIdentifier());825 will(returnValue(experiment));826 // create dataset827 for (int i = 0; i <= retryCount; i++)828 {829 createPermId(DATA_SET_CODE + i);830 }831 }832 }833 // INFO: the test that checks all possible recovery points one by one in single registration834 @DataProvider(name = "multipleCheckpointsDataProvider")835 public Object[][] multipleCheckpointsData()836 {837 return new Object[][]838 {839 { "v2-simple-testcase.py", false },840 { "v2-container-testcase.py", true } };841 }842 /**843 * This tests the registration with adventure, where the failure and recovery happens at every possible step.844 */845 @Test(dataProvider = "multipleCheckpointsDataProvider")846 public void testRecoveryAtMultipleCheckpoints(String script, boolean includeContainer)847 {848 RecoveryTestCase testCase = new RecoveryTestCase("No name");849 setUpHomeDataBaseExpectations();850 createData();851 Properties properties =852 createThreadPropertiesRelativeToScriptsFolder(script, null,853 testCase.overrideProperties);854 createHandler(properties, true, false);855 final RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails> atomicatOperationDetails =856 new RecordingMatcher<ch.systemsx.cisd.openbis.generic.shared.dto.AtomicEntityOperationDetails>();857 // create expectations858 context.checking(new MultipleErrorsExpectations(atomicatOperationDetails, includeContainer));859 /*860 * First run - register datasets, and handle exception from AS861 */862 handleAndMakeRecoverableImmediately(testCase);863 // now we have registered, but error was thrown from registration864 JythonHookTestTool.assertMessagesInWorkingDirectory(workingDirectory,865 "pre_metadata_registration");866 /*867 * Second run - check that the datasets has been registered, and run the post_registration hook The file system is made unavailable, so the868 * storage will fail. Restore the filesystem after this run.869 */870 handleAndMakeRecoverableImmediately(testCase);871 // now we know we have registered, post registration hook executed, but storage failed.872 JythonHookTestTool.assertMessagesInWorkingDirectory(workingDirectory,873 "post_metadata_registration");874 // so make filesystem avaiable this time875 makeFileSystemAvailable(workingDirectory);876 /*877 * Third run - Start after the post registration hook, and run the storage - this will succeed now. Throw exception from storage confirmation.878 */879 handleAndMakeRecoverableImmediately(testCase);880 JythonHookTestTool.assertMessagesInWorkingDirectory(workingDirectory); // assert no messages881 /*882 * Last run. now only do the storage confirm part. After this is done, the registration should be complete.883 */884 handler.handle(markerFile);885 // setTheRecoveryInfo(testCase.recoveryRertyCount, testCase.recoveryLastTry);886 // now the storage confirmation has succeeded887 assertStorageProcess(atomicatOperationDetails.recordedObject(), DATA_SET_CODE,888 "sub_data_set_1", 0, includeContainer ? 2 : 1);889 assertNoOriginalMarkerFileExists();890 assertNoRecoveryMarkerFile();891 assertDirEmpty(precommitDirectory);892 JythonHookTestTool.assertMessagesInWorkingDirectory(workingDirectory, "post_storage");893 }894 private void handleAndMakeRecoverableImmediately(RecoveryTestCase testCase)895 {896 handler.handle(markerFile);897 setTheRecoveryInfo(testCase.recoveryRertyCount, testCase.recoveryLastTry);898 }899 class MultipleErrorsExpectations extends AbstractExpectations900 {901 public MultipleErrorsExpectations(902 final RecordingMatcher<AtomicEntityOperationDetails> atomicatOperationDetails,903 boolean withContainer)904 {905 super(atomicatOperationDetails);906 prepareExpectations(withContainer);907 }908 private void prepareExpectations(boolean withContainer)909 {910 initialExpectations();911 if (withContainer)912 {913 initialContainerExpectations();914 }915 // first try - fail at registration and realize that the operation has not succeeded916 registerDataSetsAndThrow(true);917 // second handle - fail at storage918 one(openBisService).didEntityOperationsSucceed(with(any(TechId.class)));919 will(doAll(makeFileSystemUnavailableAction(),920 returnValue(EntityOperationsState.OPERATION_SUCCEEDED)));921 if (withContainer)922 {923 // third try - fail at storage confirmation924 setStorageConfirmed(true, CONTAINER_DATA_SET_CODE);925 // fourth try - success926 setStorageConfirmed(false, CONTAINER_DATA_SET_CODE);927 } else928 {929 // third try - fail at storage confirmation930 setStorageConfirmed(true);931 // fourth try - success932 setStorageConfirmed(false);933 }934 }935 }936 abstract class AbstractExpectations extends Expectations937 {938 final Experiment experiment;939 final RecordingMatcher<AtomicEntityOperationDetails> atomicatOperationDetails;940 public AbstractExpectations(941 final RecordingMatcher<AtomicEntityOperationDetails> atomicatOperationDetails)942 {943 ExperimentBuilder builder = new ExperimentBuilder().identifier(EXPERIMENT_IDENTIFIER);944 this.experiment = builder.getExperiment();945 this.atomicatOperationDetails = atomicatOperationDetails;946 }947 protected void initialExpectations()948 {949 ignoring(openBisService).heartbeat();950 // create dataset951 createPermId(DATA_SET_CODE);952 // get experiment953 atLeast(1).of(openBisService).tryGetExperiment(954 new ExperimentIdentifierFactory(experiment.getIdentifier()).createIdentifier());955 will(returnValue(experiment));956 // validate dataset957 one(dataSetValidator).assertValidDataSet(DATA_SET_TYPE,958 new File(new File(stagingDirectory, DATA_SET_CODE), "sub_data_set_1"));959 }960 protected void initialContainerExpectations()961 {962 // create dataset963 createPermId(CONTAINER_DATA_SET_CODE);964 // validate dataset965 one(dataSetValidator).assertValidDataSet(CONTAINER_DATA_SET_TYPE, null);966 }967 protected CustomAction makeFileSystemUnavailableAction()968 {969 return new CustomAction("makeSystemUnavailable")970 {971 @Override972 public Object invoke(Invocation invocation) throws Throwable973 {974 makeFileSystemUnavailable(workingDirectory);975 return null;976 }977 };978 }979 protected CustomAction makeFileSystemAvailableAction()980 {981 return new CustomAction("makeSystemAvailable")982 {983 @Override984 public Object invoke(Invocation invocation) throws Throwable985 {986 makeFileSystemAvailable(workingDirectory);987 return null;988 }989 };990 }991 /**992 * This method should make sure that the registration will fail, and it will go into the recovery mode. It means that it also has to assure993 * that the subsequent retries introduce in SP-107 are failing.994 */995 protected void registerDataSetsAndThrow(boolean canRecoverFromError)996 {997 registerDataSetsAndThrow(canRecoverFromError, true, EntityOperationsState.NO_OPERATION);998 }999 protected void registerDataSetsAndThrow(boolean canRecoverFromError, boolean drawId,1000 EntityOperationsState entityOperationsState)1001 {1002 if (drawId)1003 {1004 drawUniqueId();1005 }1006 one(openBisService).performEntityOperations(with(atomicatOperationDetails));1007 Throwable e;1008 if (canRecoverFromError)1009 {1010 e =1011 new Throwable(1012 "Potentially recoverable failure in registration");1013 } else1014 {1015 e = new UserFailureException("Unrecoverable failure in registration");1016 }1017 will(throwException(e));1018 if (canRecoverFromError)1019 {1020 // the check immediately after the exception fails as well1021 checkEntityOperationsSucceeded(entityOperationsState);1022 }1023 }1024 /**1025 * call openBisService.didEntityOperationsSucceeded1026 */1027 protected void checkEntityOperationsSucceeded(EntityOperationsState entityOperationsState)1028 {1029 one(openBisService).didEntityOperationsSucceed(with(any(TechId.class)));1030 will(returnValue(entityOperationsState));1031 }1032 /**1033 * Draw unique ID and perform entity operations1034 */1035 protected void registerDataSetsAndSucceed()1036 {1037 drawUniqueId();1038 performEntityOperations();1039 }1040 public void performEntityOperations()1041 {1042 one(openBisService).performEntityOperations(with(atomicatOperationDetails));1043 will(returnValue(new AtomicEntityOperationResult()));1044 }1045 protected void drawUniqueId()1046 {1047 one(openBisService).drawANewUniqueID();1048 will(returnValue(new Long(1)));1049 }1050 protected void registerDataSetsAndMakeFileSystemUnavailable()1051 {1052 drawUniqueId();1053 one(openBisService).performEntityOperations(with(atomicatOperationDetails));1054 will(doAll(makeFileSystemUnavailableAction(),1055 returnValue(new AtomicEntityOperationResult())));1056 }1057 /**1058 * @param shouldFail - if true the call to as should throw an exception1059 */1060 protected void setStorageConfirmed(boolean shouldFail, String... additionalCodes)1061 {1062 List<String> codes = new LinkedList<String>();1063 codes.add(DATA_SET_CODE);1064 for (String code : additionalCodes)1065 {1066 codes.add(code);1067 }1068 setStorageConfirmed(codes, shouldFail);...

Full Screen

Full Screen

Source:AbstractExpectations.java Github

copy

Full Screen

...294 public static <T> Action returnEnumeration(T ... items) {295 return new ReturnEnumerationAction(items);296 }297 298 public static Action doAll(Action...actions) {299 return new DoAllAction(actions);300 }301 302 public static Action onConsecutiveCalls(Action...actions) {303 return new ActionSequence(actions);304 }305 306 /* Naming and ordering307 */308 309 public void when(StatePredicate predicate) {310 currentBuilder().addOrderingConstraint(new InStateOrderingConstraint(predicate));311 }312 ...

Full Screen

Full Screen

doAll

Using AI Code Generation

copy

Full Screen

1import org.jmock.Mockery;2import org.jmock.Expectations;3import org.jmock.AbstractExpectations;4public class 1 {5 public static void main(String[] args) {6 Mockery context = new Mockery();7 final Interface1 mock = context.mock(Interface1.class);8 context.checking(new Expectations() {{9 oneOf (mock).doSomething();will(AbstractExpectations.doAll(10 AbstractExpectations.returnValue("Hello"),11 AbstractExpectations.returnValue("World")12 ));13 }});14 System.out.println(mock.doSomething());15 System.out.println(mock.doSomething());16 }17}18import org.jmock.Mockery;19import org.jmock.Expectations;20import org.jmock.AbstractExpectations;21public class 2 {22 public static void main(String[] args) {23 Mockery context = new Mockery();24 final Interface1 mock = context.mock(Interface1.class);25 context.checking(new Expectations() {{26 oneOf (mock).doSomething();will(AbstractExpectations.doAll(27 AbstractExpectations.returnValue("Hello"),28 AbstractExpectations.returnValue("World")29 ));30 }});31 System.out.println(mock.doSomething());32 System.out.println(mock.doSomething());33 }34}35import org.jmock.Mockery;36import org.jmock.Expectations;37import org.jmock.AbstractExpectations;38public class 3 {39 public static void main(String[] args) {40 Mockery context = new Mockery();41 final Interface1 mock = context.mock(Interface1.class);42 context.checking(new Expectations() {{43 oneOf (mock).doSomething();will(AbstractExpectations.doAll(44 AbstractExpectations.returnValue("Hello"),45 AbstractExpectations.returnValue("World")46 ));47 }});48 System.out.println(mock.doSomething());49 System.out.println(mock.doSomething());50 }51}

Full Screen

Full Screen

doAll

Using AI Code Generation

copy

Full Screen

1import org.jmock.Mockery;2import org.jmock.Expectations;3import org.jmock.Mockery;4import org.jmock.Expectations;5import org.jmock.api.ExpectationError;6import org.jmock.lib.legacy.ClassImposteriser;7import org.jmo

Full Screen

Full Screen

doAll

Using AI Code Generation

copy

Full Screen

1package com.ack.jmock;2import org.jmock.Mock;3import org.jmock.MockObjectTestCase;4import org.jmock.core.Invocation;5import org.jmock.core.Stub;6import org.jmock.core.constraint.IsEqual;7import org.jmock.core.constraint.IsInstanceOf;8import org.jmock.core.constraint.IsSame;9import org.jmock.core.constraint.IsTypeCompatibleWith;10import org.jmock.core.constraint.IsAnything;11import org.jmock.core.constraint.IsAnything;12import org.jmock.core.constraint.IsEqual;13import org.jmock.core.constraint.IsInstanceOf;14import org.jmock.core.constraint.IsSame;15import org.jmock.core.constraint.IsTypeCompatibleWith;16import org.jmock.core.constraint.IsAnything;17import org.jmock.core.constraint.IsAnything;18import org.jmock.core.constraint.IsEqual;19import org.jmock.core.constraint.IsInstanceOf;20import org.jmock.core.constraint.IsSame;21import org.jmock.core.constraint.IsTypeCompatibleWith;22import org.jmock.core.constraint.IsAnything;23import org.jmock.core.constraint.IsAnything;24import org.jmock.core.constraint.IsEqual;25import org.jmock.core.constraint.IsInstanceOf;26import org.jmock.core.constraint.IsSame;27import org.jmock.core.constraint.IsTypeCompatibleWith;28import org.jmock.core.constraint.IsAnything;29import org.jmock.core.constraint.IsAnything;30import org.jmock.core.constraint.IsEqual;31import org.jmock.core.constraint.IsInstanceOf;32import org.jmock.core.constraint.IsSame;33import org.jmock.core.constraint.IsTypeCompatibleWith;34import org.jmock.AbstractExpectations;35import org.jmock.Mock;36import org.jmock.MockObjectTestCase;37import org.jmock.core.Invocation;38import org.jmock.core.Stub;39import org.jmock.core.constraint.IsEqual;40import org.jmock.core.constraint.IsInstanceOf;41import org.jmock.core.constraint.IsSame;42import org.jmock.core.constraint.IsTypeCompatibleWith;43import org.jmock.core.constraint.IsAnything;44import org.jmock.core.constraint.IsAnything;45import org.jmock.core.constraint.IsEqual;46import org.jmock.core.constraint.IsInstanceOf;47import org.jmock.core.constraint.IsSame;48import org.jmock.core.constraint.IsTypeCompatibleWith;49import org.jmock.core.constraint.IsAnything;50import org.jmock.core.constraint.IsAnything;51import org.jmock.core.constraint.IsEqual;52import org.jmock.core.constraint.IsInstanceOf;53import org.jmock.core.constraint.IsSame;54import org.jmock.core.constraint.IsTypeCompatibleWith;55import org.jmock.core.constraint.IsAnything;56import org

Full Screen

Full Screen

doAll

Using AI Code Generation

copy

Full Screen

1package com.jmockit.examples;2import static org.junit.Assert.assertEquals;3import org.jmock.Expectations;4import org.jmock.Mockery;5import org.jmock.Sequence;6import org.jmock.States;7import org.jmock.integration.junit4.JUnit4Mockery;8import org.junit.Test;9public class DoAllTest {10 Mockery context = new JUnit4Mockery();11 public void testDoAll() {12 final States states = context.states("states").startsAs("initial");13 final Sequence sequence = context.sequence("sequence");14 final MyInterface myInterface = context.mock(MyInterface.class);15 context.checking(new Expectations() {16 {17 oneOf(myInterface).doSomething("first");18 inSequence(sequence);19 will(doAll(20 changeState("first", states),21 changeState("second", states),22 changeState("third", states)));23 oneOf(myInterface).doSomething("second");24 inSequence(sequence);25 when(states.is("second"));26 }27 });28 myInterface.doSomething("first");29 myInterface.doSomething("second");30 }31 public void testDoAllWithReturnValue() {32 final States states = context.states("states").startsAs("initial");33 final Sequence sequence = context.sequence("sequence");34 final MyInterface myInterface = context.mock(MyInterface.class);35 context.checking(new Expectations() {36 {37 oneOf(myInterface).doSomething("first");38 inSequence(sequence);39 will(doAll(40 changeState("first", states),41 changeState("second", states),42 changeState("third", states)));43 oneOf(myInterface).doSomething("second");44 inSequence(sequence);45 when(states.is("second"));46 will(returnValue("expected value"));47 }48 });49 myInterface.doSomething("first");50 String result = myInterface.doSomething("second");51 assertEquals("expected value", result);52 }53}54package com.jmockit.examples;55import static org.junit.Assert.assertEquals;56import org.jmock.Expectations;57import org.jmock.Mockery;58import org.jmock.Sequence;59import org.jmock.States;60import org.jmock.integration.junit4.JUnit4Mockery;61import org.junit.Test;62public class DoAllTest {

Full Screen

Full Screen

doAll

Using AI Code Generation

copy

Full Screen

1package org.jmock.examples;2import org.jmock.Expectations;3import org.jmock.Mockery;4import org.jmock.lib.legacy.ClassImposteriser;5public class AbstractExpectationsExample {6 public static void main(String[] args) {7 Mockery context = new Mockery();8 context.setImposteriser(ClassImposteriser.INSTANCE);9 final Collaborator mock = context.mock(Collaborator.class);10 context.checking(new Expectations() {11 {12 oneOf(mock).add("one");13 oneOf(mock).add("two");14 }15 });16 mock.add("one");17 mock.add("two");18 }19}20package org.jmock.examples;21import org.jmock.Expectations;22import org.jmock.Mockery;23import org.jmock.lib.legacy.ClassImposteriser;24public class ExpectationsExample {25 public static void main(String[] args) {26 Mockery context = new Mockery();27 context.setImposteriser(ClassImposteriser.INSTANCE);28 final Collaborator mock = context.mock(Collaborator.class);29 context.checking(new Expectations() {30 {31 doAll(32 oneOf(mock).add("one"),33 oneOf(mock).add("two")34 );35 }36 });37 mock.add("one");38 mock.add("two");39 }40}41package org.jmock.examples;42import org.jmock.Expectations;43import org.jmock.Mockery;44import org.jmock.lib.legacy.ClassImposteriser;45public class ExpectationsExample {46 public static void main(String[] args) {47 Mockery context = new Mockery();48 context.setImposteriser(ClassImposteriser.INSTANCE);49 final Collaborator mock = context.mock(Collaborator.class);50 context.checking(new Expectations() {51 {52 doAll(53 oneOf(mock).add("one"),54 oneOf(mock).add("two")55 );56 }57 });58 mock.add("one");59 mock.add("two");60 }61}62package org.jmock.examples;63import org.jmock.Expectations;64import org.jmock.Mockery;

Full Screen

Full Screen

doAll

Using AI Code Generation

copy

Full Screen

1import org.jmock.Mock;2import org.jmock.MockObjectTestCase;3public class TestAll extends MockObjectTestCase {4 public void testAll() {5 Mock mock = mock(Interface.class);6 mock.expects(once()).method("method1");7 mock.expects(once()).method("method2");8 mock.expects(once()).method("method3");9 Interface i = (Interface) mock.proxy();10 i.method1();11 i.method2();12 i.method3();13 }14}15interface Interface {

Full Screen

Full Screen

doAll

Using AI Code Generation

copy

Full Screen

1import org.jmock.Mockery;2import org.jmock.Expectations;3import org.jmock.AbstractExpectations;4public class 1 {5 public static void main(String[] args) {6 Mockery context = new Mockery();7 final Interface1 mockObject = context.mock(Interface1.class);8 context.checking(new Expectations() {{9 oneOf (mockObject).method1();10 will(AbstractExpectations.doAll(11 AbstractExpectations.returnValue(2),12 AbstractExpectations.returnValue(3),13 AbstractExpectations.returnValue(4)14 ));15 }});16 System.out.println(mockObject.method1());17 System.out.println(mockObject.method1());18 System.out.println(mockObject.method1());19 }20}

Full Screen

Full Screen

doAll

Using AI Code Generation

copy

Full Screen

1package com.oreilly.mock;2import org.jmock.cglib.MockObjectTestCase;3import org.jmock.core.Invocation;4import org.jmock.core.Stub;5import org.jmock.core.constraint.IsEqual;6import org.jmock.core.constraint.IsInstanceOf;7import org.jmock.core.constraint.IsAnything;8import org.jmock.core.constraint.IsSame;9import org.jmock.core.constraint.IsNot;10import org.jmock.core.constraint.IsNull;11import org.jmock.core.constraint.IsNotNull;12import org.jmock.core.constraint.IsGreaterThan;13import org.jmock.core.constraint.IsLessThan;14import org.jmock.core.constraint.IsIn;15import org.jmock.core.constraint.IsNotIn;16import org.jmock.core.constraint.IsCollectionContaining;17import org.jmock.core.constraint.IsStringStarting;18import org.jmock.core.constraint.IsStringEnding;19import org.jmock.core.constraint.IsStringContaining;20import org.jmock.core.constraint.IsStringMatching;21import org.jmock.core.constraint.IsTypeCompatible;22import org.jmock.core.constraint.IsCompatibleType;23import org.jmock.core.constraint.IsIdentical;24import org.jmock.core.constraint.IsNotIdentical;25import org.jmock.core.constraint.IsArrayContaining;26import org.jmock.core.constraint.IsMapContaining;27import org.jmock.core.constraint.IsSamePropertyValuesAs;28import org.jmock.core.constraint.IsEqualIncludingFields;29import org.jmock.core.constraint.IsEqualByComparingFields;30import org.jmock.core.constraint.IsEqualByComparingFieldByField;31import org.jmock.core.constraint.IsEqualByComparingFieldByFieldRecursively;32import org.jmock.core.constraint.IsEqualByComparingOnlyGivenFields;33import org.jmock.core.constraint.IsEqualByComparingOnlyGivenFieldsRecursively;34import org.jmock.core.constraint.IsEqualByComparingProperties;35import org.jmock.core.constraint.IsEqualByComparingPropertiesRecursively;36import org.jmock.core.constraint.IsEqualByValue;37import org.jmock.core.constraint.IsEqualByValueRecursively;38import org.jmock.core.constraint.IsEqualIgnoringCase;39import org.jmock.core.constraint.IsEqualIgnoringWhiteSpace;40import org.jmock.core.constraint.IsEqualNormalizingLineEndings;41import org.jmock.core.constraint.IsEqualNormalizingLineEndingsAndWhitespace;42import org.jmock.core.constraint.IsEqualNormalizingWhitespace;43import org.jmock.core.constraint.IsEqualWithDelta;44import org.jmock.core.constraint.IsSamePropertyValuesAs;45import org.jmock.core.constraint

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful