-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Tmp * Tmp * Tmp * tmp * Make test to work * PMD and update test * Bmoric/add more controller tests (#22113) * Add attempt and connection test * Add more test * Add more test * pmd * Rm unused import * Add comment * More test and address comments * PR comments
- Loading branch information
1 parent
ccc1c6c
commit da17885
Showing
24 changed files
with
2,755 additions
and
0 deletions.
There are no files selected for viewing
370 changes: 370 additions & 0 deletions
370
airbyte-commons-server/src/main/java/io/airbyte/commons/server/handlers/SourceHandler.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
plugins { | ||
id 'application' | ||
} | ||
|
||
configurations.all { | ||
exclude group: 'io.micronaut.jaxrs' | ||
} | ||
|
||
dependencies { | ||
annotationProcessor platform(libs.micronaut.bom) | ||
annotationProcessor libs.bundles.micronaut.annotation.processor | ||
annotationProcessor libs.micronaut.jaxrs.processor | ||
|
||
implementation platform(libs.micronaut.bom) | ||
implementation libs.bundles.micronaut | ||
implementation libs.micronaut.jaxrs.server | ||
|
||
// Ensure that the versions defined in deps.toml are used | ||
// instead of versions from transitive dependencies | ||
implementation(libs.flyway.core) { | ||
force = true | ||
} | ||
implementation(libs.s3) { | ||
// Force to avoid updated version brought in transitively from Micronaut 3.8+ | ||
// that is incompatible with our current Helm setup | ||
force = true | ||
} | ||
implementation(libs.aws.java.sdk.s3) { | ||
// Force to avoid updated version brought in transitively from Micronaut 3.8+ | ||
// that is incompatible with our current Helm setup | ||
force = true | ||
} | ||
|
||
implementation project(':airbyte-analytics') | ||
implementation project(':airbyte-api') | ||
implementation project(':airbyte-commons-temporal') | ||
implementation project(':airbyte-commons-server') | ||
implementation project(':airbyte-commons-worker') | ||
implementation project(':airbyte-config:init') | ||
implementation project(':airbyte-config:config-models') | ||
implementation project(':airbyte-config:config-persistence') | ||
implementation project(':airbyte-config:specs') | ||
implementation project(':airbyte-metrics:metrics-lib') | ||
implementation project(':airbyte-db:db-lib') | ||
implementation project(":airbyte-json-validation") | ||
implementation project(':airbyte-notification') | ||
implementation project(':airbyte-oauth') | ||
implementation libs.airbyte.protocol | ||
implementation project(':airbyte-persistence:job-persistence') | ||
|
||
implementation 'com.github.slugify:slugify:2.4' | ||
implementation 'commons-cli:commons-cli:1.4' | ||
implementation libs.temporal.sdk | ||
implementation 'org.apache.cxf:cxf-core:3.4.2' | ||
implementation 'org.eclipse.jetty:jetty-server:9.4.31.v20200723' | ||
implementation 'org.eclipse.jetty:jetty-servlet:9.4.31.v20200723' | ||
implementation 'org.glassfish.jaxb:jaxb-runtime:3.0.2' | ||
implementation 'org.glassfish.jersey.containers:jersey-container-servlet' | ||
implementation 'org.glassfish.jersey.inject:jersey-hk2' | ||
implementation 'org.glassfish.jersey.media:jersey-media-json-jackson' | ||
implementation 'org.glassfish.jersey.ext:jersey-bean-validation' | ||
implementation 'org.quartz-scheduler:quartz:2.3.2' | ||
implementation 'io.sentry:sentry:6.3.1' | ||
implementation 'io.swagger:swagger-annotations:1.6.2' | ||
|
||
testImplementation libs.bundles.micronaut.test | ||
testAnnotationProcessor platform(libs.micronaut.bom) | ||
testAnnotationProcessor libs.bundles.micronaut.test.annotation.processor | ||
|
||
testImplementation project(':airbyte-test-utils') | ||
testImplementation libs.postgresql | ||
testImplementation libs.platform.testcontainers.postgresql | ||
testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.1' | ||
testImplementation 'org.mockito:mockito-inline:4.7.0' | ||
} | ||
|
||
// we want to be able to access the generated db files from config/init when we build the server docker image. | ||
task copySeed(type: Copy, dependsOn: [project(':airbyte-config:init').processResources]) { | ||
from "${project(':airbyte-config:init').buildDir}/resources/main/config" | ||
into "${buildDir}/config_init/resources/main/config" | ||
} | ||
|
||
// need to make sure that the files are in the resource directory before copying. | ||
// tests require the seed to exist. | ||
test.dependsOn(project.tasks.copySeed) | ||
assemble.dependsOn(project.tasks.copySeed) | ||
|
||
mainClassName = 'io.airbyte.server.Application' | ||
|
||
application { | ||
applicationName = project.name | ||
mainClass = mainClassName | ||
applicationDefaultJvmArgs = ['-XX:+ExitOnOutOfMemoryError', '-XX:MaxRAMPercentage=75.0'] | ||
} | ||
|
||
Properties env = new Properties() | ||
rootProject.file('.env.dev').withInputStream { env.load(it) } | ||
|
||
run { | ||
// default for running on local machine. | ||
environment "DATABASE_USER", env.DATABASE_USER | ||
environment "DATABASE_PASSWORD", env.DATABASE_PASSWORD | ||
|
||
environment "CONFIG_DATABASE_USER", env.CONFIG_DATABASE_USER | ||
environment "CONFIG_DATABASE_PASSWORD", env.CONFIG_DATABASE_PASSWORD | ||
|
||
// we map the docker pg db to port 5433 so it does not conflict with other pg instances. | ||
environment "DATABASE_URL", "jdbc:postgresql://localhost:5433/${env.DATABASE_DB}" | ||
environment "CONFIG_DATABASE_URL", "jdbc:postgresql://localhost:5433/${env.CONFIG_DATABASE_DB}" | ||
|
||
environment "RUN_DATABASE_MIGRATION_ON_STARTUP", "true" | ||
|
||
environment "WORKSPACE_ROOT", env.WORKSPACE_ROOT | ||
environment "CONFIG_ROOT", "/tmp/airbyte_config" | ||
environment "TRACKING_STRATEGY", env.TRACKING_STRATEGY | ||
environment "AIRBYTE_VERSION", env.VERSION | ||
environment "AIRBYTE_ROLE", System.getenv('AIRBYTE_ROLE') | ||
environment "TEMPORAL_HOST", "localhost:7233" | ||
|
||
environment 'MICRONAUT_ENVIRONMENTS', 'control-plane' | ||
} | ||
|
||
test { | ||
systemProperty("mockito.test.enabled", "true") | ||
environment 'MICRONAUT_ENVIRONMENTS', 'test' | ||
} | ||
|
||
// produce reproducible archives | ||
// (see https://docs.gradle.org/current/userguide/working_with_files.html#sec:reproducible_archives) | ||
tasks.withType(AbstractArchiveTask) { | ||
preserveFileTimestamps = false | ||
reproducibleFileOrder = true | ||
} | ||
|
||
tasks.named("buildDockerImage") { | ||
dependsOn copyGeneratedTar | ||
} | ||
|
||
Task publishArtifactsTask = getPublishArtifactsTask("$rootProject.ext.version", project) |
36 changes: 36 additions & 0 deletions
36
airbyte-server/src/main/java/io/airbyte/server/errors/InvalidInputExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.server.errors; | ||
|
||
import io.airbyte.commons.json.Jsons; | ||
import io.airbyte.commons.server.errors.InvalidInputExceptionMapper; | ||
import io.micronaut.context.annotation.Replaces; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.HttpResponse; | ||
import io.micronaut.http.HttpStatus; | ||
import io.micronaut.http.MediaType; | ||
import io.micronaut.http.annotation.Produces; | ||
import io.micronaut.http.server.exceptions.ExceptionHandler; | ||
import io.micronaut.validation.exceptions.ConstraintExceptionHandler; | ||
import jakarta.inject.Singleton; | ||
import javax.validation.ConstraintViolationException; | ||
|
||
// https://www.baeldung.com/jersey-bean-validation#custom-exception-handler | ||
// handles exceptions related to the request body not matching the openapi config. | ||
@Produces | ||
@Singleton | ||
@Requires(classes = ConstraintViolationException.class) | ||
@Replaces(ConstraintExceptionHandler.class) | ||
public class InvalidInputExceptionHandler implements ExceptionHandler<ConstraintViolationException, HttpResponse> { | ||
|
||
@Override | ||
public HttpResponse handle(final HttpRequest request, final ConstraintViolationException exception) { | ||
return HttpResponse.status(HttpStatus.BAD_REQUEST) | ||
.body(Jsons.serialize(InvalidInputExceptionMapper.infoFromConstraints(exception))) | ||
.contentType(MediaType.APPLICATION_JSON_TYPE); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
airbyte-server/src/test/java/io/airbyte/server/apis/AttemptApiTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.server.apis; | ||
|
||
import io.airbyte.api.model.generated.InternalOperationResult; | ||
import io.airbyte.api.model.generated.SaveStatsRequestBody; | ||
import io.airbyte.commons.json.Jsons; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.context.env.Environment; | ||
import io.micronaut.core.util.StringUtils; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.HttpStatus; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
@MicronautTest | ||
@Requires(property = "mockito.test.enabled", | ||
defaultValue = StringUtils.TRUE, | ||
value = StringUtils.TRUE) | ||
@Requires(env = {Environment.TEST}) | ||
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert") | ||
class AttemptApiTest extends BaseControllerTest { | ||
|
||
@Test | ||
void testSaveState() { | ||
Mockito.when(attemptHandler.saveStats(Mockito.any())) | ||
.thenReturn(new InternalOperationResult()); | ||
final String path = "/api/v1/attempt/save_stats"; | ||
testEndpointStatus( | ||
HttpRequest.POST(path, Jsons.serialize(new SaveStatsRequestBody())), | ||
HttpStatus.OK); | ||
} | ||
|
||
@Test | ||
void testSetWorkflowInAttempt() { | ||
Mockito.when(attemptHandler.setWorkflowInAttempt(Mockito.any())) | ||
.thenReturn(new InternalOperationResult()); | ||
final String path = "/api/v1/attempt/set_workflow_in_attempt"; | ||
testEndpointStatus( | ||
HttpRequest.POST(path, Jsons.serialize(new SaveStatsRequestBody())), | ||
HttpStatus.OK); | ||
} | ||
|
||
} |
Oops, something went wrong.