-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new configuration parameter
waitForInitialLoad
to the `Breakerb…
…oxConfiguration`. This allows a user to block Dropwizard from starting for a period of time while waiting for initial `Breakerbox` configurations to be fetched. This avoids situations where you could be running with defaults or local configurations where they deviate or differ a lot from whatever `Breakerbox` has. Also, we should be applying `Breakerbox` configurations after local ones.
- Loading branch information
Chris Gray
committed
Aug 7, 2017
1 parent
e02d5c4
commit 0cb8d86
Showing
8 changed files
with
193 additions
and
37 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
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
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
107 changes: 107 additions & 0 deletions
107
...ore/src/test/java/com/yammer/tenacity/tests/ArchaiusPropertyRegisterBlockStartupTest.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,107 @@ | ||
package com.yammer.tenacity.tests; | ||
|
||
import com.github.tomakehurst.wiremock.junit.WireMockRule; | ||
import com.google.common.io.Resources; | ||
import com.google.common.primitives.Ints; | ||
import com.yammer.tenacity.core.bundle.TenacityBundleBuilder; | ||
import com.yammer.tenacity.core.bundle.TenacityBundleConfigurationFactory; | ||
import com.yammer.tenacity.core.config.BreakerboxConfiguration; | ||
import com.yammer.tenacity.core.config.TenacityConfiguration; | ||
import com.yammer.tenacity.core.properties.StringTenacityPropertyKeyFactory; | ||
import com.yammer.tenacity.core.properties.TenacityPropertyKey; | ||
import com.yammer.tenacity.core.properties.TenacityPropertyKeyFactory; | ||
import com.yammer.tenacity.testing.TenacityTestRule; | ||
import io.dropwizard.Application; | ||
import io.dropwizard.Configuration; | ||
import io.dropwizard.setup.Bootstrap; | ||
import io.dropwizard.setup.Environment; | ||
import io.dropwizard.testing.junit.DropwizardAppRule; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotNull; | ||
import java.time.Duration; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ArchaiusPropertyRegisterBlockStartupTest { | ||
@ClassRule | ||
public static final WireMockRule wireMockRule = new WireMockRule(55789); | ||
|
||
@Rule | ||
public TenacityTestRule tenacityTestRule = new TenacityTestRule(); | ||
|
||
@Rule | ||
public final DropwizardAppRule<AppConfiguration> rule = new DropwizardAppRule<>( | ||
App.class, Resources.getResource("waitForInitialLoadApp.yml").getPath()); | ||
|
||
private static class AppConfiguration extends Configuration { | ||
@NotNull @Valid | ||
private BreakerboxConfiguration breakerbox; | ||
|
||
public BreakerboxConfiguration getBreakerbox() { | ||
return breakerbox; | ||
} | ||
} | ||
|
||
public static class App extends Application<AppConfiguration> { | ||
public static void main(String[] args) throws Exception { | ||
new TenacityConfiguredBundleBuilderTest.TenacityBundleApp().run(args); | ||
} | ||
|
||
final CountDownLatch startedLatch = new CountDownLatch(1); | ||
|
||
@Override | ||
public void initialize(Bootstrap<AppConfiguration> bootstrap) { | ||
bootstrap.addBundle(TenacityBundleBuilder | ||
.<AppConfiguration>newBuilder() | ||
.configurationFactory(new TenacityBundleConfigurationFactory<AppConfiguration>() { | ||
@Override | ||
public Map<TenacityPropertyKey, TenacityConfiguration> getTenacityConfigurations(AppConfiguration applicationConfiguration) { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
@Override | ||
public TenacityPropertyKeyFactory getTenacityPropertyKeyFactory(AppConfiguration applicationConfiguration) { | ||
return new StringTenacityPropertyKeyFactory(); | ||
} | ||
|
||
@Override | ||
public BreakerboxConfiguration getBreakerboxConfiguration(AppConfiguration applicationConfiguration) { | ||
return applicationConfiguration.getBreakerbox(); | ||
} | ||
}) | ||
.build()); | ||
} | ||
|
||
@Override | ||
public void run(AppConfiguration configuration, Environment environment) throws Exception { | ||
startedLatch.countDown(); | ||
} | ||
} | ||
|
||
@BeforeClass | ||
public static void init() { | ||
wireMockRule.stubFor(get(urlEqualTo("/archaius/test")) | ||
.willReturn(aResponse() | ||
.withFixedDelay(Ints.checkedCast(Duration.ofSeconds(2).toMillis())) | ||
.withStatus(200))); | ||
} | ||
|
||
|
||
@Test | ||
public void waitingForInitialLoadBlocksDropwizardFromStarting() throws Exception { | ||
assertThat(((App)rule.getApplication()).startedLatch.await(5, TimeUnit.SECONDS)).isTrue(); | ||
|
||
verify(getRequestedFor(urlMatching("/archaius/test"))); | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
tenacity-core/src/test/resources/waitForInitialLoadApp.yml
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,13 @@ | ||
server: | ||
applicationConnectors: | ||
- type: http | ||
port: 0 | ||
adminConnectors: | ||
- type: http | ||
port: 0 | ||
|
||
breakerbox: | ||
urls: http://127.0.0.1:55789/archaius/test | ||
initialDelay: 0s | ||
delay: 60s | ||
waitForInitialLoad: 5s |