-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "gateway" and "exporter" profiles
- Loading branch information
Showing
11 changed files
with
189 additions
and
13 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
16 changes: 16 additions & 0 deletions
16
api/src/main/java/com/github/bsideup/liiklus/config/ExporterProfile.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,16 @@ | ||
package com.github.bsideup.liiklus.config; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Profile(ExporterProfile.PROFILE_NAME) | ||
public @interface ExporterProfile { | ||
|
||
String PROFILE_NAME = "exporter"; | ||
} |
16 changes: 16 additions & 0 deletions
16
api/src/main/java/com/github/bsideup/liiklus/config/GatewayProfile.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,16 @@ | ||
package com.github.bsideup.liiklus.config; | ||
|
||
import org.springframework.context.annotation.Profile; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Profile(GatewayProfile.PROFILE_NAME) | ||
public @interface GatewayProfile { | ||
|
||
String PROFILE_NAME = "gateway"; | ||
} |
13 changes: 12 additions & 1 deletion
13
app/src/main/java/com/github/bsideup/liiklus/Application.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 |
---|---|---|
@@ -1,14 +1,25 @@ | ||
package com.github.bsideup.liiklus; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import lombok.val; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
import java.util.Collections; | ||
|
||
@Slf4j | ||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) throws Exception { | ||
SpringApplication.run(Application.class, args).registerShutdownHook(); | ||
start(args); | ||
} | ||
|
||
public static ConfigurableApplicationContext start(String[] args) { | ||
val application = new SpringApplication(Application.class); | ||
application.setDefaultProperties(Collections.singletonMap("spring.profiles.active", "exporter,gateway")); | ||
|
||
return application.run(args); | ||
} | ||
} |
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
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
94 changes: 94 additions & 0 deletions
94
app/src/test/java/com/github/bsideup/liiklus/ProfilesTest.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,94 @@ | ||
package com.github.bsideup.liiklus; | ||
|
||
import com.github.bsideup.liiklus.test.AbstractIntegrationTest; | ||
import com.google.common.collect.Sets; | ||
import lombok.val; | ||
import org.assertj.core.api.AbstractThrowableAssert; | ||
import org.junit.After; | ||
import org.junit.Test; | ||
import org.springframework.boot.context.properties.bind.validation.BindValidationException; | ||
import org.springframework.context.ConfigurableApplicationContext; | ||
|
||
import java.util.Collection; | ||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
|
||
public class ProfilesTest extends AbstractIntegrationTest { | ||
|
||
static Set<String> KAFKA_PROPERTIES = AbstractIntegrationTest.getKafkaProperties(); | ||
|
||
static Set<String> DYNAMODB_PROPERTIES = AbstractIntegrationTest.getDynamoDBProperties(); | ||
|
||
Set<String> commonArgs = Sets.newHashSet("server.port=0", "grpc.inProcessServerName=liiklus-profile-test"); | ||
|
||
ConfigurableApplicationContext lastApplicationContext; | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
if (lastApplicationContext != null) { | ||
lastApplicationContext.close(); | ||
} | ||
} | ||
|
||
@Test | ||
public void testRequired() throws Exception { | ||
assertThatAppWithProps(commonArgs) | ||
.hasRootCauseInstanceOf(BindValidationException.class); | ||
|
||
assertThatAppWithProps(commonArgs, KAFKA_PROPERTIES) | ||
.hasRootCauseInstanceOf(BindValidationException.class); | ||
|
||
assertThatAppWithProps(commonArgs, DYNAMODB_PROPERTIES) | ||
.hasRootCauseInstanceOf(BindValidationException.class); | ||
|
||
assertThatAppWithProps(commonArgs, KAFKA_PROPERTIES, DYNAMODB_PROPERTIES) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
public void testExporterProfile() throws Exception { | ||
commonArgs.add("spring.profiles.active=exporter"); | ||
|
||
assertThatAppWithProps(commonArgs) | ||
.hasRootCauseInstanceOf(BindValidationException.class); | ||
|
||
assertThatAppWithProps(commonArgs, DYNAMODB_PROPERTIES) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@Test | ||
public void testGatewayProfile() throws Exception { | ||
commonArgs.add("spring.profiles.active=gateway"); | ||
|
||
assertThatAppWithProps(commonArgs) | ||
.hasRootCauseInstanceOf(BindValidationException.class); | ||
|
||
assertThatAppWithProps(commonArgs, KAFKA_PROPERTIES) | ||
.hasRootCauseInstanceOf(BindValidationException.class); | ||
|
||
assertThatAppWithProps(commonArgs, DYNAMODB_PROPERTIES) | ||
.hasRootCauseInstanceOf(BindValidationException.class); | ||
|
||
assertThatAppWithProps(commonArgs, KAFKA_PROPERTIES, DYNAMODB_PROPERTIES) | ||
.doesNotThrowAnyException(); | ||
} | ||
|
||
@SafeVarargs | ||
protected final AbstractThrowableAssert<?, ? extends Throwable> assertThatAppWithProps(Set<String>... props) { | ||
if (lastApplicationContext != null) { | ||
lastApplicationContext.close(); | ||
} | ||
|
||
return assertThatCode(() -> { | ||
val args = Stream.of(props) | ||
.flatMap(Collection::stream) | ||
.map(it -> "--" + it) | ||
.toArray(String[]::new); | ||
|
||
lastApplicationContext = Application.start(args); | ||
}); | ||
} | ||
|
||
} |
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
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