Skip to content

Commit

Permalink
feat(exporter-api): allow exporters to throw checked exceptions in co…
Browse files Browse the repository at this point in the history
…nfigure method
  • Loading branch information
menski committed Jun 6, 2019
1 parent a963be7 commit df52c92
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 7 deletions.
11 changes: 11 additions & 0 deletions exporter-api/pom.xml
Expand Up @@ -23,6 +23,17 @@
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Expand Up @@ -40,7 +40,7 @@ public interface Exporter {
*
* @param context the exporter context
*/
default void configure(Context context) {}
default void configure(Context context) throws Exception {}

/**
* Hook to perform any setup for a given exporter. This method is the first method called during
Expand Down
@@ -0,0 +1,46 @@
/*
* Copyright © 2017 camunda services GmbH (info@camunda.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.zeebe.exporter.api.spi;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

import io.zeebe.exporter.api.context.Context;
import io.zeebe.exporter.api.record.Record;
import java.io.IOException;
import org.junit.Test;

public class ExporterTest {

@Test
public void shouldAllowExporterToThrowCheckedExceptions() {
// given
final Exception expectedException = new IOException("catch me");

final Exporter exporter =
new Exporter() {
@Override
public void configure(Context context) throws Exception {
throw expectedException;
}

@Override
public void export(Record record) {}
};

// then
assertThatThrownBy(() -> exporter.configure(null)).isEqualTo(expectedException);
}
}
Expand Up @@ -314,7 +314,11 @@ protected ElasticsearchClient createClient() {

private void openExporter(ElasticsearchExporter exporter) {
testHarness = new ExporterTestHarness(exporter);
testHarness.configure("elasticsearch", config);
try {
testHarness.configure("elasticsearch", config);
} catch (Exception e) {
throw new AssertionError("Failed to configure exporter", e);
}
testHarness.open();
}

Expand Down
Expand Up @@ -62,7 +62,7 @@ public ExporterTestHarness(Exporter exporter) {
*
* @param id the ID of the exporter
*/
public void configure(String id) {
public void configure(String id) throws Exception {
final MockConfiguration<Object> configuration = new MockConfiguration<>();
configuration.setId(id);

Expand Down Expand Up @@ -91,7 +91,7 @@ public void configure(String id) {
* @param id id of the exporter
* @param toml the reference TOML document
*/
public void configure(String id, InputStream toml) {
public void configure(String id, InputStream toml) throws Exception {
final BrokerCfg config = new Toml().read(toml).to(BrokerCfg.class);
configure(id, config);
}
Expand All @@ -103,7 +103,7 @@ public void configure(String id, InputStream toml) {
* @param id the exporter ID
* @param configFile pointer to a TOML configuration file
*/
public void configure(String id, File configFile) {
public void configure(String id, File configFile) throws Exception {
final BrokerCfg config = new Toml().read(configFile).to(BrokerCfg.class);
configure(id, config);
}
Expand All @@ -118,7 +118,7 @@ public void configure(String id, File configFile) {
* @param config new return value of {@link Configuration#instantiate(Class)}
* @param <T> type of the configuration class
*/
public <T> void configure(String id, T config) {
public <T> void configure(String id, T config) throws Exception {
final MockConfiguration<T> configuration = new MockConfiguration<>(config);
configuration.setId(id);

Expand Down Expand Up @@ -261,7 +261,7 @@ public long getLastUpdatedPosition() {
return controller.getPosition();
}

private void configure(String id, BrokerCfg brokerCfg) {
private void configure(String id, BrokerCfg brokerCfg) throws Exception {
final Optional<ExporterCfg> config =
brokerCfg.getExporters().stream().filter(c -> c.getId().equals(id)).findFirst();

Expand Down

0 comments on commit df52c92

Please sign in to comment.