Skip to content

Commit

Permalink
TestSuitesSource storage
Browse files Browse the repository at this point in the history
### What's done:
- added storage for TestSuitesSource snapshots
- refactored discovering tests and test suites
- added GIT cloning with new run
  • Loading branch information
nulls committed Jul 25, 2022
1 parent 490fb3e commit 0831e19
Show file tree
Hide file tree
Showing 45 changed files with 1,411 additions and 438 deletions.
1 change: 1 addition & 0 deletions db/v-2/tables/db.changelog-tables.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<include file="git.xml" relativeToChangelogFile="true"/>
<include file="agent-status.xml" relativeToChangelogFile="true"/>
<include file="project-privacy.xml" relativeToChangelogFile="true"/>
<include file="test_suites_source.xml" relativeToChangelogFile="true"/>
<include file="test_suite.xml" relativeToChangelogFile="true"/>
<include file="test_execution.xml" relativeToChangelogFile="true"/>
<include file="execution.xml" relativeToChangelogFile="true"/>
Expand Down
22 changes: 22 additions & 0 deletions db/v-2/tables/test_suite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,26 @@
</addColumn>
</changeSet>

<changeSet id="add-test-suites-source" author="nulls">
<delete tableName="test_execution" />
<delete tableName="test" />
<delete tableName="test_suite" />
<dropForeignKeyConstraint baseTableName="test_suite" constraintName="fk_test_suite_project" />
<dropColumn tableName="test_suite">
<column name="type"/>
<column name="project_id"/>
<column name="test_root_path"/>
<column name="test_suite_repo_url"/>
</dropColumn>
<addColumn tableName="test_suite">
<column name="source_id" type="bigint">
<constraints foreignKeyName="fk_test_suite_source" references="test_suites_source(id)"/>
</column>
<column name="version" type="varchar(100)">
<constraints nullable="false"/>
</column>
</addColumn>
<addUniqueConstraint tableName="test_suite" columnNames="source_id,version"/>
</changeSet>

</databaseChangeLog>
34 changes: 34 additions & 0 deletions db/v-2/tables/test_suites_source.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">

<changeSet id="create-test-suites-source-table" author="nulls">
<createTable tableName="test_suites_source">
<column name="id" type="bigint" autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="organization_id" type="bigint">
<constraints foreignKeyName="fk_lnk_test_suites_source_organization" references="organization(id)" nullable="false"/>
</column>
<column name="name" type="varchar(255)">
<constraints nullable="false"/>
</column>
<column name="description" type="text"/>
<column name="git_id" type="bigint">
<constraints foreignKeyName="fk_lnk_test_suites_source_git" references="git(id)" nullable="false"/>
</column>
<column name="branch" type="varchar(100)">
<constraints nullable="false"/>
</column>
<column name="test_root_path" type="varchar(255)">
<constraints nullable="false"/>
</column>
</createTable>

<addUniqueConstraint tableName="test_suites_source" columnNames="organization_id,name" constraintName="test_suites_source_name"/>
<addUniqueConstraint tableName="test_suites_source" columnNames="git_id,test_root_path,branch" constraintName="test_suites_source_git_location"/>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,6 @@ class TestSuitesController(
)
}

/**
* @param testSuiteDtos suites, which need to be marked as obsolete
* @return response entity
*/
@PostMapping("/internal/markObsoleteTestSuites")
@Transactional
fun markObsoleteTestSuites(@RequestBody testSuiteDtos: List<TestSuiteDto>) =
ResponseEntity.status(HttpStatus.OK).body(testSuitesService.markObsoleteTestSuites(testSuiteDtos))

/**
* @param testSuiteDtos suites, which need to be deleted
* @return response entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ interface GitRepository : BaseEntityRepository<Git> {
* @return git by [organizationId] and [url]
*/
fun findByOrganizationAndUrl(organization: Organization, url: String): Git?

/**
* @param url
* @return all [Git] entities by [Git.url]
*/
fun findAllByUrl(url: String): List<Git>
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.saveourtool.save.backend.repository

import com.saveourtool.save.entities.TestSuite
import com.saveourtool.save.entities.TestSuitesSource
import com.saveourtool.save.testsuite.TestSuiteType
import org.springframework.data.repository.query.QueryByExampleExecutor
import org.springframework.stereotype.Repository
Expand Down Expand Up @@ -42,4 +43,35 @@ interface TestSuiteRepository : BaseEntityRepository<TestSuite>, QueryByExampleE
testRootPath: String,
testSuiteRepoUrl: String?,
): TestSuite

/**
* @param name name of the test suite
* @param source source of the test suite
* @param version version of snapshot of source
* @return matched test suite
*/
fun findByNameAndSourceAndVersion(
name: String,
source: TestSuitesSource,
version: String
): TestSuite?

/**
* @param source source of the test suite
* @param version version of snapshot of source
* @return matched test suites
*/
fun findAllBySourceAndVersion(
source: TestSuitesSource,
version: String
): List<TestSuite>


/**
* @param source source of the test suite
* @return matched test suites
*/
fun findAllBySource(
source: TestSuitesSource,
): List<TestSuite>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.saveourtool.save.backend.repository

import com.saveourtool.save.entities.Git
import com.saveourtool.save.entities.Organization
import com.saveourtool.save.entities.TestSuitesSource
import org.springframework.stereotype.Repository

/**
* Repository of [TestSuitesSource]
*/
@Repository
interface TestSuitesSourceRepository : BaseEntityRepository<TestSuitesSource> {
/**
* @param organizationId
* @param name
* @return found entity or null
*/
fun findByOrganizationIdAndName(organizationId: Long, name: String): TestSuitesSource?

/**
* @param organization
* @param git
* @param branch
* @param testRootPath
* @return found entity or null
*/
fun findByOrganizationAndGitAndBranchAndTestRootPath(organization: Organization, git: Git, branch: String, testRootPath: String): TestSuitesSource?
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ class ExecutionService(
.flatMap { testRepository.findAllByTestSuiteId(it) }
.count()
.toLong()
execution.resourcesRootPath = FilenameUtils.separatorsToUnix(executionInitializationDto.resourcesRootPath)
execution.execCmd = executionInitializationDto.execCmd
execution.batchSizeForAnalyzer = executionInitializationDto.batchSizeForAnalyzer
executionRepository.save(execution)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package com.saveourtool.save.backend.service

import com.saveourtool.save.backend.repository.GitRepository
import com.saveourtool.save.backend.utils.switchToNotFoundIfEmpty
import com.saveourtool.save.entities.Git
import com.saveourtool.save.entities.GitDto
import com.saveourtool.save.entities.Organization
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Mono

/**
* Service of git
*/
@Service
@RestController
class GitService(private val gitRepository: GitRepository) {
/**
* @param organization
Expand Down Expand Up @@ -48,4 +55,11 @@ class GitService(private val gitRepository: GitRepository) {
fun delete(organization: Organization, url: String) {
gitRepository.delete(getByOrganizationAndUrl(organization, url))
}

@GetMapping("/internal/git")
fun getById(@RequestParam id: Long): Mono<GitDto> = Mono.justOrEmpty(gitRepository.findByIdOrNull(id))
.map { it.toDto() }
.switchToNotFoundIfEmpty {
"Git entity not found by id $id"
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package com.saveourtool.save.backend.service

import com.saveourtool.save.backend.repository.OrganizationRepository
import com.saveourtool.save.backend.utils.switchToNotFoundIfEmpty
import com.saveourtool.save.domain.OrganizationSaveStatus
import com.saveourtool.save.entities.Organization
import com.saveourtool.save.entities.OrganizationStatus
import org.springframework.stereotype.Service
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Mono

/**
* Service for organization
*
* @property organizationRepository
*/
@Service
@RestController
class OrganizationService(
private val organizationRepository: OrganizationRepository,
) {
Expand Down Expand Up @@ -57,6 +63,12 @@ class OrganizationService(
*/
fun findByName(name: String) = organizationRepository.findByName(name)

@GetMapping("/internal/organization/{name}")
fun getByNameAsMono(@PathVariable name: String): Mono<Organization> = Mono.justOrEmpty(findByName(name))
.switchToNotFoundIfEmpty {
"Organization not found by name $name"
}

/**
* @param name
* @return organization by name
Expand Down
Loading

0 comments on commit 0831e19

Please sign in to comment.