Skip to content

Commit

Permalink
Pivotal ID # 185900074: Accept Requests With Large Directories Times …
Browse files Browse the repository at this point in the history
…Out (#759)

https://www.pivotaltracker.com/story/show/185900074

Avoid directories calculation at the moment of generating pagetab
  • Loading branch information
jhoanmanuelms authored Nov 6, 2023
1 parent 958c2a3 commit 8d05f6b
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ import ebi.ac.uk.model.BioFile

internal const val TO_FILE_EXTENSIONS = "ebi.ac.uk.extended.mapping.to.ToFileKt"

/**
* The file size for inner directories is not calculated in order to avoid timing out requests for submissions that
* include big sized directories. @see https://www.pivotaltracker.com/story/show/185900074
*/
fun ExtFile.toFile(): BioFile {
return when (this) {
is NfsFile -> BioFile(filePath, file.size(), type.value, attributes.map { it.toAttribute() })
is NfsFile ->
BioFile(filePath, file.size(calculateDirectories = false), type.value, attributes.map { it.toAttribute() })

is FireFile -> BioFile(filePath, size, type.value, attributes.map { it.toAttribute() })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ import ebi.ac.uk.model.LinksTable
internal const val TO_TABLE_EXTENSIONS = "ebi.ac.uk.extended.mapping.to.ToTableKt"

fun ExtFileTable.toTable(): FilesTable = FilesTable(files.map { file -> file.toFile() })

fun ExtLinkTable.toTable(): LinksTable = LinksTable(links.map { link -> link.toLink() })
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package ac.uk.ebi.biostd.persistence.filesystem.pagetab

import ac.uk.ebi.biostd.integration.SerializationService
import ac.uk.ebi.biostd.integration.SubFormat.Companion.JSON_PRETTY
import ac.uk.ebi.biostd.integration.SubFormat.Companion.TSV
import ac.uk.ebi.biostd.integration.SubFormat.Companion.XML
import ebi.ac.uk.extended.mapping.to.ToFileListMapper
import ebi.ac.uk.extended.mapping.to.ToSubmissionMapper
import ebi.ac.uk.extended.model.ExtSubmission
import ebi.ac.uk.io.RW_R__R__
import ebi.ac.uk.model.Submission
import io.github.glytching.junit.extension.folder.TemporaryFolder
import io.github.glytching.junit.extension.folder.TemporaryFolderExtension
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
import kotlinx.coroutines.test.runTest
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import java.io.File
import java.nio.file.Files

@ExtendWith(MockKExtension::class, TemporaryFolderExtension::class)
class PageTabUtilTest(
private val tempFolder: TemporaryFolder,
@MockK private val serializationService: SerializationService,
@MockK private val toSubmissionMapper: ToSubmissionMapper,
@MockK private val fileListMapper: ToFileListMapper,
@MockK private val extSubmission: ExtSubmission,
@MockK private val submission: Submission,
) {
private val testInstance = PageTabUtil(serializationService, toSubmissionMapper, fileListMapper)

@Test
fun `generate submission pagetab`() = runTest {
every { extSubmission.released } returns true
every { extSubmission.accNo } returns "S-BSST1"
every { serializationService.serializeSubmission(submission, TSV) } returns "tsv-sub"
every { serializationService.serializeSubmission(submission, XML) } returns "xml-sub"
every { serializationService.serializeSubmission(submission, JSON_PRETTY) } returns "json-sub"
coEvery { toSubmissionMapper.toSimpleSubmission(extSubmission) } returns submission

val pageTabFiles = testInstance.generateSubPageTab(extSubmission, tempFolder.root)
coVerify(exactly = 1) { toSubmissionMapper.toSimpleSubmission(extSubmission) }
assertPageTabFile(pageTabFiles.tsv, "tsv-sub")
assertPageTabFile(pageTabFiles.xml, "xml-sub")
assertPageTabFile(pageTabFiles.json, "json-sub")
}

private fun assertPageTabFile(file: File, content: String) {
assertThat(file.exists()).isTrue()
assertThat(file.readText()).isEqualTo(content)
assertThat(Files.getPosixFilePermissions(file.toPath())).isEqualTo(RW_R__R__)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,4 @@ private fun fileList2() = jsonArray(
}
)
},
{
"path" to "Folder1"
"attributes" to jsonArray(
{
"name" to "Type"
"value" to "referenced directory"
}
)
},
)
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,4 @@ private fun fileList() = tsv {
private fun fileList2() = tsv {
line("Files", "Type")
line("DataFile7.txt", "referenced")
line("Folder1", "referenced directory")
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,4 @@ private fun fileList2() = xml("table") {
}
}
}
"file" {
"path" { -"Folder1" }
"attributes" {
"attribute" {
"name" { -"Type" }
"value" { -"referenced directory" }
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,6 @@ internal val expectedAllInOneJsonInnerFileList = jsonArray(
)
"type" to "file"
},
{
"path" to "Folder1"
"size" to 27
"attributes" to jsonArray(
{
"name" to "Type"
"value" to "referenced directory"
}
)
"type" to "directory"
},
)

fun assertAllInOneSubmissionJson(json: String, accNo: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,5 @@ internal val expectedAllInOneTsvFileList = tsv {
internal val expectedAllInOneTsvInnerFileList = tsv {
line("Files", "Type")
line("DataFile7.txt", "referenced")
line("Folder1", "referenced directory")
line()
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,6 @@ internal val expectedAllInOneXmlInnerFileList = xml("table") {
}
}
}
"file" {
attribute("size", 27)
"path" { -"Folder1" }
"type" { -"directory" }
"attributes" {
"attribute" {
"name" { -"Type" }
"value" { -"referenced directory" }
}
}
}
}

fun assertAllInOneSubmissionXml(xml: String, accNo: String) {
Expand Down

0 comments on commit 8d05f6b

Please sign in to comment.