/** 基类实现消息监听接口,加上打印metaq监控日志的方法 */ @Override public ConsumeConcurrentlyStatus consumeMessage( List<MessageExt> msgs, ConsumeConcurrentlyContext context) { long startTime = System.currentTimeMillis(); logger.info("receive_message:{}", msgs.toString()); if (msgs == null || msgs.size() < 1) { logger.error("receive empty msg!"); return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } List<Serializable> msgList = new ArrayList<>(); for (MessageExt message : msgs) { msgList.add(decodeMsg(message)); } final int reconsumeTimes = msgs.get(0).getReconsumeTimes(); MsgObj msgObj = new MsgObj(); msgObj.setReconsumeTimes(reconsumeTimes); msgObj.setMsgList(msgList); msgObj.setContext(context); context.setDelayLevelWhenNextConsume(getDelayLevelWhenNextConsume(reconsumeTimes)); ConsumeConcurrentlyStatus status = doConsumeMessage(msgObj); logger.info( "ConsumeConcurrentlyStatus:{}|cost:{}", status, System.currentTimeMillis() - startTime); return status; }
protected void addOrReplace(ParsedMapping parsedMapping) { MappingKey key = new MappingKey(parsedMapping); for (int i = 0; i < mappings.size(); i++) { if (key.equals(new MappingKey(mappings.get(i)))) { logger.warn("{}\nis replaced with\n{}", mappings.get(i), parsedMapping); mappings.set(i, parsedMapping); return; } } logger.debug("Parsed {}", parsedMapping); mappings.add(parsedMapping); }
@Test public void testFindAllAlbumsByOwner() throws Exception { Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION); album.modifyUser(user); Album createdAlbum = repository.create(album); // Execute List<Album> foundAlbums = repository.findAllByOwner(user.getUserId()); // Verify em.flush(); em.clear(); Album actualAlbum = em.find(Album.class, createdAlbum.getAlbumId()); assertEquals(1, foundAlbums.size()); assertTrue(foundAlbums.contains(actualAlbum)); }
private Url decryptUrl(final Request request, final Url encryptedUrl) { if (encryptedUrl.getSegments().isEmpty()) { return encryptedUrl; } final List<String> encryptedSegments = (List<String>) encryptedUrl.getSegments(); if (encryptedSegments.size() < 1) { return null; } Url url = new Url(request.getCharset()); try { final String encryptedUrlString = (String) encryptedSegments.get(0); if (Strings.isEmpty((CharSequence) encryptedUrlString)) { return null; } final String decryptedUrl = this.getCrypt().decryptUrlSafe(encryptedUrlString); if (decryptedUrl == null) { return null; } final Url originalUrl = Url.parse(decryptedUrl, request.getCharset()); final int originalNumberOfSegments = originalUrl.getSegments().size(); final int encryptedNumberOfSegments = encryptedUrl.getSegments().size(); final HashedSegmentGenerator generator = new HashedSegmentGenerator(encryptedUrlString); int segNo; for (segNo = 1; segNo < encryptedNumberOfSegments; ++segNo) { if (segNo > originalNumberOfSegments) { break; } final String next = generator.next(); final String encryptedSegment = (String) encryptedSegments.get(segNo); if (!next.equals(encryptedSegment)) { break; } url.getSegments().add(originalUrl.getSegments().get(segNo - 1)); } while (segNo < encryptedNumberOfSegments) { url.getSegments().add(encryptedUrl.getSegments().get(segNo)); ++segNo; } url.getQueryParameters().addAll(originalUrl.getQueryParameters()); } catch (Exception e) { CryptoMapper.log.error("Error decrypting URL", e); url = null; } return url; }
/** * By default, this will always attempt to call {@link System#exit(int)} at the end of running * tests, exiting with 0 if all tests pass, 4 if any units have failed, and 5 if any unit failed * catastrophically (i.e. the entire case was not completed). This behavior and/or those values * can be overridden by overriding the {@link #succeeded()}, {@link #failed()}, and {@link * #aborted()} methods, respectively. */ public synchronized void run() { List<Unit> $units = getUnits(); // list is assumed immutable on pain of death or idiocy $numUnits = $units.size(); $numUnitsRun = 0; $numUnitsPassed = 0; $numUnitsFailed = 0; for (int $i = 0; $i < $units.size(); $i++) { Unit $unit = $units.get($i); if ($unit == null) continue; try { resetFailures(); $log.info("TEST UNIT " + $unit.getName() + " STARTING..."); $numUnitsRun++; $unit.call(); if ($unit.expectExceptionType() != null) { $numUnitsFailed++; $log.error("EXPECTED EXCEPTION; TEST CASE ABORTED."); aborted(); } if ($unitFailures == 0) { $numUnitsPassed++; $log.info("TEST UNIT " + $unit.getName() + " PASSED SUCCESSFULLY!\n"); } else { $numUnitsFailed++; $log.info( "TEST UNIT " + $unit.getName() + " FAILED (WITH " + $unitFailures + " FAILURES)!\n"); } } catch (AssertionFatal $e) { $numUnitsFailed++; $log.error("FATAL EXCEPTION; TEST CASE ABORTED.", $e); aborted(); break; } catch (AssertionFailed $e) { $numUnitsFailed++; $log.error("TEST UNIT " + $unit.getName() + " ABORTED.", $e); } catch (Throwable $e) { if ($unit.expectExceptionType() != null) { // some kind of exception was expected. if ($unit.expectExceptionType().isAssignableFrom($e.getClass())) { // and it was this kind that was expected, so this is good. $numUnitsPassed++; $unit.assertInstanceOf( $unit.expectExceptionType(), $e); // generates a normal confirmation message $log.info("TEST UNIT " + $unit.getName() + " PASSED SUCCESSFULLY!\n"); } else { // and it wasn't this kind. this represents fatal failure. $numUnitsFailed++; $log.error("FATAL EXCEPTION; TEST CASE ABORTED.", $e); aborted(); break; } } else { // no exception was expected. any exception represents fatal failure. $numUnitsFailed++; $log.error("FATAL EXCEPTION; TEST CASE ABORTED.", $e); aborted(); break; } } } if ($numUnitsFailed > 0) failed(); else succeeded(); }