-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
647 additions
and
9 deletions.
There are no files selected for viewing
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
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
54 changes: 54 additions & 0 deletions
54
...rations/base-java/src/main/java/io/airbyte/integrations/base/FailureTrackingConsumer.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,54 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Airbyte | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.airbyte.integrations.base; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public abstract class FailureTrackingConsumer<T> implements DestinationConsumer<T> { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(FailureTrackingConsumer.class); | ||
|
||
private boolean hasFailed = false; | ||
|
||
protected abstract void acceptTracked(T t) throws Exception; | ||
|
||
public void accept(T t) throws Exception { | ||
try { | ||
acceptTracked(t); | ||
} catch (Exception e) { | ||
hasFailed = true; | ||
throw e; | ||
} | ||
} | ||
|
||
protected abstract void close(boolean hasFailed) throws Exception; | ||
|
||
public void close() throws Exception { | ||
LOGGER.info("hasFailed: {}.", hasFailed); | ||
close(hasFailed); | ||
} | ||
|
||
} |
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
71 changes: 71 additions & 0 deletions
71
...ons/base-java/src/test/java/io/airbyte/integrations/base/FailureTrackingConsumerTest.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,71 @@ | ||
/* | ||
* MIT License | ||
* | ||
* Copyright (c) 2020 Airbyte | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package io.airbyte.integrations.base; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.doThrow; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class FailureTrackingConsumerTest { | ||
|
||
@Test | ||
void testNoFailure() throws Exception { | ||
final TestConsumer consumer = spy(new TestConsumer()); | ||
consumer.accept(""); | ||
consumer.close(); | ||
|
||
verify(consumer).close(false); | ||
} | ||
|
||
@Test | ||
void testWithFailure() throws Exception { | ||
final TestConsumer consumer = spy(new TestConsumer()); | ||
doThrow(new RuntimeException()).when(consumer).acceptTracked(""); | ||
|
||
// verify the exception still gets thrown. | ||
assertThrows(RuntimeException.class, () -> consumer.accept("")); | ||
consumer.close(); | ||
|
||
verify(consumer).close(true); | ||
} | ||
|
||
static class TestConsumer extends FailureTrackingConsumer<String> { | ||
|
||
@Override | ||
protected void acceptTracked(String s) { | ||
|
||
} | ||
|
||
@Override | ||
protected void close(boolean hasFailed) { | ||
|
||
} | ||
|
||
} | ||
|
||
} |
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
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,3 @@ | ||
* | ||
!Dockerfile | ||
!build |
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,8 @@ | ||
FROM airbyte/base-java:dev | ||
|
||
WORKDIR /airbyte | ||
ENV APPLICATION csv-destination | ||
|
||
COPY build/distributions/${APPLICATION}*.tar ${APPLICATION}.tar | ||
|
||
RUN tar xf ${APPLICATION}.tar --strip-components=1 |
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,31 @@ | ||
import com.bmuschko.gradle.docker.tasks.image.DockerBuildImage | ||
plugins { | ||
id 'com.bmuschko.docker-remote-api' | ||
id 'application' | ||
} | ||
dependencies { | ||
implementation project(':airbyte-config:models') | ||
implementation project(':airbyte-singer') | ||
implementation project(':airbyte-integrations:base-java') | ||
|
||
implementation 'org.apache.commons:commons-csv:1.4' | ||
} | ||
|
||
application { | ||
mainClass = 'io.airbyte.integrations.destination.csv.CsvDestination' | ||
} | ||
|
||
|
||
def image = 'airbyte/airbyte-csv-destination:dev' | ||
|
||
task imageName { | ||
doLast { | ||
println "IMAGE $image" | ||
} | ||
} | ||
|
||
task buildImage(type: DockerBuildImage) { | ||
inputDir = projectDir | ||
images.add(image) | ||
dependsOn ':airbyte-integrations:base-java:buildImage' | ||
} |
Oops, something went wrong.