콘텐츠, 시리즈 번역 로직 수정 #472
+144
@@ -0,0 +1,144 @@
|
||||
package kr.co.vividnext.sodalive.content
|
||||
|
||||
import kr.co.vividnext.sodalive.content.translation.ContentTranslationPayload
|
||||
import kr.co.vividnext.sodalive.content.translation.ContentTranslationRepository
|
||||
import kr.co.vividnext.sodalive.content.translation.TranslatedContent
|
||||
import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationTargetType
|
||||
import kr.co.vividnext.sodalive.i18n.translation.ResourceTranslationJobScheduler
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationLanguages
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationMemoryService
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationReadModelMaterializer
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationSourceField
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.PlatformTransactionManager
|
||||
import org.springframework.transaction.TransactionDefinition
|
||||
import org.springframework.transaction.annotation.Propagation
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import org.springframework.transaction.support.TransactionTemplate
|
||||
import javax.persistence.EntityManager
|
||||
import javax.persistence.LockModeType
|
||||
|
||||
data class AudioContentDetailTranslationResult(
|
||||
val languageCode: String?,
|
||||
val translated: TranslatedContent? = null,
|
||||
val detectionQuery: String? = null
|
||||
)
|
||||
|
||||
@Service
|
||||
class AudioContentDetailTranslationService(
|
||||
private val repository: AudioContentRepository,
|
||||
private val translations: ContentTranslationRepository,
|
||||
private val detector: LanguageDetectionCacheService,
|
||||
private val memories: TranslationMemoryService,
|
||||
private val materializer: TranslationReadModelMaterializer,
|
||||
private val scheduler: ResourceTranslationJobScheduler,
|
||||
private val entityManager: EntityManager,
|
||||
transactionManager: PlatformTransactionManager
|
||||
) {
|
||||
private val log = LoggerFactory.getLogger(javaClass)
|
||||
private val transaction = TransactionTemplate(transactionManager).apply {
|
||||
propagationBehavior = TransactionDefinition.PROPAGATION_REQUIRES_NEW
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
fun resolve(contentId: Long, targetLanguage: String): AudioContentDetailTranslationResult {
|
||||
var source = transaction.execute { snapshot(contentId) } ?: return AudioContentDetailTranslationResult(null)
|
||||
if (source.languageCode.isNullOrBlank()) {
|
||||
val beforeDetection = source
|
||||
try {
|
||||
val detected = detector.detectWithCache(source.query)?.detectedLanguage
|
||||
?: return AudioContentDetailTranslationResult(source.languageCode, detectionQuery = source.query)
|
||||
source = transaction.execute {
|
||||
val content = entityManager.find(AudioContent::class.java, contentId, LockModeType.PESSIMISTIC_WRITE)
|
||||
?: return@execute null
|
||||
val current = snapshot(contentId) ?: return@execute null
|
||||
if (current == beforeDetection) content.languageCode = detected
|
||||
snapshot(contentId)
|
||||
} ?: return AudioContentDetailTranslationResult(null)
|
||||
} catch (ex: Exception) {
|
||||
log.warn("Content detail language detection failed. contentId={}, error={}", contentId, ex.message)
|
||||
return AudioContentDetailTranslationResult(source.languageCode, detectionQuery = source.query)
|
||||
}
|
||||
}
|
||||
val language = source.languageCode
|
||||
if (language.isNullOrBlank()) return AudioContentDetailTranslationResult(language, detectionQuery = source.query)
|
||||
val target = targetLanguage.lowercase()
|
||||
if (
|
||||
!TranslationLanguages.isSupported(language) || !TranslationLanguages.isSupported(target) ||
|
||||
language.lowercase() == target
|
||||
) {
|
||||
return AudioContentDetailTranslationResult(language)
|
||||
}
|
||||
|
||||
val existing = transaction.execute { translations.findByContentIdAndLocale(contentId, target)?.renderedPayload }
|
||||
if (existing != null) {
|
||||
maintainRetries(contentId, target, scheduleMissing = false)
|
||||
return result(language, existing)
|
||||
}
|
||||
|
||||
return try {
|
||||
source.fields.forEach { field ->
|
||||
memories.ensureMemory(LanguageTranslationTargetType.CONTENT, field.fieldKey, field.sourceText, language, target)
|
||||
}
|
||||
val payload = transaction.execute {
|
||||
entityManager.find(AudioContent::class.java, contentId, LockModeType.PESSIMISTIC_WRITE)
|
||||
check(snapshot(contentId) == source) { "content translation source changed" }
|
||||
check(materializer.materialize(LanguageTranslationTargetType.CONTENT, contentId, target)) {
|
||||
"content translation is incomplete"
|
||||
}
|
||||
requireNotNull(translations.findByContentIdAndLocale(contentId, target)).renderedPayload
|
||||
}
|
||||
maintainRetries(contentId, target, scheduleMissing = false)
|
||||
result(language, requireNotNull(payload))
|
||||
} catch (ex: Exception) {
|
||||
log.warn("Content detail translation failed. contentId={}, locale={}, error={}", contentId, target, ex.message)
|
||||
maintainRetries(contentId, target, scheduleMissing = true)
|
||||
AudioContentDetailTranslationResult(language)
|
||||
}
|
||||
}
|
||||
|
||||
private fun maintainRetries(contentId: Long, target: String, scheduleMissing: Boolean) {
|
||||
try {
|
||||
transaction.executeWithoutResult {
|
||||
scheduler.restartFailedResourceTranslationsInCurrentTransaction(
|
||||
LanguageTranslationTargetType.CONTENT,
|
||||
listOf(contentId),
|
||||
target
|
||||
)
|
||||
if (scheduleMissing) {
|
||||
scheduler.scheduleResourceTranslation(LanguageTranslationTargetType.CONTENT, contentId, target)
|
||||
}
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
log.warn(
|
||||
"Content detail translation retry request failed. contentId={}, locale={}, error={}",
|
||||
contentId,
|
||||
target,
|
||||
ex.message
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun result(language: String, payload: ContentTranslationPayload) = AudioContentDetailTranslationResult(
|
||||
language,
|
||||
TranslatedContent(payload.title, payload.detail, payload.tags)
|
||||
)
|
||||
|
||||
private fun snapshot(contentId: Long): DetailSource? {
|
||||
val content = repository.findById(contentId).orElse(null) ?: return null
|
||||
val tags = content.audioContentHashTags.filter { it.isActive }.mapNotNull { it.hashTag?.tag }
|
||||
return DetailSource(
|
||||
content.languageCode,
|
||||
listOf(
|
||||
TranslationSourceField("title", content.title),
|
||||
TranslationSourceField("detail", content.detail),
|
||||
TranslationSourceField("tags", tags.joinToString(","))
|
||||
),
|
||||
listOf(content.title.trim(), content.detail.trim(), tags.joinToString(" ").trim())
|
||||
.filter { it.isNotBlank() }.joinToString(" ")
|
||||
)
|
||||
}
|
||||
|
||||
private data class DetailSource(val languageCode: String?, val fields: List<TranslationSourceField>, val query: String)
|
||||
}
|
||||
@@ -23,7 +23,6 @@ import kr.co.vividnext.sodalive.content.pin.PinContentRepository
|
||||
import kr.co.vividnext.sodalive.content.theme.AudioContentThemeQueryRepository
|
||||
import kr.co.vividnext.sodalive.content.theme.translation.ContentThemeTranslationRepository
|
||||
import kr.co.vividnext.sodalive.content.translation.ContentTranslationRepository
|
||||
import kr.co.vividnext.sodalive.content.translation.TranslatedContent
|
||||
import kr.co.vividnext.sodalive.explorer.ExplorerQueryRepository
|
||||
import kr.co.vividnext.sodalive.extensions.convertLocalDateTime
|
||||
import kr.co.vividnext.sodalive.fcm.FcmDeepLinkValue
|
||||
@@ -34,7 +33,6 @@ import kr.co.vividnext.sodalive.i18n.LangContext
|
||||
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
|
||||
import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationEvent
|
||||
import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationTargetType
|
||||
import kr.co.vividnext.sodalive.i18n.translation.ResourceTranslationJobScheduler
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.MemberRepository
|
||||
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
|
||||
@@ -83,8 +81,8 @@ class AudioContentService(
|
||||
private val pinContentRepository: PinContentRepository,
|
||||
private val memberRepository: MemberRepository,
|
||||
|
||||
private val resourceTranslationJobScheduler: ResourceTranslationJobScheduler,
|
||||
private val contentTranslationRepository: ContentTranslationRepository,
|
||||
private val detailTranslationService: AudioContentDetailTranslationService,
|
||||
|
||||
private val s3Uploader: S3Uploader,
|
||||
private val objectMapper: ObjectMapper,
|
||||
@@ -875,54 +873,14 @@ class AudioContentService(
|
||||
listOf()
|
||||
}
|
||||
|
||||
var translated: TranslatedContent? = null
|
||||
|
||||
/**
|
||||
* audioContent.languageCode != languageCode
|
||||
*
|
||||
* 번역 콘텐츠를 조회한다. - contentId, locale
|
||||
* 번역 콘텐츠가 있으면
|
||||
* TranslatedContent로 가공한다
|
||||
*
|
||||
* 번역 콘텐츠가 없으면
|
||||
* 누락 번역 job을 예약하고 원문 응답을 유지한다.
|
||||
*
|
||||
* 번역 대상: title, detail, tags
|
||||
*
|
||||
* 파파고로 번역한 데이터를 TranslatedContent로 가공한다
|
||||
*/
|
||||
if (audioContent.languageCode.isNullOrBlank()) {
|
||||
val translation = detailTranslationService.resolve(id, langContext.lang.code)
|
||||
if (translation.detectionQuery != null) {
|
||||
applicationEventPublisher.publishEvent(
|
||||
LanguageDetectEvent(
|
||||
id = id,
|
||||
query = listOf(audioContent.title.trim(), audioContent.detail.trim(), tag.trim())
|
||||
.filter { it.isNotBlank() }
|
||||
.joinToString(" ")
|
||||
query = translation.detectionQuery
|
||||
)
|
||||
)
|
||||
} else if (audioContent.languageCode != langContext.lang.code) {
|
||||
resourceTranslationJobScheduler.restartFailedResourceTranslations(
|
||||
LanguageTranslationTargetType.CONTENT,
|
||||
listOf(id),
|
||||
langContext.lang.code
|
||||
)
|
||||
val existing = contentTranslationRepository
|
||||
.findByContentIdAndLocale(audioContent.id!!, langContext.lang.code)
|
||||
|
||||
if (existing != null) {
|
||||
val payload = existing.renderedPayload
|
||||
translated = TranslatedContent(
|
||||
title = payload.title,
|
||||
detail = payload.detail,
|
||||
tags = payload.tags
|
||||
)
|
||||
} else {
|
||||
resourceTranslationJobScheduler.scheduleResourceTranslation(
|
||||
resourceType = LanguageTranslationTargetType.CONTENT,
|
||||
resourceId = audioContent.id!!,
|
||||
targetLanguage = langContext.lang.code
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -964,7 +922,7 @@ class AudioContentService(
|
||||
contentId = audioContent.id!!,
|
||||
title = audioContent.title,
|
||||
detail = contentDetail,
|
||||
languageCode = audioContent.languageCode,
|
||||
languageCode = translation.languageCode,
|
||||
coverImageUrl = "$coverImageHost/${audioContent.coverImage!!}",
|
||||
contentUrl = audioContentUrl,
|
||||
themeStr = themeStrTranslated,
|
||||
@@ -1009,7 +967,7 @@ class AudioContentService(
|
||||
nextContent = nextContent,
|
||||
buyerList = buyerList,
|
||||
isAvailableUsePoint = audioContent.isPointAvailable && audioContent.price > 0,
|
||||
translated = translated,
|
||||
translated = translation.translated,
|
||||
subtitle = if (
|
||||
(isExistsAudioContent || creatorId == member.id || audioContent.price <= 0) &&
|
||||
(audioContent.releaseDate == null || audioContent.releaseDate!! <= LocalDateTime.now() || creatorId == member.id)
|
||||
|
||||
+11
@@ -1,9 +1,20 @@
|
||||
package kr.co.vividnext.sodalive.content.translation
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.data.jpa.repository.Lock
|
||||
import org.springframework.data.jpa.repository.Query
|
||||
import org.springframework.data.repository.query.Param
|
||||
import javax.persistence.LockModeType
|
||||
|
||||
interface ContentTranslationRepository : JpaRepository<ContentTranslation, Long> {
|
||||
fun findByContentIdAndLocale(contentId: Long, locale: String): ContentTranslation?
|
||||
|
||||
@Lock(LockModeType.PESSIMISTIC_WRITE)
|
||||
@Query("select t from ContentTranslation t where t.contentId = :contentId and t.locale = :locale")
|
||||
fun findByContentIdAndLocaleForUpdate(
|
||||
@Param("contentId") contentId: Long,
|
||||
@Param("locale") locale: String
|
||||
): ContentTranslation?
|
||||
|
||||
fun findByContentIdInAndLocale(contentIds: List<Long>, locale: String): List<ContentTranslation>
|
||||
}
|
||||
|
||||
@@ -10,8 +10,7 @@ import java.time.LocalDateTime
|
||||
@Component
|
||||
class TranslationJobWorker(
|
||||
private val translationJobRepository: TranslationJobRepository,
|
||||
private val translationMemoryRepository: TranslationMemoryRepository,
|
||||
private val translationCoordinator: TranslationCoordinator,
|
||||
private val translationMemoryService: TranslationMemoryService,
|
||||
private val materializer: TranslationReadModelMaterializer,
|
||||
transactionManager: PlatformTransactionManager
|
||||
) {
|
||||
@@ -34,7 +33,13 @@ class TranslationJobWorker(
|
||||
val failedJobs = mutableListOf<Pair<TranslationJob, Exception>>()
|
||||
jobs.forEach { job ->
|
||||
try {
|
||||
ensureMemory(job)
|
||||
translationMemoryService.ensureMemory(
|
||||
job.resourceType,
|
||||
job.fieldKey,
|
||||
job.sourceText,
|
||||
job.sourceLanguage,
|
||||
job.targetLanguage
|
||||
)
|
||||
succeededJobs.add(job)
|
||||
} catch (ex: Exception) {
|
||||
failedJobs.add(job to ex)
|
||||
@@ -68,57 +73,6 @@ class TranslationJobWorker(
|
||||
}.orEmpty()
|
||||
}
|
||||
|
||||
private fun ensureMemory(job: TranslationJob) {
|
||||
val rejectUnchangedAwsResult = job.resourceType == LanguageTranslationTargetType.CONTENT && job.fieldKey == "tags"
|
||||
val existing = translationCoordinator.findCached(
|
||||
job.sourceHash,
|
||||
job.sourceLanguage,
|
||||
job.targetLanguage,
|
||||
rejectUnchangedAwsResult
|
||||
)
|
||||
if (existing != null) return
|
||||
|
||||
val response = translationCoordinator.translate(
|
||||
TranslateRequest(
|
||||
texts = listOf(job.sourceText),
|
||||
sourceLanguage = job.sourceLanguage,
|
||||
targetLanguage = job.targetLanguage,
|
||||
rejectUnchangedAwsResult = rejectUnchangedAwsResult
|
||||
)
|
||||
)
|
||||
val translated = response.result.translatedText.single()
|
||||
|
||||
transactionTemplate.executeWithoutResult {
|
||||
val memory = translationMemoryRepository
|
||||
.findBySourceHashAndSourceLanguageAndTargetLanguageAndProviderAndNormalizationVersion(
|
||||
sourceHash = job.sourceHash,
|
||||
sourceLanguage = job.sourceLanguage,
|
||||
targetLanguage = job.targetLanguage,
|
||||
provider = response.providerId.code,
|
||||
normalizationVersion = SourceTextNormalizer.NORMALIZATION_VERSION
|
||||
)
|
||||
if (memory == null) {
|
||||
translationMemoryRepository.save(
|
||||
TranslationMemory(
|
||||
sourceHash = job.sourceHash,
|
||||
sourceText = job.sourceText,
|
||||
sourceLanguage = job.sourceLanguage,
|
||||
targetLanguage = job.targetLanguage,
|
||||
translatedText = translated,
|
||||
provider = response.providerId.code,
|
||||
providerVersion = response.providerVersion
|
||||
)
|
||||
)
|
||||
} else if (
|
||||
rejectUnchangedAwsResult && response.providerId == LanguageProviderId.AWS &&
|
||||
SourceTextNormalizer.hasSameCommaSeparatedText(memory.sourceText, memory.translatedText)
|
||||
) {
|
||||
memory.translatedText = translated
|
||||
translationMemoryRepository.save(memory)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun completeJob(jobId: Long) {
|
||||
transactionTemplate.executeWithoutResult {
|
||||
val job = translationJobRepository.findById(jobId).orElse(null) ?: return@executeWithoutResult
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
package kr.co.vividnext.sodalive.i18n.translation
|
||||
|
||||
import org.hibernate.exception.ConstraintViolationException
|
||||
import org.springframework.dao.DataIntegrityViolationException
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.transaction.PlatformTransactionManager
|
||||
import org.springframework.transaction.TransactionDefinition
|
||||
import org.springframework.transaction.annotation.Propagation
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import org.springframework.transaction.support.TransactionTemplate
|
||||
import java.sql.SQLException
|
||||
|
||||
@Service
|
||||
class TranslationMemoryService(
|
||||
private val translationMemoryRepository: TranslationMemoryRepository,
|
||||
private val translationCoordinator: TranslationCoordinator,
|
||||
transactionManager: PlatformTransactionManager
|
||||
) {
|
||||
private val transaction = TransactionTemplate(transactionManager).apply {
|
||||
propagationBehavior = TransactionDefinition.PROPAGATION_REQUIRES_NEW
|
||||
}
|
||||
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
fun ensureMemory(
|
||||
resourceType: LanguageTranslationTargetType,
|
||||
fieldKey: String,
|
||||
sourceText: String,
|
||||
sourceLanguage: String,
|
||||
targetLanguage: String
|
||||
) {
|
||||
val text = SourceTextNormalizer.normalize(sourceText)
|
||||
if (text.isBlank()) return
|
||||
val sourceHash = SourceTextNormalizer.hash(text)
|
||||
val source = sourceLanguage.lowercase()
|
||||
val target = targetLanguage.lowercase()
|
||||
val rejectUnchangedAwsResult = resourceType == LanguageTranslationTargetType.CONTENT && fieldKey == "tags"
|
||||
val existing = transaction.execute {
|
||||
translationCoordinator.findCached(sourceHash, source, target, rejectUnchangedAwsResult)
|
||||
}
|
||||
if (existing != null) return
|
||||
|
||||
val response = translationCoordinator.translate(
|
||||
TranslateRequest(listOf(text), source, target, rejectUnchangedAwsResult)
|
||||
)
|
||||
val translated = response.result.translatedText.single()
|
||||
try {
|
||||
transaction.executeWithoutResult {
|
||||
val memory = translationMemoryRepository
|
||||
.findBySourceHashAndSourceLanguageAndTargetLanguageAndProviderAndNormalizationVersion(
|
||||
sourceHash,
|
||||
source,
|
||||
target,
|
||||
response.providerId.code,
|
||||
SourceTextNormalizer.NORMALIZATION_VERSION
|
||||
)
|
||||
if (memory == null) {
|
||||
translationMemoryRepository.save(
|
||||
TranslationMemory(
|
||||
sourceHash,
|
||||
text,
|
||||
source,
|
||||
target,
|
||||
translated,
|
||||
response.providerId.code,
|
||||
response.providerVersion
|
||||
)
|
||||
)
|
||||
} else if (
|
||||
rejectUnchangedAwsResult && response.providerId == LanguageProviderId.AWS &&
|
||||
SourceTextNormalizer.hasSameCommaSeparatedText(memory.sourceText, memory.translatedText)
|
||||
) {
|
||||
memory.translatedText = translated
|
||||
translationMemoryRepository.save(memory)
|
||||
}
|
||||
}
|
||||
} catch (ex: DataIntegrityViolationException) {
|
||||
val constraint = generateSequence<Throwable>(ex) { it.cause }
|
||||
.filterIsInstance<ConstraintViolationException>().firstOrNull()?.constraintName
|
||||
if (constraint?.contains("uk_translation_memory_source_target_provider", ignoreCase = true) != true) throw ex
|
||||
val sql = generateSequence<Throwable>(ex) { it.cause }.filterIsInstance<SQLException>().firstOrNull()
|
||||
if (sql?.sqlState != "23505" && sql?.errorCode != 1062) throw ex
|
||||
val winner = transaction.execute {
|
||||
translationCoordinator.findCached(sourceHash, source, target, rejectUnchangedAwsResult)
|
||||
}
|
||||
if (winner == null) throw ex
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -6,6 +6,7 @@ import kr.co.vividnext.sodalive.chat.character.translate.AiCharacterTranslationR
|
||||
import kr.co.vividnext.sodalive.chat.original.translation.OriginalWorkTranslation
|
||||
import kr.co.vividnext.sodalive.chat.original.translation.OriginalWorkTranslationPayload
|
||||
import kr.co.vividnext.sodalive.chat.original.translation.OriginalWorkTranslationRepository
|
||||
import kr.co.vividnext.sodalive.content.AudioContent
|
||||
import kr.co.vividnext.sodalive.content.category.CategoryTranslation
|
||||
import kr.co.vividnext.sodalive.content.category.CategoryTranslationRepository
|
||||
import kr.co.vividnext.sodalive.content.series.translation.SeriesGenreTranslation
|
||||
@@ -90,7 +91,8 @@ class TranslationReadModelMaterializer(
|
||||
detail = translations["detail"].orEmpty(),
|
||||
tags = translations["tags"].orEmpty()
|
||||
)
|
||||
val existing = contentTranslationRepository.findByContentIdAndLocale(resourceId, targetLanguage)
|
||||
entityManager.find(AudioContent::class.java, resourceId, LockModeType.PESSIMISTIC_WRITE)
|
||||
val existing = contentTranslationRepository.findByContentIdAndLocaleForUpdate(resourceId, targetLanguage)
|
||||
if (existing == null) {
|
||||
contentTranslationRepository.save(ContentTranslation(resourceId, targetLanguage, payload))
|
||||
} else {
|
||||
|
||||
+1
@@ -52,6 +52,7 @@ class TranslationSourceExtractor(
|
||||
val content = audioContentRepository.findByIdOrNull(resourceId) ?: return null
|
||||
val sourceLanguage = content.languageCode?.takeIf { it.isNotBlank() } ?: return null
|
||||
val tags = content.audioContentHashTags
|
||||
.filter { it.isActive }
|
||||
.mapNotNull { it.hashTag?.tag }
|
||||
.joinToString(",")
|
||||
return TranslationSource(
|
||||
|
||||
+389
@@ -0,0 +1,389 @@
|
||||
package kr.co.vividnext.sodalive.content
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import kr.co.vividnext.sodalive.content.hashtag.AudioContentHashTag
|
||||
import kr.co.vividnext.sodalive.content.hashtag.HashTag
|
||||
import kr.co.vividnext.sodalive.content.theme.AudioContentTheme
|
||||
import kr.co.vividnext.sodalive.content.translation.ContentTranslationRepository
|
||||
import kr.co.vividnext.sodalive.i18n.translation.LanguageTranslationTargetType
|
||||
import kr.co.vividnext.sodalive.i18n.translation.ResourceTranslationJobScheduler
|
||||
import kr.co.vividnext.sodalive.i18n.translation.SourceTextNormalizer
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationJob
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationJobRepository
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationJobStatus
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationJobWorker
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationMemory
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationMemoryRepository
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.MemberRole
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.NullAndEmptySource
|
||||
import org.junit.jupiter.params.provider.ValueSource
|
||||
import org.mockito.Mockito
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.boot.test.mock.mockito.SpyBean
|
||||
import org.springframework.boot.test.web.client.TestRestTemplate
|
||||
import org.springframework.http.HttpEntity
|
||||
import org.springframework.http.HttpHeaders
|
||||
import org.springframework.http.HttpMethod
|
||||
import org.springframework.jdbc.core.JdbcTemplate
|
||||
import org.springframework.test.context.ActiveProfiles
|
||||
import org.springframework.transaction.PlatformTransactionManager
|
||||
import org.springframework.transaction.TransactionDefinition
|
||||
import org.springframework.transaction.support.TransactionTemplate
|
||||
import java.time.LocalDateTime
|
||||
import java.util.concurrent.Callable
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
import javax.persistence.EntityManager
|
||||
|
||||
@SpringBootTest(
|
||||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
|
||||
classes = [ContentDetailTranslationTestConfiguration::class],
|
||||
properties = ["spring.cache.type=none", "spring.jpa.properties.hibernate.show_sql=false"]
|
||||
)
|
||||
@ActiveProfiles("content-detail-translation-test")
|
||||
class AudioContentDetailTranslationHttpIntegrationTest @Autowired constructor(
|
||||
private val http: TestRestTemplate,
|
||||
private val mapper: ObjectMapper,
|
||||
private val provider: DetailTranslationProvider,
|
||||
private val translations: ContentTranslationRepository,
|
||||
private val memories: TranslationMemoryRepository,
|
||||
private val jobs: TranslationJobRepository,
|
||||
private val jdbc: JdbcTemplate,
|
||||
private val worker: TranslationJobWorker,
|
||||
private val scheduler: ResourceTranslationJobScheduler,
|
||||
private val entityManager: EntityManager,
|
||||
transactionManager: PlatformTransactionManager
|
||||
) {
|
||||
private val transaction = TransactionTemplate(transactionManager).apply {
|
||||
propagationBehavior = TransactionDefinition.PROPAGATION_REQUIRES_NEW
|
||||
}
|
||||
|
||||
@SpyBean
|
||||
private lateinit var memoryWriter: TranslationMemoryRepository
|
||||
|
||||
@SpyBean
|
||||
private lateinit var jobClaims: TranslationJobRepository
|
||||
|
||||
@BeforeEach
|
||||
fun prepare() {
|
||||
provider.reset()
|
||||
jobs.deleteAllInBatch()
|
||||
translations.deleteAllInBatch()
|
||||
memories.deleteAllInBatch()
|
||||
jdbc.update("delete from language_detection_result")
|
||||
Mockito.doAnswer {
|
||||
jobs.findAll().filter { it.status == TranslationJobStatus.PENDING }.mapNotNull { it.id }
|
||||
}.`when`(jobClaims).findNextPendingGroupJobIdsForUpdate(Mockito.any(LocalDateTime::class.java) ?: LocalDateTime.now())
|
||||
// H2 JSON wraps converter output in a JSON string; keep the real converter's MySQL text contract.
|
||||
jdbc.execute("alter table content_translation alter column rendered_payload varchar(1000000)")
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("첫 상세 HTTP 응답은 번역을 커밋하고 재조회는 저장 결과를 재사용한다")
|
||||
fun shouldReturnCommittedTranslationOnFirstRequestAndReuseIt() {
|
||||
val fixture = fixture()
|
||||
|
||||
val response = detail(fixture)
|
||||
|
||||
assertTranslation(response, "English title", "English detail", "#Healing")
|
||||
transaction.executeWithoutResult {
|
||||
val payload = translations.findByContentIdAndLocale(fixture.first, "en")!!.renderedPayload
|
||||
assertEquals("English title", payload.title)
|
||||
assertEquals("English detail", payload.detail)
|
||||
assertEquals("#Healing", payload.tags)
|
||||
}
|
||||
assertEquals(3, provider.calls.get())
|
||||
assertEquals(setOf("en"), memories.findAll().map { it.targetLanguage }.toSet())
|
||||
assertEquals(0L, jobs.count())
|
||||
assertEquals(response.path("translated"), detail(fixture).path("translated"))
|
||||
assertEquals(3, provider.calls.get())
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@NullAndEmptySource
|
||||
@ValueSource(strings = [" \t "])
|
||||
@DisplayName("미감지 언어는 같은 상세 응답 전에 감지하고 언어와 번역을 커밋한다")
|
||||
fun shouldDetectMissingLanguageBeforeReturningTranslation(language: String?) {
|
||||
val fixture = fixture(language)
|
||||
|
||||
val response = detail(fixture)
|
||||
|
||||
assertTranslation(response, "English title", "English detail", "#Healing")
|
||||
assertEquals("ko", response.path("languageCode").textValue())
|
||||
assertEquals("ko", transaction.execute { entityManager.find(AudioContent::class.java, fixture.first).languageCode })
|
||||
assertEquals(listOf("원문 제목 원문 설명 #힐링"), provider.detectionQueries)
|
||||
assertEquals(0L, jobs.count())
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("기존 메모리만으로 빈 필드를 포함한 상세 번역을 저장하고 공급자를 호출하지 않는다")
|
||||
fun shouldMaterializeCachedFieldsAndKeepBlankFieldsEmpty() {
|
||||
val fixture = fixture(detail = " ", tags = false)
|
||||
memories.saveAndFlush(
|
||||
TranslationMemory(SourceTextNormalizer.hash("원문 제목"), "원문 제목", "ko", "en", "Cached title", "aws", "test")
|
||||
)
|
||||
|
||||
val response = detail(fixture)
|
||||
|
||||
assertTranslation(response, "Cached title", "", "")
|
||||
assertEquals(0, provider.calls.get())
|
||||
assertEquals(0L, jobs.count())
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = ["en", "fr"])
|
||||
@DisplayName("동일 언어와 미지원 원문 언어에는 동기 번역이나 작업을 만들지 않는다")
|
||||
fun shouldKeepOriginalForSameOrUnsupportedLanguage(language: String) {
|
||||
val fixture = fixture(language)
|
||||
|
||||
val response = detail(fixture)
|
||||
|
||||
assertTrue(response.path("translated").isNull)
|
||||
assertEquals("원문 제목", response.path("title").textValue())
|
||||
assertEquals(0, provider.calls.get())
|
||||
assertEquals(0L, jobs.count())
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("공급자 실패는 원문과 작업을 반환하고 worker가 누락 필드만 복구한다")
|
||||
fun shouldReturnOriginalAndRecoverPartialTranslationThroughWorker() {
|
||||
val fixture = fixture()
|
||||
provider.beforeTranslate = { if (provider.calls.get() == 2) provider.fail = true }
|
||||
|
||||
val response = detail(fixture)
|
||||
|
||||
assertTrue(response.path("translated").isNull)
|
||||
assertEquals("원문 제목", response.path("title").textValue())
|
||||
assertEquals(1L, memories.count())
|
||||
assertEquals(3L, jobs.count())
|
||||
provider.fail = false
|
||||
provider.beforeTranslate = {}
|
||||
assertTrue(worker.processNextGroup())
|
||||
assertEquals(4, provider.calls.get())
|
||||
assertEquals(setOf(TranslationJobStatus.COMPLETED), jobs.findAll().map { it.status }.toSet())
|
||||
assertTranslation(detail(fixture), "English title", "English detail", "#Healing")
|
||||
assertEquals(4, provider.calls.get())
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("실제 payload 제약 위반은 상세 트랜잭션을 오염시키지 않고 작업으로 복구된다")
|
||||
fun shouldIsolateRealPersistenceFailureAndRecoverFromCommittedMemories() {
|
||||
val fixture = fixture()
|
||||
jdbc.execute(
|
||||
"alter table content_translation add constraint reject_detail_payload check (content_id <> ${fixture.first})"
|
||||
)
|
||||
try {
|
||||
val response = detail(fixture)
|
||||
|
||||
assertTrue(response.path("translated").isNull)
|
||||
assertEquals("원문 제목", response.path("title").textValue())
|
||||
assertEquals(0L, translations.count())
|
||||
assertEquals(3L, memories.count())
|
||||
assertEquals(3L, jobs.count())
|
||||
} finally {
|
||||
jdbc.execute("alter table content_translation drop constraint reject_detail_payload")
|
||||
}
|
||||
assertTrue(worker.processNextGroup())
|
||||
assertTranslation(detail(fixture), "English title", "English detail", "#Healing")
|
||||
assertEquals(3, provider.calls.get())
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("메모리 update의 commit 시점 제약 위반도 원문을 반환하고 기존 재시도로 복구한다")
|
||||
fun shouldIsolateMemoryCommitFailure() {
|
||||
val fixture = fixture()
|
||||
memories.saveAndFlush(
|
||||
TranslationMemory(SourceTextNormalizer.hash("#힐링"), "#힐링", "ko", "en", "#힐링", "aws", "test")
|
||||
)
|
||||
jdbc.execute("alter table translation_memory add constraint reject_tag_update check (translated_text <> '#Healing')")
|
||||
try {
|
||||
val response = detail(fixture)
|
||||
|
||||
assertTrue(response.path("translated").isNull)
|
||||
assertEquals("원문 제목", response.path("title").textValue())
|
||||
assertEquals("#힐링", memories.findAll().single { it.sourceText == "#힐링" }.translatedText)
|
||||
assertEquals(3L, jobs.count())
|
||||
} finally {
|
||||
jdbc.execute("alter table translation_memory drop constraint reject_tag_update")
|
||||
}
|
||||
assertTrue(worker.processNextGroup())
|
||||
assertTranslation(detail(fixture), "English title", "English detail", "#Healing")
|
||||
assertEquals(4, provider.calls.get())
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("감지 실패 응답 뒤 기존 after-commit 이벤트가 언어와 비동기 작업을 복구한다")
|
||||
fun shouldRetainAfterCommitDetectionRecovery() {
|
||||
val fixture = fixture(null)
|
||||
provider.detection = null
|
||||
provider.beforeDetect = { if (provider.detectionQueries.size == 2) provider.detection = "ko" }
|
||||
|
||||
val response = detail(fixture)
|
||||
|
||||
assertTrue(response.path("translated").isNull)
|
||||
assertTrue(response.path("languageCode").isNull)
|
||||
assertEquals("ko", transaction.execute { entityManager.find(AudioContent::class.java, fixture.first).languageCode })
|
||||
assertEquals(6L, jobs.count())
|
||||
assertEquals(0, provider.calls.get())
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("감지 중 커밋된 원문과 언어 수정은 동기 감지나 외부 managed entity가 덮어쓰지 않는다")
|
||||
fun shouldPreserveConcurrentLanguageAndSourceEdit() {
|
||||
val fixture = fixture(null)
|
||||
provider.beforeDetect = {
|
||||
transaction.executeWithoutResult {
|
||||
entityManager.find(AudioContent::class.java, fixture.first).apply {
|
||||
title = "Edited title"
|
||||
languageCode = "en"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val response = detail(fixture)
|
||||
|
||||
assertEquals("en", response.path("languageCode").textValue())
|
||||
assertTrue(response.path("translated").isNull)
|
||||
transaction.executeWithoutResult {
|
||||
val content = entityManager.find(AudioContent::class.java, fixture.first)
|
||||
assertEquals("en", content.languageCode)
|
||||
assertEquals("Edited title", content.title)
|
||||
}
|
||||
assertEquals(0L, jobs.count())
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("기존 번역은 FAILED 재개 유지보수의 실제 DB 실패에도 반환된다")
|
||||
fun shouldReturnExistingTranslationWhenRetryMaintenanceFails() {
|
||||
val fixture = fixture()
|
||||
val first = detail(fixture)
|
||||
jobs.saveAndFlush(
|
||||
TranslationJob(
|
||||
LanguageTranslationTargetType.CONTENT, fixture.first, "title", SourceTextNormalizer.hash("원문 제목"),
|
||||
"원문 제목", "ko", "en", TranslationJobStatus.FAILED, 6
|
||||
)
|
||||
)
|
||||
jdbc.execute("alter table translation_job add constraint reject_restart check (status <> 'PENDING')")
|
||||
try {
|
||||
assertEquals(first.path("translated"), detail(fixture).path("translated"))
|
||||
assertEquals(TranslationJobStatus.FAILED, jobs.findAll().single().status)
|
||||
assertEquals(3, provider.calls.get())
|
||||
} finally {
|
||||
jdbc.execute("alter table translation_job drop constraint reject_restart")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("누락 번역의 동기 성공도 기존 FAILED 행만 재개하고 새 작업은 만들지 않는다")
|
||||
fun shouldRestartOnlyExistingFailedJobAfterSynchronousSuccess() {
|
||||
val fixture = fixture()
|
||||
val failed = jobs.saveAndFlush(
|
||||
TranslationJob(
|
||||
LanguageTranslationTargetType.CONTENT, fixture.first, "title", SourceTextNormalizer.hash("원문 제목"),
|
||||
"원문 제목", "ko", "en", TranslationJobStatus.FAILED, 6
|
||||
)
|
||||
)
|
||||
|
||||
assertTranslation(detail(fixture), "English title", "English detail", "#Healing")
|
||||
|
||||
val restarted = jobs.findAll().single()
|
||||
assertEquals(failed.id, restarted.id)
|
||||
assertEquals(TranslationJobStatus.PENDING, restarted.status)
|
||||
assertEquals(0, restarted.retryCount)
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("동시 상세와 worker의 메모리 유일키 경합은 커밋된 한 결과로 수렴한다")
|
||||
fun shouldConvergeConcurrentDetailAndWorkerStorage() {
|
||||
val fixture = fixture()
|
||||
scheduler.scheduleResourceTranslation(LanguageTranslationTargetType.CONTENT, fixture.first, "en")
|
||||
val inserts = CountDownLatch(3)
|
||||
val originalSave = Mockito.mockingDetails(memoryWriter).mockCreationSettings.defaultAnswer
|
||||
Mockito.doAnswer { invocation ->
|
||||
val memory = invocation.getArgument<TranslationMemory>(0)
|
||||
if (memory.sourceText == "원문 제목") {
|
||||
inserts.countDown()
|
||||
check(inserts.await(10, TimeUnit.SECONDS)) { "competing memory inserts did not arrive" }
|
||||
}
|
||||
originalSave.answer(invocation)
|
||||
}.`when`(memoryWriter).save(Mockito.any(TranslationMemory::class.java) ?: TranslationMemory("", "", "", "", "", "", ""))
|
||||
val pool = Executors.newFixedThreadPool(3)
|
||||
try {
|
||||
val left = pool.submit(Callable { detail(fixture) })
|
||||
val right = pool.submit(Callable { detail(fixture) })
|
||||
val background = pool.submit(Callable { worker.processNextGroup() })
|
||||
assertTranslation(left.get(20, TimeUnit.SECONDS), "English title", "English detail", "#Healing")
|
||||
assertTranslation(right.get(20, TimeUnit.SECONDS), "English title", "English detail", "#Healing")
|
||||
assertTrue(background.get(20, TimeUnit.SECONDS))
|
||||
assertEquals(3L, memories.count())
|
||||
assertEquals(1L, translations.count())
|
||||
assertEquals(setOf(TranslationJobStatus.COMPLETED), jobs.findAll().map { it.status }.toSet())
|
||||
val calls = provider.calls.get()
|
||||
assertTranslation(detail(fixture), "English title", "English detail", "#Healing")
|
||||
assertEquals(calls, provider.calls.get())
|
||||
} finally {
|
||||
pool.shutdownNow()
|
||||
check(pool.awaitTermination(5, TimeUnit.SECONDS))
|
||||
}
|
||||
}
|
||||
|
||||
private fun detail(fixture: Pair<Long, Long>): JsonNode {
|
||||
val response = http.exchange(
|
||||
"/audio-content/${fixture.first}?timezone=UTC",
|
||||
HttpMethod.GET,
|
||||
HttpEntity<Void>(HttpHeaders().apply { set("X-Test-Member", fixture.second.toString()) }),
|
||||
String::class.java
|
||||
)
|
||||
assertEquals(200, response.statusCodeValue, response.body)
|
||||
val body = mapper.readTree(response.body)
|
||||
assertTrue(body.path("success").booleanValue(), response.body)
|
||||
return body.path("data")
|
||||
}
|
||||
|
||||
private fun assertTranslation(response: JsonNode, title: String, detail: String, tags: String) {
|
||||
assertEquals(title, response.path("translated").path("title").textValue())
|
||||
assertEquals(detail, response.path("translated").path("detail").textValue())
|
||||
assertEquals(tags, response.path("translated").path("tags").textValue())
|
||||
}
|
||||
|
||||
private fun fixture(language: String? = "ko", detail: String = "원문 설명", tags: Boolean = true): Pair<Long, Long> =
|
||||
transaction.execute {
|
||||
val creator = Member(password = "test", nickname = "detail-creator", role = MemberRole.CREATOR)
|
||||
val viewer = Member(password = "test", nickname = "detail-viewer")
|
||||
val theme = AudioContentTheme("테마", "theme.png")
|
||||
listOf(creator, viewer, theme).forEach(entityManager::persist)
|
||||
val content = AudioContent("원문 제목", detail, language, isCommentAvailable = false).apply {
|
||||
member = creator
|
||||
this.theme = theme
|
||||
this.content = "output/audio.mp3"
|
||||
coverImage = "cover.png"
|
||||
duration = "00:01:00"
|
||||
isActive = true
|
||||
}
|
||||
entityManager.persist(content)
|
||||
if (tags) {
|
||||
listOf("#힐링" to true, "#비활성" to false).forEach { (tag, active) ->
|
||||
val hashTag = HashTag(tag)
|
||||
entityManager.persist(hashTag)
|
||||
entityManager.persist(
|
||||
AudioContentHashTag().apply {
|
||||
audioContent = content
|
||||
this.hashTag = hashTag
|
||||
isActive = active
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
requireNotNull(content.id) to requireNotNull(viewer.id)
|
||||
}!!
|
||||
}
|
||||
@@ -19,7 +19,6 @@ import kr.co.vividnext.sodalive.content.translation.ContentTranslationRepository
|
||||
import kr.co.vividnext.sodalive.explorer.ExplorerQueryRepository
|
||||
import kr.co.vividnext.sodalive.i18n.LangContext
|
||||
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
|
||||
import kr.co.vividnext.sodalive.i18n.translation.ResourceTranslationJobScheduler
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.MemberRepository
|
||||
import kr.co.vividnext.sodalive.member.block.BlockMemberRepository
|
||||
@@ -60,7 +59,6 @@ class AudioContentServiceTest {
|
||||
private lateinit var audioContentLikeRepository: AudioContentLikeRepository
|
||||
private lateinit var pinContentRepository: PinContentRepository
|
||||
private lateinit var memberRepository: MemberRepository
|
||||
private lateinit var resourceTranslationJobScheduler: ResourceTranslationJobScheduler
|
||||
private lateinit var contentTranslationRepository: ContentTranslationRepository
|
||||
private lateinit var s3Uploader: S3Uploader
|
||||
private lateinit var audioContentCloudFront: AudioContentCloudFront
|
||||
@@ -87,7 +85,6 @@ class AudioContentServiceTest {
|
||||
audioContentLikeRepository = Mockito.mock(AudioContentLikeRepository::class.java)
|
||||
pinContentRepository = Mockito.mock(PinContentRepository::class.java)
|
||||
memberRepository = Mockito.mock(MemberRepository::class.java)
|
||||
resourceTranslationJobScheduler = Mockito.mock(ResourceTranslationJobScheduler::class.java)
|
||||
contentTranslationRepository = Mockito.mock(ContentTranslationRepository::class.java)
|
||||
s3Uploader = Mockito.mock(S3Uploader::class.java)
|
||||
audioContentCloudFront = Mockito.mock(AudioContentCloudFront::class.java)
|
||||
@@ -112,8 +109,11 @@ class AudioContentServiceTest {
|
||||
audioContentLikeRepository = audioContentLikeRepository,
|
||||
pinContentRepository = pinContentRepository,
|
||||
memberRepository = memberRepository,
|
||||
resourceTranslationJobScheduler = resourceTranslationJobScheduler,
|
||||
contentTranslationRepository = contentTranslationRepository,
|
||||
detailTranslationService = Mockito.mock(AudioContentDetailTranslationService::class.java).also {
|
||||
Mockito.`when`(it.resolve(Mockito.anyLong(), Mockito.anyString()))
|
||||
.thenReturn(AudioContentDetailTranslationResult("ko"))
|
||||
},
|
||||
s3Uploader = s3Uploader,
|
||||
objectMapper = ObjectMapper(),
|
||||
audioContentCloudFront = audioContentCloudFront,
|
||||
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
package kr.co.vividnext.sodalive.content
|
||||
|
||||
import kr.co.vividnext.sodalive.aws.cloudfront.AudioContentCloudFront
|
||||
import kr.co.vividnext.sodalive.aws.s3.S3Uploader
|
||||
import kr.co.vividnext.sodalive.configs.QueryDslConfig
|
||||
import kr.co.vividnext.sodalive.content.theme.AudioContentThemeQueryRepository
|
||||
import kr.co.vividnext.sodalive.explorer.ExplorerQueryRepository
|
||||
import kr.co.vividnext.sodalive.i18n.Lang
|
||||
import kr.co.vividnext.sodalive.i18n.LangContext
|
||||
import kr.co.vividnext.sodalive.i18n.SodaMessageSource
|
||||
import kr.co.vividnext.sodalive.i18n.translation.LanguageDetectionProvider
|
||||
import kr.co.vividnext.sodalive.i18n.translation.LanguageProviderId
|
||||
import kr.co.vividnext.sodalive.i18n.translation.LanguageProviderProperties
|
||||
import kr.co.vividnext.sodalive.i18n.translation.ResourceTranslationJobScheduler
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslateRequest
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslateResult
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationCoordinator
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationJobScheduler
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationJobWorker
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationMemoryService
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationProvider
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationReadModelMaterializer
|
||||
import kr.co.vividnext.sodalive.i18n.translation.TranslationSourceExtractor
|
||||
import kr.co.vividnext.sodalive.member.Member
|
||||
import kr.co.vividnext.sodalive.member.MemberAdapter
|
||||
import kr.co.vividnext.sodalive.member.MemberRepository
|
||||
import kr.co.vividnext.sodalive.member.contentpreference.MemberContentPreferenceService
|
||||
import kr.co.vividnext.sodalive.member.contentpreference.ViewerContentPreference
|
||||
import kr.co.vividnext.sodalive.v2.creator.channel.community.translation.application.CreatorCommunityTranslationService
|
||||
import kr.co.vividnext.sodalive.v2.creatorname.application.CreatorLocalizedNameService
|
||||
import kr.co.vividnext.sodalive.v2.home.following.application.HomeFollowingNewsPublishService
|
||||
import kr.co.vividnext.sodalive.v2.recommendation.application.CreatorContentViewHistoryService
|
||||
import kr.co.vividnext.sodalive.v2.subtitle.application.SubtitleJobService
|
||||
import org.mockito.Mockito
|
||||
import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan
|
||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration
|
||||
import org.springframework.boot.test.mock.mockito.MockBean
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.context.annotation.Import
|
||||
import org.springframework.context.annotation.Profile
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
|
||||
import org.springframework.security.core.context.SecurityContextHolder
|
||||
import org.springframework.security.web.method.annotation.AuthenticationPrincipalArgumentResolver
|
||||
import org.springframework.web.filter.OncePerRequestFilter
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
|
||||
import java.util.Collections
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import javax.servlet.FilterChain
|
||||
import javax.servlet.http.HttpServletRequest
|
||||
import javax.servlet.http.HttpServletResponse
|
||||
|
||||
@Configuration
|
||||
@Profile("content-detail-translation-test")
|
||||
@EnableAutoConfiguration(exclude = [SecurityAutoConfiguration::class, ManagementWebSecurityAutoConfiguration::class])
|
||||
@EntityScan("kr.co.vividnext.sodalive")
|
||||
@EnableJpaRepositories("kr.co.vividnext.sodalive")
|
||||
@Import(
|
||||
QueryDslConfig::class, AudioContentService::class, AudioContentController::class,
|
||||
ExplorerQueryRepository::class, AudioContentThemeQueryRepository::class, SodaMessageSource::class,
|
||||
LangContext::class, TranslationSourceExtractor::class, TranslationCoordinator::class,
|
||||
TranslationJobScheduler::class, ResourceTranslationJobScheduler::class,
|
||||
TranslationReadModelMaterializer::class, LanguageDetectionCacheService::class,
|
||||
AudioContentDetailTranslationService::class, TranslationMemoryService::class, TranslationJobWorker::class,
|
||||
LanguageDetectListener::class
|
||||
)
|
||||
@MockBean(
|
||||
classes = [
|
||||
S3Uploader::class, CreatorContentViewHistoryService::class, CreatorLocalizedNameService::class,
|
||||
HomeFollowingNewsPublishService::class, SubtitleJobService::class, CreatorCommunityTranslationService::class
|
||||
]
|
||||
)
|
||||
class ContentDetailTranslationTestConfiguration : WebMvcConfigurer {
|
||||
override fun addArgumentResolvers(resolvers: MutableList<HandlerMethodArgumentResolver>) {
|
||||
resolvers.add(AuthenticationPrincipalArgumentResolver())
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun properties() = LanguageProviderProperties(listOf(LanguageProviderId.AWS), listOf(LanguageProviderId.AWS))
|
||||
|
||||
@Bean
|
||||
fun provider() = DetailTranslationProvider()
|
||||
|
||||
@Bean
|
||||
fun cloudFront(): AudioContentCloudFront = Mockito.mock(AudioContentCloudFront::class.java).also {
|
||||
Mockito.`when`(it.generateSignedURL(Mockito.anyString(), Mockito.anyLong())).thenReturn("https://signed.test/audio")
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun preferences(): MemberContentPreferenceService = Mockito.mock(MemberContentPreferenceService::class.java).also {
|
||||
Mockito.`when`(it.resolveForQuery(Mockito.any(Member::class.java) ?: Member(password = "test", nickname = "unused")))
|
||||
.thenReturn(ViewerContentPreference("KR", false, ContentType.ALL, false))
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun principalFilter(members: MemberRepository, lang: LangContext) = object : OncePerRequestFilter() {
|
||||
override fun doFilterInternal(request: HttpServletRequest, response: HttpServletResponse, chain: FilterChain) {
|
||||
val principal = MemberAdapter(members.findById(request.getHeader("X-Test-Member").toLong()).orElseThrow())
|
||||
SecurityContextHolder.getContext().authentication =
|
||||
UsernamePasswordAuthenticationToken(principal, null, principal.authorities)
|
||||
lang.setLang(Lang.EN)
|
||||
try {
|
||||
chain.doFilter(request, response)
|
||||
} finally {
|
||||
SecurityContextHolder.clearContext()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class DetailTranslationProvider : TranslationProvider, LanguageDetectionProvider {
|
||||
override val providerId = LanguageProviderId.AWS
|
||||
override val providerVersion = "test"
|
||||
val calls = AtomicInteger()
|
||||
val detectionQueries: MutableList<String> = Collections.synchronizedList(mutableListOf())
|
||||
var fail = false
|
||||
var detection: String? = "ko"
|
||||
var beforeTranslate: () -> Unit = {}
|
||||
var beforeDetect: () -> Unit = {}
|
||||
|
||||
fun reset() {
|
||||
calls.set(0)
|
||||
detectionQueries.clear()
|
||||
fail = false
|
||||
detection = "ko"
|
||||
beforeTranslate = {}
|
||||
beforeDetect = {}
|
||||
}
|
||||
|
||||
override fun detect(query: String): String? {
|
||||
detectionQueries.add(query)
|
||||
beforeDetect()
|
||||
return detection
|
||||
}
|
||||
|
||||
override fun translate(request: TranslateRequest): TranslateResult {
|
||||
calls.incrementAndGet()
|
||||
beforeTranslate()
|
||||
check(!fail) { "provider unavailable" }
|
||||
val translations = mapOf("원문 제목" to "English title", "원문 설명" to "English detail", "#힐링" to "#Healing")
|
||||
return TranslateResult(request.texts.map(translations::getValue))
|
||||
}
|
||||
}
|
||||
+13
-1
@@ -4,8 +4,10 @@ import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import kr.co.vividnext.sodalive.aws.cloudfront.AudioContentCloudFront
|
||||
import kr.co.vividnext.sodalive.aws.s3.S3Uploader
|
||||
import kr.co.vividnext.sodalive.content.AudioContent
|
||||
import kr.co.vividnext.sodalive.content.AudioContentDetailTranslationService
|
||||
import kr.co.vividnext.sodalive.content.AudioContentRepository
|
||||
import kr.co.vividnext.sodalive.content.AudioContentService
|
||||
import kr.co.vividnext.sodalive.content.LanguageDetectionCacheService
|
||||
import kr.co.vividnext.sodalive.content.PlaybackTrackingRepository
|
||||
import kr.co.vividnext.sodalive.content.comment.AudioContentCommentRepository
|
||||
import kr.co.vividnext.sodalive.content.hashtag.HashTagRepository
|
||||
@@ -36,6 +38,7 @@ import org.mockito.Mockito
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.context.ApplicationEventPublisher
|
||||
import java.util.Optional
|
||||
import javax.persistence.EntityManager
|
||||
|
||||
class AudioContentReadRetryTest : MetadataReadRetryTestSupport() {
|
||||
@Autowired
|
||||
@@ -83,8 +86,17 @@ class AudioContentReadRetryTest : MetadataReadRetryTestSupport() {
|
||||
audioContentLikeRepository = Mockito.mock(AudioContentLikeRepository::class.java),
|
||||
pinContentRepository = Mockito.mock(PinContentRepository::class.java),
|
||||
memberRepository = Mockito.mock(MemberRepository::class.java),
|
||||
resourceTranslationJobScheduler = scheduler,
|
||||
contentTranslationRepository = translations,
|
||||
detailTranslationService = AudioContentDetailTranslationService(
|
||||
repository,
|
||||
translations,
|
||||
Mockito.mock(LanguageDetectionCacheService::class.java),
|
||||
Mockito.mock(TranslationMemoryService::class.java),
|
||||
Mockito.mock(TranslationReadModelMaterializer::class.java),
|
||||
scheduler,
|
||||
Mockito.mock(EntityManager::class.java),
|
||||
transactionManager
|
||||
),
|
||||
s3Uploader = Mockito.mock(S3Uploader::class.java),
|
||||
objectMapper = ObjectMapper(),
|
||||
audioContentCloudFront = cloudFront,
|
||||
|
||||
+6
-1
@@ -231,7 +231,12 @@ class ContentTagTranslationIntegrationTest : MetadataReadRetryTestSupport() {
|
||||
}.`when`(claimRepository).findNextPendingGroupJobIdsForUpdate(
|
||||
Mockito.any(LocalDateTime::class.java) ?: LocalDateTime.now()
|
||||
)
|
||||
return TranslationJobWorker(claimRepository, memories, coordinator, materializer, transactionManager)
|
||||
return TranslationJobWorker(
|
||||
claimRepository,
|
||||
TranslationMemoryService(memories, coordinator, transactionManager),
|
||||
materializer,
|
||||
transactionManager
|
||||
)
|
||||
}
|
||||
|
||||
private fun renderedTags(): String = renderedPayload().get("tags").asText()
|
||||
|
||||
+1
@@ -64,6 +64,7 @@ import java.util.UUID
|
||||
LanguageDetectionCacheService::class,
|
||||
TranslationCoordinator::class,
|
||||
TranslationJobWorker::class,
|
||||
TranslationMemoryService::class,
|
||||
TranslationReadModelMaterializer::class,
|
||||
TranslationSourceExtractor::class,
|
||||
TranslationJobScheduler::class,
|
||||
|
||||
+37
-22
@@ -9,6 +9,7 @@ import kr.co.vividnext.sodalive.aws.s3.S3Uploader
|
||||
import kr.co.vividnext.sodalive.configs.QueryDslConfig
|
||||
import kr.co.vividnext.sodalive.content.AudioContent
|
||||
import kr.co.vividnext.sodalive.content.AudioContentController
|
||||
import kr.co.vividnext.sodalive.content.AudioContentDetailTranslationService
|
||||
import kr.co.vividnext.sodalive.content.AudioContentService
|
||||
import kr.co.vividnext.sodalive.content.ContentType
|
||||
import kr.co.vividnext.sodalive.content.LanguageDetectListener
|
||||
@@ -47,6 +48,7 @@ import org.springframework.boot.test.mock.mockito.MockBean
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Import
|
||||
import org.springframework.core.task.SyncTaskExecutor
|
||||
import org.springframework.jdbc.core.JdbcTemplate
|
||||
import org.springframework.mock.web.MockMultipartFile
|
||||
import org.springframework.scheduling.annotation.EnableAsync
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken
|
||||
@@ -58,6 +60,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPat
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders
|
||||
import org.springframework.transaction.PlatformTransactionManager
|
||||
import org.springframework.transaction.TransactionDefinition
|
||||
import org.springframework.transaction.annotation.Propagation
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import org.springframework.transaction.support.TransactionTemplate
|
||||
@@ -76,6 +79,9 @@ import javax.persistence.EntityManager
|
||||
QueryDslConfig::class,
|
||||
AdminContentService::class,
|
||||
AudioContentService::class,
|
||||
AudioContentDetailTranslationService::class,
|
||||
TranslationMemoryService::class,
|
||||
TranslationReadModelMaterializer::class,
|
||||
ExplorerQueryRepository::class,
|
||||
SodaMessageSource::class,
|
||||
AudioContentThemeQueryRepository::class,
|
||||
@@ -103,10 +109,14 @@ class MetadataTranslationHttpIntegrationTest @Autowired constructor(
|
||||
private val localizedNames: CreatorLocalizedNameService,
|
||||
private val langContext: LangContext,
|
||||
private val jobs: TranslationJobRepository,
|
||||
private val memories: TranslationMemoryRepository,
|
||||
private val jdbc: JdbcTemplate,
|
||||
private val entityManager: EntityManager,
|
||||
transactionManager: PlatformTransactionManager
|
||||
) {
|
||||
private val transaction = TransactionTemplate(transactionManager)
|
||||
private val transaction = TransactionTemplate(transactionManager).apply {
|
||||
isolationLevel = TransactionDefinition.ISOLATION_REPEATABLE_READ
|
||||
}
|
||||
|
||||
@MockBean
|
||||
private lateinit var uploader: S3Uploader
|
||||
@@ -123,8 +133,8 @@ class MetadataTranslationHttpIntegrationTest @Autowired constructor(
|
||||
@ParameterizedTest
|
||||
@NullAndEmptySource
|
||||
@ValueSource(strings = [" \t "])
|
||||
@DisplayName("언어가 없는 상세 GET은 원문을 반환하고 커밋 후 감지 언어와 번역 작업을 저장한다")
|
||||
fun shouldDetectMissingLanguageAfterDetailHttpGetCommits(languageCode: String?) {
|
||||
@DisplayName("언어가 없는 상세 GET은 동기 감지와 번역을 커밋하고 외부 managed entity의 언어는 변경하지 않는다")
|
||||
fun shouldCommitDetectedLanguageAndTranslationBeforeDetailHttpGetReturns(languageCode: String?) {
|
||||
val title = " 원문 전체 제목 "
|
||||
val detail = " 원문 전체 설명은 구매 전 미리보기보다 길며 언어 감지에는 잘린 응답 대신 마지막 문장까지 모두 포함되어야 합니다. "
|
||||
val (contentId, viewer) = transaction.execute {
|
||||
@@ -163,6 +173,22 @@ class MetadataTranslationHttpIntegrationTest @Autowired constructor(
|
||||
}!!
|
||||
val query = "원문 전체 제목 원문 전체 설명은 구매 전 미리보기보다 길며 언어 감지에는 잘린 응답 대신 마지막 문장까지 모두 포함되어야 합니다. #활성"
|
||||
Mockito.`when`(detectionCache.detectWithCache(query)).thenReturn(DetectedLanguage("ko", LanguageProviderId.AWS))
|
||||
listOf(title to "Full title", detail to "Full detail", "#활성" to "#Active").forEach { (source, translated) ->
|
||||
val normalized = SourceTextNormalizer.normalize(source)
|
||||
if (memories.findBySourceHashAndSourceLanguageAndTargetLanguageAndProviderAndNormalizationVersion(
|
||||
SourceTextNormalizer.hash(normalized),
|
||||
"ko",
|
||||
"en",
|
||||
"aws",
|
||||
SourceTextNormalizer.NORMALIZATION_VERSION
|
||||
) == null
|
||||
) {
|
||||
memories.saveAndFlush(
|
||||
TranslationMemory(SourceTextNormalizer.hash(normalized), normalized, "ko", "en", translated, "aws", "test")
|
||||
)
|
||||
}
|
||||
}
|
||||
jdbc.execute("alter table content_translation alter column rendered_payload varchar(1000000)")
|
||||
Mockito.`when`(preferences.resolveForQuery(viewer))
|
||||
.thenReturn(ViewerContentPreference("KR", false, ContentType.ALL, false))
|
||||
Mockito.`when`(cloudFront.generateSignedURL("preview/audio.mp3", 7_200_000L))
|
||||
@@ -172,6 +198,7 @@ class MetadataTranslationHttpIntegrationTest @Autowired constructor(
|
||||
UsernamePasswordAuthenticationToken(principal, null, principal.authorities)
|
||||
try {
|
||||
transaction.executeWithoutResult {
|
||||
val outerContent = entityManager.find(AudioContent::class.java, contentId)
|
||||
MockMvcBuilders.standaloneSetup(
|
||||
AudioContentController(contentService, preferences, localizedNames, langContext)
|
||||
)
|
||||
@@ -183,10 +210,13 @@ class MetadataTranslationHttpIntegrationTest @Autowired constructor(
|
||||
.andExpect(jsonPath("$.data.title").value(title))
|
||||
.andExpect(jsonPath("$.data.detail").value("${detail.take(30)}..."))
|
||||
.andExpect(jsonPath("$.data.tag").value("#활성"))
|
||||
.andExpect(jsonPath("$.data.translated").doesNotExist())
|
||||
assertEquals(languageCode, entityManager.find(AudioContent::class.java, contentId).languageCode)
|
||||
.andExpect(jsonPath("$.data.languageCode").value("ko"))
|
||||
.andExpect(jsonPath("$.data.translated.title").value("Full title"))
|
||||
.andExpect(jsonPath("$.data.translated.detail").value("Full detail"))
|
||||
.andExpect(jsonPath("$.data.translated.tags").value("#Active"))
|
||||
assertEquals(languageCode, outerContent.languageCode)
|
||||
assertEquals(0, jobs.findAll().count { it.resourceId == contentId })
|
||||
Mockito.verifyNoInteractions(detectionCache)
|
||||
Mockito.verify(detectionCache).detectWithCache(query)
|
||||
}
|
||||
transaction.executeWithoutResult {
|
||||
entityManager.clear()
|
||||
@@ -194,22 +224,7 @@ class MetadataTranslationHttpIntegrationTest @Autowired constructor(
|
||||
val stored = jobs.findAll().filter {
|
||||
it.resourceType == LanguageTranslationTargetType.CONTENT && it.resourceId == contentId
|
||||
}
|
||||
assertEquals(
|
||||
setOf(
|
||||
"title" to "en",
|
||||
"title" to "ja",
|
||||
"detail" to "en",
|
||||
"detail" to "ja",
|
||||
"tags" to "en",
|
||||
"tags" to "ja"
|
||||
),
|
||||
stored.map { it.fieldKey to it.targetLanguage }.toSet()
|
||||
)
|
||||
assertEquals(6, stored.size)
|
||||
assertEquals(setOf("ko"), stored.map { it.sourceLanguage }.toSet())
|
||||
assertEquals(setOf(TranslationJobStatus.PENDING), stored.map { it.status }.toSet())
|
||||
assertEquals(setOf(title.trim()), stored.filter { it.fieldKey == "title" }.map { it.sourceText }.toSet())
|
||||
assertEquals(setOf(detail.trim()), stored.filter { it.fieldKey == "detail" }.map { it.sourceText }.toSet())
|
||||
assertEquals(0, stored.size)
|
||||
}
|
||||
} finally {
|
||||
SecurityContextHolder.clearContext()
|
||||
|
||||
+8
-5
@@ -160,11 +160,14 @@ class TranslationJobRetryIntegrationTest @Autowired constructor(
|
||||
}
|
||||
val worker = TranslationJobWorker(
|
||||
claimRepository,
|
||||
memoryRepository,
|
||||
TranslationCoordinator(
|
||||
listOf(provider),
|
||||
LanguageProviderProperties(listOf(LanguageProviderId.PAPAGO), listOf(LanguageProviderId.PAPAGO)),
|
||||
memoryRepository
|
||||
TranslationMemoryService(
|
||||
memoryRepository,
|
||||
TranslationCoordinator(
|
||||
listOf(provider),
|
||||
LanguageProviderProperties(listOf(LanguageProviderId.PAPAGO), listOf(LanguageProviderId.PAPAGO)),
|
||||
memoryRepository
|
||||
),
|
||||
transactionManager
|
||||
),
|
||||
Mockito.mock(TranslationReadModelMaterializer::class.java),
|
||||
transactionManager
|
||||
|
||||
+13
-42
@@ -35,12 +35,7 @@ class TranslationJobWorkerTest {
|
||||
val materializer = Mockito.mock(TranslationReadModelMaterializer::class.java)
|
||||
val worker = TranslationJobWorker(
|
||||
translationJobRepository = jobRepository,
|
||||
translationMemoryRepository = memoryRepository,
|
||||
translationCoordinator = TranslationCoordinator(
|
||||
listOf(provider),
|
||||
LanguageProviderProperties(listOf(PAPAGO), listOf(PAPAGO)),
|
||||
memoryRepository
|
||||
),
|
||||
translationMemoryService = memoryService(memoryRepository, provider),
|
||||
materializer = materializer,
|
||||
transactionManager = TestTransactionManager()
|
||||
)
|
||||
@@ -63,12 +58,7 @@ class TranslationJobWorkerTest {
|
||||
val materializer = Mockito.mock(TranslationReadModelMaterializer::class.java)
|
||||
val worker = TranslationJobWorker(
|
||||
translationJobRepository = jobRepository,
|
||||
translationMemoryRepository = memoryRepository,
|
||||
translationCoordinator = TranslationCoordinator(
|
||||
listOf(provider),
|
||||
LanguageProviderProperties(listOf(PAPAGO), listOf(PAPAGO)),
|
||||
memoryRepository
|
||||
),
|
||||
translationMemoryService = memoryService(memoryRepository, provider),
|
||||
materializer = materializer,
|
||||
transactionManager = TestTransactionManager()
|
||||
)
|
||||
@@ -97,12 +87,7 @@ class TranslationJobWorkerTest {
|
||||
val materializer = Mockito.mock(TranslationReadModelMaterializer::class.java)
|
||||
val worker = TranslationJobWorker(
|
||||
translationJobRepository = jobRepository,
|
||||
translationMemoryRepository = memoryRepository,
|
||||
translationCoordinator = TranslationCoordinator(
|
||||
listOf(provider),
|
||||
LanguageProviderProperties(listOf(PAPAGO), listOf(PAPAGO)),
|
||||
memoryRepository
|
||||
),
|
||||
translationMemoryService = memoryService(memoryRepository, provider),
|
||||
materializer = materializer,
|
||||
transactionManager = TestTransactionManager()
|
||||
)
|
||||
@@ -146,12 +131,7 @@ class TranslationJobWorkerTest {
|
||||
val materializer = Mockito.mock(TranslationReadModelMaterializer::class.java)
|
||||
val worker = TranslationJobWorker(
|
||||
translationJobRepository = jobRepository,
|
||||
translationMemoryRepository = memoryRepository,
|
||||
translationCoordinator = TranslationCoordinator(
|
||||
listOf(provider),
|
||||
LanguageProviderProperties(listOf(PAPAGO), listOf(PAPAGO)),
|
||||
memoryRepository
|
||||
),
|
||||
translationMemoryService = memoryService(memoryRepository, provider),
|
||||
materializer = materializer,
|
||||
transactionManager = TestTransactionManager()
|
||||
)
|
||||
@@ -186,12 +166,7 @@ class TranslationJobWorkerTest {
|
||||
val materializer = Mockito.mock(TranslationReadModelMaterializer::class.java)
|
||||
val worker = TranslationJobWorker(
|
||||
translationJobRepository = jobRepository,
|
||||
translationMemoryRepository = memoryRepository,
|
||||
translationCoordinator = TranslationCoordinator(
|
||||
listOf(provider),
|
||||
LanguageProviderProperties(listOf(PAPAGO), listOf(PAPAGO)),
|
||||
memoryRepository
|
||||
),
|
||||
translationMemoryService = memoryService(memoryRepository, provider),
|
||||
materializer = materializer,
|
||||
transactionManager = TestTransactionManager()
|
||||
)
|
||||
@@ -229,12 +204,7 @@ class TranslationJobWorkerTest {
|
||||
val materializer = Mockito.mock(TranslationReadModelMaterializer::class.java)
|
||||
val worker = TranslationJobWorker(
|
||||
translationJobRepository = jobRepository,
|
||||
translationMemoryRepository = memoryRepository,
|
||||
translationCoordinator = TranslationCoordinator(
|
||||
listOf(provider),
|
||||
LanguageProviderProperties(listOf(PAPAGO), listOf(PAPAGO)),
|
||||
memoryRepository
|
||||
),
|
||||
translationMemoryService = memoryService(memoryRepository, provider),
|
||||
materializer = materializer,
|
||||
transactionManager = TestTransactionManager()
|
||||
)
|
||||
@@ -266,12 +236,7 @@ class TranslationJobWorkerTest {
|
||||
val materializer = Mockito.mock(TranslationReadModelMaterializer::class.java)
|
||||
val worker = TranslationJobWorker(
|
||||
translationJobRepository = jobRepository,
|
||||
translationMemoryRepository = memoryRepository,
|
||||
translationCoordinator = TranslationCoordinator(
|
||||
listOf(successfulProvider()),
|
||||
LanguageProviderProperties(listOf(PAPAGO), listOf(PAPAGO)),
|
||||
memoryRepository
|
||||
),
|
||||
translationMemoryService = memoryService(memoryRepository, successfulProvider()),
|
||||
materializer = materializer,
|
||||
transactionManager = TestTransactionManager()
|
||||
)
|
||||
@@ -307,6 +272,12 @@ class TranslationJobWorkerTest {
|
||||
)
|
||||
}
|
||||
|
||||
private fun memoryService(repository: TranslationMemoryRepository, provider: TranslationProvider) = TranslationMemoryService(
|
||||
repository,
|
||||
TranslationCoordinator(listOf(provider), LanguageProviderProperties(listOf(PAPAGO), listOf(PAPAGO)), repository),
|
||||
TestTransactionManager()
|
||||
)
|
||||
|
||||
private fun successfulProvider(): TranslationProvider {
|
||||
return object : TranslationProvider {
|
||||
override val providerId: LanguageProviderId = LanguageProviderId.PAPAGO
|
||||
|
||||
Reference in New Issue
Block a user