@Override public FindOIDsResult<AA88GuaranteePublishRequestOID> findRequestOidsForSourceSystem( final UserContext userContext, final AA88SourceSystemID sourceSystemId) { log.debug("> find all guarantee pub request oids for sourceSystem={}", sourceSystemId); // Use jpa's projections to retrieve only the record oid: // http://www.objectdb.com/java/jpa/query/jpql/select TypedQuery<AA88GuaranteePublishRequestOID> query = this.getEntityManager() .createNamedQuery( "AA88DBGuaranteePubRequestOidsForSourceSystem", AA88GuaranteePublishRequestOID.class) .setParameter("sourceSystemId", sourceSystemId.asString()); query.setHint(QueryHints.READ_ONLY, HintValues.TRUE); Collection<AA88GuaranteePublishRequestOID> oids = query.getResultList(); FindOIDsResult<AA88GuaranteePublishRequestOID> outEntities = FindOIDsResultBuilder.using(userContext).on(_modelObjectType).foundEntitiesWithOids(oids); return outEntities; }
// @Test public void testRefresh() { log.warn("============================================================="); log.warn("Test Refresh"); log.warn("============================================================="); AA88ClientAPI api = TestAPIBase.getClientApi(AA88ClientAPI.class); // Use a type that encapsulates all the tests final AA88LifeCycleServicesTestHelper testHelp = new AA88LifeCycleServicesTestHelper(api, STORAGE_SERVICES); // [1] - Create guarantees File testFileListsContainerFolder = new File(TEST_FILELIST_FOLDER_PATH.asAbsoluteString()); File[] testFileLists = testFileListsContainerFolder.listFiles(); Observable.from(testFileLists) .map( new Func1<File, AA88Guarantee>() { @Override public AA88Guarantee call(final File fileList) { log.warn("\n\n\n"); log.warn( "CREATE & DO A FIRST REFRESH for MOCK guarantee using fileList at {}", Paths.forPaths() .join(TEST_FILELIST_FOLDER_PATH, fileList.getName()) .asAbsoluteString()); AA88Guarantee guarantee = testHelp.testLifeCycle( TEST_FILELIST_FOLDER_PATH, FileName.of(fileList.getName()), Arrays.asList(AA88MethodToBeTested.START, AA88MethodToBeTested.REFRESH)); log.warn( "MOCK guarantee with oid={} CREATED & REFRESHED FOR THE FIRST TIME for fileList at {}", guarantee.getOid(), Paths.forPaths() .join(TEST_FILELIST_FOLDER_PATH, fileList.getName()) .asAbsoluteString()); log.warn("\n\n\n"); return guarantee; } }) .subscribe( new Observer<AA88Guarantee>() { @Override public void onNext(final AA88Guarantee guarantee) { _testedGuaranteesOids.add(guarantee.getOid()); } @Override public void onCompleted() { log.warn("\n\n\n\n\n\n"); log.warn( ":::::::: {} test guarantees with oids={} created__________________________", _testedGuaranteesOids.size(), _testedGuaranteesOids); } @Override public void onError(final Throwable th) { // BEWARE!!! RxJava will catch Exception and most Error. // Exceptions cannot be propagated out of RxJava // ... so even if Throwables.propagate(th) is used, the exception is NEVER thrown // outside RxJava // the only option is to use Exceptions.throwIfFatal(th) // (see https://github.com/ReactiveX/RxJava/issues/969) // Exceptions.throwIfFatal(th); th.printStackTrace(System.out); } }); // [2] - With the created guarantees, call refresh guarantee if (CollectionUtils.hasData(_testedGuaranteesOids)) { log.warn( ":::::::: With the created guarantees --> Refesh all Actives Guarantees _____________________________________________________________________"); // Call refresh all active guarantees and wait a moment to the scheduler to start api.guaranteesAPI() .getForLifeCycle() .refreshAllActiveGuarantees(AA88SourceSystemID.forId("PLATEA-Internet")); Threads.safeSleep(TimeLapse.createFor("5s")); // Check the process final Collection<BeingRefreshedGuarantee> refreshPendingGuarantees = FluentIterable.from(_testedGuaranteesOids) .transform( new Function<AA88GuaranteeOID, BeingRefreshedGuarantee>() { @Override public BeingRefreshedGuarantee apply(final AA88GuaranteeOID oid) { return new BeingRefreshedGuarantee(oid); } }) .toList(); long startTS = System.currentTimeMillis(); long elapsedMilis = 0; boolean anyRefreshPendingGuarantee = false; do { for (BeingRefreshedGuarantee b : refreshPendingGuarantees) { if (b.isRefreshed()) continue; // Check that there's NO minor version in requested status AA88Guarantee mockGuarantee = api.guaranteesAPI().getForCRUD().load(b.getOid()); if (mockGuarantee.existsMinorVersionInRequestedStatus()) { log.warn( "...the guarantee with oid={} unitId={} is still being refreshed (the notary is working)...give a moment to the notary to do it's work...", mockGuarantee.getOid(), mockGuarantee.getGuaranteedUnitId()); } else { log.warn( "The guarantee with oid={} unitId={} has been refreshed!... stop guaranteeing it", mockGuarantee.getOid(), mockGuarantee.getGuaranteedUnitId()); b.setRefreshed(true); } } anyRefreshPendingGuarantee = _anyRefreshPendingGuarantee(refreshPendingGuarantees); if (anyRefreshPendingGuarantee) { elapsedMilis = System.currentTimeMillis() - startTS; Threads.safeSleep(TimeLapse.createFor("5s")); } Assert.assertTrue( elapsedMilis < AA88LifeCycleServicesTestHelper.MAX_REFRESH_TIME_PER_GUARANTEE * _testedGuaranteesOids.size()); } while (anyRefreshPendingGuarantee); // Stop guaranteeing for (AA88GuaranteeOID oid : _testedGuaranteesOids) { log.warn("Stop guaranteein guarantee with oid={}", oid); api.guaranteesAPI().getForLifeCycle().stopGuaranteeingNow(oid); } // Check that all guarantees has been stoped for (AA88GuaranteeOID oid : _testedGuaranteesOids) { AA88Guarantee mockGuarantee = api.guaranteesAPI().getForCRUD().load(oid); Assert.assertTrue(!mockGuarantee.isActive()); } } else { log.warn("Could NOT create any mock guarantee!!!"); } }