diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartling.java b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartling.java index 15f2a76685..926a346891 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartling.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartling.java @@ -20,12 +20,14 @@ import com.box.l10n.mojito.smartling.request.Bindings; import com.box.l10n.mojito.smartling.response.File; import com.box.l10n.mojito.smartling.response.StringInfo; +import com.google.common.base.Stopwatch; import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; import com.google.common.io.Files; import io.micrometer.core.annotation.Timed; +import io.micrometer.core.instrument.MeterRegistry; import java.io.IOException; import java.util.List; import java.util.Map; @@ -83,6 +85,8 @@ public class ThirdPartyTMSSmartling implements ThirdPartyTMS { private final ThirdPartyTMSSmartlingGlossary thirdPartyTMSSmartlingGlossary; private final AssetTextUnitToTMTextUnitRepository assetTextUnitToTMTextUnitRepository; + private final MeterRegistry meterRegistry; + private final Set supportedImageExtensions = Sets.newHashSet("png", "jpg", "jpeg", "gif", "tiff"); @@ -99,7 +103,8 @@ public ThirdPartyTMSSmartling( SmartlingResultProcessor resultProcessor, ThirdPartyTMSSmartlingWithJson thirdPartyTMSSmartlingWithJson, ThirdPartyTMSSmartlingGlossary thirdPartyTMSSmartlingGlossary, - AssetTextUnitToTMTextUnitRepository assetTextUnitToTMTextUnitRepository) { + AssetTextUnitToTMTextUnitRepository assetTextUnitToTMTextUnitRepository, + MeterRegistry meterRegistry) { this( smartlingClient, textUnitSearcher, @@ -109,7 +114,8 @@ public ThirdPartyTMSSmartling( thirdPartyTMSSmartlingWithJson, thirdPartyTMSSmartlingGlossary, assetTextUnitToTMTextUnitRepository, - DEFAULT_BATCH_SIZE); + DEFAULT_BATCH_SIZE, + meterRegistry); } public ThirdPartyTMSSmartling( @@ -121,7 +127,8 @@ public ThirdPartyTMSSmartling( ThirdPartyTMSSmartlingWithJson thirdPartyTMSSmartlingWithJson, ThirdPartyTMSSmartlingGlossary thirdPartyTMSSmartlingGlossary, AssetTextUnitToTMTextUnitRepository assetTextUnitToTMTextUnitRepository, - int batchSize) { + int batchSize, + MeterRegistry meterRegistry) { this.smartlingClient = smartlingClient; this.assetPathAndTextUnitNameKeys = assetPathAndTextUnitNameKeys; this.textUnitBatchImporterService = textUnitBatchImporterService; @@ -131,6 +138,7 @@ public ThirdPartyTMSSmartling( this.thirdPartyTMSSmartlingWithJson = thirdPartyTMSSmartlingWithJson; this.thirdPartyTMSSmartlingGlossary = thirdPartyTMSSmartlingGlossary; this.assetTextUnitToTMTextUnitRepository = assetTextUnitToTMTextUnitRepository; + this.meterRegistry = meterRegistry; } @Override @@ -386,6 +394,8 @@ public void push( return; } + Stopwatch totalStopwatch = Stopwatch.createStarted(); + AndroidStringDocumentMapper mapper = new AndroidStringDocumentMapper(pluralSeparator, null); Stream singularFiles = @@ -407,6 +417,9 @@ public void push( List result = Stream.concat(singularFiles, pluralFiles).collect(Collectors.toList()); resultProcessor.processPush(result, options); + meterRegistry + .timer("ThirdPartyTMSSmartling.push", "repository", repository.getName()) + .record(totalStopwatch.stop().elapsed()); } private SmartlingFile processPushBatch( @@ -418,6 +431,7 @@ private SmartlingFile processPushBatch( SmartlingOptions options, Prefix filePrefix) { + Stopwatch stopwatch = Stopwatch.createStarted(); logger.debug("Convert text units to AndroidString for asset number: {}", batchNumber); SmartlingFile file = new SmartlingFile(); file.setFileName(getOutputSourceFile(batchNumber, repository.getName(), filePrefix.getType())); @@ -464,7 +478,9 @@ private SmartlingFile processPushBatch( }) .block(); } - + meterRegistry + .timer("ThirdPartyTMSSmartling.processPushBatch", "repository", repository.getName()) + .record(stopwatch.stop().elapsed()); return file; } @@ -479,6 +495,7 @@ public void pull( String skipAssetsWithPathPattern, List optionList) { + Stopwatch stopwatch = Stopwatch.createStarted(); SmartlingOptions options = SmartlingOptions.parseList(optionList); if (options.isJsonSync()) { @@ -520,6 +537,9 @@ public void pull( options, localeMapping, Prefix.PLURAL)); + meterRegistry + .timer("ThirdPartyTMSSmartling.pull", "repository", repository.getName()) + .record(stopwatch.stop().elapsed()); } private void processPullBatch( @@ -535,6 +555,8 @@ private void processPullBatch( for (RepositoryLocale locale : repository.getRepositoryLocales()) { + Stopwatch stopwatch = Stopwatch.createStarted(); + if (locale.getParentLocale() == null) { continue; } @@ -599,6 +621,15 @@ private void processPullBatch( logger.debug("Importing text units for locale: {}", smartlingLocale); textUnitBatchImporterService.importTextUnits(textUnits, false, true); } + + meterRegistry + .timer( + "ThirdPartyTMSSmartling.processPullBatch", + "repository", + repository.getName(), + "locale", + localeTag) + .record(stopwatch.stop().elapsed()); } } @@ -614,6 +645,8 @@ public void pushTranslations( String includeTextUnitsWithPattern, List optionList) { + Stopwatch stopwatch = Stopwatch.createStarted(); + SmartlingOptions options = SmartlingOptions.parseList(optionList); if (options.isJsonSync()) { thirdPartyTMSSmartlingWithJson.pushTranslations( @@ -685,6 +718,9 @@ public void pushTranslations( .collect(Collectors.toList()); resultProcessor.processPushTranslations(result, options); + meterRegistry + .timer("ThirdPartyTMSSmartling.pushTranslations", "repository", repository.getName()) + .record(stopwatch.stop().elapsed()); } private Set getFilterTmTextUnitIdsForPushTranslation(SmartlingOptions options) { @@ -707,8 +743,12 @@ public void pullSource( Map localeMapping) { SmartlingOptions options = SmartlingOptions.parseList(optionList); if (options.isGlossarySync()) { + Stopwatch stopwatch = Stopwatch.createStarted(); thirdPartyTMSSmartlingGlossary.pullSourceTextUnits( repository, thirdPartyProjectId, localeMapping); + meterRegistry + .timer("ThirdPartyTMSSmartling.pullSource", "repository", repository.getName()) + .record(stopwatch.stop().elapsed()); } else { throw new UnsupportedOperationException( "Pull source is only supported with glossary sync enabled."); @@ -729,6 +769,7 @@ private SmartlingFile processTranslationBatch( logger.debug("Process {} batch: {}", localeTag, batchNumber); logger.debug("Convert text units to AndroidString for asset number: {}", batchNumber); + Stopwatch stopwatch = Stopwatch.createStarted(); String sourceFilename = getOutputSourceFile(batchNumber, repository.getName(), filePrefix.getType()); String targetFilename = @@ -791,6 +832,14 @@ private SmartlingFile processTranslationBatch( .block(); } + meterRegistry + .timer( + "ThirdPartyTMSSmartlingWithJson.processTranslationBatch", + "repository", + repository.getName(), + "locale", + localeTag) + .record(stopwatch.stop().elapsed()); return file; } diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingGlossary.java b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingGlossary.java index 2e372a11f7..c8dfc7f851 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingGlossary.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingGlossary.java @@ -21,6 +21,7 @@ import com.box.l10n.mojito.smartling.response.GlossaryTargetTerm; import com.box.l10n.mojito.smartling.response.GlossaryTermTranslation; import com.google.common.base.Strings; +import io.micrometer.core.instrument.MeterRegistry; import java.io.ByteArrayInputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -58,6 +59,8 @@ public class ThirdPartyTMSSmartlingGlossary { @Autowired AssetTextUnitRepository assetTextUnitRepository; + @Autowired MeterRegistry meterRegistry; + @Value("${l10n.smartling.accountId:}") String accountId; diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJson.java b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJson.java index 31fbce104f..a9b0d6b942 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJson.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJson.java @@ -21,7 +21,9 @@ import com.box.l10n.mojito.smartling.response.Items; import com.box.l10n.mojito.smartling.response.StringInfo; import com.google.common.base.Preconditions; +import com.google.common.base.Stopwatch; import com.google.common.collect.ImmutableList; +import io.micrometer.core.instrument.MeterRegistry; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -54,6 +56,8 @@ public class ThirdPartyTMSSmartlingWithJson { TextUnitBatchImporterService textUnitBatchImporterService; SmartlingJsonKeys smartlingJsonKeys; + MeterRegistry meterRegistry; + int batchSize = 5000; public ThirdPartyTMSSmartlingWithJson( @@ -61,12 +65,14 @@ public ThirdPartyTMSSmartlingWithJson( SmartlingJsonConverter smartlingJsonConverter, TextUnitSearcher textUnitSearcher, TextUnitBatchImporterService textUnitBatchImporterService, - SmartlingJsonKeys smartlingJsonKeys) { + SmartlingJsonKeys smartlingJsonKeys, + MeterRegistry meterRegistry) { this.smartlingClient = smartlingClient; this.smartlingJsonConverter = smartlingJsonConverter; this.textUnitSearcher = textUnitSearcher; this.textUnitBatchImporterService = textUnitBatchImporterService; this.smartlingJsonKeys = smartlingJsonKeys; + this.meterRegistry = meterRegistry; } void push( @@ -82,12 +88,15 @@ void push( repository.getName(), projectId); + Stopwatch totalStopwatch = Stopwatch.createStarted(); + long partitionCount = Spliterators.partitionStreamWithIndex( getSourceTextUnitIterator( repository, skipTextUnitsWithPattern, skipAssetsWithPathPattern), batchSize, (textUnitDTOS, index) -> { + Stopwatch batchStopWatch = Stopwatch.createStarted(); String fileName = getSourceFileName(repository.getName(), index); String fileContent = smartlingJsonConverter.textUnitDTOsToJsonString( @@ -122,11 +131,20 @@ void push( throw new SmartlingClientException(msg, e); }) .block(); + meterRegistry + .timer( + "ThirdPartyTMSSmartlingWithJson.push.batch", + "repository", + repository.getName()) + .record(batchStopWatch.stop().elapsed()); return index; }) .count(); removeFileForBatchNumberGreaterOrEquals(repository.getName(), projectId, partitionCount); + meterRegistry + .timer("ThirdPartyTMSSmartlingWithJson.push") + .record(totalStopwatch.stop().elapsed()); } void removeFileForBatchNumberGreaterOrEquals( @@ -226,6 +244,8 @@ public void pushTranslations( logger.info( "Push translation from repository: {} into project: {}", repository.getName(), projectId); + Stopwatch stopwatch = Stopwatch.createStarted(); + getRepositoryLocaleWithoutRootStream(repository) .forEach( repositoryLocale -> { @@ -239,6 +259,7 @@ public void pushTranslations( includeTextUnitsWithPattern), batchSize, (textUnitDTOS, index) -> { + Stopwatch batchStopwatch = Stopwatch.createStarted(); String fileName = getSourceFileName(repository.getName(), index); String fileContent = smartlingJsonConverter.textUnitDTOsToJsonString( @@ -275,11 +296,21 @@ public void pushTranslations( throw new SmartlingClientException(msg, e); }) .block(); + meterRegistry + .timer( + "ThirdPartyTMSSmartlingWithJson.pushTranslations.batch", + "repository", + repository.getName()) + .record(batchStopwatch.stop().elapsed()); return index; }) .count(); logger.debug("Processed {} partitions", partitionCount); }); + meterRegistry + .timer( + "ThirdPartyTMSSmartlingWithJson.pushTranslations", "repository", repository.getName()) + .record(stopwatch.stop().elapsed()); } PageFetcherOffsetAndLimitSplitIterator getSourceTextUnitIterator( diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/tm/importer/TextUnitBatchImporterService.java b/webapp/src/main/java/com/box/l10n/mojito/service/tm/importer/TextUnitBatchImporterService.java index b90e3262b8..0ae815d9d0 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/tm/importer/TextUnitBatchImporterService.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/tm/importer/TextUnitBatchImporterService.java @@ -34,9 +34,11 @@ import com.box.l10n.mojito.service.tm.search.TextUnitSearcher; import com.box.l10n.mojito.service.tm.textunitdtocache.TextUnitDTOsCacheService; import com.box.l10n.mojito.service.tm.textunitdtocache.UpdateType; +import com.google.common.base.Stopwatch; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import io.micrometer.core.instrument.MeterRegistry; import java.util.AbstractMap.SimpleEntry; import java.util.List; import java.util.Map; @@ -83,6 +85,8 @@ public class TextUnitBatchImporterService { @Autowired TMTextUnitVariantCommentService tmMTextUnitVariantCommentService; + @Autowired MeterRegistry meterRegistry; + /** * Imports a batch of text units. * @@ -120,6 +124,8 @@ public PollableFuture importTextUnits( boolean integrityCheckSkipped, boolean integrityCheckKeepStatusIfFailedAndSameTarget) { + Stopwatch stopwatchTotal = Stopwatch.createStarted(); + logger.debug("Import {} text units", textUnitDTOs.size()); List textUnitForBatchImports = skipInvalidAndConvertToTextUnitForBatchImport(textUnitDTOs); @@ -138,15 +144,30 @@ public PollableFuture importTextUnits( (asset, textUnitsForBatchImport) -> { mapTextUnitsToImportWithExistingTextUnits(locale, asset, textUnitsForBatchImport); if (!integrityCheckSkipped) { + Stopwatch integrityCheckStopwatch = Stopwatch.createStarted(); applyIntegrityChecks( asset, textUnitsForBatchImport, integrityCheckKeepStatusIfFailedAndSameTarget); + meterRegistry + .timer( + "TextUnitBatchImporterService.importTextUnits.integrityChecks", + "repository", + asset.getRepository().getName(), + "asset", + asset.getPath(), + "locale", + locale.getBcp47Tag()) + .record(integrityCheckStopwatch.stop().elapsed()); } importTextUnitsOfLocaleAndAsset(locale, asset, textUnitsForBatchImport); }); }); + meterRegistry + .timer("TextUnitBatchImporterService.importTextUnits") + .record(stopwatchTotal.stop().elapsed()); + return new PollableFutureTaskResult<>(); } diff --git a/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingTest.java b/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingTest.java index 36a1c595c1..75117929a1 100644 --- a/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingTest.java +++ b/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingTest.java @@ -9,6 +9,7 @@ import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.ArgumentMatchers.matches; import static org.mockito.ArgumentMatchers.startsWith; @@ -59,6 +60,8 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.primitives.Ints; +import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Timer; import java.io.IOException; import java.time.Duration; import java.util.ArrayList; @@ -99,6 +102,10 @@ public class ThirdPartyTMSSmartlingTest extends ServiceTestBase { @Mock SmartlingClient smartlingClient; + @Mock MeterRegistry meterRegistryMock; + + @Mock Timer timerMock; + @Mock ThirdPartyTMSSmartlingWithJson mockThirdPartyTMSSmartlingWithJson; @Mock ThirdPartyTMSSmartlingGlossary mockThirdPartyTMSSmartlingGlossary; @@ -169,6 +176,11 @@ public void setUp() { doReturn(null) .when(mockTextUnitBatchImporterService) .importTextUnits(any(), eq(false), eq(true)); + doReturn(timerMock) + .when(meterRegistryMock) + .timer(anyString(), anyString(), anyString(), anyString(), anyString()); + doReturn(timerMock).when(meterRegistryMock).timer(anyString(), anyString(), anyString()); + resultProcessor = new StubSmartlingResultProcessor(); tmsSmartling = new ThirdPartyTMSSmartling( @@ -179,7 +191,8 @@ public void setUp() { resultProcessor, mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, - assetTextUnitToTMTextUnitRepository); + assetTextUnitToTMTextUnitRepository, + meterRegistryMock); mapper = new AndroidStringDocumentMapper(pluralSep, null); RetryBackoffSpec retryConfiguration = @@ -229,7 +242,8 @@ public void testPushInBatchesWithSingularsAndNoPlurals() mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, assetTextUnitToTMTextUnitRepository, - batchSize); + batchSize, + meterRegistryMock); TM tm = repository.getTm(); Asset asset = @@ -263,6 +277,7 @@ public void testPushInBatchesWithSingularsAndNoPlurals() .satisfies( file -> assertThat(readTextUnits(file, pluralSep)).hasSize(singularTextUnits % batchSize)); + verify(timerMock, atLeastOnce()).record(isA((Duration.class))); } @Test @@ -281,7 +296,8 @@ public void testRetryDuringPush() throws RepositoryNameAlreadyUsedException { mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, assetTextUnitToTMTextUnitRepository, - batchSize); + batchSize, + meterRegistryMock); // throw timeout exception for first request, following request should be successful when(smartlingClient.uploadFile(any(), any(), any(), any(), any(), any(), any())) .thenThrow( @@ -345,7 +361,8 @@ public void testRetriesExhaustedDuringPush() throws RepositoryNameAlreadyUsedExc mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, assetTextUnitToTMTextUnitRepository, - batchSize); + batchSize, + meterRegistryMock); TM tm = repository.getTm(); Asset asset = @@ -394,7 +411,8 @@ public void testPushInBatchesWithNoSingularsAndPlurals() mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, assetTextUnitToTMTextUnitRepository, - batchSize); + batchSize, + meterRegistryMock); TM tm = repository.getTm(); Asset asset = @@ -432,6 +450,7 @@ public void testPushInBatchesWithNoSingularsAndPlurals() .satisfies( file -> assertThat(readTextUnits(file, pluralSep)).hasSize(pluralTextUnits % batchSize)); + verify(timerMock, atLeastOnce()).record(isA((Duration.class))); } @Test @@ -451,7 +470,8 @@ public void testPushInBatchesWithSingularsAndPlurals() throws RepositoryNameAlre mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, assetTextUnitToTMTextUnitRepository, - batchSize); + batchSize, + meterRegistryMock); TM tm = repository.getTm(); Asset asset = @@ -518,6 +538,8 @@ public void testPushInBatchesWithSingularsAndPlurals() throws RepositoryNameAlre .satisfies( file -> assertThat(readTextUnits(file, pluralSep)).hasSize(pluralTextUnits % batchSize)); + + verify(timerMock, atLeastOnce()).record(isA((Duration.class))); } @Test @@ -580,6 +602,8 @@ public void testPushWithUploadNoBatches() { eq("NONE"), eq("^some(.*)pattern$"), isNull()); + + verify(timerMock, atLeastOnce()).record(isA((Duration.class))); } @Test @@ -664,7 +688,8 @@ public void testPullNoBatches() throws RepositoryLocaleCreationException { resultProcessor, mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, - assetTextUnitToTMTextUnitRepository); + assetTextUnitToTMTextUnitRepository, + meterRegistryMock); tmsSmartling.pull( repository, "projectId", pluralSep, localeMapping, null, null, Collections.emptyList()); @@ -777,7 +802,8 @@ public void testRetrySuccessDuringPull() resultProcessor, mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, - assetTextUnitToTMTextUnitRepository); + assetTextUnitToTMTextUnitRepository, + meterRegistryMock); tmsSmartling.pull( repository, "projectId", pluralSep, localeMapping, null, null, Collections.emptyList()); @@ -870,7 +896,8 @@ public void testRetriesExhaustedDuringPull() resultProcessor, mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, - assetTextUnitToTMTextUnitRepository); + assetTextUnitToTMTextUnitRepository, + meterRegistryMock); RuntimeException exception = assertThrows( SmartlingClientException.class, @@ -929,7 +956,8 @@ public void testPullNoBatchesLocaleMapping() throws RepositoryLocaleCreationExce resultProcessor, mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, - assetTextUnitToTMTextUnitRepository); + assetTextUnitToTMTextUnitRepository, + meterRegistryMock); tmsSmartling.pull( repository, "projectId", pluralSep, localeMapping, null, null, Collections.emptyList()); @@ -992,6 +1020,8 @@ public void testPullNoBatchesLocaleMapping() throws RepositoryLocaleCreationExce assetPath, "fr-CA", repository.getName())); + + verify(timerMock, atLeastOnce()).record(isA((Duration.class))); } @Test @@ -1037,7 +1067,8 @@ public void testPullNoBatchesPluralFix() throws RepositoryLocaleCreationExceptio resultProcessor, mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, - assetTextUnitToTMTextUnitRepository); + assetTextUnitToTMTextUnitRepository, + meterRegistryMock); tmsSmartling.pull( repository, "projectId", @@ -1169,7 +1200,8 @@ public void testPullDryRunNoBatches() throws RepositoryLocaleCreationException { resultProcessor, mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, - assetTextUnitToTMTextUnitRepository); + assetTextUnitToTMTextUnitRepository, + meterRegistryMock); tmsSmartling.pull( repository, "projectId", @@ -1201,7 +1233,8 @@ public void testPullInBatchesWithSingularsAndPlurals() mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, assetTextUnitToTMTextUnitRepository, - batchSize); + batchSize, + meterRegistryMock); Repository repository = repositoryService.createRepository(testIdWatcher.getEntityName("batchRepo")); Locale frCA = localeService.findByBcp47Tag("fr-CA"); @@ -1296,6 +1329,8 @@ public void testPullInBatchesWithSingularsAndPlurals() assertThat(captured.subList(10, 14)).allSatisfy(list -> assertThat(list).hasSize(batchSize)); assertThat(captured.subList(14, 16)) .allSatisfy(list -> assertThat(list).hasSize(pluralTextUnits % batchSize)); + + verify(timerMock, atLeastOnce()).record(isA((Duration.class))); } @Test @@ -1377,6 +1412,8 @@ public void testPushTranslationsSingularsNoBatches() eq(null), eq(null)); }); + + verify(timerMock, atLeastOnce()).record(isA((Duration.class))); } @Test @@ -1868,7 +1905,8 @@ public void testPushTranslationsInBatches() mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, assetTextUnitToTMTextUnitRepository, - batchSize); + batchSize, + meterRegistryMock); Repository repository = repositoryService.createRepository(testIdWatcher.getEntityName("batchRepo")); Locale frCA = localeService.findByBcp47Tag("fr-CA"); @@ -2020,7 +2058,8 @@ public void testBatchesFor() { mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, assetTextUnitToTMTextUnitRepository, - 3); + 3, + meterRegistryMock); assertThat(tmsSmartling.batchesFor(0)).isEqualTo(0); assertThat(tmsSmartling.batchesFor(1)).isEqualTo(1); @@ -2041,7 +2080,8 @@ public void testBatchesFor() { mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, assetTextUnitToTMTextUnitRepository, - 35); + 35, + meterRegistryMock); assertThat(tmsSmartling.batchesFor(0)).isEqualTo(0); assertThat(tmsSmartling.batchesFor(1)).isEqualTo(1); @@ -2060,7 +2100,8 @@ public void testBatchesFor() { mockThirdPartyTMSSmartlingWithJson, mockThirdPartyTMSSmartlingGlossary, assetTextUnitToTMTextUnitRepository, - 4231); + 4231, + meterRegistryMock); assertThat(tmsSmartling.batchesFor(0)).isEqualTo(0); assertThat(tmsSmartling.batchesFor(1)).isEqualTo(1); diff --git a/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJsonTest.java b/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJsonTest.java index ab44fff2a4..c2da4e4850 100644 --- a/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJsonTest.java +++ b/webapp/src/test/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSSmartlingWithJsonTest.java @@ -26,6 +26,7 @@ import com.box.l10n.mojito.test.TestIdWatcher; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import io.micrometer.core.instrument.MeterRegistry; import java.util.Arrays; import java.util.Comparator; import java.util.List; @@ -58,6 +59,8 @@ public class ThirdPartyTMSSmartlingWithJsonTest extends ServiceTestBase { @Mock ThirdPartyTMSSmartlingWithJson thirdPartyTMSSmartlingWithJsonMock; + @Mock MeterRegistry meterRegistryMock; + @Autowired(required = false) ThirdPartyService thirdPartyService; @@ -247,7 +250,7 @@ public void testGetTranslatedUnits() { ImmutableList.of(translatedTextUnitDto, untranslatedTextUnitDtoWithOriginalString); ThirdPartyTMSSmartlingWithJson thirdPartyTMSSmartlingWithJson = - new ThirdPartyTMSSmartlingWithJson(null, null, null, null, null); + new ThirdPartyTMSSmartlingWithJson(null, null, null, null, null, meterRegistryMock); ImmutableList result = thirdPartyTMSSmartlingWithJson.getTranslatedUnits(